This commit is contained in:
2026-02-24 18:47:27 -06:00
parent db9b722929
commit d531e1ca83
5 changed files with 81 additions and 2 deletions
+6
View File
@@ -0,0 +1,6 @@
{
"action": "created",
"release": {
"tag_name": "v0.0.0-test"
}
}
+39 -1
View File
@@ -26,12 +26,50 @@ jobs:
uses: docker/build-push-action@v6 uses: docker/build-push-action@v6
with: with:
push: true push: true
target: runtime
tags: | tags: |
ghcr.io/project-optima/ttscm-api:latest ghcr.io/project-optima/ttscm-api:latest
ghcr.io/project-optima/ttscm-api:${{ github.event.release.tag_name }} ghcr.io/project-optima/ttscm-api:${{ github.event.release.tag_name }}
- name: Build and push the migration image
uses: docker/build-push-action@v6
with:
push: true
target: migration
tags: |
ghcr.io/project-optima/ttscm-api-migrate:latest
ghcr.io/project-optima/ttscm-api-migrate:${{ github.event.release.tag_name }}
migrate:
name: Run Migrations
needs: [build]
runs-on: ubuntu-latest
steps:
- name: Set the Kubernetes context
uses: azure/k8s-set-context@v2
with:
method: kubeconfig
kubeconfig: ${{ secrets.KUBECONFIG }}
- name: Checkout source code
uses: actions/checkout@v4
- name: Delete previous migration job if exists
run: kubectl delete job -n optima -l app=prisma-migrate --ignore-not-found
- name: Apply migration job
run: |
TAG=${{ github.event.release.tag_name }}
sed "s/RELEASE_TAG/${TAG}/g" kubernetes/migration-job.yaml | kubectl apply -f -
- name: Wait for migration to complete
run: |
TAG=${{ github.event.release.tag_name }}
kubectl wait --for=condition=complete --timeout=120s -n optima job/prisma-migrate-${TAG}
deploy: deploy:
name: Deploy name: Deploy
needs: [build] needs: [migrate]
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Set the Kubernetes context - name: Set the Kubernetes context
+13
View File
@@ -55,3 +55,16 @@ ENV NODE_ENV=production
EXPOSE 3000 EXPOSE 3000
CMD ["./server"] CMD ["./server"]
# ---- Stage 4: Migration runner ----
FROM oven/bun:1 AS migration
WORKDIR /app
COPY package.json bun.lock ./
RUN bun install --frozen-lockfile
COPY prisma/ prisma/
COPY prisma.config.ts ./
CMD ["bunx", "prisma", "migrate", "deploy"]
+21
View File
@@ -0,0 +1,21 @@
apiVersion: batch/v1
kind: Job
metadata:
name: prisma-migrate-RELEASE_TAG
namespace: optima
labels:
app: prisma-migrate
spec:
backoffLimit: 3
ttlSecondsAfterFinished: 300
template:
spec:
containers:
- name: migrate
image: ghcr.io/project-optima/ttscm-api-migrate:RELEASE_TAG
envFrom:
- secretRef:
name: optima-api-env
restartPolicy: Never
imagePullSecrets:
- name: github-container-registry
+1
View File
@@ -21,6 +21,7 @@
"dev": "NODE_ENV=development bun --watch src/index.ts", "dev": "NODE_ENV=development bun --watch src/index.ts",
"db:gen": "prisma generate", "db:gen": "prisma generate",
"db:push": "prisma migrate dev --skip-generate", "db:push": "prisma migrate dev --skip-generate",
"db:deploy": "prisma migrate deploy",
"utils:dev": "docker compose -f .docker/docker-compose.yml up --build", "utils:dev": "docker compose -f .docker/docker-compose.yml up --build",
"utils:gen_private_keys": "bun ./utils/genPrivateKeys", "utils:gen_private_keys": "bun ./utils/genPrivateKeys",
"utils:create_admin_role": "bun ./utils/createAdminRole", "utils:create_admin_role": "bun ./utils/createAdminRole",