Publish Docker Images #94
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish Docker Images | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| workflow_dispatch: {} | |
| permissions: | |
| contents: read | |
| packages: write | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }}-docker | |
| cancel-in-progress: true | |
| jobs: | |
| discover: | |
| name: Discover functions | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.find.outputs.matrix }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| - name: Find functions from handler.json | |
| id: find | |
| run: | | |
| entries=$( | |
| for f in functions/*/handler.json; do | |
| [ -f "$f" ] || continue | |
| name=$(jq -r .name "$f") | |
| dir=$(basename "$(dirname "$f")") | |
| echo "{\"name\":\"$name\",\"dir\":\"$dir\"}" | |
| done | jq -s -c '.' | |
| ) | |
| echo "matrix={\"include\":$entries}" >> "$GITHUB_OUTPUT" | |
| echo "Discovered functions: $entries" | |
| build: | |
| name: Build ${{ matrix.name }}-fn | |
| needs: discover | |
| runs-on: ubuntu-latest | |
| if: ${{ needs.discover.outputs.matrix != '{"include":[]}' }} | |
| strategy: | |
| fail-fast: false | |
| matrix: ${{ fromJSON(needs.discover.outputs.matrix) }} | |
| env: | |
| REGISTRY: ghcr.io | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v5 | |
| with: | |
| node-version: '22' | |
| cache: '' # Disable cache - pnpm not used in this workflow | |
| - name: Generate Dockerfile | |
| run: | | |
| node --experimental-strip-types scripts/generate.ts --only=${{ matrix.dir }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GHCR | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Docker meta | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ matrix.name }}-fn | |
| tags: | | |
| type=ref,event=tag | |
| type=semver,pattern={{version}} | |
| type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }} | |
| type=sha,format=short,prefix= | |
| - name: Build and push | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: generated/${{ matrix.dir }}/Dockerfile | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| cache-from: type=gha,scope=${{ matrix.name }} | |
| cache-to: type=gha,mode=max,scope=${{ matrix.name }} |