Mirrored from GitHub
github.com/roostorg/coop
1name: Publish Docker Images
2
3on:
4 push:
5 branches: [main]
6 paths:
7 - 'server/**'
8 - 'client/**'
9 - 'db/**'
10 - 'Dockerfile'
11 - 'client/Dockerfile'
12 - '.github/workflows/publish-docker.yaml'
13 release:
14 types: [published]
15 workflow_dispatch:
16
17permissions:
18 contents: read
19
20env:
21 REGISTRY: ghcr.io
22
23jobs:
24 changes:
25 runs-on: ubuntu-latest
26 outputs:
27 server: ${{ steps.filter.outputs.server }}
28 client: ${{ steps.filter.outputs.client }}
29 db: ${{ steps.filter.outputs.db }}
30 steps:
31 - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
32
33 - uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
34 id: filter
35 if: github.event_name == 'push'
36 with:
37 filters: |
38 server:
39 - 'server/**'
40 - 'Dockerfile'
41 client:
42 - 'client/**'
43 db:
44 - 'db/**'
45
46 # On release/dispatch, paths-filter is skipped so outputs are empty.
47 # The downstream jobs use != 'false', so empty triggers a build.
48
49 build-server:
50 needs: changes
51 if: needs.changes.outputs.server != 'false'
52 runs-on: ubuntu-latest
53 permissions:
54 contents: read
55 packages: write
56 strategy:
57 matrix:
58 include:
59 - target: build_server
60 image: coop-server
61 - target: build_worker_runner
62 image: coop-worker
63 steps:
64 - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
65
66 - uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
67
68 - uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
69
70 - uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
71 with:
72 registry: ${{ env.REGISTRY }}
73 username: ${{ github.actor }}
74 password: ${{ secrets.GITHUB_TOKEN }}
75
76 - uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
77 id: meta
78 with:
79 images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ matrix.image }}
80 tags: |
81 type=sha,prefix=
82 type=ref,event=branch
83 type=semver,pattern={{version}}
84 type=semver,pattern={{major}}.{{minor}}
85 type=raw,value=latest,enable={{is_default_branch}}
86
87 - uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
88 with:
89 context: .
90 file: Dockerfile
91 target: ${{ matrix.target }}
92 push: true
93 tags: ${{ steps.meta.outputs.tags }}
94 labels: ${{ steps.meta.outputs.labels }}
95 build-args: |
96 BUILD_ID=${{ github.sha }}
97 cache-from: type=gha
98 cache-to: type=gha,mode=max
99 platforms: linux/amd64,linux/arm64
100
101 build-client:
102 needs: changes
103 if: needs.changes.outputs.client != 'false'
104 runs-on: ubuntu-latest
105 permissions:
106 contents: read
107 packages: write
108 steps:
109 - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
110
111 - uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
112
113 - uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
114
115 - uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
116 with:
117 registry: ${{ env.REGISTRY }}
118 username: ${{ github.actor }}
119 password: ${{ secrets.GITHUB_TOKEN }}
120
121 - uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
122 id: meta
123 with:
124 images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/coop-client
125 tags: |
126 type=sha,prefix=
127 type=ref,event=branch
128 type=semver,pattern={{version}}
129 type=semver,pattern={{major}}.{{minor}}
130 type=raw,value=latest,enable={{is_default_branch}}
131
132 - uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
133 with:
134 context: client
135 file: client/Dockerfile
136 target: serve
137 push: true
138 tags: ${{ steps.meta.outputs.tags }}
139 labels: ${{ steps.meta.outputs.labels }}
140 build-args: |
141 BUILD_ID=${{ github.sha }}
142 cache-from: type=gha
143 cache-to: type=gha,mode=max
144 platforms: linux/amd64,linux/arm64
145
146 # Bundles the db/ migration files + configs into an image meant to be run as a
147 # one-shot task on deploy.
148 # On push to main it publishes only when something under db/ changed (e.g. a
149 # new migration script). On a release it always publishes a versioned tag.
150 build-migrations:
151 needs: changes
152 if: needs.changes.outputs.db != 'false'
153 runs-on: ubuntu-latest
154 permissions:
155 contents: read
156 packages: write
157 steps:
158 - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
159
160 - uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
161
162 - uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
163
164 - uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
165 with:
166 registry: ${{ env.REGISTRY }}
167 username: ${{ github.actor }}
168 password: ${{ secrets.GITHUB_TOKEN }}
169
170 - uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
171 id: meta
172 with:
173 images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/coop-migrations
174 tags: |
175 type=sha,prefix=
176 type=ref,event=branch
177 type=semver,pattern={{version}}
178 type=semver,pattern={{major}}.{{minor}}
179 type=raw,value=latest,enable={{is_default_branch}}
180
181 - uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
182 with:
183 context: db
184 file: db/Dockerfile
185 push: true
186 tags: ${{ steps.meta.outputs.tags }}
187 labels: ${{ steps.meta.outputs.labels }}
188 cache-from: type=gha
189 cache-to: type=gha,mode=max
190 platforms: linux/amd64,linux/arm64