Skip to content

Commit a9ca835

Browse files
authored
feat: service deployments (#1668)
Signed-off-by: Gašper Grom <gasper.grom@gmail.com>
1 parent d6b3827 commit a9ca835

File tree

8 files changed

+121
-28
lines changed

8 files changed

+121
-28
lines changed

.dockerignore

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
node_modules
99
**/node_modules
1010

11-
# Submodules (not needed for frontend build)
12-
submodules
13-
14-
# Other services (not needed for frontend build)
15-
workers
11+
# Other services (not needed for most builds)
1612
services
1713
database
1814

.github/actions/build-docker-image/action.yaml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ inputs:
66
description: The APP_ENV to pass as a build argument
77
required: false
88
default: production
9+
dockerfile:
10+
description: Path to the Dockerfile
11+
required: true
12+
image-name:
13+
description: Image name (e.g. insights-app, package-downloads-worker)
14+
required: true
15+
build-args:
16+
description: Extra build args (newline-separated KEY=VALUE)
17+
required: false
18+
default: ''
919

1020
outputs:
1121
image:
@@ -21,7 +31,7 @@ runs:
2131
run: |
2232
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-6)
2333
IMAGE_VERSION="${SHORT_SHA}.${{ github.run_attempt }}"
24-
IMAGE_TAG="sjc.ocir.io/axbydjxa5zuh/insights-app:${IMAGE_VERSION}"
34+
IMAGE_TAG="sjc.ocir.io/axbydjxa5zuh/${{ inputs.image-name }}:${IMAGE_VERSION}"
2535
echo "IMAGE_VERSION=${IMAGE_VERSION}" >> $GITHUB_OUTPUT
2636
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_OUTPUT
2737
@@ -39,11 +49,11 @@ runs:
3949
uses: docker/build-push-action@v6
4050
with:
4151
context: .
42-
file: frontend/Dockerfile
52+
file: ${{ inputs.dockerfile }}
4353
push: true
4454
tags: ${{ steps.tag-generator.outputs.IMAGE_TAG }}
4555
build-args: |
4656
APP_ENV=${{ inputs.app-env }}
47-
NUXT_REDIS_URL=${{ env.NUXT_REDIS_URL }}
57+
${{ inputs.build-args }}
4858
no-cache: true
49-
provenance: false
59+
provenance: false

.github/workflows/production-deploy.yaml

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ name: Production Deploy
22

33
on:
44
workflow_dispatch:
5+
inputs:
6+
service:
7+
description: Service to deploy
8+
required: true
9+
type: choice
10+
default: frontend
11+
options:
12+
- frontend
13+
- package-downloads-worker
14+
- search-volume-worker
515

616
env:
717
CLOUD_ENV: lf-oracle-production
@@ -21,6 +31,36 @@ jobs:
2131
steps:
2232
- name: Checkout code
2333
uses: actions/checkout@v4
34+
with:
35+
submodules: recursive
36+
37+
- name: Set service config
38+
id: config
39+
run: |
40+
case "${{ inputs.service }}" in
41+
frontend)
42+
echo "dockerfile=frontend/Dockerfile" >> $GITHUB_OUTPUT
43+
echo "image_name=insights-app" >> $GITHUB_OUTPUT
44+
echo "k8s_deployment=insights-app-dpl" >> $GITHUB_OUTPUT
45+
echo "k8s_container=frontend" >> $GITHUB_OUTPUT
46+
;;
47+
package-downloads-worker)
48+
echo "dockerfile=workers/temporal/package_downloads_worker/Dockerfile" >> $GITHUB_OUTPUT
49+
echo "image_name=package-downloads-worker" >> $GITHUB_OUTPUT
50+
echo "k8s_deployment=package-downloads-worker-dpl" >> $GITHUB_OUTPUT
51+
echo "k8s_container=package-downloads-worker" >> $GITHUB_OUTPUT
52+
;;
53+
search-volume-worker)
54+
echo "dockerfile=workers/temporal/search_volume_worker/Dockerfile" >> $GITHUB_OUTPUT
55+
echo "image_name=insights-search-volume-worker" >> $GITHUB_OUTPUT
56+
echo "k8s_deployment=search-volume-worker-dpl" >> $GITHUB_OUTPUT
57+
echo "k8s_container=search-volume-worker" >> $GITHUB_OUTPUT
58+
;;
59+
*)
60+
echo "::error::Unknown service: ${{ inputs.service }}"
61+
exit 1
62+
;;
63+
esac
2464
2565
- name: Setup OCI CLI and Kubectl
2666
run: |
@@ -64,17 +104,21 @@ jobs:
64104
id: build-docker-image
65105
with:
66106
app-env: production
67-
env:
68-
NUXT_REDIS_URL: ${{ env.NUXT_REDIS_URL }}
107+
dockerfile: ${{ steps.config.outputs.dockerfile }}
108+
image-name: ${{ steps.config.outputs.image_name }}
109+
build-args: ''
69110

70111
- name: Update Deployment Image
71112
run: |
72-
kubectl set image deployment/insights-app-dpl frontend=${{ steps.build-docker-image.outputs.image }} -n insights
73-
kubectl rollout status deployment/insights-app-dpl -n insights --timeout=300s
113+
kubectl set image deployment/${{ steps.config.outputs.k8s_deployment }} \
114+
${{ steps.config.outputs.k8s_container }}=${{ steps.build-docker-image.outputs.image }} \
115+
-n insights
116+
kubectl rollout status deployment/${{ steps.config.outputs.k8s_deployment }} -n insights --timeout=300s
74117
75118
- name: Flush Redis cache
119+
if: inputs.service == 'frontend'
76120
run: |
77121
REDIS_URL=$(kubectl get configmap insights-config-map -n insights -o jsonpath="{.data.NUXT_REDIS_URL}")
78122
PASSWORD=$(echo "$REDIS_URL" | sed -n 's|.*://:\([^@]*\)@.*|\1|p')
79123
kubectl exec -i redis-client -n insights -- \
80-
redis-cli -h redis-svc -a "$PASSWORD" FLUSHALL
124+
redis-cli -h redis-svc -a "$PASSWORD" FLUSHALL

.github/workflows/staging-deploy.yaml

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ name: Staging Deploy
22

33
on:
44
workflow_dispatch:
5+
inputs:
6+
service:
7+
description: Service to deploy
8+
required: true
9+
type: choice
10+
default: frontend
11+
options:
12+
- frontend
13+
- package-downloads-worker
14+
- search-volume-worker
515

616
env:
717
CLOUD_ENV: lf-oracle-staging
@@ -21,6 +31,36 @@ jobs:
2131
steps:
2232
- name: Checkout code
2333
uses: actions/checkout@v4
34+
with:
35+
submodules: recursive
36+
37+
- name: Set service config
38+
id: config
39+
run: |
40+
case "${{ inputs.service }}" in
41+
frontend)
42+
echo "dockerfile=frontend/Dockerfile" >> $GITHUB_OUTPUT
43+
echo "image_name=insights-app" >> $GITHUB_OUTPUT
44+
echo "k8s_deployment=insights-app-dpl" >> $GITHUB_OUTPUT
45+
echo "k8s_container=frontend" >> $GITHUB_OUTPUT
46+
;;
47+
package-downloads-worker)
48+
echo "dockerfile=workers/temporal/package_downloads_worker/Dockerfile" >> $GITHUB_OUTPUT
49+
echo "image_name=package-downloads-worker" >> $GITHUB_OUTPUT
50+
echo "k8s_deployment=package-downloads-worker-dpl" >> $GITHUB_OUTPUT
51+
echo "k8s_container=package-downloads-worker" >> $GITHUB_OUTPUT
52+
;;
53+
search-volume-worker)
54+
echo "dockerfile=workers/temporal/search_volume_worker/Dockerfile" >> $GITHUB_OUTPUT
55+
echo "image_name=insights-search-volume-worker" >> $GITHUB_OUTPUT
56+
echo "k8s_deployment=search-volume-worker-dpl" >> $GITHUB_OUTPUT
57+
echo "k8s_container=search-volume-worker" >> $GITHUB_OUTPUT
58+
;;
59+
*)
60+
echo "::error::Unknown service: ${{ inputs.service }}"
61+
exit 1
62+
;;
63+
esac
2464
2565
- name: Setup OCI CLI and Kubectl
2666
run: |
@@ -64,10 +104,13 @@ jobs:
64104
id: build-docker-image
65105
with:
66106
app-env: staging
67-
env:
68-
NUXT_REDIS_URL: ${{ env.NUXT_REDIS_URL }}
107+
dockerfile: ${{ steps.config.outputs.dockerfile }}
108+
image-name: ${{ steps.config.outputs.image_name }}
109+
build-args: ''
69110

