Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: CI

on:
push:
branches:
- main
tags:
- "*"
pull_request:
branches:
- main

jobs:
ci:
runs-on: ubuntu-latest
env:
GIT_SHA: ${{ github.sha }}
GIT_REF: ${{ github.ref }}

steps:
- name: Checkout
uses: actions/checkout@v3

# Run go tests
- name: Run tests
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
run: make test

- name: Docker login
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

# Build or pull image
- name: Build image
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
run: make build-image

- name: Pull image
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
run: make pull-image

# Test the image
- name: Test image
run: make test-image

# Push or promote image
- name: Push image
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
run: |
make push-image

- name: Promote image
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
run: |
make promote-image
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM golang:1.18.10-bullseye as builder

ARG coredns_version=1.10.1
ARG plugin_name=kubenodes
ARG plugin_repo=github.com/infobloxopen/kubenodes

RUN go mod download github.com/coredns/coredns@v${coredns_version}

WORKDIR $GOPATH/pkg/mod/github.com/coredns/coredns@v${coredns_version}
RUN go mod download

RUN sed -i "/kubernetes/i ${plugin_name}:${plugin_repo}" plugin.cfg && \
echo "kubeapi:github.com/coredns/kubeapi" >> plugin.cfg && \
go get ${plugin_repo}

RUN make coredns && \
mv coredns /tmp/coredns

FROM scratch

COPY --from=builder /etc/ssl/certs /etc/ssl/certs
COPY --from=builder /tmp/coredns /coredns

EXPOSE 53 53/udp
ENTRYPOINT ["/coredns"]
29 changes: 29 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
GIT_SHA ?= $(shell echo `git rev-parse --verify HEAD^{commit}`)
GITHUB_REPOSITORY ?= example/kubenodes
IMAGE_NAME ?= ghcr.io/${GITHUB_REPOSITORY}-coredns
TEST_IMAGE = ${IMAGE_NAME}:${GIT_SHA}

default: build-image

test:
go test

build-image:
docker build -t ${TEST_IMAGE} .

push-image:
docker push ${TEST_IMAGE}

pull-image:
docker pull ${TEST_IMAGE}

test-image:
docker run --rm ${TEST_IMAGE} -plugins | grep kubenodes

RELEASE_IMAGE = ${IMAGE_NAME}:$(subst refs/tags/,,${GIT_REF})
promote-image:
ifndef GIT_REF
$(error GIT_REF is not set)
endif
docker tag ${TEST_IMAGE} ${RELEASE_IMAGE}
docker push ${RELEASE_IMAGE}