Skip to content

Deploy to Dev

Deploy to Dev #267

Workflow file for this run

name: Deploy to Dev
on:
workflow_run:
workflows: [CI]
types:
- completed
branches: [dev]
jobs:
on-success:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
# - name: Fetch .env file from server
# uses: appleboy/scp-action@master
# with:
# host: ${{ secrets.HOST }}
# username: ${{ secrets.USERNAME }}
# password: ${{ secrets.PASSWORD }}
# source: "/var/www/aihomework/dev/.env"
# target: ".env"
- name: Install sshpass
run: sudo apt-get install sshpass
- name: Fetch .env file from server
run: |
sshpass -p ${{ secrets.PASSWORD }} scp -o StrictHostKeyChecking=no ${{ secrets.USERNAME }}@${{ secrets.HOST }}:/var/www/aihomework/dev/.env .env
env:
SSH_HOST: ${{ secrets.HOST }}
SSH_USERNAME: ${{ secrets.USERNAME }}
SSH_PASSWORD: ${{ secrets.PASSWORD }}
- name: Build Docker images
run: |
docker compose --env-file .env -f docker-compose.yml build
- name: List Docker images
run: docker images
- name: Save Docker images to tarball
run: |
docker save hng_boilerplate_expressjs-backend:latest | gzip > dev-images.tar.gz
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: dev-images
path: dev-images.tar.gz
- name: Copy Docker images to server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
source: "dev-images.tar.gz"
target: "~/images-tar"
- name: Deploy to server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
script: |
cd ~/dev-deployment/hng_boilerplate_expressjs
git stash
git checkout dev
git pull
docker load -i ~/images-tar/dev-images.tar.gz
docker compose -f docker-compose.yml down
docker compose -f docker-compose.yml up -d
on-failure:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
- run: echo "CI Workflow failed. Dev deployment was not triggered."