Skip to content

Commit e297c7f

Browse files
authored
Add supervisor build pipeline (#1772)
* dockerignore node_modules in subdirectories * image tag action should handle re2 tags * add supervisor containerfile * add publish worker re2 workflow * fix copypasta * require branch check
1 parent 3089caf commit e297c7f

File tree

5 files changed

+165
-1
lines changed

5 files changed

+165
-1
lines changed

.dockerignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
# dependencies
1111

12-
node_modules
12+
**/node_modules
1313
.pnp
1414
.pnp.js
1515

.github/actions/get-image-tag/action.yml

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ runs:
3131
sha=$(echo ${{ github.sha }} | head -c7)
3232
ts=$(date +%s)
3333
tag=${env}-${sha}-${ts}
34+
elif [[ "${{ github.ref_name }}" == re2-*-* ]]; then
35+
env=$(echo ${{ github.ref_name }} | cut -d- -f2)
36+
sha=$(echo ${{ github.sha }} | head -c7)
37+
ts=$(date +%s)
38+
tag=${env}-${sha}-${ts}
3439
elif [[ "${{ github.ref_name }}" == v.docker.* ]]; then
3540
version="${GITHUB_REF_NAME#v.docker.}"
3641
tag="v${version}"
+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: "⚒️ Publish Worker RE2"
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
image_tag:
7+
description: The image tag to publish
8+
type: string
9+
required: false
10+
default: ""
11+
push:
12+
tags:
13+
- "re2-test-*"
14+
- "re2-prod-*"
15+
16+
permissions:
17+
packages: write
18+
contents: read
19+
20+
jobs:
21+
check-branch:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Fail if re2-prod-* is pushed from a non-main branch
25+
if: startsWith(github.ref_name, 're2-prod-') && github.base_ref != 'main'
26+
run: |
27+
echo "🚫 re2-prod-* tags can only be pushed from the main branch."
28+
exit 1
29+
build:
30+
needs: check-branch
31+
strategy:
32+
matrix:
33+
package: [supervisor]
34+
runs-on: ubuntu-latest
35+
env:
36+
DOCKER_BUILDKIT: "1"
37+
steps:
38+
- name: ⬇️ Checkout git repo
39+
uses: actions/checkout@v4
40+
41+
- name: 📦 Get image repo
42+
id: get_repository
43+
run: |
44+
if [[ "${{ matrix.package }}" == *-provider ]]; then
45+
provider_type=$(echo "${{ matrix.package }}" | cut -d- -f1)
46+
repo=provider/${provider_type}
47+
else
48+
repo="${{ matrix.package }}"
49+
fi
50+
echo "repo=${repo}" >> "$GITHUB_OUTPUT"
51+
52+
- id: get_tag
53+
uses: ./.github/actions/get-image-tag
54+
with:
55+
tag: ${{ inputs.image_tag }}
56+
57+
- name: 🐋 Set up Docker Buildx
58+
uses: docker/setup-buildx-action@v3
59+
60+
# ..to avoid rate limits when pulling images
61+
- name: 🐳 Login to DockerHub
62+
uses: docker/login-action@v3
63+
with:
64+
username: ${{ secrets.DOCKERHUB_USERNAME }}
65+
password: ${{ secrets.DOCKERHUB_TOKEN }}
66+
67+
- name: 🚢 Build Container Image
68+
run: |
69+
docker build -t infra_image -f ./apps/${{ matrix.package }}/Containerfile .
70+
71+
# ..to push image
72+
- name: 🐙 Login to GitHub Container Registry
73+
uses: docker/login-action@v3
74+
with:
75+
registry: ghcr.io
76+
username: ${{ github.repository_owner }}
77+
password: ${{ secrets.GITHUB_TOKEN }}
78+
79+
- name: 🐙 Push to GitHub Container Registry
80+
run: |
81+
docker tag infra_image "$REGISTRY/$REPOSITORY:$IMAGE_TAG"
82+
docker push "$REGISTRY/$REPOSITORY:$IMAGE_TAG"
83+
env:
84+
REGISTRY: ghcr.io/triggerdotdev
85+
REPOSITORY: ${{ steps.get_repository.outputs.repo }}
86+
IMAGE_TAG: ${{ steps.get_tag.outputs.tag }}
87+
88+
- name: 🐙 Push 'v3' tag to GitHub Container Registry
89+
if: steps.get_tag.outputs.is_semver == 'true'
90+
run: |
91+
docker tag infra_image "$REGISTRY/$REPOSITORY:v3"
92+
docker push "$REGISTRY/$REPOSITORY:v3"
93+
env:
94+
REGISTRY: ghcr.io/triggerdotdev
95+
REPOSITORY: ${{ steps.get_repository.outputs.repo }}

apps/supervisor/Containerfile

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
FROM node:22-alpine@sha256:9bef0ef1e268f60627da9ba7d7605e8831d5b56ad07487d24d1aa386336d1944 AS node-22-alpine
2+
3+
WORKDIR /app
4+
5+
FROM node-22-alpine AS pruner
6+
7+
COPY --chown=node:node . .
8+
RUN npx -q [email protected] prune --scope=supervisor --docker
9+
RUN find . -name "node_modules" -type d -prune -exec rm -rf '{}' +
10+
11+
FROM node-22-alpine AS base
12+
13+
RUN apk add --no-cache dumb-init
14+
15+
COPY --chown=node:node .gitignore .gitignore
16+
COPY --from=pruner --chown=node:node /app/out/json/ .
17+
COPY --from=pruner --chown=node:node /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
18+
COPY --from=pruner --chown=node:node /app/out/pnpm-workspace.yaml ./pnpm-workspace.yaml
19+
20+
FROM base AS dev-deps
21+
RUN corepack enable
22+
ENV NODE_ENV development
23+
24+
RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store pnpm fetch --no-frozen-lockfile
25+
RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store pnpm install --ignore-scripts --no-frozen-lockfile
26+
27+
FROM base AS prod-deps
28+
RUN corepack enable
29+
ENV NODE_ENV production
30+
31+
RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store pnpm install --prod --no-frozen-lockfile
32+
33+
COPY --from=pruner --chown=node:node /app/internal-packages/database/prisma/schema.prisma /app/internal-packages/database/prisma/schema.prisma
34+
35+
ENV NPM_CONFIG_IGNORE_WORKSPACE_ROOT_CHECK true
36+
RUN pnpx [email protected] generate --schema /app/internal-packages/database/prisma/schema.prisma
37+
38+
FROM base AS builder
39+
RUN corepack enable
40+
41+
COPY --from=pruner --chown=node:node /app/out/full/ .
42+
COPY --from=dev-deps --chown=node:node /app/ .
43+
COPY --chown=node:node turbo.json turbo.json
44+
COPY --chown=node:node .configs/tsconfig.base.json .configs/tsconfig.base.json
45+
COPY --chown=node:node scripts/updateVersion.ts scripts/updateVersion.ts
46+
47+
RUN pnpm run generate && \
48+
pnpm run -r --filter supervisor... build
49+
50+
FROM base AS runner
51+
52+
RUN corepack enable
53+
ENV NODE_ENV production
54+
55+
COPY --from=pruner --chown=node:node /app/out/full/ .
56+
COPY --from=prod-deps --chown=node:node /app .
57+
COPY --from=builder --chown=node:node /app/apps/supervisor ./apps/supervisor
58+
59+
EXPOSE 8000
60+
61+
USER node
62+
63+
CMD [ "/usr/bin/dumb-init", "--", "pnpm", "run", "--filter", "supervisor", "start"]

apps/supervisor/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"main": "dist/index.js",
66
"type": "module",
77
"scripts": {
8+
"build": "tsc",
89
"dev": "tsx --experimental-sqlite --require dotenv/config --watch src/index.ts",
910
"start": "node --experimental-sqlite dist/index.js",
1011
"typecheck": "tsc --noEmit"

0 commit comments

Comments
 (0)