Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] merge prod and dev Dockerfile #1194

Merged
merged 8 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# [Node Stage to get node_modolues and node dependencies]
FROM node:8.16.0-buster-slim as node_stage
FROM node:8.16.0-buster-slim as node_base
# [Python Stage for Django web server]
FROM python:3.10.14-slim-bullseye as python_base
mattwang44 marked this conversation as resolved.
Show resolved Hide resolved

FROM node_base as node_dependencies
COPY ./yarn.lock yarn.lock
COPY ./package.json package.json

RUN apt-get update
RUN apt-get install python-pip -y

RUN npm install -g yarn
RUN yarn install --dev --frozen-lockfile \
mattwang44 marked this conversation as resolved.
Show resolved Hide resolved
&& rm -rf $HOME/.cache/yarn/*

RUN yarn install --dev --frozen-lockfile

# [Python Stage for Django web server]
FROM python:3.10.14-slim-bullseye as python_stage
FROM python_base as python_dependencies

ENV PYTHONUNBUFFERED=1 \
mattwang44 marked this conversation as resolved.
Show resolved Hide resolved
PYTHONDONTWRITEBYTECODE=1 \
Expand All @@ -26,15 +26,6 @@ ENV PYTHONUNBUFFERED=1 \
ENV BASE_DIR /usr/local
ENV APP_DIR $BASE_DIR/app

COPY --from=node_stage /node_modules $APP_DIR/node_modules
COPY --from=node_stage /usr/local/bin/node /usr/local/bin/node

# make nodejs accessible and executable globally
ENV NODE_PATH $APP_DIR/node_modules/
ENV PATH /usr/local/bin:$PATH

# Add bin directory used by `pip install --user`
ENV PATH /home/docker/.local/bin:$PATH

# Infrastructure tools
# gettext is used for django to compile .po to .mo files.
mattwang44 marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -49,23 +40,33 @@ RUN apt-get install -y \
libxml2-dev \
libxslt-dev

# APP directory setup
RUN adduser --system --disabled-login docker \
&& mkdir -p "$BASE_DIR" "$APP_DIR" "$APP_DIR/src/assets" "$APP_DIR/src/media" \
&& chown -R docker:nogroup "$BASE_DIR" "$APP_DIR"

# Install Poetry
RUN pip install --no-cache-dir pip==23.3.2 && \
pip install --no-cache-dir poetry==1.8.2

# Install Python dependencies (only main dependencies)
COPY --chown=docker:nogroup pyproject.toml poetry.lock ./
# Install Python dependencies
COPY pyproject.toml poetry.lock ./
RUN poetry install --no-root && \
mhsiungw marked this conversation as resolved.
Show resolved Hide resolved
yes | poetry cache clear --all pypi

# Add poetry bin directory to PATH
ENV PATH="${WORKDIR}/.venv/bin:$PATH"

COPY --from=node_dependencies /node_modules $APP_DIR/node_modules
COPY --from=node_dependencies /usr/local/bin/node /usr/local/bin/node

# Make nodejs accessible and executable globally
ENV NODE_PATH $APP_DIR/node_modules/

FROM python_dependencies as dev


FROM python_dependencies as prod
# APP directory setup
RUN adduser --system --disabled-login docker \
&& mkdir -p "$BASE_DIR" "$APP_DIR" "$APP_DIR/src/assets" "$APP_DIR/src/media" \
&& chown -R docker:nogroup "$BASE_DIR" "$APP_DIR"

# Finally, copy all the project files along with source files
COPY --chown=docker:nogroup ./ $APP_DIR

Expand Down
52 changes: 0 additions & 52 deletions dev.Dockerfile

This file was deleted.

9 changes: 5 additions & 4 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ services:
container_name: pycontw_dev
build:
context: .
dockerfile: dev.Dockerfile
dockerfile: Dockerfile
target: dev
volumes:
- ./src:/app/src
- ./logs:/app/logs
- ./src:/usr/local/app/src
- ./logs:/usr/local/app/logs
ports:
- "8000:8000"
depends_on:
Expand All @@ -26,5 +27,5 @@ services:
- DJANGO_SUPERUSER_USERNAME=admin
- DJANGO_SUPERUSER_PASSWORD=1234
- [email protected]
working_dir: /app/src
working_dir: /usr/local/app/src
command: tail -f /dev/null
9 changes: 6 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
version: "3.5"
services:
web:
build: .
build:
context: .
dockerfile: Dockerfile
target: prod
container_name: pycontw-2024
hostname: pycontw-2024
entrypoint: ""
Expand Down Expand Up @@ -37,9 +40,9 @@ services:
volumes:
- ${MEDIA_ROOT}:/usr/local/app/src/media
networks:
- network
- network-2024
mattwang44 marked this conversation as resolved.
Show resolved Hide resolved

networks:
network:
network-2024:
external: true
name: network-2024
Loading