Skip to content

Commit c63b13e

Browse files
committed
change migrations to use single shot
1 parent b6718ee commit c63b13e

4 files changed

Lines changed: 52 additions & 4 deletions

File tree

.github/workflows/master-pipeline.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,28 @@ jobs:
7373
cd giveth-all
7474
docker compose pull
7575
76-
rollout-deploy-1:
76+
migrate:
7777
needs: deploy
7878
runs-on: ubuntu-latest
79+
steps:
80+
- name: SSH and Run DB Migrations (one-shot)
81+
uses: appleboy/ssh-action@v1.0.0
82+
with:
83+
host: ${{ secrets.PROD_HOST_ALL }}
84+
username: ${{ secrets.PROD_USERNAME_ALL }}
85+
key: ${{ secrets.PROD_PRIVATE_KEY_ALL }}
86+
port: ${{ secrets.SSH_PORT }}
87+
script: |
88+
set -e
89+
cd giveth-all
90+
echo "Running database migrations (one-shot) before rollout"
91+
# One-shot container: runs migrations, then exits. Non-zero exit fails the deploy.
92+
docker compose run --rm impact-graph-migrations
93+
echo "Migrations complete"
94+
95+
rollout-deploy-1:
96+
needs: migrate
97+
runs-on: ubuntu-latest
7998
steps:
8099
- name: SSH and Redeploy
81100
uses: appleboy/ssh-action@v1.0.0

.github/workflows/staging-pipeline.yml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,32 @@ jobs:
132132
133133
echo "✅ Verified image pulled: ghcr.io/giveth/impact-graph@${{ needs.publish.outputs.image-digest }}"
134134
135-
rollout-deploy-1:
135+
migrate:
136136
needs: deploy
137137
runs-on: ubuntu-latest
138+
permissions:
139+
contents: none # Minimal - only for actions to work
140+
steps:
141+
- name: SSH and Run DB Migrations (one-shot)
142+
uses: appleboy/ssh-action@v1.2.2
143+
with:
144+
host: ${{ secrets.STAGING_HOST_ALL }}
145+
username: ${{ secrets.STAGING_USERNAME_ALL }}
146+
key: ${{ secrets.STAGING_PRIVATE_KEY_ALL }}
147+
port: ${{ secrets.SSH_PORT }}
148+
script: |
149+
set -e
150+
cd giveth-all
151+
# Load the verified image SHA so migrations run on the exact image being deployed
152+
export $(cat .env.impact-graph | xargs)
153+
echo "🗃️ Running database migrations using verified image: $IMPACT_GRAPH_IMAGE"
154+
# One-shot container: runs migrations, then exits. Non-zero exit fails the deploy.
155+
docker compose run --rm impact-graph-migrations
156+
echo "✅ Migrations complete"
157+
158+
rollout-deploy-1:
159+
needs: migrate
160+
runs-on: ubuntu-latest
138161
permissions:
139162
contents: none # Minimal - only for actions to work
140163
steps:

Dockerfile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#https://hub.docker.com/_/node?tab=tags&page=1
2-
FROM node:20.11.0-alpine3.18
2+
FROM node:22.18.0-alpine3.21
33

44
WORKDIR /usr/src/app
55

@@ -11,7 +11,7 @@ COPY tsconfig.json .
1111

1212
RUN apk add --update alpine-sdk
1313
RUN apk add git python3
14-
RUN apk add --no-cache chromium --repository=http://dl-cdn.alpinelinux.org/alpine/v3.18/main
14+
RUN apk add --no-cache chromium --repository=http://dl-cdn.alpinelinux.org/alpine/v3.21/main
1515
RUN npm ci
1616
RUN npm i -g ts-node
1717

@@ -23,3 +23,8 @@ COPY test ./test
2323
COPY migration ./migration
2424

2525
RUN npm run build
26+
27+
# Default startup runs the app WITHOUT migrations. Database migrations are run by a
28+
# dedicated one-shot container/CI step (npm run start:docker:migrate) to avoid multiple
29+
# replicas racing to migrate on boot. Compose services may override this command.
30+
CMD ["npm", "run", "production"]

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@
242242
"dev": "NODE_ENV=development node ./build/src/index.js",
243243
"production": "NODE_ENV=production node ./build/src/index.js",
244244
"start:docker:server": "npm run db:migrate:run:production && npm run production",
245+
"start:docker:migrate": "npm run db:migrate:run:production",
245246
"start:docker:locally": "npm run db:migrate:run:local && npm run dev",
246247
"postinstall": "patch-package"
247248
},

0 commit comments

Comments
 (0)