-
-
Notifications
You must be signed in to change notification settings - Fork 669
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
Refactor: Dockerimage #5007
Refactor: Dockerimage #5007
Conversation
Is git actually required in the image now? I would say yes, as some plugins are installed via git. |
To install via git we would need the git executable, yeah |
Now the image weights about 629MB. I'd love if we could reduce the needed dependencies for the database drivers. |
What's really interesting and what could be used to consider using an alpine image would be this Dockerfile. It's an other open source project that's also based on Django and also has to deal with lots of images (from your cooked meals) and also has ldap support already built in and weights out 350mb (uncompressed). |
@wolflu05 two things immediately stick out in the linked image
Might be worth applying that to our image |
I already do this as much as I can and know with multistage builds. The packages that are installed in the production stage are needed for inventree to work, because they provide native linked libraries that get imported from e.g. the pip psql lib.
I tried squashing all image layers, but this also doesn't reduce the size of the image. |
I just tried how alpine turns out. Here is a little comparison with the current state (0080176) of pushed files:
* all builds on MacBook Pro 2019 (docker cache disabled) |
The alpine image is looking pretty appealing then! |
FYI, adding LDAP needed packages adds about 5MB to the alpine image, so it weights: Dockerfile changesdiff --git a/Dockerfile b/Dockerfile
index d60ab788b..46c0ba518 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -77,7 +77,7 @@ FROM inventree_base as build_base
# Install build required system packages
RUN apt-get update && apt-get install -y --no-install-recommends \
- gcc g++ libffi-dev libssl-dev && \
+ gcc g++ python3-dev libffi-dev libssl-dev libldap2-dev libsasl2-dev && \
apt-get autoclean && apt-get autoremove
# For ARMv7 architecture, add the pinwheels repo (for cryptography library)
diff --git a/Dockerfile.alpine b/Dockerfile.alpine
index 5990bd53a..0f261bae2 100644
--- a/Dockerfile.alpine
+++ b/Dockerfile.alpine
@@ -46,7 +46,7 @@ LABEL org.label-schema.schema-version="1.0" \
org.label-schema.vcs-ref=${commit_tag}
RUN apk add --no-cache \
- git gnupg gettext py-cryptography bash \
+ git gnupg gettext py-cryptography bash openldap \
# Image format support
libjpeg libwebp zlib \
# Weasyprint requirements : https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#alpine-3-12
@@ -69,7 +69,7 @@ COPY ./docker/requirements.txt base_requirements.txt
COPY ./requirements.txt ./
RUN apk add --no-cache --virtual .build-deps \
- gcc g++ musl-dev openssl-dev libffi-dev cargo python3-dev \
+ gcc g++ musl-dev openssl-dev libffi-dev cargo python3-dev openldap-dev \
# Image format dev libs
jpeg-dev openjpeg-dev libwebp-dev zlib-dev \
# DB specific dev libs
diff --git a/requirements.txt b/requirements.txt
index 487dcfead..8bac49a90 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -305,5 +305,8 @@ zipp==3.15.0
zopfli==0.2.2
# via fonttools
+python-ldap==3.4.3
+django-auth-ldap==4.2.0
+
# The following packages are considered to be unsafe in a requirements file:
# setuptools |
Interested to hear what @matmair has to say to this alpine approach. |
It certainly saves a lot of bandwidth. And the LDAP addition seems minor, but I have no horse in that race :) |
If it works why not. Have you verified that ldap actually resolved all objectTypes and both ldap and ldaps with the installed dependencies? @wolflu05 The size reduction is very impressive. Is there something significantly different to the linked project? They seem to be even smaller so I wonder how much we need to change to achieve that size. With the amount the image gets pulled this PR certainly has positive carbon-footprint implications. The change from Debian to Alpin should to be marked breaking and mentioned in the release notes, plugins will need to adapt their (native) install instructions to work on the docker as apt will not work. |
Not fully, need some further testing.
They don't use lots of things we need:
Yes definitely it will break some things. Idea: provide both alpine and Debian for the next release for a smooth transition period until plugins are adapted. Further analysis needed: Does switching out the images work easily with an already installed InvenTree. Maybe the venv that's mounted via volume contains some files that are not compatible with alpine. |
We definitely need to investigate this before we push this :) |
Oh and I forgot the biggest point why our alpine image is bigger than tandoors. Our codebase weights about 90MB with all the translated templates and po files. |
That should be solved by #2789 as we will only ship messages |
@wolflu05 I think we can remove gnupg - we do not ship the code that used it anymore. Would be interested in your thoughts on #5017 - background |
@wolflu05 just a friendly bump to see where you are up to with this :) |
Need to remove gnupg and do some more testing with other db drivers and also with existing installs. |
Are we still want to support the dev target from our current image? I don't think it's necessary as we have devcontainer and native install. |
I support moving entirely to alpine for base image
I suppose this is a fair point? But is there a downside to leaving it in, at least for a while, for anyone who would still be using this? |
|
@matmair @SchrodingersGat I'm done now with the changes I wanted to do. The image now weights
🚧 Help neededI already tested a lot of scenarios with existing installs, other dbms, already installed plugins, ... and everything worked so far. Before this is ready to merge, I'd like to ask if you could test this too so we do not overlook something. |
@wolflu05 awesome :) I'll take a look at this tonight |
The development image works as expected on my end. @matmair any final thoughts before we merge this in? |
LGTM; I take it that we are fully removing support for the Raspberry Pi architecture with this as the package resources are removed? |
# Weasyprint requirements : https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#debian-11 | ||
poppler-utils libpango-1.0-0 libpangoft2-1.0-0 \ | ||
RUN apk add --no-cache \ | ||
git gettext py-cryptography \ |
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.
Not sure we need git any more
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.
What about to install a plugin from a remote git repo?
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.
I do not think it is a good idea to push that way to install plugins; discovery is slower and the support for nested plugins is limited; pip as a distribution way is way cleaner
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.
I would argue to keep git and add a big note somewhere to the plugin dev
section. Sometimes you just want to test something and then git is easier.
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.
pip as a distribution way is way cleaner
Absolutely agreed, but there may be users who have their own plugins not available via pip?
|
||
# Server init entrypoint | ||
ENTRYPOINT ["/bin/bash", "./init.sh"] | ||
COPY InvenTree ./InvenTree |
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.
Should we clean up what we ship in a next step? Ie. remove contrib things, assets and anything else that is not needed to run the app.
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.
I don't think there is much we can remove, we already only copy the InvenTree folder.
@wolflu05 does removing RPi support gain us any space? I would imagine not? Perhaps it is beneficial to leave it in for anyone who wants to target raspbian |
Not sure, haven't tested, because I have no access to one, should I add it and Someone of you test it? |
I don't have a way to test it really, but I think maybe we should just leave those lines in. Unless you are building to target raspbian, they don't do anything |
@wolflu05 thanks for the fine work here :) |
@wolflu05 this PR truly was a breaking change: https://github.com/inventree/InvenTree/actions/runs/5506646753/jobs/10035587151 Looks like we did not run through the complete set of unit tests... Updateok, I missed that this line was deleted - these are pretty critical for report generation! Was this intentional, or an oversight? We'll need to add these back in. FixSee #5213 |
This PR refactors the docker image to reduce its size dramatically. It now weights
524MB
.TODO
fixes #4924