Skip to content

Docker improvements - #3042

Merged
SchrodingersGat merged 41 commits into
inventree:masterfrom
SchrodingersGat:docker-image
May 28, 2022
Merged

SchrodingersGat merged 41 commits into
inventree:masterfrom
SchrodingersGat:docker-image

Conversation

@SchrodingersGat

@SchrodingersGat SchrodingersGat commented May 20, 2022 •

Copy link
Copy Markdown
Member

Experimenting with changing docker image base from alpine to python:slim

Also trying to remove requirement for cairo, and update to latest version of weasyprint.

Weasyprint updates

Changing to a python:slim base docker image has seemingly fixed the issues which were preventing an update to django-weasyprint - ref #2456 .

Image Comparison

Alpine python:slim
Size 1.82GB 932MB
Build Time 390s 232s 151s

TODO

  • Update docker installation instructions to match new format - Docker improvements #3042
  • Get the git commit hash back into the production image (we no longer include the .git directory)
  • Simplify docker build-and-push process (consolidate to a single .github workflow)
  • Fix root user issues for production image

- Changed from alpine to python:slim
- Removed some database libs (because we *connect* to a db, not host it)
@SchrodingersGat SchrodingersGat added enhancement This is an suggested enhancement or new feature CI CI / unit testing ecosystem docker Docker / docker-compose setup Relates to the InvenTree setup / installation process labels May 20, 2022
@SchrodingersGat SchrodingersGat modified the milestones: 0.7.0, 0.8.0 May 20, 2022
@matmair

matmair commented May 23, 2022

Copy link
Copy Markdown
Member

@SchrodingersGat these numbers look much better. Do you think we could get under 500 MBs? That is the magical number for a lot of included private docker registries.

@SchrodingersGat

Copy link
Copy Markdown
Member Author

I think that 500MB would be an ambitious target, not sure what else we can trim at this point!

@matmair

matmair commented May 23, 2022 •

Copy link
Copy Markdown
Member

@SchrodingersGat have you tried the python-alpine image? It seems to be only 90MB. I just tried - It does not help.

- Only drop to non-root user as part of "production" build
- Mounted external volumes make it tricky when in the dev build
- Might want to revisit this later on
- reduce required system packages
-
@SchrodingersGat
SchrodingersGat deleted the docker-image branch May 24, 2022 14:06
@SchrodingersGat
SchrodingersGat restored the docker-image branch May 24, 2022 14:07
@SchrodingersGat

SchrodingersGat commented May 24, 2022 •

Copy link
Copy Markdown
Member Author

@matmair any idea why the sqlite coverage checks are failing here? Nominally I have not changed any internal code or tests, only the docker image, but the test is not running under docker...

Edit: It is because I have updated the weasyprint version, and your wonderful unit tests have thrown an error ⭐

@SchrodingersGat

Copy link
Copy Markdown
Member Author

@matmair reasonable. I'll leave the CI stuff how it is.

@SchrodingersGat
SchrodingersGat requested a review from matmair May 28, 2022 15:02
@SchrodingersGat

Copy link
Copy Markdown
Member Author

@matmair I think this is getting pretty close now - LMK what you think. I would like to get this merged in before thinking about signing the docker image in a different PR

@matmair matmair left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SchrodingersGat there are a few open questions form my side - especially moving the dockerfile and removing deploy info.


on:
release:
types: [published]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great for automation

uses: ./.github/actions/setup
with:
apt-dependency: gettext
apt-dependency: gettext poppler-utils

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we mabybe add this requirement to the docs?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point - I'll add this to inventree/inventree-docs#295

@@ -1,21 +0,0 @@
# Checks version number
name: version number

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The less workflows the better!

