Skip to content

Commit

Permalink
Merge pull request #3 from h2020charisma/develop
Browse files Browse the repository at this point in the history
Promote the latest development changes to the stable branch
  • Loading branch information
kerberizer authored Feb 26, 2024
2 parents 19269e7 + a8d91c3 commit 38ed6f5
Show file tree
Hide file tree
Showing 35 changed files with 3,695 additions and 952 deletions.
1 change: 1 addition & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ jobs:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'develop') }}
type=raw,value=stable,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
Expand Down
65 changes: 65 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
on: # yamllint disable-line rule:truthy
push:
branches:
- main
- develop
pull_request:
workflow_dispatch:

env:
POETRY_VERSION: 1.7.1

jobs:

test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- '3.9'
- '3.10'
- '3.11'

steps:
- name: Checkout the repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Load the cached Poetry installation
id: cached-poetry
uses: actions/cache@v4
with:
path: ~/.local
key: poetry-${{ env.POETRY_VERSION }}-0

- name: Install Poetry
if: steps.cached-poetry.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1
with:
version: ${{ env.POETRY_VERSION }}
virtualenvs-create: true
virtualenvs-in-project: true

- name: Load the cached dependencies
id: cached-deps
uses: actions/cache@v4
with:
path: .venv
key: py${{ matrix.python-version }}-deps-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
if: steps.cache-deps.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root

- name: Perform package installation
run: poetry install --no-interaction

- name: Run tests
run: poetry run pytest
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "pynanomapper"]
path = pynanomapper
path = extern/pynanomapper
url = https://github.com/ideaconsult/pynanomapper.git
[submodule "ramanchada2"]
path = ramanchada2
path = extern/ramanchada2
url = https://github.com/h2020charisma/ramanchada2.git
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.9
3.11
21 changes: 11 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
FROM python:3.9-slim as requirements-stage
FROM python:3.11-slim as requirements-stage

WORKDIR /tmp

RUN pip install poetry

COPY ./pyproject.toml ./poetry.lock* /tmp/
COPY ./pynanomapper /tmp/pynanomapper
COPY ./ramanchada2 /tmp/ramanchada2
COPY ./extern/pynanomapper /tmp/extern/pynanomapper
COPY ./extern/ramanchada2 /tmp/extern/ramanchada2

RUN poetry export -f requirements.txt --output requirements.txt --without-hashes
RUN poetry export -f requirements.txt --output requirements.txt --without=dev --without-hashes

FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9-slim
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.11-slim

LABEL maintainer="Luchesar ILIEV <luchesar.iliev@gmail.com>" \
org.opencontainers.image.created=$BUILD_DATE \
Expand All @@ -24,15 +24,16 @@ LABEL maintainer="Luchesar ILIEV <luchesar.iliev@gmail.com>" \
org.opencontainers.image.version="latest"

COPY --from=requirements-stage /tmp/requirements.txt /app/requirements.txt
COPY ./pynanomapper /tmp/pynanomapper
COPY ./ramanchada2 /tmp/ramanchada2
COPY ./extern/pynanomapper /tmp/extern/pynanomapper
COPY ./extern/ramanchada2 /tmp/extern/ramanchada2

RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt

RUN find /tmp -mindepth 1 -delete

ENV RAMANCHADA_API_CONFIG="/app/app/config/config.yaml"
COPY ./src/rcapi /app/rcapi

COPY ./app /app/app
RUN sed -i '/^upload_dir:/s|:.*|: "/var/uploads"|' /app/rcapi/config/config.yaml

RUN sed -i '/^upload_dir:/s|:.*|: "/var/uploads"|' /app/app/config/config.yaml
ENV RAMANCHADA_API_CONFIG="/app/rcapi/config/config.yaml"
ENV MODULE_NAME="rcapi.main"
50 changes: 46 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,48 @@
# ramanchada-api

## Dev notes
A web API for the RamanChada 2 Raman spectroscopy harmonisation library, incorporating the AMBIT/eNanoMapper data model.

## Developer notes

### Installation

[Install Poetry](https://python-poetry.org/docs/#installation), then run:
```
poetry install
```

### Run development server

```
poetry run dev
```

### Work in a shell with installed package and dependencies

```
poetry shell
```

Exit with `exit` or Ctrl-D.

### Add dependency

```
poetry add <pkgname>
```

### Run tests

```
poetry run pytest
```

### Test Docker image

```
docker build -t ramanchada-api:latest .
docker run -it --rm -p 127.0.0.1:8000:80 ramanchada-api
```

### Submodule update

Expand All @@ -11,7 +53,7 @@ git commit -am "Pull the latest commit for the submodules"
git push
```

### Run interminal
### Run development server (old)
```
uvicorn src.rcapi.main:app --reload
```
uvicorn app.main:app --reload
```
58 changes: 52 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,68 @@
networks:
ramanchada_api_prod:
name: ramanchada-api-prod
ramanchada_api_dev:
name: ramanchada-api-dev

volumes:
uploads-prod:
driver: zfs
name: ${ZFSROOT}/ramanchada-api-uploads-prod
uploads-dev:
driver: zfs
name: ${ZFSROOT}/ramanchada-api-uploads-dev

services:

develop:
prod:
image: ghcr.io/h2020charisma/ramanchada-api:stable
container_name: ramanchada-api-prod
hostname: ramanchada-api-prod
restart: unless-stopped
labels:
traefik.enable: 'true'
traefik.http.routers.ramanchada-api-prod.entrypoints: tcp80v4*,tcp443v4*,tcp80v6*,tcp443v6*
traefik.http.routers.ramanchada-api-prod.rule: Host(`api.ramanchada.ideaconsult.net`)
traefik.http.routers.ramanchada-api-prod.middlewares: ramanchada-api-prod-cors
traefik.http.middlewares.ramanchada-api-prod-cors.headers.accessControlAllowCredentials: 'true'
traefik.http.middlewares.ramanchada-api-prod-cors.headers.accessControlAllowHeaders: >-
Authorization,
Cache-Control,
Content-Type,
DNT,
If-Modified-Since,
Keep-Alive,
User-Agent,
X-CustomHeader,
X-Requested-With
traefik.http.middlewares.ramanchada-api-prod-cors.headers.accessControlAllowMethods: >-
GET,
OPTIONS,
POST
traefik.http.middlewares.ramanchada-api-prod-cors.headers.accessControlAllowOriginList: >-
https://enanomapper.adma.ai,
https://enm-dev.adma.ai,
https://enm-experimental.adma.ai,
https://h5web-comp.vercel.app,
https://search.charisma.ideaconsult.net
traefik.http.middlewares.ramanchada-api-prod-cors.headers.accessControlMaxAge: 1728000
traefik.http.middlewares.ramanchada-api-prod-cors.headers.addVaryHeader: 'true'
com.centurylinklabs.watchtower.enable: 'true'
com.centurylinklabs.watchtower.scope: frequent
networks:
- ramanchada_api_prod
volumes:
- uploads-prod:/var/uploads

dev:
image: ghcr.io/h2020charisma/ramanchada-api:develop
container_name: ramanchada-api-dev
hostname: ramanchada-api-dev
restart: unless-stopped
labels:
traefik.enable: 'true'
traefik.http.routers.ramanchada-api-dev.entrypoints: tcp80v4*,tcp443v4*,tcp80v6*,tcp443v6*
traefik.http.routers.ramanchada-api-dev.rule: Host(`api.ramanchada.ideaconsult.net`)
traefik.http.routers.ramanchada-api-dev.rule: Host(`api-dev.ramanchada.ideaconsult.net`)
traefik.http.routers.ramanchada-api-dev.middlewares: ramanchada-api-dev-cors
traefik.http.middlewares.ramanchada-api-dev-cors.headers.accessControlAllowCredentials: 'true'
traefik.http.middlewares.ramanchada-api-dev-cors.headers.accessControlAllowHeaders: >-
Expand All @@ -35,10 +80,11 @@ services:
OPTIONS,
POST
traefik.http.middlewares.ramanchada-api-dev-cors.headers.accessControlAllowOriginList: >-
https://search-dev.data.enanomapper.net,
https://search-experimental.data.enanomapper.net,
https://search.charisma.ideaconsult.net,
https://search.data.enanomapper.net
https://enanomapper.adma.ai,
https://enm-dev.adma.ai,
https://enm-experimental.adma.ai,
https://h5web-comp.vercel.app,
https://search.charisma.ideaconsult.net
traefik.http.middlewares.ramanchada-api-dev-cors.headers.accessControlMaxAge: 1728000
traefik.http.middlewares.ramanchada-api-dev-cors.headers.addVaryHeader: 'true'
com.centurylinklabs.watchtower.enable: 'true'
Expand Down
1 change: 1 addition & 0 deletions extern/ramanchada2
Submodule ramanchada2 added at 1bf736
Loading

0 comments on commit 38ed6f5

Please sign in to comment.