From 870a66e80e266b6a4d1f1ce3f25a6c68e4489ee2 Mon Sep 17 00:00:00 2001 From: Siddharth Kannan Date: Sat, 13 Jul 2024 12:04:52 +0900 Subject: [PATCH 1/6] Add plugin.cfg with the required plugins --- plugin.cfg | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 plugin.cfg diff --git a/plugin.cfg b/plugin.cfg new file mode 100644 index 00000000..0e770936 --- /dev/null +++ b/plugin.cfg @@ -0,0 +1,10 @@ +# This file defines the order in which plugins are executed for an incoming request. +# The order of plugins in the Corefile is immaterial. +# Reference: https://coredns.io/2017/06/08/how-queries-are-processed-in-coredns/ +# Order of plugin execution is from top to bottom. +metadata:metadata +prometheus:metrics +log:log +any:any +blocker:blocker +forward:forward \ No newline at end of file From 074daebef774fc85f3346e0411d8106599fe6c70 Mon Sep 17 00:00:00 2001 From: Siddharth Kannan Date: Sat, 13 Jul 2024 12:05:01 +0900 Subject: [PATCH 2/6] Build a binary by cloning coredns --- .github/workflows/build-binary.yml | 92 ++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 .github/workflows/build-binary.yml diff --git a/.github/workflows/build-binary.yml b/.github/workflows/build-binary.yml new file mode 100644 index 00000000..470d46f5 --- /dev/null +++ b/.github/workflows/build-binary.yml @@ -0,0 +1,92 @@ +name: Build Binary + +on: + push: + # Enable after development is completed. + # tags: + # - v* + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: write + strategy: + matrix: + go-version: [ '1.22.5' ] + os-flavor: [ 'linux' ] + architecture: [ 'amd64', 'arm', 'arm64' ] + path-to-build: [ './cmd/email-random' ] + + steps: + # You can test your matrix by printing the current Go version + - name: Display Go version + run: go version + # Fetch the coredns repository first + - name: Fetch the coredns repository at a tag + uses: actions/checkout@v4 + with: + repository: 'coredns/coredns' + ref: 'v1.11.1' + # Fetch this repository first + - name: Fetch the present repository + uses: actions/checkout@v4 + with: + path: './plugin/blocker' + - name: Move plugin.cfg to the top level + run: | + ls -lsh plugin.cfg + head plugin.cfg + mv ./plugin/blocker/plugin.cfg ./plugin.cfg + ls -lsh plugin.cfg + head plugin.cfg + - name: Test everything works well + run: | + ls -lsh coredns + ls -lsh coredns/plugin + ls -lsh coredns/plugin/blocker/ + # Caching is enabled by default when using setup-go + - name: Setup Go ${{ matrix.go-version }} + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go-version }} + - name: Generate plugin configuration based things and make binary + run: | + OUTPUT_FILE_NAME="./$(basename ${{ matrix.path-to-build }})-${{ matrix.os-flavor }}-${{ matrix.architecture }}" + go generate + make BINARY=$OUTPUT_FILE_NAME + file ./$OUTPUT_FILE_NAME + # - name: Build binary for the given paths + # id: build-binary + # run: | + # echo "Ref: ${{ github.ref }}; Commit: $GITHUB_SHA" + + # OUTPUT_FILE_NAME="./$(basename ${{ matrix.path-to-build }})-${{ matrix.os-flavor }}-${{ matrix.architecture }}" + + # GOOS=${{ matrix.os-flavor }} GOARCH=${{ matrix.architecture }} \ + # go build \ + # -ldflags="-X \"github.com/icyflame/kindle-my-clippings-parser/internal/env.Version=${{ github.ref }} $GITHUB_SHA\"" \ + # -o $OUTPUT_FILE_NAME ${{ matrix.path-to-build }} + + # sha256sum $OUTPUT_FILE_NAME > $OUTPUT_FILE_NAME.checksum + + # file ./$OUTPUT_FILE_NAME + # file ./$OUTPUT_FILE_NAME.checksum + + # chmod 755 ./$OUTPUT_FILE_NAME + # chmod 644 ./$OUTPUT_FILE_NAME.checksum + + # tar --create --gzip --file ./$OUTPUT_FILE_NAME.tar.gz ./$OUTPUT_FILE_NAME ./$OUTPUT_FILE_NAME.checksum + + # ls -lsh . + + # { + # echo 'OUTPUT_FILES<> "$GITHUB_OUTPUT" + # - name: Upload binaries if a tag was pushed + # uses: softprops/action-gh-release@v2 + # if: startsWith(github.ref, 'refs/tags/') + # with: + # files: ${{ steps.build-binary.outputs.OUTPUT_FILES }} From 554af2a90dca273cad0c982631ffafa381400d6d Mon Sep 17 00:00:00 2001 From: Siddharth Kannan Date: Sat, 13 Jul 2024 12:07:10 +0900 Subject: [PATCH 3/6] Coredns is at $GITHUB_WORKSPACE, not under any other path --- .github/workflows/build-binary.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-binary.yml b/.github/workflows/build-binary.yml index 470d46f5..f33cf3ad 100644 --- a/.github/workflows/build-binary.yml +++ b/.github/workflows/build-binary.yml @@ -42,9 +42,9 @@ jobs: head plugin.cfg - name: Test everything works well run: | - ls -lsh coredns - ls -lsh coredns/plugin - ls -lsh coredns/plugin/blocker/ + ls -lsh . + ls -lsh ./plugin + ls -lsh ./plugin/blocker/ # Caching is enabled by default when using setup-go - name: Setup Go ${{ matrix.go-version }} uses: actions/setup-go@v5 From 8ce510817f07dc255f70efb26a0dc6a7cfbfc4c9 Mon Sep 17 00:00:00 2001 From: Siddharth Kannan Date: Sat, 13 Jul 2024 12:15:38 +0900 Subject: [PATCH 4/6] Build binary using same command as before Add blocker plugin version to version string. --- .github/workflows/build-binary.yml | 59 ++++++++++++++---------------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/.github/workflows/build-binary.yml b/.github/workflows/build-binary.yml index f33cf3ad..c9543870 100644 --- a/.github/workflows/build-binary.yml +++ b/.github/workflows/build-binary.yml @@ -16,7 +16,6 @@ jobs: go-version: [ '1.22.5' ] os-flavor: [ 'linux' ] architecture: [ 'amd64', 'arm', 'arm64' ] - path-to-build: [ './cmd/email-random' ] steps: # You can test your matrix by printing the current Go version @@ -50,43 +49,39 @@ jobs: uses: actions/setup-go@v5 with: go-version: ${{ matrix.go-version }} - - name: Generate plugin configuration based things and make binary + - name: Build binary of CoreDNS + id: build-binary run: | - OUTPUT_FILE_NAME="./$(basename ${{ matrix.path-to-build }})-${{ matrix.os-flavor }}-${{ matrix.architecture }}" - go generate - make BINARY=$OUTPUT_FILE_NAME - file ./$OUTPUT_FILE_NAME - # - name: Build binary for the given paths - # id: build-binary - # run: | - # echo "Ref: ${{ github.ref }}; Commit: $GITHUB_SHA" + echo "Ref: ${{ github.ref }}; Commit: $GITHUB_SHA" - # OUTPUT_FILE_NAME="./$(basename ${{ matrix.path-to-build }})-${{ matrix.os-flavor }}-${{ matrix.architecture }}" + OUTPUT_FILE_NAME="./coredns-${{ matrix.os-flavor }}-${{ matrix.architecture }}" - # GOOS=${{ matrix.os-flavor }} GOARCH=${{ matrix.architecture }} \ - # go build \ - # -ldflags="-X \"github.com/icyflame/kindle-my-clippings-parser/internal/env.Version=${{ github.ref }} $GITHUB_SHA\"" \ - # -o $OUTPUT_FILE_NAME ${{ matrix.path-to-build }} + go generate - # sha256sum $OUTPUT_FILE_NAME > $OUTPUT_FILE_NAME.checksum + GOOS=${{ matrix.os-flavor }} GOARCH=${{ matrix.architecture }} CGO_ENABLED=0 \ + go build -v \ + -ldflags="-s -w -X \"github.com/coredns/coredns/coremain.GitCommit=Blocker plugin ${{ github.ref }} $GITHUB_SHA\"" \ + -o $OUTPUT_FILE_NAME - # file ./$OUTPUT_FILE_NAME - # file ./$OUTPUT_FILE_NAME.checksum + sha256sum $OUTPUT_FILE_NAME > $OUTPUT_FILE_NAME.checksum - # chmod 755 ./$OUTPUT_FILE_NAME - # chmod 644 ./$OUTPUT_FILE_NAME.checksum + file ./$OUTPUT_FILE_NAME + file ./$OUTPUT_FILE_NAME.checksum - # tar --create --gzip --file ./$OUTPUT_FILE_NAME.tar.gz ./$OUTPUT_FILE_NAME ./$OUTPUT_FILE_NAME.checksum + chmod 755 ./$OUTPUT_FILE_NAME + chmod 644 ./$OUTPUT_FILE_NAME.checksum - # ls -lsh . + tar --create --gzip --file ./$OUTPUT_FILE_NAME.tar.gz ./$OUTPUT_FILE_NAME ./$OUTPUT_FILE_NAME.checksum - # { - # echo 'OUTPUT_FILES<> "$GITHUB_OUTPUT" - # - name: Upload binaries if a tag was pushed - # uses: softprops/action-gh-release@v2 - # if: startsWith(github.ref, 'refs/tags/') - # with: - # files: ${{ steps.build-binary.outputs.OUTPUT_FILES }} + ls -lsh . + + { + echo 'OUTPUT_FILES<> "$GITHUB_OUTPUT" + - name: Upload binaries if a tag was pushed + uses: softprops/action-gh-release@v2 + if: startsWith(github.ref, 'refs/tags/') + with: + files: ${{ steps.build-binary.outputs.OUTPUT_FILES }} From 4c3540e52e78f6c767489f153b291ebf1c274ded Mon Sep 17 00:00:00 2001 From: Siddharth Kannan Date: Sat, 13 Jul 2024 12:18:00 +0900 Subject: [PATCH 5/6] Remove unnecessary "./" and clean-up task Confirm version string: $ ./coredns -version CoreDNS-1.11.1 linux/amd64, go1.22.5, Blocker plugin refs/heads/build-binary-coredns 6b1fd5b5868fd71f20499a76369d9643ee317be2 --- .github/workflows/build-binary.yml | 32 ++++++++++-------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/.github/workflows/build-binary.yml b/.github/workflows/build-binary.yml index c9543870..924a8aab 100644 --- a/.github/workflows/build-binary.yml +++ b/.github/workflows/build-binary.yml @@ -18,32 +18,20 @@ jobs: architecture: [ 'amd64', 'arm', 'arm64' ] steps: - # You can test your matrix by printing the current Go version - - name: Display Go version - run: go version - # Fetch the coredns repository first + # Fetch the coredns repository first. This is expanded at ./ - name: Fetch the coredns repository at a tag uses: actions/checkout@v4 with: repository: 'coredns/coredns' ref: 'v1.11.1' - # Fetch this repository first + # Fetch this repository next. It is put inside ./plugin/blocker/ - name: Fetch the present repository uses: actions/checkout@v4 with: path: './plugin/blocker' - - name: Move plugin.cfg to the top level + - name: Move plugin.cfg from blocker plugin to the top level (coredns level) run: | - ls -lsh plugin.cfg - head plugin.cfg mv ./plugin/blocker/plugin.cfg ./plugin.cfg - ls -lsh plugin.cfg - head plugin.cfg - - name: Test everything works well - run: | - ls -lsh . - ls -lsh ./plugin - ls -lsh ./plugin/blocker/ # Caching is enabled by default when using setup-go - name: Setup Go ${{ matrix.go-version }} uses: actions/setup-go@v5 @@ -54,24 +42,24 @@ jobs: run: | echo "Ref: ${{ github.ref }}; Commit: $GITHUB_SHA" - OUTPUT_FILE_NAME="./coredns-${{ matrix.os-flavor }}-${{ matrix.architecture }}" + OUTPUT_FILE_NAME="coredns-${{ matrix.os-flavor }}-${{ matrix.architecture }}" go generate GOOS=${{ matrix.os-flavor }} GOARCH=${{ matrix.architecture }} CGO_ENABLED=0 \ - go build -v \ + go build \ -ldflags="-s -w -X \"github.com/coredns/coredns/coremain.GitCommit=Blocker plugin ${{ github.ref }} $GITHUB_SHA\"" \ -o $OUTPUT_FILE_NAME sha256sum $OUTPUT_FILE_NAME > $OUTPUT_FILE_NAME.checksum - file ./$OUTPUT_FILE_NAME - file ./$OUTPUT_FILE_NAME.checksum + file $OUTPUT_FILE_NAME + file $OUTPUT_FILE_NAME.checksum - chmod 755 ./$OUTPUT_FILE_NAME - chmod 644 ./$OUTPUT_FILE_NAME.checksum + chmod 755 $OUTPUT_FILE_NAME + chmod 644 $OUTPUT_FILE_NAME.checksum - tar --create --gzip --file ./$OUTPUT_FILE_NAME.tar.gz ./$OUTPUT_FILE_NAME ./$OUTPUT_FILE_NAME.checksum + tar --create --gzip --file $OUTPUT_FILE_NAME.tar.gz $OUTPUT_FILE_NAME $OUTPUT_FILE_NAME.checksum ls -lsh . From 9178046fbcccf9602c21b9fa2f996b93ad004c72 Mon Sep 17 00:00:00 2001 From: Siddharth Kannan Date: Sat, 13 Jul 2024 12:21:51 +0900 Subject: [PATCH 6/6] Build binaries only for named tags --- .github/workflows/build-binary.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-binary.yml b/.github/workflows/build-binary.yml index 924a8aab..b50ad8e1 100644 --- a/.github/workflows/build-binary.yml +++ b/.github/workflows/build-binary.yml @@ -2,9 +2,8 @@ name: Build Binary on: push: - # Enable after development is completed. - # tags: - # - v* + tags: + - v* jobs: build: