Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

老师你好, 我是使用的coredns是通过docker安装的, 请问下 coredns_custom_build 考虑支持构建docker镜像吗? #28

Open
fa1seut0pia opened this issue Aug 10, 2024 · 0 comments

Comments

@fa1seut0pia
Copy link

coredns_custom_build 中, 没搜索到docker关键字, 于是过来问问

下边是我的 docker-compose.yaml 文件, 使用的是官方的镜像 coredns/coredns

 services:
   coredns:
     container_name: coredns
     restart: always
     volumes:
       - ./data:/etc/coredns
     ports:
       - 53:53/udp
     image: coredns/coredns
     command: -conf /etc/coredns/Corefile
     environment:
       - TZ=Asia/Shanghai

最近我想让coredns支持ads功能, 在这里找到了
由于其没有构建docker镜像, 我尝试自己构建, 下边是参考脚本

#!/bin/bash

 # Step 1: Fetch the webpage content
 URL="https://coredns.minidump.info/dl/coredns-linux-amd64.zip"
 WEBPAGE=$(curl -s $URL)

 # Step 2: Parse the download URL from the webpage content
 # Assuming the download link is directly provided in the URL
 DOWNLOAD_URL=$(echo "$WEBPAGE" | grep -oP '(?<=href=")[^"]*coredns-linux-amd64.zip')

 # If the DOWNLOAD_URL is relative, prepend the base URL
 if [[ $DOWNLOAD_URL != http* ]]; then
     BASE_URL=$(echo $URL | grep -oP 'https?://[^/]+')
     DOWNLOAD_URL="$BASE_URL/$DOWNLOAD_URL"
 fi

 # Step 3: Download the file using wget or curl
 wget -O coredns-linux-amd64.zip "$DOWNLOAD_URL"
 # or
 # curl -o coredns-linux-amd64.zip "$DOWNLOAD_URL"

 echo "Downloaded to coredns-linux-amd64.zip"

 unzip -d . coredns-linux-amd64.zip
 cd coredns-linux-amd64

 curl -ssLO https://github.com/coredns/coredns/raw/master/Dockerfile

 docker buildx create --use --name coredns-env-builder
 docker buildx build --platform linux/amd64 -t coredns-custom .

因网络环境问题, 后面把脚本移植成workflow放在Actions中执行构建

name: Build and Publish

on:
  workflow_dispatch:

jobs:
  build-and-publish:
    runs-on: ubuntu-latest

    - name: Get CoreDNS download URL
      id: get-url
      run: |
        URL="https://coredns.minidump.info/dl/coredns-linux-amd64.zip"
        WEBPAGE=$(curl -s $URL)
        DOWNLOAD_URL=$(echo "$WEBPAGE" | grep -oP '(?<=href=")[^"]*coredns-linux-amd64.zip')
        echo "::set-output name=download_url::$DOWNLOAD_URL"

    - name: Download CoreDNS binary
      run: |
        curl -s -L -o coredns-linux-amd64.zip "${{ steps.get-url.outputs.download_url }}"

    - name: Unzip CoreDNS binary
      run: |
        unzip -d . coredns-linux-amd64.zip

    - name: Download Dockerfile
      run: |
        curl -s -L -o coredns-linux-amd64/Dockerfile https://github.com/coredns/coredns/raw/master/Dockerfile

    - name: Set up Docker Buildx
      uses: docker/setup-buildx-action@v2
        
    - name: Log in to Docker Hub
      uses: docker/login-action@v2
      with:
        username: ${{ secrets.DOCKER_USERNAME }}
        password: ${{ secrets.DOCKER_PASSWORD }}

    - name: Build and push Docker image
      run: |
        cd coredns-linux-amd64
        docker buildx build --platform linux/amd64 -t ${{ secrets.DOCKER_USERNAME }}/coredns-custom:latest --push .

最终得到 coredns-custom 镜像, 一切正常

希望老师能支持构建Docker镜像,感谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant