Make docker image smaller by caching .pyc and removing .py files

This commit is contained in:
dmunozv04
2024-01-14 16:38:39 +01:00
parent db26bff3d2
commit f620ed2fcc

View File

@@ -1,19 +1,28 @@
# syntax=docker/dockerfile:1 # syntax=docker/dockerfile:1
FROM python:3.11-alpine3.19 as compiler
FROM python:3.11-alpine WORKDIR /app
COPY src .
RUN python3 -m compileall -b -f . && \
find . -name "*.py" -type f -delete
FROM python:3.11-alpine3.19
ENV PIP_NO_CACHE_DIR=off iSPBTV_docker=True iSPBTV_data_dir=data TERM=xterm-256color COLORTERM=truecolor ENV PIP_NO_CACHE_DIR=off iSPBTV_docker=True iSPBTV_data_dir=data TERM=xterm-256color COLORTERM=truecolor
COPY requirements.txt . COPY requirements.txt .
RUN pip install --upgrade pip wheel && \ RUN pip install --upgrade pip wheel && \
pip install -r requirements.txt pip install -r requirements.txt && \
pip uninstall -y pip wheel && \
python3 -m compileall -b -f /usr/local/lib/python3.11/site-packages && \
find /usr/local/lib/python3.11/site-packages -name "*.py" -type f -delete && \
find /usr/local/lib/python3.11/ -name "__pycache__" -type d -exec rm -rf {} +
WORKDIR /app WORKDIR /app
RUN python -m compileall COPY --from=compiler /app .
COPY src . ENTRYPOINT ["python3", "-u", "main.pyc"]
ENTRYPOINT ["python3", "-u", "main.py"]