Docker: Compile sources into docker image
MODIFY
Dockerfile
Dockerfile
@@ -7,16 +7,20 @@ RUN pip install pipenv
COPY Pipfile* ./
RUN pipenv install --deploy
-# Create __version__ from $APP_VERSION
-FROM base AS version
+FROM base AS compile
ARG APP_VERSION=$APP_VERSION
ENV APP_VERSION=$APP_VERSION
-RUN mkdir -p /app/plextraktsync
+COPY plextraktsync ./plextraktsync/
+# Create __version__ from $APP_VERSION
RUN echo "__version__ = '${APP_VERSION:-unknown}'" > plextraktsync/__init__.py
RUN cat plextraktsync/__init__.py
RUN python -c "from plextraktsync import __version__; print(__version__)"
+# Compile sources
+RUN python -m compileall .
+RUN chmod -R a+rX,g-w .
+
FROM base
ENTRYPOINT ["python", "-m", "plextraktsync"]
@@ -30,6 +34,5 @@ ENV \
VOLUME /app/config
# Copy things together
-COPY plextraktsync ./plextraktsync/
-COPY --from=version /app/plextraktsync/__init__.py plextraktsync/
COPY --from=build /root/.local/share/virtualenvs/app-*/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
+COPY --from=compile /app/plextraktsync plextraktsync/

Docker: Compile sources into docker image