|
| 1 | +name: Publish Docker Images |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
| 8 | + workflow_dispatch: {} |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: read |
| 12 | + packages: write |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: ${{ github.workflow }}-${{ github.ref }}-docker |
| 16 | + cancel-in-progress: true |
| 17 | + |
| 18 | +jobs: |
| 19 | + discover: |
| 20 | + name: Discover functions |
| 21 | + runs-on: ubuntu-latest |
| 22 | + outputs: |
| 23 | + matrix: ${{ steps.find.outputs.matrix }} |
| 24 | + steps: |
| 25 | + - name: Checkout |
| 26 | + uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Find functions from handler.json |
| 29 | + id: find |
| 30 | + run: | |
| 31 | + entries=$( |
| 32 | + for f in functions/*/handler.json; do |
| 33 | + [ -f "$f" ] || continue |
| 34 | + name=$(jq -r .name "$f") |
| 35 | + dir=$(basename "$(dirname "$f")") |
| 36 | + echo "{\"name\":\"$name\",\"dir\":\"$dir\"}" |
| 37 | + done | jq -s -c '.' |
| 38 | + ) |
| 39 | + echo "matrix={\"include\":$entries}" >> "$GITHUB_OUTPUT" |
| 40 | + echo "Discovered functions: $entries" |
| 41 | +
|
| 42 | + build: |
| 43 | + name: Build ${{ matrix.name }}-fn |
| 44 | + needs: discover |
| 45 | + runs-on: ubuntu-latest |
| 46 | + if: ${{ needs.discover.outputs.matrix != '{"include":[]}' }} |
| 47 | + |
| 48 | + strategy: |
| 49 | + fail-fast: false |
| 50 | + matrix: ${{ fromJSON(needs.discover.outputs.matrix) }} |
| 51 | + |
| 52 | + env: |
| 53 | + REGISTRY: ghcr.io |
| 54 | + |
| 55 | + steps: |
| 56 | + - name: Checkout |
| 57 | + uses: actions/checkout@v4 |
| 58 | + |
| 59 | + - name: Setup Node.js |
| 60 | + uses: actions/setup-node@v4 |
| 61 | + with: |
| 62 | + node-version: '22' |
| 63 | + |
| 64 | + - name: Generate Dockerfile |
| 65 | + run: | |
| 66 | + node --experimental-strip-types scripts/generate.ts --only=${{ matrix.dir }} |
| 67 | +
|
| 68 | + - name: Set up Docker Buildx |
| 69 | + uses: docker/setup-buildx-action@v3 |
| 70 | + |
| 71 | + - name: Log in to GHCR |
| 72 | + if: github.event_name != 'pull_request' |
| 73 | + uses: docker/login-action@v3 |
| 74 | + with: |
| 75 | + registry: ${{ env.REGISTRY }} |
| 76 | + username: ${{ github.actor }} |
| 77 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 78 | + |
| 79 | + - name: Docker meta |
| 80 | + id: meta |
| 81 | + uses: docker/metadata-action@v5 |
| 82 | + with: |
| 83 | + images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ matrix.name }}-fn |
| 84 | + tags: | |
| 85 | + type=ref,event=tag |
| 86 | + type=semver,pattern={{version}} |
| 87 | + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }} |
| 88 | + type=sha,format=short,prefix= |
| 89 | +
|
| 90 | + - name: Build and push |
| 91 | + uses: docker/build-push-action@v5 |
| 92 | + with: |
| 93 | + context: . |
| 94 | + file: generated/${{ matrix.dir }}/Dockerfile |
| 95 | + push: ${{ github.event_name != 'pull_request' }} |
| 96 | + tags: ${{ steps.meta.outputs.tags }} |
| 97 | + cache-from: type=gha,scope=${{ matrix.name }} |
| 98 | + cache-to: type=gha,mode=max,scope=${{ matrix.name }} |
0 commit comments