-
-
Notifications
You must be signed in to change notification settings - Fork 707
Optimize Dockerfile and build process #4039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wilmardo
wants to merge
8
commits into
TandoorRecipes:develop
Choose a base branch
from
wilmardo:docker2
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6b17f7a
feat: move frontend build into docker build
wilmardo 3f18588
refactor: move version.py out out Docker build into CI stage
wilmardo 9bf5150
feat: reduce the amount of files in the docker container to the bare …
wilmardo 4386155
build(docker): avoid unnecessary layers with heredoc RUN (format: shfmt)
theProf 607d9ab
build(docker): use --link flag with COPY and group together
theProf 68d3f62
build(docker): remove unnecessary mkdir
theProf 7ce4ff0
chore(docker): sort packages for readability
theProf 853ea74
chore(docker): linting and comment spacing
theProf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ LICENSE | |
.env | ||
.env.template | ||
.github | ||
.git | ||
.idea | ||
.prettierignore | ||
LICENSE.md | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,87 @@ | ||
# Build frontend | ||
FROM node:22-alpine AS build | ||
COPY --link ./vue3 /opt/recipes/vue3 | ||
WORKDIR /opt/recipes/vue3 | ||
RUN yarn install --frozen-lockfile && \ | ||
yarn build | ||
|
||
# Main app image | ||
FROM python:3.13-alpine3.22 | ||
|
||
#Install all dependencies. | ||
RUN apk add --no-cache postgresql-libs postgresql-client gettext zlib libjpeg libwebp libxml2-dev libxslt-dev openldap git libgcc libstdc++ nginx tini envsubst nodejs npm | ||
# Install all dependencies. | ||
RUN apk add --no-cache \ | ||
envsubst \ | ||
gettext \ | ||
libgcc \ | ||
libjpeg \ | ||
libstdc++ \ | ||
libwebp \ | ||
libxml2-dev \ | ||
libxslt-dev \ | ||
nginx \ | ||
nodejs \ | ||
npm \ | ||
openldap \ | ||
postgresql-client \ | ||
postgresql-libs \ | ||
tini \ | ||
zlib | ||
|
||
#Print all logs without buffering it. | ||
ENV PYTHONUNBUFFERED=1 \ | ||
DOCKER=true | ||
|
||
#This port will be used by gunicorn. | ||
# This port will be used by gunicorn. | ||
EXPOSE 80 8080 | ||
|
||
#Create app dir and install requirements. | ||
RUN mkdir /opt/recipes | ||
# Create app dir and install requirements. | ||
WORKDIR /opt/recipes | ||
|
||
COPY requirements.txt ./ | ||
|
||
# remove Development dependencies from requirements.txt | ||
RUN sed -i '/# Development/,$d' requirements.txt | ||
RUN apk add --no-cache --virtual .build-deps gcc musl-dev postgresql-dev zlib-dev jpeg-dev libwebp-dev openssl-dev libffi-dev cargo openldap-dev python3-dev xmlsec-dev xmlsec build-base g++ curl rust && \ | ||
python -m venv venv && \ | ||
/opt/recipes/venv/bin/python -m pip install --upgrade pip && \ | ||
venv/bin/pip debug -v && \ | ||
venv/bin/pip install wheel==0.45.1 && \ | ||
venv/bin/pip install setuptools_rust==1.10.2 && \ | ||
venv/bin/pip install -r requirements.txt --no-cache-dir &&\ | ||
COPY --link requirements.txt ./ | ||
|
||
RUN <<EOF | ||
# remove Development dependencies from requirements.txt | ||
sed -i '/# Development/,$d' requirements.txt | ||
apk add --no-cache --virtual .build-deps \ | ||
build-base \ | ||
cargo \ | ||
curl \ | ||
g++ \ | ||
gcc \ | ||
jpeg-dev \ | ||
libffi-dev \ | ||
libwebp-dev \ | ||
musl-dev \ | ||
postgresql-dev \ | ||
python3-dev \ | ||
openldap-dev \ | ||
openssl-dev \ | ||
xmlsec \ | ||
xmlsec-dev \ | ||
rust \ | ||
zlib-dev | ||
python -m venv venv | ||
venv/bin/python -m pip install --upgrade pip | ||
venv/bin/pip debug -v | ||
venv/bin/pip install wheel==0.45.1 | ||
venv/bin/pip install setuptools_rust==1.10.2 | ||
venv/bin/pip install -r requirements.txt --no-cache-dir | ||
apk --purge del .build-deps | ||
EOF | ||
Comment on lines
+40
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest moving building the venv to a separate stage. This way we would have one stage for the frontend and its build dependencies, one stage for the backend and its build dependencies, and one final image with runtime dependencies. |
||
|
||
#Copy project and execute it. | ||
COPY . ./ | ||
# Copy minimal parts of project to run | ||
COPY --link ./recipes/ /opt/recipes/recipes | ||
COPY --link ./cookbook/ /opt/recipes/cookbook | ||
COPY --link ./http.d/ /opt/recipes/http.d | ||
COPY --link --chmod=755 \ | ||
./boot.sh \ | ||
./manage.py \ | ||
/opt/recipes | ||
|
||
# Add compiled frontend | ||
COPY --link --from=build \ | ||
/opt/recipes/cookbook/static/vue3/ \ | ||
/opt/recipes/cookbook/static/vue3/ | ||
|
||
# delete default nginx config and link it to tandoors config | ||
# create symlinks to access and error log to show them on stdout | ||
|
@@ -44,10 +97,4 @@ RUN rm -rf /etc/nginx/http.d && \ | |
# --retries=3 \ | ||
# CMD [ "/usr/bin/wget", "--no-verbose", "--tries=1", "--spider", "http://127.0.0.1:8080/openapi" ] | ||
|
||
# collect information from git repositories | ||
RUN /opt/recipes/venv/bin/python version.py | ||
# delete git repositories to reduce image size | ||
RUN find . -type d -name ".git" | xargs rm -rf | ||
|
||
RUN chmod +x boot.sh | ||
ENTRYPOINT ["/sbin/tini", "--", "/opt/recipes/boot.sh"] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather out of scope for this PR, but I think the Python dev dependencies should be moved to another file to cleanly separate them, for example in
requirements_dev.txt
.