Skip to content

randome quote for a single day #33

randome quote for a single day

randome quote for a single day #33

Workflow file for this run

name: Deploy to Vultr
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up SSH
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.VULTR_SSH_PRIVATE_KEY }}
- name: Verify SSH connection
run: ssh -o StrictHostKeyChecking=no root@${{ secrets.VULTR_IP }} "echo 'SSH connection successful'"
# Git clone instead of SCP
- name: Deploy code to Vultr
run: ssh -o StrictHostKeyChecking=no root@${{ secrets.VULTR_IP }} "cd /root/deploy/happiness-backend && git pull || git clone [email protected]:WAI-laboratory/happiness-backend.git /root/deploy/happiness-backend"
# Add a step to install dependencies and build the project
- name: Install dependencies and build project
run: |
npm install
npm run build
- name: Build and run Docker container
run: |
ssh -o StrictHostKeyChecking=no root@${{ secrets.VULTR_IP }} "
# Build the image from the source code
docker build -t happiness-backend-image /root/deploy/happiness-backend;
# Stop the running container if it exists
CONTAINER_ID=\$(docker ps -q -f name=happiness-backend);
if [ ! -z \"\$CONTAINER_ID\" ]; then
docker container stop \$CONTAINER_ID;
fi;
# Remove the stopped container if it exists
CONTAINER_ID=\$(docker ps -a -q -f name=happiness-backend);
if [ ! -z \"\$CONTAINER_ID\" ]; then
docker container rm \$CONTAINER_ID;
fi;
# Run the newly built image
docker container run -d -p 3010:3010 --name happiness-backend --network app-network happiness-backend-image;
"