mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-07-11 23:32:56 +02:00
docker: try to reduce image size
This commit is contained in:
@@ -1,47 +1,35 @@
|
|||||||
# pull official base image
|
FROM python:3.11-slim-buster AS python-build-stage
|
||||||
FROM python:3.11-slim-buster AS python
|
|
||||||
LABEL authors="Herculino de Miranda Trotta"
|
|
||||||
|
|
||||||
FROM docker.io/python AS python-build-stage
|
RUN apt-get update && apt-get install --no-install-recommends -y \
|
||||||
|
build-essential \
|
||||||
|
gettext \
|
||||||
|
libpq-dev \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
RUN apt update && apt install --no-install-recommends -y \
|
|
||||||
# dependencies for building Python packages \
|
|
||||||
build-essential \
|
|
||||||
# psycopg2 dependencies \
|
|
||||||
gettext \
|
|
||||||
libpq-dev
|
|
||||||
|
|
||||||
# Requirements are installed here to ensure they will be cached.
|
|
||||||
COPY ../requirements.txt .
|
COPY ../requirements.txt .
|
||||||
|
RUN pip wheel --wheel-dir /usr/src/app/wheels -r requirements.txt
|
||||||
|
|
||||||
# Create Python Dependency and Sub-Dependency Wheels.
|
FROM python:3.11-slim-buster AS python-run-stage
|
||||||
RUN pip wheel --wheel-dir /usr/src/app/wheels \
|
|
||||||
-r requirements.txt
|
|
||||||
|
|
||||||
|
|
||||||
FROM docker.io/python AS python-run-stage
|
|
||||||
#COPY --from=webpack_build /usr/src/frontend/build /usr/src/frontend/build
|
|
||||||
|
|
||||||
# set work directory
|
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
# set environment variables
|
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||||
ENV PYTHONDONTWRITEBYTECODE 1
|
PYTHONUNBUFFERED=1
|
||||||
ENV PYTHONUNBUFFERED 1
|
|
||||||
|
|
||||||
COPY --from=python-build-stage /usr/src/app/wheels /wheels/
|
COPY --from=python-build-stage /usr/src/app/wheels /wheels/
|
||||||
RUN apt update && apt install --no-install-recommends -y gettext
|
|
||||||
RUN pip install --upgrade pip
|
RUN apt-get update && \
|
||||||
RUN pip install --no-cache-dir --no-index --find-links=/wheels/ /wheels/* \
|
apt-get install --no-install-recommends -y gettext && \
|
||||||
&& rm -rf /wheels/
|
rm -rf /var/lib/apt/lists/* && \
|
||||||
|
pip install --upgrade pip && \
|
||||||
|
pip install --no-cache-dir --no-index --find-links=/wheels/ /wheels/* && \
|
||||||
|
rm -rf /wheels/ ~/.cache/pip/*
|
||||||
|
|
||||||
COPY ./docker/dev/django/start /start
|
COPY ./docker/dev/django/start /start
|
||||||
RUN sed -i 's/\r$//g' /start
|
|
||||||
RUN chmod +x /start
|
|
||||||
|
|
||||||
COPY ./docker/dev/procrastinate/start /start-procrastinate
|
COPY ./docker/dev/procrastinate/start /start-procrastinate
|
||||||
RUN sed -i 's/\r$//g' /start-procrastinate
|
RUN sed -i 's/\r$//g' /start && \
|
||||||
RUN chmod +x /start-procrastinate
|
chmod +x /start && \
|
||||||
|
sed -i 's/\r$//g' /start-procrastinate && \
|
||||||
|
chmod +x /start-procrastinate
|
||||||
|
|
||||||
# copy project
|
|
||||||
COPY ./app .
|
COPY ./app .
|
||||||
|
|||||||
@@ -1,71 +1,56 @@
|
|||||||
# pull official base image
|
FROM python:3.11.8-slim-buster AS python-build-stage
|
||||||
FROM python:3.11.8-slim-buster AS python
|
|
||||||
LABEL authors="Herculino de Miranda Trotta"
|
|
||||||
|
|
||||||
FROM docker.io/python AS python-build-stage
|
|
||||||
|
|
||||||
RUN apt-get update && apt-get install --no-install-recommends -y \
|
RUN apt-get update && apt-get install --no-install-recommends -y \
|
||||||
# dependencies for building Python packages
|
build-essential \
|
||||||
build-essential \
|
gettext \
|
||||||
gettext \
|
libpq-dev \
|
||||||
# psycopg2 dependencies
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
libpq-dev
|
|
||||||
|
|
||||||
# Requirements are installed here to ensure they will be cached.
|
|
||||||
COPY ./requirements.txt .
|
COPY ./requirements.txt .
|
||||||
|
RUN pip wheel --wheel-dir /usr/src/app/wheels -r requirements.txt
|
||||||
# Create Python Dependency and Sub-Dependency Wheels.
|
|
||||||
RUN pip wheel --wheel-dir /usr/src/app/wheels \
|
|
||||||
-r requirements.txt
|
|
||||||
|
|
||||||
FROM node:lts-alpine AS webpack_build
|
FROM node:lts-alpine AS webpack_build
|
||||||
|
|
||||||
WORKDIR /usr/src/frontend
|
WORKDIR /usr/src/frontend
|
||||||
|
|
||||||
COPY ./frontend .
|
COPY ./frontend .
|
||||||
COPY ./app/templates /usr/src/app/templates
|
COPY ./app/templates /usr/src/app/templates
|
||||||
RUN npm config set registry https://registry.npmmirror.com/
|
RUN npm config set registry https://registry.npmmirror.com/ && \
|
||||||
RUN npm install --verbose
|
npm install --verbose && \
|
||||||
RUN npm run build
|
npm run build && \
|
||||||
|
npm cache clean --force
|
||||||
|
|
||||||
FROM docker.io/python AS python-run-stage
|
FROM python:3.11.8-slim-buster AS python-run-stage
|
||||||
COPY --from=webpack_build /usr/src/frontend/build /usr/src/frontend/build
|
COPY --from=webpack_build /usr/src/frontend/build /usr/src/frontend/build
|
||||||
|
|
||||||
# set work directory
|
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
RUN addgroup --system app \
|
RUN addgroup --system app && \
|
||||||
&& adduser --system --ingroup app app
|
adduser --system --ingroup app app
|
||||||
|
|
||||||
# set environment variables
|
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||||
ENV PYTHONDONTWRITEBYTECODE 1
|
PYTHONUNBUFFERED=1
|
||||||
ENV PYTHONUNBUFFERED 1
|
|
||||||
|
|
||||||
COPY --from=python-build-stage /usr/src/app/wheels /wheels/
|
COPY --from=python-build-stage /usr/src/app/wheels /wheels/
|
||||||
RUN apt update && apt install --no-install-recommends -y gettext
|
RUN apt-get update && \
|
||||||
RUN pip install --upgrade pip
|
apt-get install --no-install-recommends -y gettext && \
|
||||||
RUN pip install --no-cache-dir --no-index --find-links=/wheels/ /wheels/* \
|
rm -rf /var/lib/apt/lists/* && \
|
||||||
&& rm -rf /wheels/
|
pip install --upgrade pip && \
|
||||||
|
pip install --no-cache-dir --no-index --find-links=/wheels/ /wheels/* && \
|
||||||
|
rm -rf /wheels/ ~/.cache/pip/*
|
||||||
|
|
||||||
COPY --chown=app:app ./docker/prod/django/start /start
|
COPY --chown=app:app ./docker/prod/django/start /start
|
||||||
RUN sed -i 's/\r$//g' /start
|
|
||||||
RUN chmod +x /start
|
|
||||||
|
|
||||||
COPY --chown=app:app ./docker/prod/procrastinate/start /start-procrastinate
|
COPY --chown=app:app ./docker/prod/procrastinate/start /start-procrastinate
|
||||||
RUN sed -i 's/\r$//g' /start-procrastinate
|
RUN sed -i 's/\r$//g' /start && \
|
||||||
RUN chmod +x /start-procrastinate
|
chmod +x /start && \
|
||||||
|
sed -i 's/\r$//g' /start-procrastinate && \
|
||||||
|
chmod +x /start-procrastinate
|
||||||
|
|
||||||
# copy project
|
COPY --chown=app:app ./app .
|
||||||
COPY ./app .
|
|
||||||
|
|
||||||
# chown all the files to the app user
|
RUN chown -R app:app /usr/src/app && \
|
||||||
RUN chown -R app:app /usr/src/app
|
chown -R app:app /usr/src/frontend && \
|
||||||
RUN chown -R app:app /usr/src/frontend
|
mkdir /temp && \
|
||||||
|
chown -R app:app /temp
|
||||||
|
|
||||||
RUN mkdir /temp
|
|
||||||
RUN chown -R app:app /temp
|
|
||||||
|
|
||||||
# change to the app user
|
|
||||||
USER app
|
USER app
|
||||||
|
|
||||||
RUN python manage.py compilemessages --settings "WYGIWYH.settings"
|
RUN python manage.py compilemessages --settings "WYGIWYH.settings"
|
||||||
|
|||||||
Reference in New Issue
Block a user