Skip to content

Commit

Permalink
chore: deployment pipeline for PROD
Browse files Browse the repository at this point in the history
* create prod compose file
* create pipeline for containers deployment
* add api & web version input for pipeline
  • Loading branch information
abu271 authored Dec 26, 2024
1 parent 4b1122d commit e4d0906
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python application
name: Django Book API

on:
push:
Expand Down
68 changes: 68 additions & 0 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
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
36 changes: 36 additions & 0 deletions docker-compose-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
services:
web:
image: devchem/octo:bookstore_v{{web_version}}
ports:
- "3004:3004"
environment:
- VITE_BOOK_API_URL=http://localhost:8000

api:
image: devchem/octo:bookapi_v{{api_version}}
ports:
- "8000:8000"
command: >
sh -c "python manage.py migrate &&
python manage.py runserver 0.0.0.0:8000"
environment:
- DB_HOST=${DB_HOST}
- DB_NAME=${DB_NAME}
- DB_USER=${DB_USER}
- DB_PASSWORD=${DB_PASSWORD}
- DJANGO_SECRET_KEY=${DJANGO_SECRET_KEY}
depends_on:
- db
user: "user" # Run the app service as the non-root user

db:
image: postgres:13-alpine
environment:
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
volumes:
- postgres_data:/var/lib/postgresql/data/

volumes:
postgres_data:
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ services:
image: devchem/octo:bookapi_v1.0.0
ports:
- "8000:8000"
# This volume is used for hot reloading
volumes:
- ./app:/app
command: >
Expand Down

0 comments on commit e4d0906

Please sign in to comment.