-
Notifications
You must be signed in to change notification settings - Fork 0
64 lines (51 loc) · 2.05 KB
/
Copy pathcd_frontend.yml
File metadata and controls
64 lines (51 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
name: Deploy Frontend
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
file: ./apps/excalidraw-frontend/Dockerfile
build-args: |
DATABASE_URL=${{ secrets.DATABASE_URL }}
NEXT_PUBLIC_BACKEND_URL=${{ secrets.NEXT_PUBLIC_BACKEND_URL }}
NEXT_PUBLIC_WS_URL=${{ secrets.NEXT_PUBLIC_WS_URL }}
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/frontend:${{ github.sha }}
- name: Deploy to VM
run: |
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/ssh_key
chmod 600 ~/ssh_key
ssh -o StrictHostKeyChecking=no -i ~/ssh_key ubuntu@13.234.30.94 << 'EOF'
echo "Pulling latest image..."
docker pull adarsh9770/frontend:${{ github.sha }}
echo "Stopping old container..."
docker rm -f frontend 2>/dev/null || true
echo "Starting new container..."
docker run -d --name frontend -p 3000:3000 \
-e DATABASE_URL=${{ secrets.DATABASE_URL }} \
-e NEXT_PUBLIC_BACKEND_URL=${{ secrets.NEXT_PUBLIC_BACKEND_URL }} \
-e NEXT_PUBLIC_WS_URL=${{ secrets.NEXT_PUBLIC_WS_URL }} \
-e EMAIL_USER=${{ secrets.EMAIL_USER }} \
-e EMAIL_PASSWORD=${{ secrets.EMAIL_PASSWORD }} \
-e NEXT_PUBLIC_FRONTEND_URL=${{ secrets.NEXT_PUBLIC_FRONTEND_URL }} \
adarsh9770/frontend:${{ github.sha }}
echo "Cleaning dangling images..."
docker image prune -f
docker ps
EOF