55 types : [created]
66
77permissions :
8- contents : write
8+ contents : write # Needed for uploading release assets
9+ packages : write # Needed for pushing packages (Docker images) to GHCR
910
1011jobs :
1112 build :
1213 runs-on : ubuntu-22.04
1314
1415 steps :
1516 # ---------------------------------------------------------------
16- # 1 — Checkout with full history (tags needed for git describe)
17+ # 1 — Checkout with full history (tags needed for git describe)
1718 # ---------------------------------------------------------------
1819 - name : Checkout repository
1920 uses : actions/checkout@v4
2021 with :
2122 fetch-depth : 0
2223
2324 # ---------------------------------------------------------------
24- # 2 — Export build‑time metadata (VERSION, COMMIT, DATE)
25+ # 2 — Export build‑time metadata (VERSION, COMMIT, DATE)
2526 # ---------------------------------------------------------------
2627 - name : Export build metadata
2728 run : |
28- echo "VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo development)" >>"$GITHUB_ENV"
29+ # Use the release tag name directly for VERSION
30+ echo "VERSION=${{ github.event.release.tag_name }}" >>"$GITHUB_ENV"
2931 echo "COMMIT=$(git rev-parse --short HEAD || echo unknown)" >>"$GITHUB_ENV"
3032 echo "DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >>"$GITHUB_ENV"
33+ echo "REPO_LOWER=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_ENV"
3134
3235 # ---------------------------------------------------------------
33- # 3 — Fast Go installer
36+ # 3 — Fast Go installer
3437 # ---------------------------------------------------------------
3538 - name : Setup Go (fast)
3639 uses : WillAbides/setup-go-faster@v1.14.0
3740 with :
38- go-version : ' 1.21.x'
41+ go-version : ' 1.21.x' # Consider updating if needed
3942
4043 # ---------------------------------------------------------------
41- # 4 — Fix mirrors, add arm64 repos, install cross tool‑chain
44+ # 4 — Fix mirrors, add arm64 repos, install cross tool‑chain
4245 # ---------------------------------------------------------------
4346 - name : Configure apt and install cross tool‑chain
4447 run : |
4548 set -euxo pipefail
46-
47- # a) enable the architecture
4849 sudo dpkg --add-architecture arm64
49-
50- # b) swap flaky Azure mirror for canonical one
5150 sudo sed -Ei 's|http://azure\.archive\.ubuntu\.com/ubuntu|http://archive.ubuntu.com/ubuntu|g' /etc/apt/sources.list
52-
53- # c) restrict existing mirrors to amd64 only
5451 sudo sed -Ei 's/^deb /deb [arch=amd64] /' /etc/apt/sources.list
55-
56- # d) add ports.ubuntu.com as the arm64 mirror
5752 sudo tee /etc/apt/sources.list.d/arm64-ports.list > /dev/null <<'EOF'
5853 deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports jammy main restricted universe multiverse
5954 deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports jammy-updates main restricted universe multiverse
6055 deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports jammy-security main restricted universe multiverse
6156 deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports jammy-backports main restricted universe multiverse
6257 EOF
63-
64- # e) refresh indices (retry on transient 404s)
6558 for i in {1..5}; do sudo apt-get update -qq && break || sleep 5; done
66-
67- # f) install cross compiler + headers
6859 for i in {1..5}; do \
6960 sudo apt-get install -y --no-install-recommends \
7061 build-essential \
@@ -74,12 +65,10 @@ jobs:
7465 libpam0g-dev:arm64 \
7566 && break || { sudo apt-get -y --fix-broken install || true; sleep 5; }; \
7667 done
77-
78- # g) sanity check
7968 dpkg -l gcc-aarch64-linux-gnu linux-libc-dev:arm64 libpam0g-dev:arm64
8069
8170 # ---------------------------------------------------------------
82- # 5 — Cache Go modules / build cache
71+ # 5 — Cache Go modules / build cache
8372 # ---------------------------------------------------------------
8473 - name : Cache Go modules
8574 uses : actions/cache@v4
9281 ${{ runner.os }}-go-
9382
9483 # ---------------------------------------------------------------
95- # 6 — Build linux/amd64
84+ # 6 — Build linux/amd64 binary
9685 # ---------------------------------------------------------------
97- - name : Build linux/amd64
86+ - name : Build linux/amd64 binary
9887 run : |
9988 mkdir -p dist
10089 CGO_ENABLED=1 GOOS=linux GOARCH=amd64 \
10594 -o dist/clab-api-server-linux-amd64 ./cmd/server
10695
10796 # ---------------------------------------------------------------
108- # 7 — Build linux/arm64
97+ # 7 — Build linux/arm64 binary
10998 # ---------------------------------------------------------------
110- - name : Build linux/arm64
99+ - name : Build linux/arm64 binary
111100 env :
112101 CC : aarch64-linux-gnu-gcc
113102 PKG_CONFIG_PATH : /usr/lib/aarch64-linux-gnu/pkgconfig
@@ -120,18 +109,65 @@ jobs:
120109 -o dist/clab-api-server-linux-arm64 ./cmd/server
121110
122111 # ---------------------------------------------------------------
123- # 8 — Make binaries executable
112+ # 8 — Make binaries executable (Optional but good practice)
124113 # ---------------------------------------------------------------
125114 - name : Make binaries executable
126115 run : |
127116 chmod +x dist/clab-api-server-linux-*
128117
129118 # ---------------------------------------------------------------
130- # 9 — Upload binaries to the GitHub Release page
119+ # Docker Buildx Setup and Login
120+ # ---------------------------------------------------------------
121+ - name : Set up QEMU
122+ uses : docker/setup-qemu-action@v3
123+
124+ - name : Set up Docker Buildx
125+ uses : docker/setup-buildx-action@v3
126+
127+ - name : Log in to GitHub Container Registry
128+ uses : docker/login-action@v3
129+ with :
130+ registry : ghcr.io
131+ username : ${{ github.actor }}
132+ password : ${{ secrets.GITHUB_TOKEN }}
133+
134+ # ---------------------------------------------------------------
135+ # Extract Docker metadata (tags, labels)
136+ # ---------------------------------------------------------------
137+ - name : Extract Docker metadata for simple-container
138+ id : meta_simple
139+ uses : docker/metadata-action@v5
140+ with :
141+ images : ghcr.io/${{ env.REPO_LOWER }}/clab-api-server # Use lowercase repo name
142+ tags : |
143+ type=schedule
144+ type=ref,event=branch
145+ type=ref,event=pr
146+ type=semver,pattern={{version}} # e.g., v1.2.3
147+ type=semver,pattern={{major}}.{{minor}} # e.g., v1.2
148+ type=sha # Git SHA
149+
150+ # ---------------------------------------------------------------
151+ # Build and push simple-container multi-arch image
152+ # ---------------------------------------------------------------
153+ - name : Build and push simple-container
154+ uses : docker/build-push-action@v5
155+ with :
156+ context : . # Build context is the repo root
157+ file : ./docker/simple-container/Dockerfile # Path to the Dockerfile
158+ platforms : linux/amd64,linux/arm64 # Target platforms
159+ push : true # Push the image to the registry
160+ tags : ${{ steps.meta_simple.outputs.tags }} # Use tags generated by metadata-action
161+ labels : ${{ steps.meta_simple.outputs.labels }} # Use labels generated by metadata-action
162+ cache-from : type=gha # Enable GitHub Actions cache for build layers
163+ cache-to : type=gha,mode=max
164+
165+ # ---------------------------------------------------------------
166+ # 9 — Upload binaries to the GitHub Release page
131167 # ---------------------------------------------------------------
132- - name : Upload Release Assets
168+ - name : Upload Release Assets (Binaries)
133169 uses : softprops/action-gh-release@v1
134170 with :
135171 files : |
136172 dist/clab-api-server-linux-amd64
137- dist/clab-api-server-linux-arm64
173+ dist/clab-api-server-linux-arm64
0 commit comments