Skip to content

Commit c47b13c

Browse files
committed
feat: Implement base project structure for mini-workflow-engine, comprising a Next.js frontend, Node.js backend, Prisma ORM, and Docker/GCP deployment configurations.
1 parent b5e2ecc commit c47b13c

31 files changed

+9212
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Deploy to GCP
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
env:
9+
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
10+
REGION: asia-south1
11+
BACKEND_REPO: backend-repo
12+
FRONTEND_REPO: frontend-repo
13+
14+
jobs:
15+
deploy:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: "read"
19+
id-token: "write"
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
25+
- name: Google Auth
26+
uses: google-github-actions/auth@v2
27+
with:
28+
credentials_json: "${{ secrets.GCP_CREDENTIALS }}"
29+
30+
- name: Set up Cloud SDK
31+
uses: google-github-actions/setup-gcloud@v2
32+
33+
- name: Configure Docker
34+
run: gcloud auth configure-docker asia-south1-docker.pkg.dev
35+
36+
# Backend Build & Deploy
37+
- name: Build Backend Info
38+
id: backend-meta
39+
run: echo "TAG=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
40+
41+
- name: Build and Push Backend
42+
uses: docker/build-push-action@v5
43+
with:
44+
context: ./backend
45+
push: true
46+
tags: asia-south1-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.BACKEND_REPO }}/backend:${{ steps.backend-meta.outputs.TAG }}
47+
48+
- name: Deploy Backend
49+
uses: google-github-actions/deploy-cloudrun@v2
50+
with:
51+
service: workflow-backend
52+
image: asia-south1-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.BACKEND_REPO }}/backend:${{ steps.backend-meta.outputs.TAG }}
53+
region: ${{ env.REGION }}
54+
flags: --add-cloudsql-instances=${{ env.PROJECT_ID }}:${{ env.REGION }}:workflow-db
55+
env_vars: |
56+
DATABASE_URL=${{ secrets.DATABASE_URL }}
57+
NODE_ENV=production
58+
59+
# Frontend Build & Deploy
60+
- name: Build and Push Frontend
61+
uses: docker/build-push-action@v5
62+
with:
63+
context: ./frontend
64+
push: true
65+
build-args: |
66+
NEXT_PUBLIC_API_URL=https://workflow-backend-pw42423.a.run.app
67+
# Note: You need to replace the URL above after first deployment or use runtime env injection
68+
tags: asia-south1-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.FRONTEND_REPO }}/frontend:${{ steps.backend-meta.outputs.TAG }}
69+
70+
- name: Deploy Frontend
71+
uses: google-github-actions/deploy-cloudrun@v2
72+
with:
73+
service: workflow-frontend
74+
image: asia-south1-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.FRONTEND_REPO }}/frontend:${{ steps.backend-meta.outputs.TAG }}
75+
region: ${{ env.REGION }}

backend/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
# Keep environment variables out of version control
3+
.env
4+
5+
/src/generated/prisma

backend/Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM node:18-alpine AS builder
2+
WORKDIR /app
3+
COPY package*.json ./
4+
RUN npm ci
5+
COPY . .
6+
RUN npx prisma generate
7+
RUN npm run build
8+
RUN npm prune --production
9+
10+
FROM node:18-alpine AS runner
11+
WORKDIR /app
12+
ENV NODE_ENV=production
13+
COPY --from=builder /app/node_modules ./node_modules
14+
COPY --from=builder /app/dist ./dist
15+
COPY --from=builder /app/package.json ./package.json
16+
COPY --from=builder /app/prisma ./prisma
17+
18+
EXPOSE 4000
19+
CMD ["sh", "-c", "npx prisma migrate deploy && npm start"]

0 commit comments

Comments
 (0)