Skip to content

Commit 4145090

Browse files
authored
[Enhancement] GitHub Actions (#977)
Move from DroneCI + VMs for platform builds + DockerHub to Github Actions + buildx + ghcr
1 parent a3413dd commit 4145090

File tree

8 files changed

+358
-464
lines changed

8 files changed

+358
-464
lines changed

.drone.yml

-431
This file was deleted.

.github/workflows/release.yaml

+169-9
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,187 @@
1-
name: Release
1+
name: Test & Release
22

3-
on: workflow_dispatch
3+
on:
4+
- push
5+
- workflow_dispatch
6+
7+
env:
8+
IMAGE_REGISTRY: ghcr.io
9+
IMAGE_BASE_REPO: k3d-io
10+
IMAGE_PLATFORMS: linux/amd64,linux/arm64,linux/arm/v7
11+
GO_VERSION: "1.17.x"
12+
DOCKER_VERSION: "20.10"
413

514
jobs:
6-
release:
15+
test-suite:
16+
name: Full Test Suite
717
runs-on: ubuntu-20.04
818
steps:
19+
# Setup
920
- uses: actions/checkout@v2
1021
- name: Setup Go environment
1122
uses: actions/setup-go@v2
1223
with:
13-
go-version: "1.17.x"
24+
go-version: "${{ env.GO_VERSION }}"
1425
- name: Setup Docker
1526
uses: docker-practice/actions-setup-docker@master
1627
with:
17-
docker_version: "20.10"
28+
docker_version: "${{ env.DOCKER_VERSION }}"
1829
- name: Setup CI Tools
1930
run: make ci-setup
20-
- name: lint
31+
# Code Check
32+
- name: Run Static Analysis
2133
run: make lint
22-
- name: test
34+
# Tests
35+
- name: Run Go Tests
2336
run: make test
24-
- name: e2e
37+
- name: Run E2E Tests
38+
timeout-minutes: 20
2539
run: make e2e
26-
- name: build
40+
# Builds
41+
- name: Test Platform Builds
42+
run: make build-cross
43+
- name: Test Helper Image Builds
44+
run: make build-helper-images
45+
46+
release:
47+
name: Build & Release
48+
# Only run on tags
49+
runs-on: ubuntu-20.04
50+
steps:
51+
# Setup
52+
- uses: actions/checkout@v2
53+
- name: Setup Go environment
54+
uses: actions/setup-go@v2
55+
with:
56+
go-version: "${{ env.GO_VERSION }}"
57+
- name: Setup CI Tools
58+
run: make ci-setup
59+
# Go Build
60+
- name: Build k3d Binary
2761
run: make build-cross
62+
# Container Image Setup
63+
- name: Setup Docker
64+
uses: docker-practice/actions-setup-docker@master
65+
with:
66+
docker_version: "${{ env.DOCKER_VERSION }}"
67+
- name: Log in to the Container registry
68+
uses: docker/login-action@v1
69+
with:
70+
registry: ${{ env.IMAGE_REGISTRY }}
71+
username: ${{ github.actor }}
72+
password: ${{ secrets.GITHUB_TOKEN }}
73+
- name: Set up QEMU
74+
uses: docker/setup-qemu-action@v1
75+
- name: Set up Docker Buildx
76+
uses: docker/setup-buildx-action@v1
77+
# Gather Docker Metadata
78+
- name: Docker Metadata k3d-binary
79+
id: meta-k3d-binary
80+
env:
81+
IMAGE_ID: k3d
82+
uses: docker/metadata-action@v3
83+
with:
84+
images: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_BASE_REPO }}/${{ env.IMAGE_ID }}
85+
github-token: ${{ secrets.GITHUB_TOKEN }}
86+
bake-target: docker-metadata-${{ env.IMAGE_ID }}
87+
tags: |
88+
type=semver,pattern={{major}}
89+
type=semver,pattern={{major}}.{{minor}}
90+
type=semver,pattern={{version}}
91+
type=ref,event=branch
92+
type=ref,event=pr
93+
type=sha
94+
- name: Docker Metadata k3d-dind
95+
id: meta-k3d-dind
96+
env:
97+
IMAGE_ID: k3d
98+
IMAGE_SUFFIX: "-dind"
99+
uses: docker/metadata-action@v3
100+
with:
101+
images: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_BASE_REPO }}/${{ env.IMAGE_ID }}
102+
github-token: ${{ secrets.GITHUB_TOKEN }}
103+
bake-target: docker-metadata-${{ env.IMAGE_ID }}${{ env.IMAGE_SUFFIX }}
104+
tags: |
105+
type=semver,pattern={{major}}
106+
type=semver,pattern={{major}}.{{minor}}
107+
type=semver,pattern={{version}}
108+
type=ref,event=branch
109+
type=ref,event=pr
110+
type=sha
111+
flavor: |
112+
suffix=${{ env.IMAGE_SUFFIX }}
113+
- name: Docker Metadata k3d-proxy
114+
id: meta-k3d-proxy
115+
env:
116+
IMAGE_ID: k3d-proxy
117+
uses: docker/metadata-action@v3
118+
with:
119+
images: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_BASE_REPO }}/${{ env.IMAGE_ID }}
120+
github-token: ${{ secrets.GITHUB_TOKEN }}
121+
bake-target: docker-metadata-${{ env.IMAGE_ID }}
122+
tags: |
123+
type=semver,pattern={{major}}
124+
type=semver,pattern={{major}}.{{minor}}
125+
type=semver,pattern={{version}}
126+
type=ref,event=branch
127+
type=ref,event=pr
128+
type=sha
129+
- name: Docker Metadata k3d-tools
130+
id: meta-k3d-tools
131+
env:
132+
IMAGE_ID: k3d-tools
133+
uses: docker/metadata-action@v3
134+
with:
135+
images: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_BASE_REPO }}/${{ env.IMAGE_ID }}
136+
github-token: ${{ secrets.GITHUB_TOKEN }}
137+
bake-target: docker-metadata-${{ env.IMAGE_ID }}
138+
tags: |
139+
type=semver,pattern={{major}}
140+
type=semver,pattern={{major}}.{{minor}}
141+
type=semver,pattern={{version}}
142+
type=ref,event=branch
143+
type=ref,event=pr
144+
type=sha
145+
- name: Merge Metadata Bake Definitions
146+
run: |
147+
INPUT=(${{ steps.meta-k3d-binary.outputs.bake-file }} ${{ steps.meta-k3d-dind.outputs.bake-file }} ${{ steps.meta-k3d-proxy.outputs.bake-file }} ${{ steps.meta-k3d-tools.outputs.bake-file }})
148+
OUT_FILE=./bake-metadata.json
149+
OUT_FILE_TMP=./bake-metadata-tmp.json
150+
151+
cat << EOF > $OUT_FILE
152+
{
153+
"target": {}
154+
}
155+
EOF
156+
157+
for file in "${INPUT[@]}"; do
158+
cat $OUT_FILE > $OUT_FILE_TMP
159+
jq -s '.[0] * .[1]' $OUT_FILE_TMP $file > $OUT_FILE
160+
done
161+
162+
rm "$OUT_FILE_TMP"
163+
# Build and Push container images
164+
- name: Build Images
165+
uses: docker/[email protected]
166+
with:
167+
files: |
168+
./docker-bake.hcl
169+
./bake-metadata.json
170+
targets: release
171+
push: false
172+
- name: Wait for tests to succeed
173+
uses: lewagon/[email protected]
174+
with:
175+
ref: ${{ github.ref }}
176+
check-name: "Full Test Suite"
177+
repo-token: ${{ secrets.GITHUB_TOKEN }}
178+
wait-interval: 20
179+
- name: Push Images
180+
if: startsWith(github.ref, 'refs/tags/')
181+
uses: docker/[email protected]
182+
with:
183+
files: |
184+
./docker-bake.hcl
185+
./bake-metadata.json
186+
targets: release
187+
push: true

