-
Notifications
You must be signed in to change notification settings - Fork 0
107 lines (91 loc) · 3.14 KB
/
docker.yaml
File metadata and controls
107 lines (91 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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 pnpm
uses: pnpm/action-setup@v6
# Pinned to v4: setup-node@v5 auto-detects pnpm via the
# packageManager field in package.json and tries to cache the
# store, which fails here because this workflow doesn't run
# `pnpm install` on the runner — the store path doesn't exist
# and v5 promotes the "missing path" warning to an error.
# Sticking to v4 until v5's auto-cache can be opted out cleanly.
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Generate Dockerfile
run: |
node --experimental-strip-types scripts/generate.ts --only=${{ matrix.dir }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v6
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@v7
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 }}