-
Notifications
You must be signed in to change notification settings - Fork 7
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
Update Dockerfile configuration #195
Open
mcdonnnj
wants to merge
32
commits into
develop
Choose a base branch
from
improvement/update_Dockerfile_configuration
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 31 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
a1b9e94
Use the full identifier for source Docker images
mcdonnnj bac905d
Use a specific version of Alpine Linux
mcdonnnj ce1247a
Merge pull request #187 from cisagov/improvement/use_full_image_source
mcdonnnj 5088fdc
Install cisagov/skeleton-python-library directly
mcdonnnj 22aa084
Remove unused OS package dependencies
mcdonnnj 66032ea
Change the secret message being checks in tests
mcdonnnj aa39972
Merge pull request #188 from cisagov/improvement/install_skeleton-pyt…
mcdonnnj 6b36d69
Remove package upgrading
mcdonnnj 45f104a
Pin Python packages directly installed
mcdonnnj 446c9b5
Move WORKDIR instruction
mcdonnnj 0a49b3e
Merge pull request #189 from cisagov/improvement/make_builds_more_rep…
mcdonnnj 8534e1d
Prefer calling pip as a module
mcdonnnj 8113726
Use a Python virtual environment in the Docker image
mcdonnnj 77b5e34
Explain `ln` options being used
mcdonnnj 35e8753
Merge pull request #190 from cisagov/improvement/use_Python_venv
mcdonnnj 2266949
Add a pipenv configuration
mcdonnnj d530d07
Install Python dependencies using pipenv
mcdonnnj adfcfdb
Use a multi-stage Docker build
mcdonnnj 8e03ad9
Install core Python packages into the system Python environment
mcdonnnj c45345f
Fix outdated comment in the Dockerfile
mcdonnnj d42ae8f
Fix typo in Dockerfile comment
mcdonnnj 1b3e9d8
Merge pull request #191 from cisagov/improvement/pin_Python_configura…
mcdonnnj 2811690
Update image tag information in the README
mcdonnnj 5a601fe
Add instructions for managing Python dependencies
mcdonnnj 6d487cf
Merge pull request #192 from cisagov/improvement/update_readme
mcdonnnj 0d7cc8f
Bump setuptools from 69.1.0 to 69.1.1
mcdonnnj b28481f
Bump Python from 3.12.0 to 3.12.2
mcdonnnj fff262b
Bump Alpine Linux from 3.18 to 3.19
mcdonnnj dd7d982
Bump cisagov/skeleton-python-library from 0.0.1 to 0.2.0
mcdonnnj e054517
Bump version from 0.0.1 to 0.2.0
mcdonnnj d2c1ba2
Merge pull request #193 from cisagov/improvement/update_dependencies
mcdonnnj ae46c28
Correct usage of the term "symlink"
mcdonnnj 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 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 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,8 +1,59 @@ | ||
ARG VERSION=unspecified | ||
# Official Docker images are in the form library/<app> while non-official | ||
# images are in the form <user>/<app>. | ||
FROM docker.io/library/python:3.12.2-alpine3.19 as compile-stage | ||
|
||
FROM python:3.12.0-alpine | ||
### | ||
# Unprivileged user variables | ||
### | ||
ARG CISA_USER="cisa" | ||
ENV CISA_HOME="/home/${CISA_USER}" | ||
ENV VIRTUAL_ENV="${CISA_HOME}/.venv" | ||
|
||
ARG VERSION | ||
# Versions of the Python packages installed directly | ||
ENV PYTHON_PIP_VERSION=24.0 | ||
ENV PYTHON_PIPENV_VERSION=2023.12.1 | ||
ENV PYTHON_SETUPTOOLS_VERSION=69.1.1 | ||
ENV PYTHON_WHEEL_VERSION=0.42.0 | ||
|
||
### | ||
# Install the specified versions of pip, setuptools, and wheel into the system | ||
# Python environment; install the specified version of pipenv into the system Python | ||
# environment; set up a Python virtual environment (venv); and install the specified | ||
# versions of pip, setuptools, and wheel into the venv. | ||
# | ||
# Note that we use the --no-cache-dir flag to avoid writing to a local | ||
# cache. This results in a smaller final image, at the cost of | ||
# slightly longer install times. | ||
### | ||
RUN python3 -m pip install --no-cache-dir --upgrade \ | ||
pip==${PYTHON_PIP_VERSION} \ | ||
setuptools==${PYTHON_SETUPTOOLS_VERSION} \ | ||
wheel==${PYTHON_WHEEL_VERSION} \ | ||
&& python3 -m pip install --no-cache-dir --upgrade \ | ||
pipenv==${PYTHON_PIPENV_VERSION} \ | ||
# Manually create the virtual environment | ||
&& python3 -m venv ${VIRTUAL_ENV} \ | ||
# Ensure the core Python packages are installed in the virtual environment | ||
&& ${VIRTUAL_ENV}/bin/python3 -m pip install --no-cache-dir --upgrade \ | ||
pip==${PYTHON_PIP_VERSION} \ | ||
setuptools==${PYTHON_SETUPTOOLS_VERSION} \ | ||
wheel==${PYTHON_WHEEL_VERSION} | ||
|
||
### | ||
# Check the Pipfile configuration and then install the Python dependencies into | ||
# the virtual environment. | ||
# | ||
# Note that pipenv will install into a virtual environment if the VIRTUAL_ENV | ||
# environment variable is set. | ||
### | ||
WORKDIR /tmp | ||
COPY src/Pipfile src/Pipfile.lock ./ | ||
RUN pipenv check --verbose \ | ||
&& pipenv install --clear --deploy --extra-pip-args "--no-cache-dir" --verbose | ||
|
||
# Official Docker images are in the form library/<app> while non-official | ||
# images are in the form <user>/<app>. | ||
FROM docker.io/library/python:3.12.2-alpine3.19 as build-stage | ||
|
||
### | ||
# For a list of pre-defined annotation keys and value types see: | ||
|
@@ -27,15 +78,7 @@ ARG CISA_GID=${CISA_UID} | |
ARG CISA_USER="cisa" | ||
ENV CISA_GROUP=${CISA_USER} | ||
ENV CISA_HOME="/home/${CISA_USER}" | ||
|
||
### | ||
# Upgrade the system | ||
# | ||
# Note that we use apk --no-cache to avoid writing to a local cache. | ||
# This results in a smaller final image, at the cost of slightly | ||
# longer install times. | ||
### | ||
RUN apk --update --no-cache --quiet upgrade | ||
ENV VIRTUAL_ENV="${CISA_HOME}/.venv" | ||
|
||
### | ||
# Create unprivileged user | ||
|
@@ -44,52 +87,25 @@ RUN addgroup --system --gid ${CISA_GID} ${CISA_GROUP} \ | |
&& adduser --system --uid ${CISA_UID} --ingroup ${CISA_GROUP} ${CISA_USER} | ||
|
||
### | ||
# Dependencies | ||
# Copy in the Python virtual environment created in compile-stage, Sym-link the | ||
# Python binary in the venv to the system-wide Python and add the venv to the PATH. | ||
mcdonnnj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# | ||
# Note that we use apk --no-cache to avoid writing to a local cache. | ||
# This results in a smaller final image, at the cost of slightly | ||
# longer install times. | ||
### | ||
ENV DEPS \ | ||
ca-certificates \ | ||
openssl \ | ||
py-pip | ||
RUN apk --no-cache --quiet add ${DEPS} | ||
|
||
### | ||
# Make sure pip, setuptools, and wheel are the latest versions | ||
# | ||
# Note that we use pip3 --no-cache-dir to avoid writing to a local | ||
# cache. This results in a smaller final image, at the cost of | ||
# slightly longer install times. | ||
### | ||
RUN pip3 install --no-cache-dir --upgrade \ | ||
pip \ | ||
setuptools \ | ||
wheel | ||
|
||
WORKDIR ${CISA_HOME} | ||
|
||
### | ||
# Install Python dependencies | ||
# | ||
# Note that we use pip3 --no-cache-dir to avoid writing to a local | ||
# cache. This results in a smaller final image, at the cost of | ||
# slightly longer install times. | ||
### | ||
RUN wget --output-document sourcecode.tgz \ | ||
https://github.com/cisagov/skeleton-python-library/archive/v${VERSION}.tar.gz \ | ||
&& tar --extract --gzip --file sourcecode.tgz --strip-components=1 \ | ||
&& pip3 install --no-cache-dir --requirement requirements.txt \ | ||
&& ln -snf /run/secrets/quote.txt src/example/data/secret.txt \ | ||
&& rm sourcecode.tgz | ||
# Note that we sym-link the Python binary in the venv to the system-wide Python so that | ||
# any calls to `python3` will use our virtual environment. We are using short flags | ||
mcdonnnj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# because the ln binary in Alpine Linux does not support long flags. The -f instructs | ||
# ln to remove the existing file and the -s instructs ln to create a symbolic link. | ||
### | ||
COPY --from=compile-stage --chown=${CISA_USER}:${CISA_GROUP} ${VIRTUAL_ENV} ${VIRTUAL_ENV} | ||
RUN ln -fs "$(command -v python3)" "${VIRTUAL_ENV}"/bin/python3 | ||
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. TIL you can |
||
ENV PATH="${VIRTUAL_ENV}/bin:$PATH" | ||
|
||
### | ||
# Prepare to run | ||
### | ||
ENV ECHO_MESSAGE="Hello World from Dockerfile" | ||
WORKDIR ${CISA_HOME} | ||
USER ${CISA_USER}:${CISA_GROUP} | ||
EXPOSE 8080/TCP | ||
VOLUME ["/var/log"] | ||
ENTRYPOINT ["example"] | ||
CMD ["--log-level", "DEBUG"] | ||
CMD ["--log-level", "DEBUG", "8", "2"] |
This file contains 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 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,3 +1,4 @@ | ||
--requirement requirements-test.txt | ||
ipython | ||
pipenv | ||
semver |
This file contains 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[[source]] | ||
url = "https://pypi.org/simple" | ||
verify_ssl = true | ||
name = "pypi" | ||
|
||
# List any Python dependencies for the image here | ||
[packages] | ||
# This should match the version of the image | ||
example = {file = "https://github.com/cisagov/skeleton-python-library/archive/v0.2.0.tar.gz"} | ||
|
||
# This version should match the version of Python in the image | ||
[requires] | ||
python_full_version = "3.12.2" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 +1 @@ | ||
__version__ = "0.0.1" | ||
__version__ = "0.2.0" |
This file contains 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
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.
Since this is the
compile-stage
of the build, do we need to optimize for layer count. i.e., does it still make sense to concatenate each command with&&
versus having discreetRUN
s.I ask because I think you will get a more localized error statement when something fails when the command is decomposed. There may be some other gains to be had as well with caching, and parallelization.