Skip to content

Commit 5a71ce1

Browse files
committed
ci: add support for target OS and architecture in build configuration
1 parent af6ee3f commit 5a71ce1

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

.github/workflows/build-dev.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ on:
2020
jobs:
2121
build:
2222
runs-on: ubuntu-latest
23+
strategy:
24+
matrix:
25+
os: [ linux ]
26+
arch: [ amd64 ]
2327
steps:
2428
- name: Checkout
2529
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
@@ -59,10 +63,13 @@ jobs:
5963
provenance: false
6064
build-args: |
6165
APP_VERSION=dev-build.${{ steps.vars.outputs.short_sha }}
66+
TARGET_OS=${{ matrix.os }}
67+
TARGET_ARCH=${{ matrix.arch }}
6268
push: false
6369
load: true
6470
tags: ${{ steps.meta.outputs.tags }}
6571
labels: ${{ steps.meta.outputs.labels }}
72+
platforms: ${{ matrix.os }}/${{ matrix.arch }}
6673
cache-from: type=gha
6774
cache-to: type=gha,mode=max
6875

@@ -86,8 +93,11 @@ jobs:
8693
provenance: false
8794
build-args: |
8895
APP_VERSION=dev-build.${{ steps.vars.outputs.short_sha }}
96+
TARGET_OS=${{ matrix.os }}
97+
TARGET_ARCH=${{ matrix.arch }}
8998
push: ${{ github.event_name != 'pull_request' }}
9099
tags: ${{ steps.meta.outputs.tags }}
91100
labels: ${{ steps.meta.outputs.labels }}
101+
platforms: ${{ matrix.os }}/${{ matrix.arch }}
92102
cache-from: type=gha
93103
cache-to: type=gha,mode=max

.github/workflows/build.yaml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ on:
1515
jobs:
1616
build:
1717
runs-on: ubuntu-latest
18+
strategy:
19+
matrix:
20+
os:
21+
- linux
22+
arch:
23+
- amd64
24+
- arm64
1825
steps:
1926
- name: Checkout
2027
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
@@ -50,11 +57,11 @@ jobs:
5057
provenance: false
5158
build-args: |
5259
APP_VERSION=${{ github.ref_name }}
60+
TARGET_OS=${{ matrix.os }}
61+
TARGET_ARCH=${{ matrix.arch }}
5362
push: ${{ startsWith(github.ref, 'refs/tags/') }}
5463
tags: ${{ steps.meta.outputs.tags }}
5564
labels: ${{ steps.meta.outputs.labels }}
56-
platforms: |
57-
linux/amd64
58-
linux/arm64
65+
platforms: ${{ matrix.os }}/${{ matrix.arch }}
5966
cache-from: type=gha
6067
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
FROM golang:1.24.5@sha256:14fd8a55e59a560704e5fc44970b301d00d344e45d6b914dda228e09f359a088 AS build-stage
33

44
ARG APP_VERSION=dev
5+
ARG TARGET_OS=linux
6+
ARG TARGET_ARCH=amd64
57

68
# Set destination for COPY
79
WORKDIR /app
@@ -20,7 +22,8 @@ COPY . ./
2022
# Set build environment
2123
ENV GOCACHE=/root/.cache/go-build \
2224
CGO_ENABLED=0 \
23-
GOOS=linux
25+
GOOS=${TARGET_OS} \
26+
GOARCH=${TARGET_ARCH}
2427

2528
# Build and strip binary
2629
RUN --mount=type=cache,target=/go/pkg/mod/ \

0 commit comments

Comments
 (0)