Skip to content

Commit

Permalink
optimize dockerfile prod
Browse files Browse the repository at this point in the history
  • Loading branch information
submarcos committed Jun 26, 2024
1 parent 7770858 commit 0c61753
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
ARG NODE_MAJOR_VERSION=20

FROM ubuntu:noble as base
FROM ubuntu:noble AS base

ARG NODE_MAJOR_VERSION

ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV DEBIAN_FRONTEND noninteractive
ENV TZ UTC
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=UTC

RUN mkdir -p /app/backend app/front-end/dist && chown -R ubuntu:ubuntu /app
WORKDIR /app
Expand Down Expand Up @@ -35,9 +35,9 @@ COPY .docker/entrypoint.sh /usr/local/bin/entrypoint.sh

ENTRYPOINT ["/bin/sh", "-e", "/usr/local/bin/entrypoint.sh"]

FROM base as build
FROM base AS build

ENV NODE_ENV development
ENV NODE_ENV=development
ARG NODE_MAJOR_VERSION

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
Expand All @@ -55,8 +55,7 @@ COPY --chown=ubuntu:ubuntu front-end/ /app/front-end

WORKDIR /app/front-end

RUN npm ci
RUN npm run build
RUN npm ci --no-audit

WORKDIR /app

Expand All @@ -66,7 +65,7 @@ COPY backend/requirements.txt /app/requirements.txt
RUN --mount=type=cache,target=/home/ubuntu/.cache/pip,sharing=locked \
/app/venv/bin/pip install -r /app/requirements.txt

FROM build as dev
FROM build AS dev

COPY backend/dev-requirements.txt /app/dev-requirements.txt
RUN --mount=type=cache,target=/home/ubuntu/.cache/pip,sharing=locked,uid=1,gid=1 \
Expand All @@ -76,9 +75,9 @@ WORKDIR /app/backend

CMD ["/app/venv/bin/python", "manage.py", "runserver", "0.0.0.0:8000"]

FROM base as prod
FROM base AS prod

ENV NODE_ENV production
ENV NODE_ENV=production

WORKDIR /app/backend

Expand All @@ -94,7 +93,7 @@ COPY --chown=ubuntu:ubuntu front-end/package.json /app/front-end/package.json

WORKDIR /app/front-end

RUN npm ci
RUN npm ci --no-audit --only=production

COPY --chown=ubuntu:ubuntu --from=build /app/venv /app/venv
COPY --chown=ubuntu:ubuntu --from=build /app/front-end/dist /app/front-end/dist
Expand All @@ -107,7 +106,7 @@ RUN /app/venv/bin/django-admin compilemessages

CMD ["/app/venv/bin/gunicorn", "project.wsgi:application", "--bind", "0.0.0.0:8000"]

FROM base as front-dev
FROM base AS front-dev

WORKDIR /app/front-end

Expand Down

0 comments on commit 0c61753

Please sign in to comment.