Skip to content

Commit ec0c754

Browse files
committed
chore: add CI/CD workflows and Docker support for frontend & WebSocket
1 parent 7f846a7 commit ec0c754

File tree

10 files changed

+477
-721
lines changed

10 files changed

+477
-721
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.github/workflows/cd_frontend.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Deploy the frontend
2+
on:
3+
push:
4+
branches: [main]
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout the code
10+
uses: actions/checkout@v2
11+
12+
- name: Docker login
13+
uses: docker/login-action@v2
14+
with:
15+
username: ${{ secrets.DOCKER_USERNAME }}
16+
password: ${{ secrets.DOCKER_PASSWORD }}
17+
18+
- name: Build and push
19+
uses: docker/build-push-action@v4
20+
with:
21+
context: .
22+
file: ./docker/Dockerfile.frontend
23+
build-args:
24+
- DATABASE_URL=${{ secrets.DATABASE_URL }}
25+
push: true
26+
tags: coderomm/collabydraw:${{ github.sha }}
27+
## Step to deploy this to a VM

.github/workflows/cd_ws.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Deploy the websocket server
2+
on:
3+
push:
4+
branches: [main]
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout the code
10+
uses: actions/checkout@v2
11+
12+
- name: Docker login
13+
uses: docker/login-action@v2
14+
with:
15+
username: ${{ secrets.DOCKER_USERNAME }}
16+
password: ${{ secrets.DOCKER_PASSWORD }}
17+
18+
- name: Build and push
19+
uses: docker/build-push-action@v4
20+
with:
21+
context: .
22+
file: ./docker/Dockerfile.websocket
23+
push: true
24+
tags: coderomm/collabydraw-websocket:${{ github.sha }}
25+
- name: Deploy to the VM
26+
run: |
27+
echo "${{ secrets.SSH_PRIVATE_KEY }}" &> ~/ssh_key
28+
chmod 700 /home/runner/ssh_key
29+
ssh -o StrictHostKeyChecking=no -i ~/ssh_key [email protected] -t "docker stop user_backend && docker run --name user_backend -d -p 8080:8080 coderomm/collabydraw-websocket:${{ github.sha }}"

apps/ws/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"dev": "pnpm run build && pnpm run start"
99
},
1010
"devDependencies": {
11-
"@repo/backend-common": "workspace:*",
1211
"@repo/common": "workspace:*",
1312
"@repo/db": "workspace:*",
1413
"@repo/typescript-config": "workspace:*",

docker-compose.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# docker-compose.yml
2+
version: '3.8'
3+
4+
services:
5+
frontend:
6+
build:
7+
context: ./apps/collabydraw
8+
dockerfile: Dockerfile
9+
ports:
10+
- "3000:3000"
11+
environment:
12+
- NODE_ENV=production
13+
depends_on:
14+
- websocket
15+
- database
16+
17+
websocket:
18+
build:
19+
context: ./apps/ws
20+
dockerfile: Dockerfile
21+
ports:
22+
- "8080:8080"
23+
environment:
24+
- NODE_ENV=production
25+
depends_on:
26+
- database
27+
28+
database:
29+
image: postgres:13-alpine
30+
environment:
31+
POSTGRES_DB: collabydraw
32+
POSTGRES_PASSWORD: your_secure_password
33+
volumes:
34+
- postgres-data:/var/lib/postgresql/data
35+
ports:
36+
- "5432:5432"
37+
38+
volumes:
39+
postgres-data:

docker/Dockerfile.frontend

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
FROM node:20-alpine AS base
2+
3+
# Install pnpm
4+
RUN npm install -g pnpm
5+
6+
WORKDIR /usr/src/app
7+
8+
# Add ARG for DATABASE_URL
9+
ARG DATABASE_URL
10+
ENV DATABASE_URL=${DATABASE_URL}
11+
12+
# Copy necessary files for dependency installation
13+
COPY ./packages ./packages
14+
COPY ./package.json ./package.json
15+
COPY ./pnpm-lock.yaml ./pnpm-lock.yaml
16+
COPY ./turbo.json ./turbo.json
17+
COPY ./apps/frontend ./apps/frontend
18+
19+
# Install dependencies
20+
RUN pnpm install --frozen-lockfile
21+
22+
# Generate database
23+
# add this "db:generate": "cd packages/db && bunx prisma generate && cd ../..",
24+
RUN pnpm run db:generate
25+
26+
# Build the application with database URL
27+
RUN DATABASE_URL=${DATABASE_URL} pnpm run build
28+
29+
# Expose the port
30+
EXPOSE 3000
31+
32+
# Start the web application
33+
CMD ["pnpm", "run", "start:web"]

docker/Dockerfile.websocket

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM node:20-alpine AS base
2+
3+
# Install pnpm
4+
RUN npm install -g pnpm
5+
6+
WORKDIR /usr/src/app
7+
8+
# Copy necessary files for dependency installation
9+
COPY ./packages ./packages
10+
COPY ./package.json ./package.json
11+
COPY ./pnpm-lock.yaml ./pnpm-lock.yaml
12+
COPY ./turbo.json ./turbo.json
13+
COPY ./apps/ws ./apps/ws
14+
15+
# Install dependencies
16+
RUN pnpm install --frozen-lockfile
17+
18+
# Generate database (assuming you have a db:generate script)
19+
RUN pnpm run db:generate
20+
21+
# Expose the port
22+
EXPOSE 8081
23+
24+
# Start the ws service
25+
CMD ["pnpm", "run", "start:ws"]

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
"build": "turbo build",
66
"dev": "turbo dev",
77
"lint": "turbo lint",
8-
"format": "prettier --write \"**/*.{ts,tsx,md}\""
8+
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
9+
"db:generate": "cd packages/db && prisma generate && cd ../..",
10+
"start:collabydraw": "cd apps/collabydraw && pnpm run start",
11+
"start:ws": "cd apps/ws && pnpm run build"
912
},
1013
"devDependencies": {
1114
"prettier": "^3.5.0",

packages/db/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"devDependencies": {
1717
"@repo/typescript-config": "workspace:*",
1818
"@types/node": "^22.13.1",
19-
"prisma": "^6.3.1"
19+
"prisma": "^6.5.0"
2020
},
2121
"dependencies": {
2222
"@prisma/client": "6.3.1"

0 commit comments

Comments
 (0)