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

Set PYTHONPYCACHEPREFIX to /tmp during build phase. #442

Merged
merged 2 commits into from
Oct 25, 2022

Conversation

robdimsdale
Copy link
Member

Summary

This PR enables reproducible builds by discarding the __pycache__ directories at the end of the build phase for this buildpack and all subsequent buildpacks that depend on this.

This is in contrast to the current behavior of persisting the __pycache__ directories in each buildpack's layer.

It also updates the README to include this new configuration and various other minor README improvements.

We have not observed any performance issues with this configuration: discarding the __pycache__ directories at the end of each buildpack's build phase does not seem to impact the performance of any buildpack.

Background

  • The __pycache__ directories are not reproducible and are effectively opaque to us. We cannot make them reproducible, so discarding them is the only option for reproducible builds.
  • The PYTHONPYCACHEPREFIX environment variable was chosen to allow users to override it if needed, whereas setting PYTHONDONTWRITEBYTECODE=true would have been harder, if not impossible, to allow users to override.
  • Setting this environment variable as a build environment on the layer (v.s. e.g. in process via os.SetEnv()) means all subsequent buildpacks (e.g. pip, poetry, etc) will have this environment variable set automatically by the lifecycle, rather than having to implement this themselves in each buildpack.
  • We only set this environment variable for the build phase (and not the launch phase) to allow users to continue to leverage __pycache__ directories at launch time if they wish. The current launch-time behavior of defaulting to $HOME/.pycache is unchanged.

Use Cases

Enables reproducible builds in this buildpack and some subsequent buildpacks.

Fixes #426

Checklist

  • I have viewed, signed, and submitted the Contributor License Agreement.
  • I have linked issue(s) that this PR should close using keywords or the Github UI (See docs)
  • I have added an integration test, if necessary.
  • I have reviewed the styleguide for guidance on my code quality.
  • I'm happy with the commit history on this PR (I have rebased/squashed as needed).

@robdimsdale robdimsdale added the semver:minor A change requiring a minor version bump label Oct 19, 2022
@robdimsdale robdimsdale requested a review from a team as a code owner October 19, 2022 17:44
@robdimsdale robdimsdale self-assigned this Oct 19, 2022
ryanmoran
ryanmoran previously approved these changes Oct 19, 2022
- This enables reproducible builds by discarding the `__pycache__` directories
  (instead of the current behavior of persisting them in the cpython layer).
- The `__pycache__` directories are not reproducible and are effectively opaque
  to us. We cannot make them reproducible, so discarding them is the only
  option for reproducible builds.
- The PYTHONPYCACHEPREFIX environment variable was chosen to allow users to
  override it if needed, whereas setting PYTHONDONTWRITEBYTECODE=true would
  have been harder, if not impossible, to allow users to override.
- Setting this environment variable as a build environment on the layer
  (v.s. e.g. in process via os.SetEnv()) means all subsequent buildpacks (e.g.
  pip, poetry, etc) will have this environment variable set automatically by
  the lifecycle.
- We only set this environment variable for the build phase (and not the launch
  phase) to allow users to continue to leverage `__pycache__` directories at
  launch time if they wish. The current launch-time behavior of defaulting to
  $HOME/.pycache is unchanged.
- Also update the README to include this new feature and various other minor
  README improvements.
@joshuatcasey joshuatcasey enabled auto-merge (squash) October 25, 2022 17:59
@joshuatcasey joshuatcasey merged commit 37ddf83 into main Oct 25, 2022
@joshuatcasey joshuatcasey deleted the set-tmp-pycacheprefix-build branch October 25, 2022 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver:minor A change requiring a minor version bump
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Prevent __pycache__ directories in /layers at build time
3 participants