70111
- name: Update Deployment Image
71112
run: |
72-
kubectl set image deployment/insights-app-dpl frontend=${{ steps.build-docker-image.outputs.image }} -n insights
73-
kubectl rollout status deployment/insights-app-dpl -n insights --timeout=300s
113+
kubectl set image deployment/${{ steps.config.outputs.k8s_deployment }} \
114+
${{ steps.config.outputs.k8s_container }}=${{ steps.build-docker-image.outputs.image }} \
115+
-n insights
116+
kubectl rollout status deployment/${{ steps.config.outputs.k8s_deployment }} -n insights --timeout=300s

frontend/Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# syntax=docker/dockerfile:1.4
2-
ARG NODE_VERSION=22
2+
ARG NODE_VERSION=24
33

44
# ============================================
55
# Base stage: Node with pnpm via corepack
@@ -33,10 +33,8 @@ RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store \
3333
FROM deps AS builder
3434

3535
ARG APP_ENV=production
36-
ARG NUXT_REDIS_URL
3736

3837
ENV NUXT_APP_ENV=$APP_ENV
39-
ENV NUXT_REDIS_URL=$NUXT_REDIS_URL
4038
ENV NODE_OPTIONS=--max-old-space-size=4096
4139

4240
WORKDIR /app

workers/temporal/package_downloads_worker/src/Dockerfile.package_downloads_worker.dockerignore renamed to workers/temporal/package_downloads_worker/.dockerignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ scripts/
1515
.flake8
1616
*.md
1717
Makefile
18-
backend/
18+
backend/

workers/temporal/package_downloads_worker/src/Dockerfile.package_downloads_worker renamed to workers/temporal/package_downloads_worker/Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
FROM node:20-alpine as builder
1+
FROM node:24-alpine AS builder
22

33
RUN apk add --no-cache python3 make g++
44

55
WORKDIR /usr/insights/app
6-
RUN npm install -g corepack@latest && corepack enable pnpm && corepack prepare pnpm@9.15.0 --activate
6+
RUN npm install -g corepack@latest && corepack enable pnpm && corepack prepare pnpm@10.12.4 --activate
77

88
COPY ./package.json ./pnpm-workspace.yaml ./pnpm-lock.yaml ./
9-
RUN pnpm fetch
9+
COPY ./patches ./patches
10+
RUN pnpm fetch --ignore-scripts
1011

1112
COPY ./submodules ./submodules
1213
COPY ./workers/temporal/base ./workers/temporal/base
1314
COPY ./workers/temporal/package_downloads_worker ./workers/temporal/package_downloads_worker
1415

1516
RUN pnpm i --frozen-lockfile
1617

17-
FROM node:20-bookworm-slim as runner
18+
FROM node:20-bookworm-slim AS runner
1819

1920
WORKDIR /usr/insights/app
20-
RUN npm install -g corepack@latest && corepack enable pnpm && corepack prepare pnpm@9.15.0 --activate && apt update && apt install -y ca-certificates --no-install-recommends && rm -rf /var/lib/apt/lists/*
21+
RUN npm install -g corepack@latest && corepack enable pnpm && corepack prepare pnpm@10.12.4 --activate && apt update && apt install -y ca-certificates --no-install-recommends && rm -rf /var/lib/apt/lists/*
2122

2223
COPY --from=builder /usr/insights/app/node_modules ./node_modules
2324
COPY --from=builder /usr/insights/app/submodules ./submodules

workers/temporal/search_volume_worker/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ RUN npm install -g corepack@latest && \
1717

1818
# Copy root-level files
1919
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
20+
COPY patches ./patches
2021

2122
COPY ./workers/temporal/search_volume_worker/package.json ./workers/temporal/search_volume_worker/
2223

2324
# Pre-fetch dependencies and use a Docker cache mount for pnpm to speed up subsequent builds
2425
RUN --mount=type=cache,id=pnpm,target=${PNPM_CACHE_DIR} pnpm config set store-dir ${PNPM_CACHE_DIR} && \
25-
pnpm fetch --frozen-lockfile
26+
pnpm fetch --frozen-lockfile --ignore-scripts
2627

2728
COPY ./submodules ./submodules
2829
COPY ./workers/temporal/base ./workers/temporal/base

0 commit comments

Comments
 (0)