Skip to content

Commit 795dd15

Browse files
authored
feat(ecran): Separation between workers, main and migrator (#294)
1 parent 9e7ae98 commit 795dd15

11 files changed

+250
-33
lines changed

.github/workflows/docker-build-push.yaml

+101-6
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@ on:
55
branches:
66
- "main"
77

8+
env:
9+
DOCKER_BUILDKIT: 1
10+
811
jobs:
9-
docker:
12+
version:
1013
runs-on: arc-arm64
14+
outputs:
15+
new_tag: ${{ steps.tag_version.outputs.new_tag }}
16+
changelog: ${{ steps.tag_version.outputs.changelog }}
1117
steps:
1218
- name: Checkout
1319
uses: actions/checkout@v4
@@ -22,15 +28,22 @@ jobs:
2228
tag: ${{ steps.tag_version.outputs.new_tag }}
2329
name: Release ${{ steps.tag_version.outputs.new_tag }}
2430
body: ${{ steps.tag_version.outputs.changelog }}
25-
- name: Docker meta
26-
id: meta
31+
32+
build-ecran:
33+
needs: version
34+
runs-on: arc-arm64
35+
steps:
36+
- name: Checkout
37+
uses: actions/checkout@v4
38+
- name: Docker meta for ecran
39+
id: meta_ecran
2740
uses: docker/metadata-action@v5
2841
with:
2942
images: |
3043
gitea.grisha.cloud/lab/ecran
3144
tags: |
3245
type=ref,event=branch
33-
type=semver,pattern={{version}},value=${{ steps.tag_version.outputs.new_tag }}
46+
type=semver,pattern={{version}},value=${{ needs.version.outputs.new_tag }}
3447
type=sha
3548
- name: Set up QEMU
3649
uses: docker/setup-qemu-action@v3
@@ -48,8 +61,90 @@ jobs:
4861
platforms: linux/arm64
4962
context: ./apps/ecran
5063
file: ./apps/ecran/Dockerfile
51-
tags: ${{ steps.meta.outputs.tags }}
52-
labels: ${{ steps.meta.outputs.labels }}
64+
tags: ${{ steps.meta_ecran.outputs.tags }}
65+
labels: ${{ steps.meta_ecran.outputs.labels }}
5366
push: true
5467
cache-from: type=registry,ref=gitea.grisha.cloud/lab/ecran:latest
5568
cache-to: type=inline
69+
build-args: |
70+
BUILDKIT_INLINE_CACHE=1
71+
72+
build-ecran-worker:
73+
needs: version
74+
runs-on: arc-arm64
75+
steps:
76+
- name: Checkout
77+
uses: actions/checkout@v4
78+
- name: Docker meta for ecran-worker
79+
id: meta_ecran_worker
80+
uses: docker/metadata-action@v5
81+
with:
82+
images: |
83+
gitea.grisha.cloud/lab/ecran-worker
84+
tags: |
85+
type=ref,event=branch
86+
type=semver,pattern={{version}},value=${{ needs.version.outputs.new_tag }}
87+
type=sha
88+
- name: Set up QEMU
89+
uses: docker/setup-qemu-action@v3
90+
- name: Set up Docker Buildx
91+
uses: docker/setup-buildx-action@v3
92+
- name: Login to Docker Hub
93+
uses: docker/login-action@v3
94+
with:
95+
registry: gitea.grisha.cloud
96+
username: ${{ secrets.REGISTRY_USERNAME }}
97+
password: ${{ secrets.REGISTRY_TOKEN }}
98+
- name: Build and push ecran-worker
99+
uses: docker/build-push-action@v5
100+
with:
101+
platforms: linux/arm64
102+
context: ./apps/ecran
103+
file: ./apps/ecran/Dockerfile.worker
104+
tags: ${{ steps.meta_ecran_worker.outputs.tags }}
105+
labels: ${{ steps.meta_ecran_worker.outputs.labels }}
106+
push: true
107+
cache-from: type=registry,ref=gitea.grisha.cloud/lab/ecran-worker:latest
108+
cache-to: type=inline
109+
build-args: |
110+
BUILDKIT_INLINE_CACHE=1
111+
112+
build-ecran-migrator:
113+
needs: version
114+
runs-on: arc-arm64
115+
steps:
116+
- name: Checkout
117+
uses: actions/checkout@v4
118+
- name: Docker meta for ecran-migrator
119+
id: meta_ecran_migrator
120+
uses: docker/metadata-action@v5
121+
with:
122+
images: |
123+
gitea.grisha.cloud/lab/ecran-migrator
124+
tags: |
125+
type=ref,event=branch
126+
type=semver,pattern={{version}},value=${{ needs.version.outputs.new_tag }}
127+
type=sha
128+
- name: Set up QEMU
129+
uses: docker/setup-qemu-action@v3
130+
- name: Set up Docker Buildx
131+
uses: docker/setup-buildx-action@v3
132+
- name: Login to Docker Hub
133+
uses: docker/login-action@v3
134+
with:
135+
registry: gitea.grisha.cloud
136+
username: ${{ secrets.REGISTRY_USERNAME }}
137+
password: ${{ secrets.REGISTRY_TOKEN }}
138+
- name: Build and push ecran-migrator
139+
uses: docker/build-push-action@v5
140+
with:
141+
platforms: linux/arm64
142+
context: ./apps/ecran
143+
file: ./apps/ecran/Dockerfile.migrator
144+
tags: ${{ steps.meta_ecran_migrator.outputs.tags }}
145+
labels: ${{ steps.meta_ecran_migrator.outputs.labels }}
146+
push: true
147+
cache-from: type=registry,ref=gitea.grisha.cloud/lab/ecran-migrator:latest
148+
cache-to: type=inline
149+
build-args: |
150+
BUILDKIT_INLINE_CACHE=1

apps/ecran/Dockerfile

+5-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:lts-slim AS base
1+
FROM node:lts-alpine AS base
22

33
FROM base AS deps
44
WORKDIR /app
@@ -21,28 +21,13 @@ ENV NEXT_TELEMETRY_DISABLED=1
2121
RUN addgroup --system --gid 1001 nodejs
2222
RUN adduser --system --uid 1001 nextjs
2323
COPY --from=builder /app/public ./public
24-
COPY --from=builder /app/drizzle ./drizzle
25-
COPY --from=builder /app/src/db ./src/db
26-
COPY --from=builder /app/src/temporal ./src/temporal
27-
28-
RUN npm install \
29-
tsx \
30-
drizzle-orm \
31-
postgres \
32-
@temporalio/client \
33-
@temporalio/worker \
34-
@temporalio/workflow \
35-
@temporalio/activity
24+
COPY --from=builder /app/.next/standalone ./
25+
COPY --from=builder /app/.next/static ./.next/static
3626

3727
# Set the correct permission for prerender cache
38-
RUN mkdir .next
39-
RUN chown nextjs:nodejs .next
40-
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
41-
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
28+
RUN chown -R nextjs:nodejs .next
4229
USER nextjs
4330
EXPOSE 3000
4431
ENV PORT=3000
4532

46-
# server.js is created by next build from the standalone output
47-
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
48-
CMD HOSTNAME="0.0.0.0" node server.js
33+
CMD ["node", "server.js"]

apps/ecran/Dockerfile.migrator

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM node:lts-slim
2+
3+
WORKDIR /app
4+
5+
COPY package.json ./
6+
RUN npm install --only=production
7+
8+
COPY src/db ./src/db
9+
COPY drizzle ./drizzle
10+
11+
CMD ["npx", "tsx", "src/db/migrate.ts"]

apps/ecran/Dockerfile.worker

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM node:lts-slim
2+
3+
WORKDIR /app
4+
5+
COPY package.json ./
6+
RUN npm install --only=production
7+
8+
COPY src ./src
9+
10+
CMD ["npm", "run", "start:worker"]

apps/ecran/kustomize/ecran-deployment.yaml

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ spec:
1818
- name: proompteng-registry
1919
initContainers:
2020
- name: run-migrations
21-
image: gitea.proompteng.ai/lab/ecran:0.0.1
22-
imagePullPolicy: Always
23-
command: ['npm', 'run', 'migrations']
21+
image: gitea.grisha.cloud/lab/ecran-migrator:latest
2422
env:
2523
- name: DB_URI
2624
valueFrom:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
labels:
5+
app.kubernetes.io/name: ecran-worker
6+
name: ecran-worker
7+
namespace: ecran
8+
spec:
9+
replicas: 3
10+
selector:
11+
matchLabels:
12+
app.kubernetes.io/name: ecran-worker
13+
template:
14+
metadata:
15+
labels:
16+
app.kubernetes.io/name: ecran-worker
17+
spec:
18+
imagePullSecrets:
19+
- name: proompteng-registry
20+
containers:
21+
- name: ecran-worker
22+
image: gitea.proompteng.ai/lab/ecran-worker:0.0.1
23+
imagePullPolicy: Always
24+
command: ['npm', 'run', 'start:worker']
25+
env:
26+
# ... (keep the existing env variables)
27+
resources:
28+
limits:
29+
cpu: '1'
30+
memory: '1Gi'
31+
requests:
32+
cpu: '100m'
33+
memory: '100Mi'

apps/ecran/kustomize/temporal-worker-deployment.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ metadata:
66
name: temporal-worker
77
namespace: ecran
88
spec:
9+
replicas: 3
910
selector:
1011
matchLabels:
1112
app.kubernetes.io/name: temporal-worker
@@ -18,7 +19,7 @@ spec:
1819
- name: proompteng-registry
1920
containers:
2021
- name: temporal-worker
21-
image: gitea.proompteng.ai/lab/ecran:0.0.1
22+
image: gitea.proompteng.ai/lab/ecran-worker:0.0.1
2223
imagePullPolicy: Always
2324
command: ['npm', 'run', 'start:worker']
2425
env:

scripts/build-ecran-migrator.sh

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
# Set variables
4+
IMAGE_NAME="gitea.proompteng.ai/lab/ecran-migrator"
5+
DOCKERFILE="apps/ecran/Dockerfile.migrator"
6+
CONTEXT_PATH="apps/ecran"
7+
8+
# Check if a tag is provided as an argument
9+
if [ $# -eq 1 ]; then
10+
TAG=$1
11+
else
12+
# If no tag is provided, use the current date and time
13+
TAG=$(date +"%Y%m%d_%H%M%S")
14+
fi
15+
16+
# Full image name with tag
17+
FULL_IMAGE_NAME="${IMAGE_NAME}:${TAG}"
18+
19+
# Build the Docker image
20+
echo "Building Docker image: ${FULL_IMAGE_NAME}"
21+
docker buildx build --platform linux/arm64 -t ${FULL_IMAGE_NAME} -f ${DOCKERFILE} ${CONTEXT_PATH} --push
22+
23+
# Check if the build was successful
24+
if [ $? -eq 0 ]; then
25+
echo "Docker image built and pushed successfully: ${FULL_IMAGE_NAME}"
26+
else
27+
echo "Docker image build or push failed"
28+
exit 1
29+
fi

scripts/build-ecran-worker.sh

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
# Set variables
4+
IMAGE_NAME="gitea.proompteng.ai/lab/ecran-worker"
5+
DOCKERFILE="apps/ecran/Dockerfile.worker"
6+
CONTEXT_PATH="apps/ecran"
7+
8+
# Check if a tag is provided as an argument
9+
if [ $# -eq 1 ]; then
10+
TAG=$1
11+
else
12+
# If no tag is provided, use the current date and time
13+
TAG=$(date +"%Y%m%d_%H%M%S")
14+
fi
15+
16+
# Full image name with tag
17+
FULL_IMAGE_NAME="${IMAGE_NAME}:${TAG}"
18+
19+
# Build the Docker image
20+
echo "Building Docker image: ${FULL_IMAGE_NAME}"
21+
docker buildx build --platform linux/arm64 -t ${FULL_IMAGE_NAME} -f ${DOCKERFILE} ${CONTEXT_PATH} --push
22+
23+
# Check if the build was successful
24+
if [ $? -eq 0 ]; then
25+
echo "Docker image built and pushed successfully: ${FULL_IMAGE_NAME}"
26+
else
27+
echo "Docker image build or push failed"
28+
exit 1
29+
fi

scripts/build-ecran.sh

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
# Set variables
4+
IMAGE_NAME="gitea.proompteng.ai/lab/ecran"
5+
DOCKERFILE="apps/ecran/Dockerfile"
6+
CONTEXT_PATH="apps/ecran"
7+
8+
# Check if a tag is provided as an argument
9+
if [ $# -eq 1 ]; then
10+
TAG=$1
11+
else
12+
# If no tag is provided, use the current date and time
13+
TAG=$(date +"%Y%m%d_%H%M%S")
14+
fi
15+
16+
# Full image name with tag
17+
FULL_IMAGE_NAME="${IMAGE_NAME}:${TAG}"
18+
19+
# Build the Docker image
20+
echo "Building Docker image: ${FULL_IMAGE_NAME}"
21+
docker buildx build --platform linux/arm64 -t ${FULL_IMAGE_NAME} -f ${DOCKERFILE} ${CONTEXT_PATH} --push
22+
23+
# Check if the build was successful
24+
if [ $? -eq 0 ]; then
25+
echo "Docker image built and pushed successfully: ${FULL_IMAGE_NAME}"
26+
else
27+
echo "Docker image build or push failed"
28+
exit 1
29+
fi

scripts/docker_build_push.sh

-3
This file was deleted.

0 commit comments

Comments
 (0)