-
Notifications
You must be signed in to change notification settings - Fork 0
51 lines (42 loc) · 1.54 KB
/
deployBackend.yml
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
name: Deploy Backend to Docker Hub and DigitalOcean
on:
push:
branches:
- main
- backend
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20.11.1'
- name: Build Docker image
run: |
docker build -t portfolio-backend-app -f Dockerfile .
- name: Log in to Docker Hub
env:
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
run: |
echo "$DOCKER_HUB_ACCESS_TOKEN" | docker login --username "$DOCKER_HUB_USERNAME" --password-stdin
- name: Tag Docker image
run: |
docker tag portfolio-backend-app:latest amarjha01/portfoliopioneer:latest
- name: Push Docker image to Docker Hub
run: |
docker push amarjha01/portfoliopioneer:latest
- name: Deploy to DigitalOcean Droplet
uses: appleboy/[email protected]
with:
host: ${{ secrets.DIGITALOCEAN_IP }}
username: ${{ secrets.DIGITALOCEAN_SSH_USER }}
key: ${{ secrets.DIGITALOCEAN_SSH_KEY }}
script: |
docker pull amarjha01/portfoliopioneer:latest
docker stop portfolio-backend-container || true
docker rm portfolio-backend-container || true
docker run -d --name portfolio-backend-container -p 80:5000 amarjha01/portfoliopioneer:latest