Skip to content

Commit c85eb0e

Browse files
committed
Add db migrations
1 parent db43152 commit c85eb0e

File tree

3 files changed

+58
-6
lines changed

3 files changed

+58
-6
lines changed

.github/workflows/deploy.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ jobs:
4242
run: |
4343
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
4444
45-
- name: Build, tag, and push image to ECR
46-
id: build-image
45+
- name: Build, tag, and push app image to ECR
46+
id: build-app-image
4747
if: ${{ !contains(github.event.head_commit.message , '[skip build]') }}
4848
env:
4949
SHA_TAG: ${{ steps.vars.outputs.sha_short }}
@@ -61,6 +61,22 @@ jobs:
6161
6262
docker push $ECR_REGISTRY/$AWS_ECR_NAME --all-tags
6363
64+
- name: Build, tag, and push migrator image to ECR
65+
id: build-migrator
66+
if: ${{ !contains(github.event.head_commit.message , '[skip build]') }}
67+
env:
68+
SHA_TAG: ${{ steps.vars.outputs.sha_short }}
69+
LATEST_TAG: latest
70+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
71+
run: |
72+
# Build image for database migrations
73+
docker build --target migrator \
74+
-t $ECR_REGISTRY/$AWS_ECR_NAME:migrator \
75+
-f ./Dockerfile \
76+
.
77+
78+
docker push $ECR_REGISTRY/$AWS_ECR_NAME:migrator
79+
6480
- name: Deploying Service to Kubernetes with Helm
6581
id: deploy
6682
uses: bitovi/github-actions-deploy-eks-helm@v1.2.10

Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@ RUN touch README.md || true
2929
# Build the application
3030
RUN pnpm build
3131

32+
# Stage 2.5: Migration stage (optional - for running migrations)
33+
FROM node:25-alpine AS migrator
34+
WORKDIR /app
35+
RUN npm install -g pnpm
36+
37+
# Copy dependencies and migration files
38+
COPY --from=deps /app/node_modules ./node_modules
39+
COPY --from=builder /app/drizzle ./drizzle
40+
COPY --from=builder /app/drizzle.config.ts ./drizzle.config.ts
41+
COPY --from=builder /app/lib ./lib
42+
COPY --from=builder /app/package.json ./package.json
43+
44+
# This stage can be used to run migrations
45+
# Run with: docker build --target migrator -t myapp-migrator .
46+
# Then: docker run --env DATABASE_URL=xxx myapp-migrator pnpm db:push
47+
3248
# Stage 3: Runner
3349
FROM node:25-alpine AS runner
3450
WORKDIR /app

deploy/staging/values.yaml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
shared_env: &shared_env
2+
DATABASE_URL:
3+
type: parameterStore
4+
name: db-url
5+
parameter_name: /eks/maker-staging/keeperhub/db-url
6+
17
replicaCount: 1
28

39
service:
@@ -24,11 +30,27 @@ httpWwwRedirect:
2430
enabled: false
2531
httpBasicAuth:
2632
enabled: false
33+
2734
image:
2835
repository: ${ECR_REGISTRY}/keeperhub-staging
2936
tag: latest
3037
pullPolicy: Always
3138

39+
deployment:
40+
enabled: true
41+
initContainers:
42+
- name: db-migration
43+
image: "${ECR_REGISTRY}/keeperhub-staging:migrator"
44+
command:
45+
- /bin/sh
46+
- -c
47+
args:
48+
- |
49+
echo "Running database migrations..."
50+
pnpm db:push
51+
echo "Migrations completed successfully"
52+
env: *shared_env
53+
3254
serviceAccount:
3355
create: false
3456

@@ -43,6 +65,7 @@ resources:
4365
memory: 256Mi
4466

4567
env:
68+
<<: *shared_env
4669
HOSTNAME:
4770
type: kv
4871
value: "0.0.0.0"
@@ -80,10 +103,7 @@ env:
80103
type: parameterStore
81104
name: etherscan-api-key
82105
parameter_name: /eks/maker-staging/keeper-app/etherscan-api-key
83-
DATABASE_URL:
84-
type: parameterStore
85-
name: db-url
86-
parameter_name: /eks/maker-staging/keeperhub/db-url
106+
87107
externalSecrets:
88108
clusterSecretStoreName: maker-staging
89109

0 commit comments

Comments
 (0)