- Start a VM
- Install docker on the machine - https://docs.vultr.com/how-to-install-docker-on-ubuntu-24-04?ref=9141994&utm_source=performance-max-apac&utm_medium=paidmedia&obility_id=16876059738&&utm_campaign=APAC_-_India_-_Performance_Max_-_1001&utm_term=&utm_content=&ref=9141994&gad_source=1&gclid=CjwKCAiAtsa9BhAKEiwAUZAszSjSQLJrr8cY3CDDgj1g178tdSyBtQW9dyHnv_g5W86oCYteD68zMhoC45MQAvD_BwE
- Get a DB from neon.tech, migrate the DB
- Run the image
docker run -p 8080:8080 -e DATABASE_URL=your_db_url your_repo
- Add the final step in the cd pipeline
name: Continuous Deployment (Prod) (Backend)
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
file: ./docker/Dockerfile.backend
push: true
tags: 100xdevs/user-app-backend:${{ github.sha }}
- run: |
echo "${{ secrets.SSH_PRIVATE_KEY }}" &> ~/ssh_key
mkdir -p /home/runner/.ssh
ls /home/runner/.ssh
touch /home/runner/.ssh/known_hosts
echo "${{ secrets.KNOWN_HOSTS }}" &> /home/runner/.ssh/known_hosts
chmod 700 /home/runner/ssh_key
ssh -o StrictHostKeyChecking=no -i ~/ssh_key [email protected] -t "docker stop user_backend && docker run --name user_backend -d -p 8080:8080 100xdevs/user-app-backend:${{ github.sha }}"