Skip to content

Commit 11ab80d

Browse files
author
Simen Andrè Vikestrand Skogum
committed
feat: add initial GitHub Actions workflow for building and pushing development images
1 parent 0d35ee3 commit 11ab80d

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Build & Push Dev Images
2+
3+
on:
4+
push:
5+
branches: [ dev ]
6+
7+
permissions:
8+
contents: read
9+
packages: write
10+
11+
jobs:
12+
detect:
13+
runs-on: ubuntu-latest
14+
outputs:
15+
matrix: ${{ steps.set.outputs.matrix }}
16+
steps:
17+
- uses: actions/checkout@v4
18+
with: { fetch-depth: 0 }
19+
- id: set
20+
shell: bash
21+
run: |
22+
set -euo pipefail
23+
base="${{ github.event.before }}"
24+
head="${{ github.sha }}"
25+
26+
# Find changed Dockerfiles or VERSION files; build all if first push
27+
if [ -z "$base" ] || [ "$base" = "0000000000000000000000000000000000000000" ]; then
28+
paths="$(git ls-files 'salamicontainers/**/Dockerfile')"
29+
else
30+
paths="$(git diff --name-only "$base" "$head" -- 'salamicontainers/**/Dockerfile' 'salamicontainers/**/VERSION' || true)"
31+
[ -n "$paths" ] || paths="$(git ls-files 'salamicontainers/**/Dockerfile')"
32+
fi
33+
34+
# Collect app dirs that contain a Dockerfile
35+
dirs="$(for p in $paths; do d="$(dirname "$p")"; [ -f "$d/Dockerfile" ] && echo "$d"; done | sort -u)"
36+
37+
includes="[]"
38+
for d in $dirs; do
39+
# Expect: salamicontainers/salami/<app>/<major>/Dockerfile
40+
major="$(basename "$d")"
41+
app="$(basename "$(dirname "$d")")"
42+
ver="$(tr -d '\n\r\t ' < "$d/VERSION")"
43+
image="ghcr.io/${{ github.repository_owner }}/salami-${app}-${major}"
44+
tags="${image}:${ver}-dev,${image}:dev"
45+
includes="$(jq -c --arg dir "$d" --arg img "$image" --arg ver "$ver" --arg tags "$tags" \
46+
'. + [{dir:$dir,image:$img,version:$ver,tags:$tags}]' <<<"$includes")"
47+
done
48+
49+
echo "matrix=$(jq -c '{include: .}' <<<"$includes")" >> "$GITHUB_OUTPUT"
50+
51+
- name: Show matrix
52+
run: echo '${{ steps.set.outputs.matrix }}' | jq .
53+
54+
build-and-push:
55+
needs: detect
56+
if: ${{ needs.detect.outputs.matrix != '' }}
57+
runs-on: ubuntu-latest
58+
strategy:
59+
fail-fast: false
60+
matrix: ${{ fromJson(needs.detect.outputs.matrix) }}
61+
steps:
62+
- uses: actions/checkout@v4
63+
with: { fetch-depth: 0 }
64+
- uses: docker/setup-buildx-action@v3
65+
66+
- name: Login to GHCR
67+
run: echo "${{ github.token }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
68+
69+
- name: Build and push ${{ matrix.image }}
70+
shell: bash
71+
run: |
72+
set -euo pipefail
73+
IFS=, read -r TAG1 TAG2 <<<"${{ matrix.tags }}"
74+
docker buildx build \
75+
--platform linux/amd64,linux/arm64 \
76+
-f "${{ matrix.dir }}/Dockerfile" \
77+
--build-arg APP_VERSION="${{ matrix.version }}" \
78+
-t "$TAG1" -t "$TAG2" \
79+
--push \
80+
"${{ matrix.dir }}"

0 commit comments

Comments
 (0)