Skip to content

Commit

Permalink
Merge pull request #2 from icyflame/build-binary-coredns
Browse files Browse the repository at this point in the history
Build coredns binary for multiple architectures and OS
  • Loading branch information
icyflame authored Jul 13, 2024
2 parents 4f388dc + 9178046 commit 1e6061e
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/build-binary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Build Binary

on:
push:
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' ]

steps:
# 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 next. It is put inside ./plugin/blocker/
- name: Fetch the present repository
uses: actions/checkout@v4
with:
path: './plugin/blocker'
- name: Move plugin.cfg from blocker plugin to the top level (coredns level)
run: |
mv ./plugin/blocker/plugin.cfg ./plugin.cfg
# 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: Build binary of CoreDNS
id: build-binary
run: |
echo "Ref: ${{ github.ref }}; Commit: $GITHUB_SHA"
OUTPUT_FILE_NAME="coredns-${{ matrix.os-flavor }}-${{ matrix.architecture }}"
go generate
GOOS=${{ matrix.os-flavor }} GOARCH=${{ matrix.architecture }} CGO_ENABLED=0 \
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
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<<EOF'
echo $OUTPUT_FILE_NAME.tar.gz
echo EOF
} >> "$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 }}
10 changes: 10 additions & 0 deletions plugin.cfg
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1e6061e

Please sign in to comment.