Skip to content

Commit b5aa26a

Browse files
committed
give the people an image
1 parent 3828cce commit b5aa26a

7 files changed

Lines changed: 388 additions & 12 deletions

File tree

‎.dockerignore‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Kept out of the image build context. The manifests stage in the Dockerfile
2+
# finds every package.json, so each workspace package must stay in the context
3+
# even when only its manifest is used: examples/ is in the lockfile.
4+
.git
5+
.github
6+
.vscode
7+
.DS_Store
8+
*.log
9+
docs
10+
node_modules
11+
**/node_modules
12+
**/dist
13+
**/test
14+
**/vitest.config.ts
15+
examples/**/*.ts
16+
examples/**/tsconfig.json
17+
.release-please-manifest.json
18+
release-please-config.json
19+
Dockerfile
20+
.dockerignore

‎.github/workflows/docker.yml‎

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: Docker
2+
3+
# Builds each destination's image on both architectures release.yml publishes,
4+
# natively rather than under QEMU, and runs the CLI from the built image.
5+
# Nothing is pushed; release.yml publishes to GHCR.
6+
7+
on:
8+
push:
9+
branches: [main]
10+
pull_request:
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
docker:
17+
name: Docker ${{ matrix.destination }} on ${{ matrix.runner }}
18+
runs-on: ${{ matrix.runner }}
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
# One entry per destination package: packages/sync-<destination>.
23+
destination:
24+
- postgres
25+
runner: [ubuntu-latest, ubuntu-24.04-arm]
26+
steps:
27+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
28+
with:
29+
persist-credentials: false
30+
31+
# The docker-container driver is what makes the GitHub Actions layer
32+
# cache usable; the default driver cannot export cache.
33+
- uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
34+
35+
# Socket Firewall is off until PUBLIC_SOCKET_FIREWALL_TOKEN reaches this
36+
# repo. To turn it on, uncomment this block; the plain build below then
37+
# only runs as the public external-fork fallback.
38+
#
39+
# The action writes a second npmrc under RUNNER_TEMP (the directory has
40+
# to exist first) which the Dockerfile mounts as a BuildKit secret, and
41+
# add-hosts null-routes the public registries inside the build the same
42+
# way the action does on the runner.
43+
# - name: Prepare Docker install config directory
44+
# run: mkdir -p "$RUNNER_TEMP/sfw-docker-npm"
45+
#
46+
# - name: Setup Socket Firewall
47+
# id: sfw
48+
# uses: workos/setup-socket-firewall@ca93dd8aa351f54f4729fe3377a9be23c631c25d
49+
# env:
50+
# NPM_CONFIG_USERCONFIG: ${{ runner.temp }}/sfw-docker-npm/.npmrc
51+
# with:
52+
# token: ${{ secrets.PUBLIC_SOCKET_FIREWALL_TOKEN }}
53+
# allow-external-fork-fallback: true
54+
#
55+
# - name: Build image with Socket Firewall
56+
# if: steps.sfw.outputs.active == 'true'
57+
# uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
58+
# with:
59+
# context: .
60+
# push: false
61+
# load: true
62+
# tags: sync-${{ matrix.destination }}:ci
63+
# build-args: |
64+
# DESTINATION=${{ matrix.destination }}
65+
# SFW_REQUIRED=true
66+
# add-hosts: |
67+
# registry.npmjs.org:127.0.0.1
68+
# registry.yarnpkg.com:127.0.0.1
69+
# secret-files: |
70+
# npmrc=${{ runner.temp }}/sfw-docker-npm/.npmrc
71+
# cache-from: type=gha,scope=sync-${{ matrix.destination }}-${{ runner.arch }}
72+
# cache-to: type=gha,mode=max,scope=sync-${{ matrix.destination }}-${{ runner.arch }}
73+
#
74+
# - name: Teardown Socket Firewall
75+
# if: ${{ always() && steps.sfw.outputs.active == 'true' }}
76+
# uses: workos/setup-socket-firewall/teardown@ca93dd8aa351f54f4729fe3377a9be23c631c25d
77+
#
78+
# - name: Remove private Docker install config
79+
# if: ${{ always() }}
80+
# env:
81+
# SFW_NPM_CONFIG_FILE: ${{ runner.temp }}/sfw-docker-npm/.npmrc
82+
# run: |
83+
# rm -f "$SFW_NPM_CONFIG_FILE"
84+
# if [ -e "$SFW_NPM_CONFIG_FILE" ]; then
85+
# echo "::error::Private Docker install config was not removed."
86+
# exit 1
87+
# fi
88+
89+
# Once the Socket Firewall block is on, give this step
90+
# `if: steps.sfw.outputs.active != 'true'` so it only runs as the
91+
# public external-fork fallback.
92+
- name: Build image
93+
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
94+
with:
95+
context: .
96+
push: false
97+
load: true
98+
tags: sync-${{ matrix.destination }}:ci
99+
build-args: |
100+
DESTINATION=${{ matrix.destination }}
101+
cache-from: type=gha,scope=sync-${{ matrix.destination }}-${{ runner.arch }}
102+
cache-to: type=gha,mode=max,scope=sync-${{ matrix.destination }}-${{ runner.arch }}
103+
104+
# The entrypoint runs, and the build carries the stream catalog, with no
105+
# database or credentials involved.
106+
- name: Container smoke test
107+
env:
108+
IMAGE: sync-${{ matrix.destination }}:ci
109+
run: |
110+
docker run --rm "$IMAGE" | grep -q '^Usage'
111+
docker run --rm "$IMAGE" streams | jq -e 'any(.[]; .stream == "users")'

