Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate off Anaconda to Poetry and create dedicated RMG-Py builder image #165

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .env.dev
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# environment configuration for vscode
RMGpy=../RMG-Py
PYTHONPATH=${RMGpy}:${PYTHONPATH}
POSTGRES_DB=postgres
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/docker-builds.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Docker Builds
on:
push:
branches: [ master ]
jobs:
docker_builds:
name: Docker Builds
runs-on: ubuntu-latest
steps:
- name: Checkout main
- uses: actions/checkout@v2
with:
path: main
- name: Checkout RMG-models
- uses: actions/checkout@v2
with:
repository: comocheng/RMG-models
token: ${{ secrets.PAT }}
path: rmg-models
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build RMG Image
uses: docker/build-push-action@v2
with:
file: main/Dockerfile.rmg
push: true
tags: comocheng/kms-rmg:latest
- name: Build Application Image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: comocheng/kms:latest
17 changes: 0 additions & 17 deletions .github/workflows/kms-build.yml

This file was deleted.

15 changes: 5 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
name: CI/CD
name: CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
types: [ opened, synchronize, ready_for_review ]
jobs:
testing:
name: Testing
tests:
name: Tests
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
steps:
- uses: actions/checkout@v2
- name: Run Tests
run: |
echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
docker pull ghcr.io/comocheng/kineticmodelssite/kms-build:latest
cp .env.dev .env
docker volume create rmg-models
docker-compose run web ./bin/test.sh --rm
- name: Tests
run: docker-compose run web ./bin/test.sh --rm
34 changes: 25 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
FROM ghcr.io/comocheng/kineticmodelssite/kms-build:latest
# Fetch RMG-Py build
FROM comocheng/kms-rmg:latest as rmg

COPY environment.yml /app/
RUN conda config --set channel_priority strict
RUN conda env update --prefix $ENV_PREFIX --file environment.yml
RUN conda clean -afy
ENV PATH /kms_env/bin:$PATH
ENV CONDA_DEFAULT_ENV /kms_env
RUN source activate /kms_env
# Application
FROM python:3.9-alpine

COPY . /app/
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
POETRY_HOME="/opt/poetry" \
POETRY_NO_INTERACTION=1

COPY --from=rmg /rmg/RMG-Py/rmgpy /rmgpy

RUN apk add --no-cache curl \
&& (curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -)
ENV PATH="$POETRY_HOME/bin:$PATH" \
PYTHONPATH="/rmgpy:$PYTHONPATH"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that RMG-Py is not specified as a dependency in the pyproject.toml - the dependency is added to the PYTHONPATH here


WORKDIR /app

COPY main/pyproject.toml poetry.lock ./
RUN poetry install --no-dev --no-interaction

COPY rmg-models/ /rmg-models
COPY main/ .

CMD [ "./bin/entrypoint.sh" ]
19 changes: 0 additions & 19 deletions Dockerfile.build

This file was deleted.

21 changes: 21 additions & 0 deletions Dockerfile.rmg
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Builds RMG-Py from source to /rmg/RMG-Py/rmgpy
FROM continuumio/miniconda3:latest

RUN apt update && apt -y install \
g++ \
gcc \
git \
make

WORKDIR /rmg
RUN git clone https://github.com/ReactionMechanismGenerator/RMG-Py.git \
&& git clone https://github.com/ReactionMechanismGenerator/RMG-database.git

WORKDIR /rmg/RMG-Py
ENV PYTHONUNBUFFERED=1

RUN conda env create -v --file environment.yml
SHELL ["conda", "run", "-n", "rmg_env", "/bin/bash", "-c"]
RUN make

WORKDIR /rmg/RMG-Py/rmgpy
6 changes: 2 additions & 4 deletions bin/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/bin/bash

python manage.py collectstatic --noinput
python manage.py migrate --noinput
gunicorn kms.wsgi --bind 0.0.0.0:8000
poetry run python manage.py migrate --noinput
poetry run gunicorn kms.wsgi --bind 0.0.0.0:8000
4 changes: 2 additions & 2 deletions bin/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

set -e

python -m flake8
python manage.py test --settings=kms.test_settings --pattern="test_*unit.py" --noinput
poetry run python -m flake8
poetry run python manage.py test --settings=kms.test_settings --pattern="test_*unit.py" --noinput
2 changes: 1 addition & 1 deletion database/scripts/import_rmg_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def import_rmg_models(apps, schema_editor):
logger.info(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
for name in model_names:
setattr(models, name, apps.get_model("database", name))
path = os.getenv("RMGMODELSPATH", "./rmg-models/")
path = os.getenv("RMGMODELSPATH", "/rmg-models/")
skip_list = ["PCI2011/193-Mehl"]
model_paths = get_models(path, skip_list)

Expand Down
12 changes: 4 additions & 8 deletions docker-compose.debug.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
version: "3.8"
version: "3.7"

services:
db:
image: postgres
env_file: .env.dev
ports:
- "5432:5432"
env_file:
- ./.env.dev
debug:
build: .
tty: true
env_file:
- ./.env.dev
env_file: .env.dev
volumes:
- .:/app
- rmg-models:/app/rmg-models
- conda:/kms_env
ports:
- "5678:5678"
- "8080:8080"
depends_on:
- db

volumes:
rmg-models:
external: true
conda:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This volume should no longer be necessary

external: true
20 changes: 5 additions & 15 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
version: "3.8"
version: "3.7"

services:
db:
image: postgres
expose:
- 5432
env_file:
- ./.env
env_file: .env
web:
build: .
command: ./bin/entrypoint.sh
build: comocheng/kms
env_file: .env
volumes:
- .:/app
- static:/app/static
- media:/app/media
- rmg-models:/app/rmg-models
expose:
- 8000
depends_on:
- db
env_file:
- ./.env
nginx:
build: ./nginx
volumes:
Expand All @@ -30,8 +21,7 @@ services:
- "8000:80"
depends_on:
- web

volumes:
static:
media:
rmg-models:
external: true
33 changes: 0 additions & 33 deletions environment.yml

This file was deleted.

Loading