Skip to content

Commit

Permalink
Merge pull request #206 from rcpch/dockerise
Browse files Browse the repository at this point in the history
Dockerise
  • Loading branch information
eatyourpeas authored Mar 19, 2024
2 parents 807a4bc + ef9f23e commit 4c2f306
Show file tree
Hide file tree
Showing 28 changed files with 16,340 additions and 744 deletions.
31 changes: 20 additions & 11 deletions .github/workflows/all-branches-and-PRs-test.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@

name: Run tests for all new pushes and PRs (when opened or edited)
name: Run Pytest on pushes to main branches or PRs to any branch

on:
push:
pull_request:
types: [opened, edited]

branches:
- "*"
push:
branches:
- development
- staging
- live

jobs:
run-pytest:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@master
- uses: actions/checkout@v4 # latest as at February 2024

- name: Set up Python version
uses: actions/setup-python@v1
- name: Set up Python version ${{ matrix.python-version }}
uses: actions/setup-python@v5 # latest as at March 2024
with:
python-version: "3.8.x"
python-version: ${{ matrix.python-version }}

- name: Display Python version
run: python -c "import sys; print(sys.version)"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements/test-requirements.txt
pip install -r requirements/development-requirements.txt
- name: Run pytest
run: |
pytest --no-header -vv
pytest --no-header -vv
69 changes: 69 additions & 0 deletions .github/workflows/staging_rcpch-dgc-server-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions
# More info on Python, GitHub Actions, and Azure App Service: https://aka.ms/python-webapps-actions

name: Build and deploy Python app to Azure Web App - rcpch-dgc-server-staging

on:
push:
branches:
- staging
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4 # latest as at March 2024

- name: Set up Python version
uses: actions/setup-python@v5 # latest as at March 2024
with:
python-version: '3.12'

- name: Create and start virtual environment
run: |
python -m venv venv
source venv/bin/activate
- name: Install dependencies
run: pip install -r requirements.txt

# Optional: Add step to run tests here (PyTest, Django test suites, etc.)

- name: Zip artifact for deployment
run: zip release.zip ./* -r

- name: Upload artifact for deployment jobs
uses: actions/upload-artifact@v4 # latest as at March 2024
with:
name: python-app
path: |
release.zip
!venv/
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

steps:
- name: Download artifact from build job
uses: actions/download-artifact@v4 # latest as at March 2024
with:
name: python-app

- name: Unzip artifact for deployment
run: unzip release.zip


- name: 'Deploy to Azure Web App'
uses: azure/webapps-deploy@v3 # latest as at March 2024
id: deploy-to-webapp
with:
app-name: 'rcpch-dgc-server-staging'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_20EF65F771AA44219C3529732124EFCE }}
14 changes: 8 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
FROM python:3.8-buster
FROM python:3.12-bookworm

RUN apt-get update -y
COPY requirements/common-requirements.txt .

WORKDIR /app
COPY requirements/development-requirements.txt .

COPY . /app
RUN pip install -r development-requirements.txt

EXPOSE 8000

RUN pip install -r requirements.txt
WORKDIR /app

COPY . /app

CMD [ "uvicorn" "main:app" "--reload" ]
CMD ["uvicorn", "main:app", "--reload", "--host", "0.0.0.0", "--port", "8000"]
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# NOTE The below is the Docker Compose specification version NOT the Python version:
version: "3.8"

services:
growth-api:
build: .
volumes:
- .:/app
ports:
- "8000:8000"
1 change: 0 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.openapi.utils import get_openapi
from pydantic import BaseSettings

# local / rcpch imports
from rcpchgrowth import chart_functions, constants
Expand Down
Loading

0 comments on commit 4c2f306

Please sign in to comment.