Skip to content

Commit 29ae168

Browse files
committed
Build images with matrix
1 parent e8bbe05 commit 29ae168

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

.github/workflows/cd.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ jobs:
1010
permissions:
1111
packages: write
1212
contents: read
13-
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
app_image: [ '', 'ubuntu20.04', 'ubuntu22.04' ]
1417
steps:
1518
- uses: actions/checkout@v3
1619

@@ -29,12 +32,16 @@ jobs:
2932
run: |
3033
VERSION=${GITHUB_REF/refs\/tags\//}
3134
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
35+
# if app_image == '' then '' else '-<app_image>'
36+
IMAGE_TAG_SUFFIX=$([ ${{ matrix.app_image }} == '' ] && echo '' || echo -${{ matrix.app_image }})
37+
echo "IMAGE_TAG_SUFFIX=${IMAGE_TAG_SUFFIX}" >> $GITHUB_OUTPUT
3238
3339
- name: Build and push
3440
id: docker-build
3541
uses: docker/build-push-action@v4
3642
with:
3743
push: true
38-
build-args:
39-
- VERSION=${{ steps.set-version.outputs.VERSION }}
40-
tags: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ steps.set-version.outputs.VERSION }}
44+
build-args: |
45+
VERSION=${{ steps.set-version.outputs.VERSION }}
46+
APP_IMAGE=${{ matrix.app_image }}
47+
tags: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ steps.set-version.outputs.VERSION }}${{ steps.set-version.outputs.IMAGE_TAG_SUFFIX }}

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
ARG APP_IMAGE=ubuntu:latest
2+
13
# Build
24
FROM --platform=$BUILDPLATFORM golang:1.21-alpine AS build
35

@@ -25,7 +27,7 @@ RUN go build -trimpath \
2527
-o file.d ./cmd/file.d
2628

2729
# Deploy
28-
FROM ubuntu:20.04
30+
FROM $APP_IMAGE
2931

3032
RUN apt update
3133
RUN apt install systemd strace tcpdump traceroute telnet iotop curl jq iputils-ping htop -y

0 commit comments

Comments
 (0)