Comment thread Dockerfile
@@ -49,82 +50,82 @@ LABEL org.label-schema.schema-version="1.0" \
org.label-schema.vendor="inventree" \
org.label-schema.name="inventree/inventree" \
org.label-schema.url="https://hub.docker.com/r/inventree/inventree" \
org.label-schema.vcs-url=${INVENTREE_GIT_REPO} \
org.label-schema.vcs-branch=${INVENTREE_GIT_BRANCH} \
org.label-schema.vcs-ref=${INVENTREE_GIT_TAG}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SchrodingersGat don't we need this tag?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The git commit information is now passed through to the docker image at build time - the "production" image does not contain the .git directory any longer

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tags are exposed if the image is up - right? A user once told me that he uses the image labels for kubernetes automation.

Comment on lines +384 to +386
"""Test that the git commit information is extracted successfully"""

envs = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: To conform with google docstyle there eshould be no newline here

Comment thread docker/production/.env
INVENTREE_LOG_LEVEL=WARNING

# InvenTree admin account details
# Un-comment (and complete) these lines to auto-create an admin acount

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving unused passwords in the env can be dangerous - should we maybe also add a note about this?

Suggestion:

Remove the entered credentials after the first run

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

Comment thread requirements.txt
flake8-docstrings==1.6.0 # docstring format testing
gunicorn>=20.1.0 # Gunicorn web server
importlib_metadata # Backport for importlib.metadata
inventree # Install the latest version of the InvenTree API python library

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea why that was in here in the first place? Seems to be a non-dependency for deployment enviroments

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it crept in during my testing and never got removed. No real reason to have it here at all.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am currently looking into pip-tools and using full dependency pinning - that might be more stable for testing and deployment. The secondary dependencies could vary the way we do it now.

Comment thread tasks.py

# Install required Python packages with PIP
c.run('pip3 install -U -r requirements.txt')
c.run('pip3 install --no-cache-dir --disable-pip-version-check -U -r requirements.txt')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Won't --no-cache-dir increase the download traffic a lot?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm not sure about that. Might be worth checking. My understanding was that it reduced the final docker image size

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did not know that - always learning new stuff! Then I think this is the right step 👍

Comment thread docker-compose.yml
# This directory specified where InvenTree source code is stored "outside" the docker containers
# By default, this directory is one level above the "docker" directory
device: ${INVENTREE_EXT_VOLUME:-../}
device: ${INVENTREE_EXT_VOLUME:-./}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Any specific reason for the move?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. Previously the docker build was performed from within the ./docker directory, and involved re-downloading the source code from git based on the specified tag. However as we are now building from the github workflow, we have already defined the context of the built image (latest / stable / tag) and so we can use the simpler process of copying source files into the image.

However this needs to be performed from the top-level directory as you cannot COPY files from a directory above

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems more efficient, I like it!

Comment thread deploy/supervisord.conf
@@ -1,46 +0,0 @@
; # Supervisor Config File

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Why is this removed? I am pretty sure we are linking to this in the docs for bare metal installs

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah you're right. I did a cursory search and thought it was orphaned.. I'll add it back in.

@SchrodingersGat
SchrodingersGat requested a review from matmair May 28, 2022 22:12
@SchrodingersGat

Copy link
Copy Markdown
Member Author

@matmair thanks for the review. Have made a few changes as suggested

@matmair

matmair commented May 28, 2022

Copy link
Copy Markdown
Member

@matmair thanks for the review. Have made a few changes as suggested

@SchrodingersGat great changes! Should be fine now in my view.

@SchrodingersGat

SchrodingersGat commented May 28, 2022 •

Copy link
Copy Markdown
Member Author

@matmair regarding the --no-cache-dir option:

build time / image size

with --no-cache-dir option

185s / 989MB

without --no-cache-dir option

115s / 1.04GB

I'd say the hit to image size is worth it, given the major reduction in build time

@SchrodingersGat
SchrodingersGat merged commit b9fd263 into inventree:master May 28, 2022
@SchrodingersGat
SchrodingersGat deleted the docker-image branch May 28, 2022 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI CI / unit testing ecosystem docker Docker / docker-compose enhancement This is an suggested enhancement or new feature plugin Plugin ecosystem report Report/Label generation setup Relates to the InvenTree setup / installation process

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FR] Conslidate docker CI steps Remove cairo dependency

2 participants