Skip to content

Commit ec0d710

Browse files
authored
Merge pull request #23 from STRRL/build-image
feat: makefile to build binary and image at local machine
2 parents 9f9e425 + 1f52512 commit ec0d710

File tree

6 files changed

+1217
-53
lines changed

6 files changed

+1217
-53
lines changed

.github/workflows/upload_image.yaml

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,6 @@ on:
77
types: [published]
88

99
jobs:
10-
build-coredns:
11-
strategy:
12-
matrix:
13-
arch: [amd64, arm64]
14-
runs-on: ${{ fromJson('{"amd64":"ubuntu-latest", "arm64":["self-hosted", "Linux", "ARM64"]}')[matrix.arch] }}
15-
16-
container:
17-
image: golang:1.13
18-
19-
steps:
20-
- name: Clone CoreDNS
21-
run: |
22-
apt update -y && apt install git make -y
23-
24-
git clone https://github.com/coredns/coredns.git .
25-
git checkout 7d5f5b87a4fb310d442f7ef0d52e3fead0e10d39
26-
sed -i 's/stable/buster/g' Dockerfile
27-
28-
- uses: actions/checkout@v3
29-
with:
30-
path: 'plugin/k8s_dns_chaos'
31-
32-
- name: Build Chaos CoreDNS
33-
run: |
34-
echo "k8s_dns_chaos:github.com/chaos-mesh/k8s_dns_chaos" >> plugin.cfg
35-
# TODO: replace with the local repo, not stuck with a certain commit
36-
go mod edit -require github.com/chaos-mesh/k8s_dns_chaos@649fd5298a454eb59b6080fd670e7f7ea1f5b1b4
37-
SWAGGER=1 UI=1 make coredns
38-
39-
- name: upload coredns binary
40-
uses: actions/upload-artifact@v2
41-
with:
42-
name: coredns-${{ matrix.arch }}
43-
path: coredns
44-
retention-days: 7
45-
4610
build-docker-image:
4711
strategy:
4812
matrix:
@@ -70,29 +34,12 @@ jobs:
7034
username: ${{ github.actor }}
7135
password: ${{ secrets.GITHUB_TOKEN }}
7236

73-
- name: Clone CoreDNS
74-
run: |
75-
apt update -y && apt install git make -y
76-
77-
git clone https://github.com/coredns/coredns.git .
78-
git checkout 7d5f5b87a4fb310d442f7ef0d52e3fead0e10d39
79-
sed -i 's/stable/buster/g' Dockerfile
80-
81-
- name: Download coredns binary
82-
uses: actions/download-artifact@v2
83-
with:
84-
name: coredns-${{ matrix.arch }}
85-
path: coredns-artifacts
86-
8737
- name: Build Chaos CoreDNS Image
8838
env:
8939
IMAGE_TAG: ${{ steps.image_tag.outputs.image_tag }}
9040
ARCH: ${{ matrix.arch }}
9141
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
9242
run: |
93-
# permissions would be lost after transfer by github artifacts, see: https://github.com/chaos-mesh/k8s_dns_chaos/issues/20
94-
chmod +x coredns-artifacts/coredns
95-
mv coredns-artifacts/coredns coredns
9643
docker build -t ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chaos-coredns:$IMAGE_TAG-$ARCH .
9744
9845
- name: Upload Chaos CoreDNS

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313

1414
# Dependency directories (remove the comment below to include it)
1515
# vendor/
16+
17+
# binary artifact
18+
coredns

Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# syntax=docker/dockerfile:experimental
2+
3+
FROM golang:1.19 AS build-env
4+
ENV GO111MODULE on
5+
WORKDIR /
6+
RUN git clone --depth 1 --branch v1.7.0 https://github.com/coredns/coredns
7+
COPY . /k8s_dns_chaos
8+
RUN ln -s /k8s_dns_chaos /coredns/plugin/k8s_dns_chaos
9+
RUN echo "k8s_dns_chaos:k8s_dns_chaos" >> plugin.cfg
10+
RUN cd coredns && make
11+
12+
FROM debian:stable-slim AS certs
13+
RUN apt-get update && apt-get -uy upgrade
14+
RUN apt-get -y install ca-certificates && update-ca-certificates
15+
16+
FROM scratch
17+
LABEL org.opencontainers.image.source=https://github.com/chaos-mesh/k8s_dns_chaos
18+
COPY --from=certs /etc/ssl/certs /etc/ssl/certs
19+
COPY --from=build-env /coredns/coredns /coredns
20+
EXPOSE 53 53/udp
21+
ENTRYPOINT ["/coredns"]

Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.DEFAULT_GOAL:=help
2+
3+
.PHONY: image
4+
image: ## Build the latest container image
5+
DOCKER_BUILDKIT=1 docker build -t ghcr.io/chaos-mesh/chaos-coredns:latest .
6+
7+
.PHONY: coredns
8+
coredns: image ## Build the coredns executable binary
9+
docker container create --name extract-coredns ghcr.io/chaos-mesh/chaos-coredns:latest
10+
docker container cp extract-coredns:/coredns ./coredns
11+
docker container rm -f extract-coredns
12+
13+
# The help will print out all targets with their descriptions organized bellow their categories. The categories are represented by `##@` and the target descriptions by `##`.
14+
# The awk commands is responsible to read the entire set of makefiles included in this invocation, looking for lines of the file as xyz: ## something, and then pretty-format the target and help. Then, if there's a line with ##@ something, that gets pretty-printed as a category.
15+
# More info over the usage of ANSI control characters for terminal formatting: https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
16+
# More info over awk command: http://linuxcommand.org/lc3_adv_awk.php
17+
.PHONY: help
18+
help: ## Display this help
19+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

go.mod

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
module github.com/chaos-mesh/k8s_dns_chaos
2+
3+
go 1.19
4+
5+
require (
6+
github.com/caddyserver/caddy v1.0.5
7+
github.com/coredns/coredns v1.7.0
8+
github.com/golang/protobuf v1.5.2
9+
github.com/miekg/dns v1.1.43
10+
github.com/pingcap/tidb-tools v6.3.0+incompatible
11+
github.com/prometheus/client_golang v1.11.0
12+
golang.org/x/net v0.0.0-20210614182718-04defd469f4e
13+
google.golang.org/grpc v1.41.0
14+
k8s.io/api v0.22.2
15+
k8s.io/apimachinery v0.22.2
16+
k8s.io/client-go v0.22.2
17+
k8s.io/klog v1.0.0
18+
)
19+
20+
require (
21+
cloud.google.com/go v0.94.1 // indirect
22+
github.com/beorn7/perks v1.0.1 // indirect
23+
github.com/cespare/xxhash/v2 v2.1.1 // indirect
24+
github.com/davecgh/go-spew v1.1.1 // indirect
25+
github.com/evanphx/json-patch v4.11.0+incompatible // indirect
26+
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 // indirect
27+
github.com/go-logr/logr v1.0.0 // indirect
28+
github.com/gogo/protobuf v1.3.2 // indirect
29+
github.com/google/go-cmp v0.5.6 // indirect
30+
github.com/google/gofuzz v1.2.0 // indirect
31+
github.com/google/uuid v1.1.2 // indirect
32+
github.com/googleapis/gax-go/v2 v2.1.1 // indirect
33+
github.com/googleapis/gnostic v0.5.5 // indirect
34+
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 // indirect
35+
github.com/imdario/mergo v0.3.12 // indirect
36+
github.com/json-iterator/go v1.1.11 // indirect
37+
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
38+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
39+
github.com/modern-go/reflect2 v1.0.1 // indirect
40+
github.com/opentracing/opentracing-go v1.2.0 // indirect
41+
github.com/pingcap/check v0.0.0-20211026125417-57bd13f7b5f0 // indirect
42+
github.com/pingcap/errors v0.11.4 // indirect
43+
github.com/pkg/errors v0.9.1 // indirect
44+
github.com/prometheus/client_model v0.2.0 // indirect
45+
github.com/prometheus/common v0.31.1 // indirect
46+
github.com/prometheus/procfs v0.6.0 // indirect
47+
github.com/spf13/pflag v1.0.5 // indirect
48+
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
49+
golang.org/x/sys v0.0.0-20210917161153-d61c044b1678 // indirect
50+
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect
51+
golang.org/x/text v0.3.6 // indirect
52+
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
53+
google.golang.org/api v0.58.0 // indirect
54+
google.golang.org/appengine v1.6.7 // indirect
55+
google.golang.org/genproto v0.0.0-20210917145530-b395a37504d4 // indirect
56+
google.golang.org/protobuf v1.27.1 // indirect
57+
gopkg.in/inf.v0 v0.9.1 // indirect
58+
gopkg.in/yaml.v2 v2.4.0 // indirect
59+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
60+
k8s.io/klog/v2 v2.20.0 // indirect
61+
k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e // indirect
62+
k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a // indirect
63+
sigs.k8s.io/structured-merge-diff/v4 v4.1.2 // indirect
64+
sigs.k8s.io/yaml v1.2.0 // indirect
65+
)

0 commit comments

Comments
 (0)