Skip to content

Commit

Permalink
update yml for multi-tag
Browse files Browse the repository at this point in the history
  • Loading branch information
kohanlee1995 committed Dec 5, 2023
1 parent 5b30372 commit b446fe6
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,33 @@ env:
IMAGE_NAME: ${{ github.repository }}

jobs:
metadata:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.generate-matrix.outputs.matrix }} # contains a list of the module names encoded as json
modulenames: ${{ steps.generate-matrix.outputs.modulenames }} # contains a simple, space-separated list of the module names
steps:
- name: Checkout
uses: actions/checkout@v3

- name: generate matrix
id: generate-matrix
# adapted from https://stackoverflow.com/a/74829694
run: |
modulenames="$(ls *.yml | sed 's/.yml//' | paste -s -d ' ')"
echo "modulenames=$modulenames" >> $GITHUB_OUTPUT
# echo $modulenames | tr ' ' '\n' | sed 's/^/type=gha,scope=builder-/' | paste -s
matrix=$(echo $modulenames | jq -R 'split(" ") | {include: map({modulename: .})}')
echo "matrix=$(echo $matrix | jq -c)" >> $GITHUB_OUTPUT
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: [metadata]
strategy:
matrix: ${{ fromJson(needs.metadata.outputs.matrix) }}

steps:
- name: Checkout repository
Expand All @@ -44,15 +66,21 @@ jobs:
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: prune
run: docker system prune -af

- name: Build and push Docker image
id: builder
uses: docker/build-push-action@v3
with:
context: .
file: Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.modulename }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
target: builder
build-args: |
"modulename=${{ matrix.modulename }}"

0 comments on commit b446fe6

Please sign in to comment.