Dockerfile

+11-10
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,23 @@ RUN make build -e GIT_TAG_OVERRIDE=${GIT_TAG_OVERRIDE} && bin/k3d version
1616
# -> used e.g. in our CI pipelines for testing #
1717
#######################################################
1818
FROM docker:$DOCKER_VERSION-dind as dind
19-
ARG OS=linux
20-
ARG ARCH=amd64
19+
ARG OS
20+
ARG ARCH
21+
22+
ENV OS=${OS}
23+
ENV ARCH=${ARCH}
24+
25+
# Helper script to install some tooling
26+
COPY scripts/install-tools.sh /scripts/install-tools.sh
2127

2228
# install some basic packages needed for testing, etc.
23-
RUN docker version; \
24-
echo ">>> building for ${OS}/${ARCH}" && \
25-
apk update && \
29+
RUN apk update && \
2630
apk add bash curl sudo jq git make netcat-openbsd
2731

2832
# install kubectl to interact with the k3d cluster
29-
RUN curl -L https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/${OS}/${ARCH}/kubectl -o /usr/local/bin/kubectl && \
30-
chmod +x /usr/local/bin/kubectl
31-
3233
# install yq (yaml processor) from source, as the busybox yq had some issues
33-
RUN curl -L https://github.com/mikefarah/yq/releases/download/v4.9.6/yq_${OS}_${ARCH} -o /usr/bin/yq &&\
34-
chmod +x /usr/bin/yq
34+
RUN /scripts/install-tools.sh kubectl yq
35+
3536
COPY --from=builder /app/bin/k3d /bin/k3d
3637

