From 5c3aa29ac7f1c9b651b520c04c5967206cf7eea5 Mon Sep 17 00:00:00 2001 From: Michael Irwin Date: Fri, 27 Oct 2023 13:55:40 -0400 Subject: [PATCH] Fix file mounts (work dir change) and python reloading Signed-off-by: Michael Irwin --- docker-compose.yml | 10 +++++----- vote/Dockerfile | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 05fdaad44f..3ee1bb53b5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,9 +4,9 @@ services: vote: - build: ./vote - # use python rather than gunicorn for local dev - command: python app.py + build: + context: ./vote + target: dev depends_on: redis: condition: service_healthy @@ -17,7 +17,7 @@ services: retries: 3 start_period: 10s volumes: - - ./vote:/app + - ./vote:/usr/local/app ports: - "5000:80" networks: @@ -32,7 +32,7 @@ services: db: condition: service_healthy volumes: - - ./result:/app + - ./result:/usr/local/app ports: - "5001:80" - "127.0.0.1:9229:9229" diff --git a/vote/Dockerfile b/vote/Dockerfile index 75703ad63f..9e812ca958 100644 --- a/vote/Dockerfile +++ b/vote/Dockerfile @@ -1,7 +1,7 @@ -# Using official python runtime base image -FROM python:3.11-slim +# Define a base stage that uses the official python runtime base image +FROM python:3.11-slim AS base -# add curl for healthcheck +# Add curl for healthcheck RUN apt-get update && \ apt-get install -y --no-install-recommends curl && \ rm -rf /var/lib/apt/lists/* @@ -13,6 +13,16 @@ WORKDIR /usr/local/app COPY requirements.txt ./requirements.txt RUN pip install --no-cache-dir -r requirements.txt +# Define a stage specifically for development, where it'll watch for +# filesystem changes +FROM base AS dev +RUN pip install watchdog +ENV FLASK_ENV=development +CMD ["python", "app.py"] + +# Define the final stage that will bundle the application for production +FROM base AS final + # Copy our code from the current folder to the working directory inside the container COPY . .