-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* create prod compose file * create pipeline for containers deployment * add api & web version input for pipeline
- Loading branch information
Showing
4 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
.github/workflows/python-app.yml → .github/workflows/book-api.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters