diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..fb0cb9d --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,88 @@ +name: Build & Publish Docker Images + +on: + push: + branches: + - master + workflow_dispatch: + inputs: + dry_run: + description: 'Build images only, do not push' + required: false + default: 'true' + +jobs: + discover-dockerfiles: + runs-on: ubuntu-latest + outputs: + dockerfiles: ${{ steps.extract.outputs.dockerfiles }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Generate matrix from manifest.yaml + id: extract + run: | + files=() + roots=$(yq e -r 'keys | .[]' manifest.yaml) + for root in $roots; do + while read -r version; do + dockerfile="./${root}/${version}/Dockerfile" + # Read image_name including tag + image_name=$(yq e -r ".${root}.versions.\"${version}\".image_name" manifest.yaml) + if [ -n "$image_name" ] && [ "$image_name" != "null" ]; then + files+=("$dockerfile|$image_name") + fi + done < <(yq e -r ".${root}.versions | keys | .[]" manifest.yaml) + done + + # Convert array to compact JSON for GitHub Actions matrix + json=$(printf '%s\n' "${files[@]}" | jq -R -c . | jq -c -s .) + echo "dockerfiles=$json" >> $GITHUB_OUTPUT + + build-and-push: + needs: discover-dockerfiles + runs-on: ubuntu-latest + strategy: + matrix: + entry: ${{ fromJson(needs.discover-dockerfiles.outputs.dockerfiles) }} + + env: + DRY_RUN: ${{ github.event.inputs.dry_run }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Docker Hub + if: ${{ env.DRY_RUN != 'true' }} + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Parse Dockerfile and image + id: metadata + run: | + dockerfile="${{ matrix.entry }}" + dockerfile="${dockerfile%%|*}" + image="${{ matrix.entry }}" + image="${image##*|}" # Already includes tag from manifest + dir=$(dirname "$dockerfile") + short_sha="${GITHUB_SHA:0:7}" + + echo "directory=$dir" >> $GITHUB_OUTPUT + echo "image=$image" >> $GITHUB_OUTPUT + echo "short_sha=$short_sha" >> $GITHUB_OUTPUT + + - name: Build and push image + uses: docker/build-push-action@v6 + with: + context: ${{ steps.metadata.outputs.directory }} + file: ${{ steps.metadata.outputs.directory }}/Dockerfile + push: ${{ env.DRY_RUN != 'true' }} + tags: | + ${{ steps.metadata.outputs.image }} diff --git a/manifest.yaml b/manifest.yaml index f6030bb..0938668 100644 --- a/manifest.yaml +++ b/manifest.yaml @@ -1,24 +1,28 @@ dotnet: versions: '8.0/aspnet': + image_name: clickview/dotnet-core-aspnet:8.0 data: image_repo: mcr.microsoft.com/dotnet/aspnet image_version: 8.0.19 image_type: bookworm-slim env_version_key: ASPNETCORE_VERSION '8.0/runtime': + image_name: clickview/dotnet-core-runtime:8.0 data: image_repo: mcr.microsoft.com/dotnet/runtime image_version: 8.0.19 image_type: bookworm-slim env_version_key: DOTNET_VERSION '9.0/aspnet': + image_name: clickview/dotnet-core-aspnet:9.0 data: image_repo: mcr.microsoft.com/dotnet/aspnet image_version: 9.0.8 image_type: bookworm-slim env_version_key: ASPNETCORE_VERSION '9.0/runtime': + image_name: clickview/dotnet-core-runtime:9.0 data: image_repo: mcr.microsoft.com/dotnet/runtime image_version: 9.0.8 @@ -28,8 +32,10 @@ dotnet: dotnet-sdk: versions: '8.0': + image_name: clickview/dotnet-core-sdk:8.0 data: image_version: 8.0.413-bookworm-slim '9.0': + image_name: clickview/dotnet-core-sdk:9.0 data: image_version: 9.0.304-bookworm-slim