Skip to content

Commit

Permalink
Merge pull request #163 from AutomatingSciencePipeline/python-develop…
Browse files Browse the repository at this point in the history
…ment-hot-reload

Python development hot reload
  • Loading branch information
SpookyBeverage authored Mar 11, 2023
2 parents 5bf14f7 + 5ad498d commit 57802da
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 35 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"--no-debugger", // I have no idea why VSCode suggested this be here, I assume it turns off flask's own debugger?
"--host=0.0.0.0",
"-p",
"5050"
"5050" // TODO try to read env var for BACKEND_PORT? or up to the dev to manage this?
],
"jinja": true,
"justMyCode": false
Expand Down
10 changes: 8 additions & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@
}
},
{
"label": "Docker Compose Up (Attached)",
"label": "DEVELOPMENT Docker Compose Up (Attached)",
"type": "shell",
"command": "docker-compose up --build",
"command": "docker compose --file docker-compose.yml --file docker-compose.dev.yml up --build",
"problemMatcher": []
},
{
"label": "PRODUCTION Docker Compose Up (Attached)",
"type": "shell",
"command": "docker compose up --build",
"problemMatcher": []
}
]
Expand Down
2 changes: 1 addition & 1 deletion Monorepo.wiki
62 changes: 38 additions & 24 deletions apps/backend/backend.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,46 +1,60 @@
# For more information, please refer to https://aka.ms/vscode-docker-python
FROM python:3.8-slim
FROM python:3.8-slim AS base

ARG BACKEND_PORT
ENV BACKEND_PORT=$BACKEND_PORT

# Keeps Python from generating .pyc files in the container
# This doesn't benefit the performance of the system
# https://stackoverflow.com/questions/59732335/is-there-any-disadvantage-in-using-pythondontwritebytecode-in-docker
ENV PYTHONDONTWRITEBYTECODE=1

# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1

RUN apt-get update
RUN apt-get update && \
apt-get install -y --no-install-recommends \
# For file type identification via bytes
libmagic1 \
#Ths should also get Java 11? -David
default-jdk

#Ths should also get Java 11? -David
RUN apt-get install default-jdk -y
# Ability to pass in JVM options
ARG JAVA_OPTS
ENV JAVA_OPTS=$JAVA_OPTS

# For file type identification via bytes
RUN apt-get install libmagic1 -y

# RUN apt-get update && \
# apt-get -y install sudo

# Install requirements
# Copy in python requirements definitions, but don't install yet, dev and prod need different deps
RUN pip install pipenv
COPY Pipfile .
COPY Pipfile.lock .




FROM base AS development
# Args explanation: https://stackoverflow.com/a/49705601
# https://pipenv-fork.readthedocs.io/en/latest/basics.html#pipenv-install
RUN pipenv install --system --deploy --ignore-pipfile
# and also https://stackoverflow.com/a/53101932
RUN pipenv install --system --deploy --ignore-pipfile --dev

WORKDIR /app
COPY . /app

# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers
# RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
# RUN usermod -aG sudo appuser
# USER appuser
# RUN chmod -R a=rwx /app
# The source code will be bind monuted in via docker compose, so we don't need to copy it in here

USER root
ENV FLASK_ENV development
ENV FLASK_DEBUG 1
CMD flask run --host=0.0.0.0 --no-debugger -p $BACKEND_PORT

# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug

# TODO switch to ${BACKEND_PORT}
CMD ["flask", "run", "--host=0.0.0.0", "-p", "5050"]


FROM base AS production
# Args explanation: https://stackoverflow.com/a/49705601
# https://pipenv-fork.readthedocs.io/en/latest/basics.html#pipenv-install
RUN pipenv install --system --deploy --ignore-pipfile

WORKDIR /app
COPY . /app

USER root
ENV FLASK_ENV production
CMD flask run --host=0.0.0.0 -p $BACKEND_PORT
12 changes: 12 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Use this docker-compose file in addition to the base one in order to set up development configurations for the containers
# https://docs.docker.com/compose/extends/

version: '3'
name: glados-project

services:
app-backend:
build:
target: development
volumes:
- ./apps/backend/:/app
17 changes: 10 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
# Usage
# Start: docker-compose up
# With helpers: docker-compose -f docker-compose.yml -f ./.devcontainer/docker-compose.dev.yml up
# Stop: docker-compose down
# Destroy: docker-compose -f docker-compose.yml -f ./.devcontainer/docker-compose.dev.yml down -v --remove-orphans
# Start: docker compose up
# With helpers: docker compose -f docker-compose.yml -f ./.devcontainer/docker-compose.dev.yml up
# Stop: docker compose down
# Destroy: docker compose -f docker-compose.yml -f ./.devcontainer/docker-compose.dev.yml down -v --remove-orphans

version: '3'
name: glados-project

# Make sure you have a .env file in the root of the project, it supplies variables in the ${}

services:
app-backend:
build:
context: ./apps/backend
dockerfile: ./backend.Dockerfile
target: production
container_name: glados-backend
environment:
FIREBASE_KEY: ${FIREBASE_KEY}
BACKEND_PORT: ${BACKEND_PORT}
volumes:
- ./apps/backend/ExperimentFiles:/app/ExperimentFiles
# TODO switch to ${BACKEND_PORT}
ports:
# TODO does this need to be exposed to host?
- 5050:5050
- ${BACKEND_PORT}:${BACKEND_PORT}
expose:
- "5050"
- "${BACKEND_PORT}"

app-frontend:
build:
Expand Down

0 comments on commit 57802da

Please sign in to comment.