Skip to content

Commit

Permalink
Dockerise backend API (#124)
Browse files Browse the repository at this point in the history
* add new CORS origin

* add dockerfile for API

* add api

* rename api container

* add backend-api

* add backend-api docker build workflow
  • Loading branch information
lincent authored Jun 19, 2024
1 parent 9a0c6be commit 6978c25
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/backend-api-docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build and publish backend API docker image

on:
[workflow_dispatch]

jobs:
publish_image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: checkout
uses: actions/checkout@v4
- name: lowercase the repository name
run: |
echo "REPO=${GITHUB_REPOSITORY@L}" >> "${GITHUB_ENV}"
- name: login
run: |
echo ${{ secrets.GITHUB_TOKEN}} | docker login --username ${{ github.actor }} --password-stdin ghcr.io
- name: build
run: |
cd air-quality-backend
docker build . -t ghcr.io/${REPO}/vairify-backend-api:latest -f Dockerfile.api
- name: publish
run: |
docker push ghcr.io/${REPO}/vairify-backend-api:latest
17 changes: 17 additions & 0 deletions air-quality-backend/Dockerfile.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM continuumio/miniconda3

WORKDIR /usr/src/app
COPY conda/environment.yml .
RUN conda env create -f environment.yml

SHELL ["conda", "run", "-n", "air-quality-backend", "/bin/bash", "-c"]

COPY pyproject.toml .
RUN poetry install

COPY src/ ./src
COPY README.md logging.ini ./

RUN poetry install

ENTRYPOINT ["conda", "run", "--no-capture-output", "-n", "air-quality-backend", "fastapi", "run", "./src/air_quality/api/main.py"]
1 change: 1 addition & 0 deletions air-quality-backend/src/air_quality/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

origins = [
"http://localhost:5173",
"http://127.0.0.1:5173",
]

load_dotenv()
Expand Down
25 changes: 25 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,30 @@ services:
- MONGO_DB_NAME=${MONGO_DB_NAME}
- CDSAPI_URL=${CDSAPI_URL}
- CDSAPI_KEY=${CDSAPI_KEY}
api:
container_name: backend-api
depends_on:
- db
ports:
- 8000:8000
build:
context: ./air-quality-backend/
dockerfile: Dockerfile.api
environment:
- MONGO_DB_URI=mongodb://mongo:27017
- MONGO_DB_NAME=${MONGO_DB_NAME}
entrypoint:
- conda
- run
- --no-capture-output
- -n
- air-quality-backend
- fastapi
- dev
- ./src/air_quality/api/main.py
- --host
- 0.0.0.0
volumes:
- ./air-quality-backend/src/:/usr/src/app/src/
volumes:
database:
10 changes: 10 additions & 0 deletions deployment/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,15 @@ services:
- MONGO_DB_NAME=${MONGO_DB_NAME}
- CDSAPI_URL=${CDSAPI_URL}
- CDSAPI_KEY=${CDSAPI_KEY}
api:
container_name: backend-api
image: ghcr.io/ecmwfcode4earth/vairify/vairify-backend-api
depends_on:
- db
ports:
- 8000:8000
environment:
- MONGO_DB_URI=mongodb://mongo:27017
- MONGO_DB_NAME=${MONGO_DB_NAME}
volumes:
database:

0 comments on commit 6978c25

Please sign in to comment.