‎.github/workflows/release-please.yml‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ name: Release Please
1111
on:
1212
workflow_dispatch:
1313

14-
# id-token: write is not used by this workflow directly, but the caller's
15-
# token permissions cap what the called release.yml may request — its
16-
# publish job needs id-token: write for npm trusted publishing (OIDC).
17-
# Without it here, the whole run fails at startup with a workflow-file error.
14+
# id-token: write and packages: write are not used by this workflow directly,
15+
# but the caller's token permissions cap what the called release.yml may
16+
# request — its publish job needs id-token: write for npm trusted publishing
17+
# (OIDC) and its publish-ghcr job needs packages: write to push the image.
18+
# Without them here, the whole run fails at startup with a workflow-file error.
1819
permissions:
1920
contents: write
2021
pull-requests: write
2122
id-token: write
23+
packages: write
2224

2325
jobs:
2426
# Each package is its own release-please component with its own version,

‎.github/workflows/release.yml‎

Lines changed: 141 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
name: Release
22

33
# Publishes one package to npm from its component tag (sync-engine-v1.2.3,
4-
# sync-postgres-v0.4.0). release-please calls this once per package it
5-
# released; re-run it by hand for an existing tag if a run failed — a
6-
# version already on npm is skipped, so a retry converges.
4+
# sync-postgres-v0.4.0), and the destination packages — the ones with a CLI —
5+
# to GHCR as a container image after that. release-please calls this once per
6+
# package it released; re-run it by hand for an existing tag if a run failed —
7+
# a version already on npm is skipped and an image push is idempotent, so a
8+
# retry converges.
79

