Skip to content

Commit

Permalink
merge dockerfiles into one
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsiungw committed May 5, 2024
1 parent 5de4d15 commit 4978c7c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 81 deletions.
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

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 \
&& 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 \
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.
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 && \
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

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

0 comments on commit 4978c7c

Please sign in to comment.