Skip to content

Add GitHub Actions workflow to build and push challenge images to GHCR #2

Add GitHub Actions workflow to build and push challenge images to GHCR

Add GitHub Actions workflow to build and push challenge images to GHCR #2

name: Publish Challenge Images
on:

Check failure on line 3 in .github/workflows/publish-images.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/publish-images.yml

Invalid workflow file

You have an error in your yaml syntax on line 3
push:
branches: [main]
paths:
- "*/Dockerfile"
- "*/requirements.txt"
- "*/app/**"
- ".github/workflows/publish-images.yml"
workflow_dispatch:
env:
REGISTRY: ghcr.io
jobs:
detect-challenges:
runs-on: ubuntu-latest
outputs:
challenges: ${{ steps.find.outputs.challenges }}
steps:
- uses: actions/checkout@v4
- id: find
run: |
challenges=$(ls -d */ | grep -v '_template\|\.github' | sed 's/\///' | jq -R -s -c 'split("\n") | map(select(length >
0))')
echo "challenges=$challenges" >> "$GITHUB_OUTPUT"
build-and-push:
needs: detect-challenges
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix:
challenge: ${{ fromJson(needs.detect-challenges.outputs.challenges) }}
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/kryptsec/oasis-challenges/${{ matrix.challenge }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=sha,prefix=
- uses: docker/build-push-action@v6
with:
context: ./${{ matrix.challenge }}
push: true
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max