810
on:
911
workflow_call:
@@ -35,6 +37,12 @@ jobs:
3537
permissions:
3638
contents: read
3739
id-token: write
40+
outputs:
41+
component: ${{ steps.pkg.outputs.component }}
42+
destination: ${{ steps.pkg.outputs.destination }}
43+
version: ${{ steps.pkg.outputs.version }}
44+
description: ${{ steps.pkg.outputs.description }}
45+
image: ${{ steps.pkg.outputs.image }}
3846
steps:
3947
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
4048
with:
@@ -72,11 +80,20 @@ jobs:
7280
*-*) NPM_TAG=beta ;;
7381
*) NPM_TAG=latest ;;
7482
esac
83+
# A package with a `bin` is a destination and ships as an image too;
84+
# the engine is a library and does not. The Dockerfile's DESTINATION
85+
# arg is the component without its sync- prefix.
86+
IMAGE="$(node -p "require('./$DIR/package.json').bin ? 'true' : 'false'")"
87+
DESCRIPTION="$(node -p "require('./$DIR/package.json').description ?? ''")"
7588
{
7689
echo "dir=$DIR"
7790
echo "name=$NAME"
91+
echo "component=$COMPONENT"
92+
echo "destination=${COMPONENT#sync-}"
7893
echo "version=$VERSION"
7994
echo "npm_tag=$NPM_TAG"
95+
echo "image=$IMAGE"
96+
echo "description=$DESCRIPTION"
8097
} >> "$GITHUB_OUTPUT"
8198
8299
# Socket Firewall is off until PUBLIC_SOCKET_FIREWALL_TOKEN reaches this
@@ -119,3 +136,124 @@ jobs:
119136
TARBALL="$(pnpm --filter "./$DIR" pack --json --pack-destination "$RUNNER_TEMP" \
120137
| node -p "JSON.parse(require('fs').readFileSync(0, 'utf8')).filename")"
121138
npm publish "$TARBALL" --tag "$NPM_TAG" --access public --provenance
139+
140+
# A multi-arch image for each destination package, after its npm package is
141+
# out so the two never sit at different versions. The image name is the npm
142+
# name without its scope: @workos/sync-postgres → ghcr.io/workos/sync-postgres.
143+
publish-ghcr:
144+
name: Publish container image to GHCR
145+
needs: publish
146+
if: ${{ needs.publish.outputs.image == 'true' }}
147+
runs-on: ubuntu-latest
148+
permissions:
149+
contents: read
150+
packages: write
151+
steps:
152+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
153+
with:
154+
ref: ${{ inputs.tag_name }}
155+
persist-credentials: false
156+
157+
- name: Determine image tags
158+
id: image
159+
env:
160+
COMPONENT: ${{ needs.publish.outputs.component }}
161+
VERSION: ${{ needs.publish.outputs.version }}
162+
OWNER: ${{ github.repository_owner }}
163+
run: |
164+
case "$VERSION" in
165+
*-*) CHANNEL=beta ;;
166+
*) CHANNEL=latest ;;
167+
esac
168+
# github.sha is the commit the workflow ran from, not the tag's.
169+
REVISION="$(git rev-parse HEAD)"
170+
SHORT_SHA="$(git rev-parse --short HEAD)"
171+
IMAGE="ghcr.io/${OWNER}/${COMPONENT}"
172+
{
173+
echo "tags=${IMAGE}:${VERSION},${IMAGE}:${CHANNEL},${IMAGE}:sha-${SHORT_SHA}"
174+
echo "revision=$REVISION"
175+
} >> "$GITHUB_OUTPUT"
176+
177+
- uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
178+
with:
179+
registry: ghcr.io
180+
username: ${{ github.actor }}
181+
password: ${{ secrets.GITHUB_TOKEN }}
182+
183+
# QEMU + Buildx let a single amd64 runner build and push a multi-arch
184+
# manifest list (amd64 + arm64) so ARM hosts pull a native image. The
185+
# node:24-alpine base is already multi-arch.
186+
- uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4.4.0
187+
- uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
188+
189+
# Socket Firewall is off until PUBLIC_SOCKET_FIREWALL_TOKEN reaches this
190+
# repo. To turn it on, uncomment this block; the plain publish below is
191+
# then skipped, and a run without the firewall fails instead.
192+
# - name: Prepare Docker install config directory
193+
# run: mkdir -p "$RUNNER_TEMP/sfw-docker-npm"
194+
#
195+
# - name: Setup Socket Firewall
196+
# id: sfw
197+
# uses: workos/setup-socket-firewall@ca93dd8aa351f54f4729fe3377a9be23c631c25d
198+
# env:
199+
# NPM_CONFIG_USERCONFIG: ${{ runner.temp }}/sfw-docker-npm/.npmrc
200+
# with:
201+
# token: ${{ secrets.PUBLIC_SOCKET_FIREWALL_TOKEN }}
202+
#
203+
# - name: Require Socket Firewall for container publication
204+
# if: steps.sfw.outputs.active != 'true'
205+
# run: |
206+
# echo "::error::Socket Firewall must be active before container publication."
207+
# exit 1
208+
#
209+
# - name: Publish image with Socket Firewall
210+
# uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
211+
# with:
212+
# context: .
213+
# platforms: linux/amd64,linux/arm64
214+
# push: true
215+
# tags: ${{ steps.image.outputs.tags }}
216+
# labels: |
217+
# org.opencontainers.image.version=${{ needs.publish.outputs.version }}
218+
# org.opencontainers.image.revision=${{ steps.image.outputs.revision }}
219+
# org.opencontainers.image.description=${{ needs.publish.outputs.description }}
220+
# build-args: |
221+
# DESTINATION=${{ needs.publish.outputs.destination }}
222+
# SFW_REQUIRED=true
223+
# add-hosts: |
224+
# registry.npmjs.org:127.0.0.1
225+
# registry.yarnpkg.com:127.0.0.1
226+
# secret-files: |
227+
# npmrc=${{ runner.temp }}/sfw-docker-npm/.npmrc
228+
#
229+
# - name: Teardown Socket Firewall
230+
# if: ${{ always() && steps.sfw.outputs.active == 'true' }}
231+
# uses: workos/setup-socket-firewall/teardown@ca93dd8aa351f54f4729fe3377a9be23c631c25d
232+
#
233+
# - name: Remove private Docker install config
234+
# if: ${{ always() }}
235+
# env:
236+
# SFW_NPM_CONFIG_FILE: ${{ runner.temp }}/sfw-docker-npm/.npmrc
237+
# run: |
238+
# rm -f "$SFW_NPM_CONFIG_FILE"
239+
# if [ -e "$SFW_NPM_CONFIG_FILE" ]; then
240+
# echo "::error::Private Docker install config was not removed."
241+
# exit 1
242+
# fi
243+
244+
# Once the Socket Firewall block is on, delete this step: the Require
245+
# step refuses to publish without the firewall, and the firewalled
246+
# publish takes its place.
247+
- name: Publish image
248+
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
249+
with:
250+
context: .
251+
platforms: linux/amd64,linux/arm64
252+
push: true
253+
tags: ${{ steps.image.outputs.tags }}
254+
labels: |
255+
org.opencontainers.image.version=${{ needs.publish.outputs.version }}
256+
org.opencontainers.image.revision=${{ steps.image.outputs.revision }}
257+
org.opencontainers.image.description=${{ needs.publish.outputs.description }}
258+
build-args: |
259+
DESTINATION=${{ needs.publish.outputs.destination }}

0 commit comments

Comments
 (0)