Skip to content

Deploy to Prod

Deploy to Prod #12

Workflow file for this run

name: Deploy to Prod
on:
workflow_dispatch:
inputs:
api_version:
description: 'api version for docker image'
required: true
type: string
web_version:
description: 'web version for docker image'
required: true
type: string
push:
branches:
- 'ops/deployment-pipeline'
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install SSH client
run: sudo apt-get install -y openssh-client
- name: Shutdown running containers
env:
SSH_KEY: ${{ secrets.SSH_KEY }}
HOST: ${{ secrets.HOST }}
USERNAME: ${{ secrets.USERNAME }}
run: |
echo "$SSH_KEY" > private_key
chmod 600 private_key
ssh -i private_key -o StrictHostKeyChecking=no $USERNAME@$HOST << 'EOF'
cd /home/thor/apps/bookstore-app
docker compose -f docker-compose-prod.yml down
if [ -f docker-compose-prod.yml ]; then
rm docker-compose-prod.yml
fi
exit
EOF
- name: Copy docker-compose-prod.yml to server
env:
SSH_KEY: ${{ secrets.SSH_KEY }}
HOST: ${{ secrets.HOST }}
USERNAME: ${{ secrets.USERNAME }}
run: |
scp -i private_key -o StrictHostKeyChecking=no docker-compose-prod.yml $USERNAME@$HOST:/home/thor/apps/bookstore-app/
scp -i private_key -o StrictHostKeyChecking=no ./app/manage.py $USERNAME@$HOST:/home/thor/apps/bookstore-app/
- name: Start up containers
env:
SSH_KEY: ${{ secrets.SSH_KEY }}
HOST: ${{ secrets.HOST }}
USERNAME: ${{ secrets.USERNAME }}
run: |
ssh -i private_key -o StrictHostKeyChecking=no $USERNAME@$HOST << 'EOF'
cd /home/thor/apps/bookstore-app
docker compose -f docker-compose-prod.yml up -d
exit
EOF