Skip to content

Commit 284894f

Browse files
authored
Add multi-arch Docker build & GHCR publishing (#1278)
# Summary This PR addresses failures to run Yggdrasil on ARM systems. The root cause was the lack of ARM artifacts/images, which led to exec format error and similar issues. ## What’s added: - ```Dockerfile.multiarch``` — multi-stage Go build that correctly propagates GOOS/GOARCH for linux/amd64, linux/arm64, linux/armhf and linux/armel platform. - ```entrypoint.sh``` - Introduced ENV **ALLOW_IPV6_FORWARDING**. When set to a truthy value (e.g., true), the entrypoint executes: ```sysctl -w net.ipv6.conf.all.forwarding=1```. - GitHub Action for multi-arch builds and publishing to GHCR — triggered via ```workflow_dispatch```, push to ```master``` and release via tags (with docker semantic tags e.g. v0.5.12 → 0.5.12, 0.5, 0). Example published images: [https://github.com/Forne/yggdrasil-go/pkgs/container/yggdrasil-go](https://github.com/Forne/yggdrasil-go/pkgs/container/yggdrasil-go) ## Testing ✅ Ubuntu (24.04, amd64) — image runs correctly. ✅ macOS (Apple Silicon, arm64) — image runs correctly. ✅ MikroTik RouterOS (arm64) — image runs under the RouterOS container package.
1 parent 89a3718 commit 284894f

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

.github/workflows/docker.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Docker Build
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [ main, master ]
7+
tags: [ 'v*' ]
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
permissions:
14+
contents: read
15+
packages: write
16+
17+
env:
18+
REGISTRY: ghcr.io
19+
IMAGE_NAME: ${{ github.repository }}
20+
21+
jobs:
22+
build-docker:
23+
name: Build Docker Package
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v5
27+
with:
28+
fetch-depth: 0
29+
30+
- name: Set up Docker Buildx
31+
uses: docker/setup-buildx-action@v3
32+
33+
- name: Login to GitHub Container Registry
34+
uses: docker/login-action@v3
35+
with:
36+
registry: ${{ env.REGISTRY }}
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: Docker metadata
41+
id: meta
42+
uses: docker/metadata-action@v5
43+
with:
44+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
45+
tags: |
46+
type=ref,event=tag
47+
type=semver,pattern={{version}}
48+
type=semver,pattern={{major}}.{{minor}}
49+
type=semver,pattern={{major}}
50+
type=sha
51+
52+
- name: Build and push
53+
uses: docker/build-push-action@v6
54+
id: docker_build
55+
with:
56+
context: .
57+
file: ./contrib/docker/Dockerfile.multiarch
58+
platforms: linux/amd64,linux/arm64,linux/armhf,linux/armel
59+
push: true
60+
tags: ${{ steps.meta.outputs.tags }}
61+
labels: ${{ steps.meta.outputs.labels }}
62+
provenance: false
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# syntax=docker/dockerfile:1
2+
FROM --platform=$BUILDPLATFORM docker.io/golang:alpine as builder
3+
4+
COPY . /src
5+
WORKDIR /src
6+
7+
ARG TARGETOS
8+
ARG TARGETARCH
9+
ENV CGO_ENABLED=0
10+
ENV GOOS=${TARGETOS} GOARCH=${TARGETARCH}
11+
12+
RUN apk add git && ./build && go build -o /src/genkeys cmd/genkeys/main.go
13+
14+
FROM docker.io/alpine
15+
16+
COPY --from=builder /src/yggdrasil /usr/bin/yggdrasil
17+
COPY --from=builder /src/yggdrasilctl /usr/bin/yggdrasilctl
18+
COPY --from=builder /src/genkeys /usr/bin/genkeys
19+
COPY contrib/docker/entrypoint.sh /usr/bin/entrypoint.sh
20+
21+
# RUN addgroup -g 1000 -S yggdrasil-network \
22+
# && adduser -u 1000 -S -g 1000 --home /etc/yggdrasil-network yggdrasil-network
23+
#
24+
# USER yggdrasil-network
25+
# TODO: Make running unprivileged work
26+
27+
VOLUME [ "/etc/yggdrasil-network" ]
28+
29+
ENTRYPOINT [ "/usr/bin/entrypoint.sh" ]

contrib/docker/entrypoint.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@ if [ ! -f "$CONF_DIR/config.conf" ]; then
99
yggdrasil --genconf > "$CONF_DIR/config.conf"
1010
fi
1111

12+
if [ -n "$ALLOW_IPV6_FORWARDING" ]; then
13+
echo "set sysctl -w net.ipv6.conf.all.forwarding=1"
14+
sysctl -w net.ipv6.conf.all.forwarding=1
15+
fi
16+
1217
yggdrasil --useconf < "$CONF_DIR/config.conf"
1318
exit $?

0 commit comments

Comments
 (0)