Skip to content

Commit

Permalink
adding new local dev support
Browse files Browse the repository at this point in the history
  • Loading branch information
veenhouse committed Sep 1, 2022
1 parent 0df6c98 commit bdb4647
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 31 deletions.
12 changes: 6 additions & 6 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 <your-package-list-here>

# [Optional] Uncomment this line to install global node packages.
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1


28 changes: 11 additions & 17 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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.
Expand All @@ -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",
Expand Down
46 changes: 46 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:
10 changes: 7 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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*
Expand Down Expand Up @@ -135,3 +138,4 @@ dmypy.json

# Pyre type checker
.pyre/
/Dockerfile.dev-db
38 changes: 38 additions & 0 deletions Dockerfile.new
Original file line number Diff line number Diff line change
@@ -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"]
25 changes: 25 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:
10 changes: 5 additions & 5 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit bdb4647

Please sign in to comment.