diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..efb31e3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +app/node_modules/ +app/static/vendor/ diff --git a/Dockerfile b/Dockerfile index 3b47662..b146890 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,16 @@ -FROM python:3.12-slim +FROM node:22-slim AS assets + +WORKDIR /app +COPY app/package.json ./ +COPY app/scripts ./scripts +RUN npm install --omit=dev --no-audit --no-fund + +FROM python:3.12-slim AS base ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ FLASK_HOST=0.0.0.0 -# hadolint ignore=DL3008 -RUN apt-get update && apt-get install -y --no-install-recommends nodejs npm && rm -rf /var/lib/apt/lists/* - WORKDIR /tmp/build COPY pyproject.toml README.md main.py ./ @@ -15,6 +19,14 @@ RUN python -m pip install --no-cache-dir . WORKDIR /app COPY app/ . -RUN npm install --prefix /app CMD ["python", "app.py"] + +FROM base AS dev + +# hadolint ignore=DL3008 +RUN apt-get update && apt-get install -y --no-install-recommends nodejs npm && rm -rf /var/lib/apt/lists/* + +FROM base AS runtime + +COPY --from=assets /app/static/vendor ./static/vendor diff --git a/docker-compose.yml b/docker-compose.yml index 7f0dda4..e72eb1a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,6 +7,7 @@ services: build: context: . dockerfile: Dockerfile + target: dev container_name: portfolio ports: - "${PORT:?PORT must be set in .env (see env.example)}:${PORT:?PORT must be set in .env (see env.example)}"