Skip to content

Commit 482b46c

Browse files
committed
refactor: update backend deployment workflow for DigitalOcean
1 parent 515480e commit 482b46c

File tree

2 files changed

+29
-38
lines changed

2 files changed

+29
-38
lines changed

.github/workflows/backend-deploy-do.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ on:
1313
- 'pnpm-lock.yaml'
1414
- '.github/workflows/backend-deploy.yml'
1515
- 'Docker/Dockerfile.api'
16-
workflow_dispatch:
16+
workflow_dispatch: # Allow manual triggering
1717

1818
jobs:
1919
deploy:
Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
name: Deploy Backend to Production (AWS EC2)
1+
# This workflow deploys the backend application to a DigitalOcean Droplet.
2+
# It builds a simple Docker image (without PM2) and runs it on the server.
3+
4+
name: Deploy Backend to Production (DigitalOcean - Simple)
25

36
on:
4-
# push:
5-
# branches:
6-
# - main
7-
# paths:
8-
# - 'apps/api/**'
9-
# - 'packages/**'
10-
# - 'pnpm-lock.yaml'
11-
# - '.github/workflows/backend-deploy.yml'
12-
# - 'Docker/Dockerfile.api'
7+
push:
8+
branches:
9+
- main
10+
paths:
11+
- 'apps/api/**'
12+
- 'packages/**'
13+
- 'pnpm-lock.yaml'
14+
- '.github/workflows/backend-deploy.yml'
15+
- 'Docker/Dockerfile.api'
1316
workflow_dispatch: # Allow manual triggering
1417

1518
jobs:
1619
deploy:
17-
name: Build and Deploy Backend to AWS EC2
20+
name: Build and Deploy Backend to DigitalOcean Droplet
1821
runs-on: ubuntu-latest
1922

2023
steps:
@@ -34,45 +37,33 @@ jobs:
3437
uses: docker/build-push-action@v5
3538
with:
3639
context: .
40+
# This should point to your simplified Dockerfile
3741
file: ./Docker/Dockerfile.api
3842
push: true
3943
tags: |
4044
${{ secrets.DOCKER_USERNAME }}/simcasino-api:latest
4145
${{ secrets.DOCKER_USERNAME }}/simcasino-api:${{ github.sha }}
4246
43-
- name: Deploy to AWS EC2
47+
- name: Deploy to DigitalOcean Droplet
4448
uses: appleboy/ssh-action@v1.0.3
4549
with:
46-
host: ${{ secrets.SSH_HOST }}
47-
username: ${{ secrets.SSH_USERNAME }}
48-
key: ${{ secrets.SSH_KEY }}
50+
host: ${{ secrets.DO_SSH_HOST }}
51+
username: ${{ secrets.DO_SSH_USERNAME }}
52+
key: ${{ secrets.DO_SSH_KEY }}
4953
script: |
50-
# Pull the latest Docker image from Docker Hub
54+
set -e
55+
echo "🚀 Starting simple deployment on the server..."
56+
57+
# 1. Pull the latest image
58+
echo "1/3: Pulling latest Docker image..."
5159
docker pull ${{ secrets.DOCKER_USERNAME }}/simcasino-api:latest
5260
53-
# Stop and remove the existing container to prevent conflicts
54-
# '|| true' ensures the script doesn't fail if the container doesn't exist
61+
# 2. Stop and remove the existing container
62+
echo "2/3: Stopping and removing existing container..."
5563
docker stop simcasino-api || true
5664
docker rm simcasino-api || true
5765
58-
# Run the new container with environment variables from GitHub Secrets
66+
# 3. Run the new container
67+
echo "3/3: Starting new container..."
5968
docker run -d \
6069
--name simcasino-api \
61-
--restart always \
62-
-p 5000:5000 \
63-
-e NODE_ENV=production \
64-
-e DATABASE_URL="${{ secrets.DATABASE_URL }}" \
65-
-e COOKIE_SECRET="${{ secrets.COOKIE_SECRET }}" \
66-
-e CORS_ORIGIN="${{ secrets.CORS_ORIGIN }}" \
67-
-e GOOGLE_CLIENT_ID="${{ secrets.GOOGLE_CLIENT_ID }}" \
68-
-e GOOGLE_CLIENT_SECRET="${{ secrets.GOOGLE_CLIENT_SECRET }}" \
69-
-e CLIENT_URL="${{ secrets.CLIENT_URL }}" \
70-
-e REDIRECT_URL="${{ secrets.REDIRECT_URL }}" \
71-
${{ secrets.DOCKER_USERNAME }}/simcasino-api:latest
72-
73-
- name: Deployment Notification
74-
if: success()
75-
run: |
76-
echo "✅ Backend successfully deployed to AWS EC2."
77-
echo " Commit: ${{ github.sha }}"
78-
echo " Image Tag: ${{ secrets.DOCKER_USERNAME }}/simcasino-api:${{ github.sha }}"

0 commit comments

Comments
 (0)