3738
#########################################

Makefile

+3-5
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ endif
3030
K3D_IMAGE_TAG := $(GIT_TAG:v%=%)
3131

3232
# get latest k3s version: grep the tag and replace + with - (difference between git and dockerhub tags)
33-
K3S_TAG := $(shell curl --silent "https://update.k3s.io/v1-release/channels/stable" | egrep -o '/v[^ ]+"' | sed -E 's/\/|\"//g' | sed -E 's/\+/\-/')
33+
K3S_TAG := $(shell curl --silent --retry 3 "https://update.k3s.io/v1-release/channels/stable" | egrep -o '/v[^ ]+"' | sed -E 's/\/|\"//g' | sed -E 's/\+/\-/')
3434

3535
ifeq ($(K3S_TAG),)
3636
$(warning K3S_TAG undefined: couldn't get latest k3s image tag!)
37-
$(warning Output of curl: $(shell curl --silent "https://update.k3s.io/v1-release/channels/stable"))
37+
$(warning Output of curl: $(shell curl "https://update.k3s.io/v1-release/channels/stable"))
3838
$(error exiting)
3939
endif
4040

@@ -228,6 +228,4 @@ ci-setup:
228228
$(GO) get $(PKG_GOX)
229229

230230
@echo "Installing kubectl..."
231-
curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
232-
chmod +x ./kubectl
233-
mv ./kubectl /usr/local/bin/kubectl
231+
./scripts/install-tools.sh kubectl

docker-bake.hcl

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// release group
2+
group "release" {
3+
targets = ["binary", "dind", "proxy", "tools"]
4+
}
5+
6+
// filled by GitHub Actions
7+
target "docker-metadata-k3d" {}
8+
target "docker-metadata-k3d-dind" {}
9+
target "docker-metadata-k3d-proxy" {}
10+
target "docker-metadata-k3d-tools" {}
11+
12+
// default options for creating a release
13+
target "default-release-options" {
14+
platforms = ["linux/amd64", "linux/arm64", "linux/arm/v7"]
15+
}
16+
17+
target "binary" {
18+
inherits = ["default-release-options", "docker-metadata-k3d"]
19+
dockerfile = "Dockerfile"
20+
context = "."
21+
target = "binary-only"
22+
}
23+
24+
target "dind" {
25+
inherits = ["docker-metadata-k3d-dind"] // dind does not inherit defaults, as dind base image is not available for armv7
26+
platforms = ["linux/amd64", "linux/arm64"]
27+
dockerfile = "Dockerfile"
28+
context = "."
29+
target = "dind"
30+
}
31+
32+
target "proxy" {
33+
inherits = ["default-release-options", "docker-metadata-k3d-proxy"]
34+
context = "proxy/"
35+
}
36+
37+
target "tools" {
38+
inherits = ["default-release-options", "docker-metadata-k3d-tools"]
39+
context = "tools/"
40+
}

proxy/Dockerfile

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
FROM nginx:1.19-alpine
22
# TODO:_ consider switching to https://github.com/abtreece/confd to not maintain a custom fork anymore
3-
ARG CONFD_REPO=iwilltry42/confd
4-
ARG CONFD_VERSION=0.17.0-rc.0
5-
ARG OS=linux
6-
ARG ARCH=amd64
7-
RUN echo "Building for '${OS}/${ARCH}'..." \
8-
&& mkdir -p /etc/confd \
9-
&& wget "https://github.com/${CONFD_REPO}/releases/download/v${CONFD_VERSION}/confd-${CONFD_VERSION}-${OS}-${ARCH}" -O /usr/bin/confd \
10-
&& chmod +x /usr/bin/confd
3+
4+
ARG OS
5+
ARG ARCH
6+
7+
ENV OS=${OS}
8+
ENV ARCH=${ARCH}
9+
COPY install-confd.sh /scripts/install-confd.sh
10+
RUN mkdir -p /etc/confd \
11+
&& /scripts/install-confd.sh
1112

1213
COPY templates /etc/confd/templates/
1314
COPY conf.d /etc/confd/conf.d/
1415
COPY nginx-proxy /usr/bin/
1516

16-
ENTRYPOINT nginx-proxy
17+
ENTRYPOINT nginx-proxy

proxy/install-confd.sh

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/sh
2+
3+
# initArch discovers the architecture for this system.
4+
initArch() {
5+
if [ -z $ARCH ]; then
6+
ARCH=$(uname -m)
7+
case $ARCH in
8+
armv5*) ARCH="armv5";;
9+
armv6*) ARCH="armv6";;
10+
armv7*) ARCH="arm";;
11+
aarch64) ARCH="arm64";;
12+
x86) ARCH="386";;
13+
x86_64) ARCH="amd64";;
14+
i686) ARCH="386";;
15+
i386) ARCH="386";;
16+
esac
17+
fi
18+
}
19+
20+
# initOS discovers the operating system for this system.
21+
initOS() {
22+
if [ -z $OS ]; then
23+
OS=$(uname|tr '[:upper:]' '[:lower:]')
24+
25+
case "$OS" in
26+
# Minimalist GNU for Windows
27+
mingw*) OS='windows';;
28+
esac
29+
fi
30+
}
31+
32+
33+
install_confd() {
34+
echo "Installing confd for $OS/$ARCH..."
35+
CONFD_REPO=iwilltry42/confd
36+
CONFD_VERSION=0.17.0-rc.0
37+
curl -sSfL "https://github.com/${CONFD_REPO}/releases/download/v${CONFD_VERSION}/confd-${CONFD_VERSION}-${OS}-${ARCH}" -o ./confd
38+
chmod +x ./confd
39+
mv ./confd /usr/local/bin/confd
40+
}
41+
42+
43+
#
44+
# MAIN
45+
#
46+
47+
initOS
48+
initArch
49+
install_confd

0 commit comments

Comments
 (0)