Skip to content
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

Install Python dependencies with pipenv #191

Conversation

mcdonnnj
Copy link
Member

🗣 Description

This pull request updates the image configuration to use Pipenv to install Python dependencies (finally worked up to a big change PR!). As part of that change it also switches to a multi-stage build.

Note

I am creating this pull request against a branch that will represent a larger body of work. This branch will later have a pull request against develop once the body of work is completed.

💭 Motivation and context

Since Docker image builds should be as repeatable as possible it makes sense to pin any Python dependencies to specific versions. Pipenv is used because it works well for Python deployment as it does not need any Python packaging. The multi-stage build just helps keep the final image slim as well as removing anything used for set up that is not needed for the image to function. You can see with other changes in place we are now at less than half the size of the previous image configuration:

$ docker image ls | grep example
cisagov/example                              improvement-pin_Python_configuration   bbdb68674dd2   11 minutes ago   110MB
cisagov/example                              latest                                 6f004e5869aa   4 years ago      223MB

🧪 Testing

Automated tests pass.

✅ Pre-approval checklist

  • This PR has an informative and human-readable title.
  • Changes are limited to a single goal - eschew scope creep!
  • All relevant type-of-change labels have been added.
  • I have read the CONTRIBUTING document.
  • These code changes follow cisagov code standards.
  • All relevant repo and/or project documentation has been updated
    to reflect the changes in this PR.
  • All new and existing tests pass.

This configuration includes a Pipfile configuration file and the
generated Pipfile.lock file that pins to specific versions for the
Python dependencies for this project. This will help us ensure
repeatable builds. The pipenv package is added as a developmental
requirement to support these files.
Now that we have a pipenv configuration we will use it to install the
Python dependencies for the image. The `build` workflow is updated to
no longer pass the VERSION build argument in line with this change.
Switch to using a multi-stage build in the Dockerfile. This reduces
image size since pipenv and its dependencices are not needed in the
final image. It also ensures that the system Python environment is
unmodified.
Install the core Python packages (pip, setuptools, and wheel) into the
system Python environment before installing pipenv. This keeps things
consistent with our usual approach to Python environments.
@mcdonnnj mcdonnnj added breaking change This issue or pull request involves changes to existing functionality improvement This issue or pull request will add or improve functionality, maintainability, or ease of use dependencies Pull requests that update a dependency file docker Pull requests that update Docker code labels Feb 28, 2024
@mcdonnnj mcdonnnj self-assigned this Feb 28, 2024
Copy link
Member

@jsf9k jsf9k left a comment

Choose a reason for hiding this comment

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

One small thing.

Dockerfile Outdated Show resolved Hide resolved
Copy link
Member

@dav3r dav3r left a comment

Choose a reason for hiding this comment

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

Outside the scope of this PR, but might as well clean it up while we are here - these versions in the README are out of sync with the current version (0.0.1):

skeleton-docker/README.md

Lines 142 to 144 in 8e03ad9

|`cisagov/example:1.2.3`| An exact release version. |
|`cisagov/example:1.2`| The most recent release matching the major and minor version numbers. |
|`cisagov/example:1`| The most recent release matching the major version number. |

They should look like this:

|`cisagov/example:0.0.1`| An exact release version. |
|`cisagov/example:0.0`| The most recent release matching the major and minor version numbers. |
|`cisagov/example:0`| The most recent release matching the major version number. |

I couldn't find a way to make this a commit suggestion.

Dockerfile Outdated Show resolved Hide resolved
src/Pipfile Show resolved Hide resolved
@mcdonnnj
Copy link
Member Author

Outside the scope of this PR, but might as well clean it up while we are here - these versions in the README are out of sync with the current version (0.0.1):

skeleton-docker/README.md

Lines 142 to 144 in 8e03ad9

|`cisagov/example:1.2.3`| An exact release version. |
|`cisagov/example:1.2`| The most recent release matching the major and minor version numbers. |
|`cisagov/example:1`| The most recent release matching the major version number. |

They should look like this:

|`cisagov/example:0.0.1`| An exact release version. |
|`cisagov/example:0.0`| The most recent release matching the major and minor version numbers. |
|`cisagov/example:0`| The most recent release matching the major version number. |

I couldn't find a way to make this a commit suggestion.

If you are amenable I will fix this in a later PR when I bump the version of cisagov/skeleton-python-library that is used. I think the original intent was to just use an example version vs. matching the version of the image 🤷

mcdonnnj and others added 2 commits February 28, 2024 12:04
The comment references a command that is no longer being run.

Co-authored-by: Shane Frasier <[email protected]>
@dav3r
Copy link
Member

dav3r commented Feb 28, 2024

If you are amenable I will fix this in a later PR when I bump the version of cisagov/skeleton-python-library that is used. I think the original intent was to just use an example version vs. matching the version of the image 🤷

That's fine with me, thanks. 👍

Copy link
Member

@dav3r dav3r left a comment

Choose a reason for hiding this comment

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

Excellent work! 👍

@mcdonnnj mcdonnnj merged commit 1b3e9d8 into improvement/update_Dockerfile_configuration Feb 28, 2024
16 checks passed
@mcdonnnj mcdonnnj deleted the improvement/pin_Python_configuration branch February 28, 2024 19:18
This was referenced Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change This issue or pull request involves changes to existing functionality dependencies Pull requests that update a dependency file docker Pull requests that update Docker code improvement This issue or pull request will add or improve functionality, maintainability, or ease of use
Projects
Development

Successfully merging this pull request may close these issues.

3 participants