Skip to content

Commit e4ff182

Browse files
authored
Merge pull request #35 from clickviewapp/github-action
Add github action to publish docker images
2 parents b4f07f6 + 0ceb324 commit e4ff182

2 files changed

Lines changed: 94 additions & 0 deletions

File tree

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Build & Publish Docker Images
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
workflow_dispatch:
8+
inputs:
9+
dry_run:
10+
description: 'Build images only, do not push'
11+
required: false
12+
default: 'true'
13+
14+
jobs:
15+
discover-dockerfiles:
16+
runs-on: ubuntu-latest
17+
outputs:
18+
dockerfiles: ${{ steps.extract.outputs.dockerfiles }}
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
23+
- name: Generate matrix from manifest.yaml
24+
id: extract
25+
run: |
26+
files=()
27+
roots=$(yq e -r 'keys | .[]' manifest.yaml)
28+
for root in $roots; do
29+
while read -r version; do
30+
dockerfile="./${root}/${version}/Dockerfile"
31+
# Read image_name including tag
32+
image_name=$(yq e -r ".${root}.versions.\"${version}\".image_name" manifest.yaml)
33+
if [ -n "$image_name" ] && [ "$image_name" != "null" ]; then
34+
files+=("$dockerfile|$image_name")
35+
fi
36+
done < <(yq e -r ".${root}.versions | keys | .[]" manifest.yaml)
37+
done
38+
39+
# Convert array to compact JSON for GitHub Actions matrix
40+
json=$(printf '%s\n' "${files[@]}" | jq -R -c . | jq -c -s .)
41+
echo "dockerfiles=$json" >> $GITHUB_OUTPUT
42+
43+
build-and-push:
44+
needs: discover-dockerfiles
45+
runs-on: ubuntu-latest
46+
strategy:
47+
matrix:
48+
entry: ${{ fromJson(needs.discover-dockerfiles.outputs.dockerfiles) }}
49+
50+
env:
51+
DRY_RUN: ${{ github.event.inputs.dry_run }}
52+
53+
steps:
54+
- name: Checkout repository
55+
uses: actions/checkout@v4
56+
57+
- name: Set up Docker Buildx
58+
uses: docker/setup-buildx-action@v3
59+
60+
- name: Log in to Docker Hub
61+
if: ${{ env.DRY_RUN != 'true' }}
62+
uses: docker/login-action@v3
63+
with:
64+
username: ${{ secrets.DOCKERHUB_USERNAME }}
65+
password: ${{ secrets.DOCKERHUB_TOKEN }}
66+
67+
- name: Parse Dockerfile and image
68+
id: metadata
69+
run: |
70+
dockerfile="${{ matrix.entry }}"
71+
dockerfile="${dockerfile%%|*}"
72+
image="${{ matrix.entry }}"
73+
image="${image##*|}" # Already includes tag from manifest
74+
dir=$(dirname "$dockerfile")
75+
short_sha="${GITHUB_SHA:0:7}"
76+
77+
echo "directory=$dir" >> $GITHUB_OUTPUT
78+
echo "image=$image" >> $GITHUB_OUTPUT
79+
echo "short_sha=$short_sha" >> $GITHUB_OUTPUT
80+
81+
- name: Build and push image
82+
uses: docker/build-push-action@v6
83+
with:
84+
context: ${{ steps.metadata.outputs.directory }}
85+
file: ${{ steps.metadata.outputs.directory }}/Dockerfile
86+
push: ${{ env.DRY_RUN != 'true' }}
87+
tags: |
88+
${{ steps.metadata.outputs.image }}

manifest.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
dotnet:
22
versions:
33
'8.0/aspnet':
4+
image_name: clickview/dotnet-core-aspnet:8.0
45
data:
56
image_repo: mcr.microsoft.com/dotnet/aspnet
67
image_version: 8.0.22
78
image_type: bookworm-slim
89
env_version_key: ASPNETCORE_VERSION
910
'8.0/runtime':
11+
image_name: clickview/dotnet-core-runtime:8.0
1012
data:
1113
image_repo: mcr.microsoft.com/dotnet/runtime
1214
image_version: 8.0.22
1315
image_type: bookworm-slim
1416
env_version_key: DOTNET_VERSION
1517
'9.0/aspnet':
18+
image_name: clickview/dotnet-core-aspnet:9.0
1619
data:
1720
image_repo: mcr.microsoft.com/dotnet/aspnet
1821
image_version: 9.0.11
1922
image_type: bookworm-slim
2023
env_version_key: ASPNETCORE_VERSION
2124
'9.0/runtime':
25+
image_name: clickview/dotnet-core-runtime:9.0
2226
data:
2327
image_repo: mcr.microsoft.com/dotnet/runtime
2428
image_version: 9.0.11
@@ -28,8 +32,10 @@ dotnet:
2832
dotnet-sdk:
2933
versions:
3034
'8.0':
35+
image_name: clickview/dotnet-core-sdk:8.0
3136
data:
3237
image_version: 8.0.416-bookworm-slim
3338
'9.0':
39+
image_name: clickview/dotnet-core-sdk:9.0
3440
data:
3541
image_version: 9.0.308-bookworm-slim

0 commit comments

Comments
 (0)