backend file updated #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |