diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index ad21f07..f0b34cd 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,14 +1,14 @@ -# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.245.0/containers/python-3/.devcontainer/base.Dockerfile - # [Choice] Python version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.10, 3.9, 3.8, 3.7, 3.6, 3-bullseye, 3.10-bullseye, 3.9-bullseye, 3.8-bullseye, 3.7-bullseye, 3.6-bullseye, 3-buster, 3.10-buster, 3.9-buster, 3.8-buster, 3.7-buster, 3.6-buster -ARG VARIANT="3.10-bullseye" +ARG VARIANT=3-bullseye FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT} +ENV PYTHONUNBUFFERED 1 + # [Choice] Node.js version: none, lts/*, 16, 14, 12, 10 ARG NODE_VERSION="none" RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi -# [Optional] If your pip requirements rarely change, uncomment this section to add them to the image. +# [Optional] If your requirements rarely change, uncomment this section to add them to the image. # COPY requirements.txt /tmp/pip-tmp/ # RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \ # && rm -rf /tmp/pip-tmp @@ -17,5 +17,5 @@ RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/ # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ # && apt-get -y install --no-install-recommends -# [Optional] Uncomment this line to install global node packages. -# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 \ No newline at end of file + + diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 34929e3..be1db70 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,19 +1,11 @@ // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: -// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.0/containers/python-3 +// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.0/containers/python-3-postgres +// Update the VARIANT arg in docker-compose.yml to pick a Python version { - "name": "Python 3", - "build": { - "dockerfile": "Dockerfile", - "context": "..", - "args": { - // Update 'VARIANT' to pick a Python version: 3, 3.10, 3.9, 3.8, 3.7, 3.6 - // Append -bullseye or -buster to pin to an OS version. - // Use -bullseye variants on local on arm64/Apple Silicon. - "VARIANT": "3.8", - // Options - "NODE_VERSION": "lts/*" - } - }, + "name": "Python 3 & PostgreSQL", + "dockerComposeFile": "docker-compose.yml", + "service": "app", + "workspaceFolder": "/workspace", // Configure tool-specific properties. "customizations": { @@ -32,7 +24,8 @@ "python.linting.mypyPath": "/usr/local/py-utils/bin/mypy", "python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle", "python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle", - "python.linting.pylintPath": "/usr/local/py-utils/bin/pylint" + "python.linting.pylintPath": "/usr/local/py-utils/bin/pylint", + "python.testing.pytestPath": "/usr/local/py-utils/bin/pytest" }, // Add the IDs of extensions you want installed when the container is created. @@ -44,10 +37,11 @@ }, // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], + // This can be used to network with other containers or the host. + // "forwardPorts": [5000, 5432], // Use 'postCreateCommand' to run commands after the container is created. - // "postCreateCommand": "pip3 install --user -r requirements.txt", + // "postCreateCommand": "pip install --user -r requirements.txt", // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. "remoteUser": "vscode", diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..7485e64 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,46 @@ +version: '3.8' + +services: + app: + container_name: dev-env + build: + context: .. + dockerfile: .devcontainer/Dockerfile + args: + # Update 'VARIANT' to pick a version of Python: 3, 3.10, 3.9, 3.8, 3.7, 3.6 + # Append -bullseye or -buster to pin to an OS version. + # Use -bullseye variants on local arm64/Apple Silicon. + VARIANT: "3.8" + # Optional Node.js version to install + NODE_VERSION: "lts/*" + + volumes: + - ..:/workspace:cached + + # Overrides default command so things don't shut down after the process ends. + command: sleep infinity + + # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. + network_mode: service:db + # Uncomment the next line to use a non-root user for all processes. + # user: vscode + + env_file: + - ../.dev.env + + # Use "forwardPorts" in **devcontainer.json** to forward an app port locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) + + db: + image: postgres:latest + container_name: dev-db + restart: unless-stopped + volumes: + - postgresql:/var/lib/postgresql/data + env_file: + - ../.dev-db.env + # Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally. + # (Adding the "ports" property to this file will not forward from a Codespace. + +volumes: + postgresql: diff --git a/.gitignore b/.gitignore index 7ec3611..77654d9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,10 @@ -chp_db_fixture.json.gz -#deployment-script -deployment-script +# env files for development +.dev-db.env +.dev.env + +# data files for development chp.sql +chp_db_fixture.json.gz #SSH Keys id_rsa* @@ -135,3 +138,4 @@ dmypy.json # Pyre type checker .pyre/ +/Dockerfile.dev-db \ No newline at end of file diff --git a/Dockerfile.new b/Dockerfile.new new file mode 100644 index 0000000..8812297 --- /dev/null +++ b/Dockerfile.new @@ -0,0 +1,38 @@ +################ +# venv builder # +################ +FROM python:3.8.3 as venv_builder + +COPY requirements.txt . +RUN python3 -m venv /opt/venv +RUN /opt/venv/bin/pip install -r requirements.txt + +########### +# CHP API # +########### +FROM python:3.8.3-slim as chp-api + +# set environment variables +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 +ENV TZ=America/New_York +ENV SERVER_DIR=/chp_api/ +ENV VIRTUAL_ENV_PATH=/opt/venv + +# copy venv from venv builder image +COPY --from=venv_builder ${VIRTUAL_ENV_PATH} ${VIRTUAL_ENV_PATH} + +# copy project +COPY ./chp_api $SERVER_DIR + +# copy entry point +COPY ./entrypoint.sh ${SERVER_DIR} + +# enter app directory +WORKDIR $SERVER_DIR + +# Enable venv +ENV PATH="/opt/venv/bin:$PATH" +# run server +# ENTRYPOINT ["./entrypoint.sh"] +CMD ["python", "manage.py", "runserver"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..227b45e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +version: '3.8' + +services: + api: + build: + context: . + dockerfile: Dockerfile + container_name: chp-api + command: python manage.py runserver 0.0.0.0:8000 + volumes: + - static_volume:/chp_api/staticfiles + expose: + - 80 + env_file: + - ./.dev.env + db: + image: postgres:latest + restart: unless-stopped + volumes: + - ../chp.sql:/var/lib/postgresql/data + env_file: + - .dev-db.env + +volumes: + static_volume: \ No newline at end of file diff --git a/requirements-dev.txt b/requirements-dev.txt index 2ced061..39c2337 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,6 +1,6 @@ -chp_learn @ git+https://github.com/di2ag/chp_learn.git@master -chp_utils @ git+https://github.com/di2ag/chp_utils.git@master -trapi_model @ git+https://github.com/di2ag/trapi_model.git@master -chp_look_up @ git+https://github.com/di2ag/chp_look_up.git@master -gene-specificity @ git+https://github.com/di2ag/gene-specificity.git@master +chp_learn @ git+https://github.com/di2ag/chp_learn.git@master +chp_utils @ git+https://github.com/di2ag/chp_utils.git@master +trapi_model @ git+https://github.com/di2ag/trapi_model.git@master +chp_look_up @ git+https://github.com/di2ag/chp_look_up.git@master +gene-specificity @ git+https://github.com/di2ag/gene-specificity.git@master reasoner-validator @ git+https://github.com/di2ag/reasoner-validator.git@master \ No newline at end of file