Skip to content

Commit

Permalink
chore: re-write workflow + docker deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
Angel-Dijoux committed Nov 3, 2023
1 parent 9f748b6 commit a5f228e
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 31 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/deploy_database_production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: deploy_database_production
concurrency: deploy_database_production

on:
workflow_dispatch:
workflow_call:
secrets:
DATABASE_USERNAME:
required: true
DATABASE_PASSWORD:
required: true

jobs:
upgrade:
runs-on: self-hosted
steps:
- uses: actions/checkout@v3
- name: Upgrade database
run: docker-compose up -d backend_upgrade
- name: Stop container
run: docker-compose stop -d backend_upgrade
- name: Remove image
run: docker rmi elki_97413/onisep_backend_update:latest
env:
DATABASE_USERNAME: ${{ secrets.DATABASE_USERNAME }}
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }}
38 changes: 28 additions & 10 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Deployment
name: Deployments

on:
workflow_dispatch:
workflow_call:
push:
branches:
Expand All @@ -19,17 +20,34 @@ env:
ONISEP_APP_ID: ${{ secrets.ONISEP_APP_ID }}

jobs:
build:
deploy-datatabse:
uses: ./.github/workflows/deploy_database_production.yml
secrets: inherit
deploy-api:
runs-on: self-hosted

steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Stop running Docker container
run: docker stop api
- name: remove container
run: docker rm api
- name: Remove previous Docker image
run: docker rmi onisep_api-api:latest
- name: Build and Run Docker container
run: docker-compose up -d

- name: Check if container exists
id: check-container
run: |
if docker ps -a | grep -q 'onisep-api'; then
echo "Container onisep api exists"
echo "::set-output name=container_exists::true"
else
echo "Container onisep api does not exist"
echo "::set-output name=container_exists::false"
fi
- name: Stop and Remove Old Container
if: steps.check-container.outputs.container_exists == 'true'
run: docker-compose stop onisep-api && docker-compose rm -f onisep-api

- name: Remove Old Image
if: steps.check-container.outputs.container_exists == 'true'
run: docker rmi elki_97413/onisep:latest

- name: Build Docker image and Start New Container
run: docker-compose up -d onisep-api
10 changes: 9 additions & 1 deletion .github/workflows/flake8.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: flake8 Lint
name: flake8 & ruff linter

on: [push]

Expand All @@ -17,3 +17,11 @@ jobs:
uses: py-actions/flake8@v2
with:
args: "--config=./.flake8"
ruff-check:
runs-on: ubuntu-latest
name: check
steps:
- uses: actions/checkout@v3
- uses: chartboost/ruff-action@v1
with:
args: "--config=./pyproject.toml"
19 changes: 19 additions & 0 deletions Dockerfile.database
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM python:slim-buster AS build
ENV PYTHONUNBUFFERED 1

LABEL authors="Angel-Dijoux"

WORKDIR /app

ENV JWT_SECRET_KEY=UNUSED
ENV ENV=production
ENV FLASK_APP=src


COPY requirements.txt Pipfile Pipfile.lock ./

RUN pip install --user --no-cache-dir pipenv

COPY . .

ENV PATH="${PATH}:/root/.local/bin"
4 changes: 0 additions & 4 deletions Dockerfile → Dockerfile.prod
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ RUN pip install --no-cache-dir -r requirements.txt

COPY . .

COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

EXPOSE 5005

CMD ["gunicorn", "run:app" ,"-c" ,"gunicorn.conf.py" ]
30 changes: 26 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ services:
- 8484:80
depends_on:
- db

api:
onisep-api:
image: elki_97413/onisep:latest
build:
context: .
dockerfile: Dockerfile
dockerfile: Dockerfile.prod
container_name: onisep-api
restart: always
ports:
- 5005:5005
Expand All @@ -39,7 +40,28 @@ services:
DATABASE_USERNAME: ${DATABASE_USERNAME}
DATABASE_PASSWORD: ${DATABASE_PASSWORD}
DATABASE_HOST: db
container_name: api
ONISEP_EMAIL: ${ONISEP_EMAIL}
ONISEP_PASSWORD: ${ONISEP_PASSWORD}
ONISEP_APP_ID: ${ONISEP_APP_ID}
backend_upgrade:
image: elki_97413/onisep_backend_update:latest
build:
context: .
dockerfile: Dockerfile.database
environment:
DATABASE_HOST: db
DATABASE_USERNAME: ${DATABASE_USERNAME}
DATABASE_PASSWORD: ${DATABASE_PASSWORD}
depends_on:
- db
command:
- /bin/sh
- -c
- |
pipenv install --deploy --ignore-pipfile
echo "------- Dependencies installed -------"
pipenv run flask db upgrade
echo "------- Database upgraded -------"
volumes:
db:
12 changes: 0 additions & 12 deletions entrypoint.sh

This file was deleted.

0 comments on commit a5f228e

Please sign in to comment.