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

Initial implementation #3

Merged
merged 71 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
719f105
Functions MVP
edmorley Dec 9, 2022
d87a78d
Install salesforce-functions from PyPI now it's been published
edmorley Dec 14, 2022
4e5ba1e
Fix CI after salesforce-functions 0.2.0 release
edmorley Jan 2, 2023
fca044c
Bump minimum Rust version to 1.66
edmorley Jan 2, 2023
406f255
Only use major versions in Cargo.toml
edmorley Jan 2, 2023
f687559
Skip check changelog for Dependabot PRs
edmorley Jan 2, 2023
35a6dde
Refresh lockfile
edmorley Jan 2, 2023
11efc72
Remove support for skipping check-changelog using the PR description
edmorley Jan 6, 2023
f518418
Update buildpacks/github-actions to 5.0.1
edmorley Jan 6, 2023
cc2fb09
Remove workarounds for slow M1 performance
edmorley Jan 14, 2023
d0ed798
Refresh Cargo.lock
edmorley Jan 17, 2023
fb848be
Update test after salesforce-functions v0.3.0 release
edmorley Jan 17, 2023
a4abc3f
Remove functions integration test for too-old Python
edmorley Jan 27, 2023
40aa0af
Remove caching support from the pip layer
edmorley Jan 27, 2023
2abc573
Add VSCode configs
edmorley Jan 27, 2023
ef88b80
Bump minimum Rust version to 1.67
edmorley Jan 27, 2023
1be9dc4
Refresh Cargo.lock
edmorley Jan 27, 2023
42343e3
Switch Dependabot to monthly
edmorley Jan 27, 2023
3489dc5
Switch GitHub Action runner image back to `ubuntu-latest`
edmorley Jan 27, 2023
eb98a86
Remove now-unused test fixture
edmorley Jan 27, 2023
47d06d5
Pass detect for non-functions too
edmorley Jan 28, 2023
76c2822
Update to pip 23.0, setuptools 67.0.0, wheel 0.38.4
edmorley Jan 31, 2023
da42891
Clean up functions handling
edmorley Feb 1, 2023
1ac2ec6
More unit tests, rustdocs and comments
edmorley Feb 1, 2023
448921e
Switch buildpack ID back to `heroku/python`
edmorley Feb 1, 2023
92046bb
Test `heroku/buildpacks:20` in CI too
edmorley Feb 1, 2023
6c32581
Shorten CI job name
edmorley Feb 1, 2023
d849fae
Update Cargo dependencies
edmorley Feb 3, 2023
f85f39d
Update to setuptools 67.1.0
edmorley Feb 3, 2023
bbe592d
Remove notes.md
edmorley Feb 3, 2023
d5bb909
Update LICENSE year
edmorley Feb 3, 2023
2f66e68
Move fixtures under tests/fixtures/
edmorley Feb 3, 2023
7387625
Switch check-changelog to `ubuntu-latest`
edmorley Feb 3, 2023
8ef2a84
Fix functions integration test after 0.5.0 release
edmorley Feb 3, 2023
70373e5
Add CHANGELOG.md
edmorley Feb 3, 2023
1d2db46
Only run CI on PRs not branches
edmorley Feb 3, 2023
a53fd3e
Switch from env var to `--disable-pip-version-check`
edmorley Feb 7, 2023
c9bae31
Python/pip layer refactoring + unit tests
edmorley Feb 7, 2023
631b212
Refresh Cargo.lock
edmorley Feb 7, 2023
391519e
Cleanup errors.rs
edmorley Feb 7, 2023
bb01b50
Add `.env_clear()` to all `Command` usages
edmorley Feb 8, 2023
49fdb60
Refactor pip dependencies layer env handling + add a test
edmorley Feb 8, 2023
2b6bf42
s/env/command_env/
edmorley Feb 9, 2023
4ad4245
More rustdocs/comments
edmorley Feb 9, 2023
09083da
s/functions/salesforce_functions/
edmorley Feb 9, 2023
ea35f11
Improve naming of error enums and their variants
edmorley Feb 9, 2023
401984a
Clean up SOURCE_DATE_EPOCH usages
edmorley Feb 9, 2023
7e5873b
Bump default Python to the newly released 3.11.2
edmorley Feb 10, 2023
f8ccc42
Switch back to using `PIP_DISABLE_PIP_VERSION_CHECK`
edmorley Feb 16, 2023
1924ef0
Add integration tests
edmorley Feb 16, 2023
a8febff
Try `--test-threads 10` for integration tests in CI
edmorley Feb 20, 2023
a7e3148
`--test-threads 6`
edmorley Feb 20, 2023
544dba9
`--test-threads 4`
edmorley Feb 20, 2023
04d0c16
`--test-threads 5`
edmorley Feb 20, 2023
fa4b16e
Update Swatinem/rust-cache to v2.2.1
edmorley Feb 24, 2023
457a017
Improve cache and logging
edmorley Feb 24, 2023
583b04f
Refactor Python runtime archive URL generation
edmorley Feb 27, 2023
2a92049
Update dependencies
edmorley Feb 27, 2023
9bc83dd
Refactor PackagingToolVersions
edmorley Feb 27, 2023
9048996
More rustdocs
edmorley Feb 27, 2023
c602666
Refactor integration tests
edmorley Feb 28, 2023
ff1c62c
Add work item numbers to some of the TODOs
edmorley Feb 28, 2023
f22600c
Misc cleanup
edmorley Mar 1, 2023
b189360
Address review comments
edmorley Mar 1, 2023
e95f00e
Add a release script
edmorley Mar 1, 2023
630d74f
Add duplicate version check to release workflow
edmorley Mar 1, 2023
7dce0d5
Fix comment typo
edmorley Mar 3, 2023
1922305
Clarify comment about env var inheritance
edmorley Mar 6, 2023
55349e4
Fix comment typo in package_manager.rs
edmorley Mar 6, 2023
b2b796f
Update to setuptools 67.5.0
edmorley Mar 6, 2023
dd390e9
Refresh Cargo.lock
edmorley Mar 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Release Buildpack

on:
workflow_dispatch:

permissions:
contents: write

env:
BUILDPACK_DOCKER_REPO: docker.io/heroku/buildpack-python
CARGO_TERM_COLOR: always

jobs:
# Releases the buildpack to Docker Hub and registers it with the CNB Buildpack Registry.
# This release process intentionally does not create a .cnb file release for now, since
# there are currently no use-cases that need it for Python.
release:
name: Release heroku/python
runs-on: ubuntu-latest
steps:
# Setup
- name: Checkout
uses: actions/checkout@v3
- name: Install musl-tools
run: sudo apt-get install musl-tools --no-install-recommends
- name: Update Rust toolchain
run: rustup update
- name: Install Rust linux-musl target
run: rustup target add x86_64-unknown-linux-musl
- name: Rust Cache
uses: Swatinem/rust-cache@v2.2.1
- name: Install libcnb-cargo
run: cargo install libcnb-cargo
- name: Install Pack CLI
uses: buildpacks/github-actions/setup-pack@v5.0.1
- name: Install yj and crane
uses: buildpacks/github-actions/setup-tools@v5.0.1
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
registry: docker.io
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}

# Build
- name: Compile the buildpack
run: cargo libcnb package --release

# Publish
- name: Read buildpack metadata
run: |
echo "buildpack_id=$(yj -t < buildpack.toml | jq -r .buildpack.id)" >> $GITHUB_ENV
echo "buildpack_version=$(yj -t < buildpack.toml | jq -r .buildpack.version)" >> $GITHUB_ENV
- name: Check version is unique on Docker Hub
run: |
if docker manifest inspect "${{ env.BUILDPACK_DOCKER_REPO }}:${{ env.buildpack_version }}" > /dev/null; then
echo "Duplicate version found on Docker Hub ${{ env.BUILDPACK_DOCKER_REPO }}:${{ env.buildpack_version }}"
exit 1
fi
- name: Publish the buildpack to Docker Hub
run: pack buildpack package --path target/buildpack/release/heroku_python --publish "${{ env.BUILDPACK_DOCKER_REPO }}:${{ env.buildpack_version }}"
- name: Calculate the buildpack image digest
run: echo "buildpack_digest=$(crane digest ${{ env.BUILDPACK_DOCKER_REPO }}:${{ env.buildpack_version }})" >> $GITHUB_ENV
- name: Register the new version with the CNB Buildpack Registry
uses: docker://ghcr.io/buildpacks/actions/registry/request-add-entry:5.0.1
with:
token: ${{ secrets.CNB_REGISTRY_RELEASE_BOT_GITHUB_TOKEN }}
id: ${{ env.buildpack_id }}
version: ${{ env.buildpack_version }}
address: ${{ env.BUILDPACK_DOCKER_REPO }}@${{ env.buildpack_digest }}
- name: Create GitHub release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ env.buildpack_version }}
release_name: v${{ env.buildpack_version }}
body: |
See the [CHANGELOG](./CHANGELOG.md) for details.
draft: false
5 changes: 2 additions & 3 deletions src/layers/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ fn generate_layer_env(layer_path: &Path, python_version: &PythonVersion) -> Laye
//
// One option to solve all of the above, would be to delete the `.pyc` files from the image
// at the end of the buildpack's build phase, however:
// - This means they need to be regenerated at app start boot, slowing boot times.
// - This means they need to be regenerated at app boot, slowing boot times.
// (For a simple Django project on a Perf-M, boot time increases from ~0.5s to ~1.5s.)
// - If any other later buildpack runs any of the Python files added by this buildpack, then
// the timestamp based `.pyc` files will be created again, re-introducing non-determinism.
Expand Down Expand Up @@ -425,11 +425,10 @@ impl From<PythonLayerError> for BuildpackError {

#[cfg(test)]
mod tests {
use super::*;
use indoc::indoc;
use libcnb::data::stack_id;

use super::*;

#[test]
fn cache_invalidation_reason_unchanged() {
let metadata = PythonLayerMetadata {
Expand Down
2 changes: 2 additions & 0 deletions src/packaging_tool_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use serde::{Deserialize, Serialize};

/// The versions of various packaging tools used during the build.
/// These are always installed, and are independent of the chosen package manager.
/// Strings are unused instead of a semver version, since these packages don't use
edmorley marked this conversation as resolved.
Show resolved Hide resolved
/// semver, and we never introspect the version parts anyway.
edmorley marked this conversation as resolved.
Show resolved Hide resolved
#[derive(Clone, Deserialize, PartialEq, Serialize)]
edmorley marked this conversation as resolved.
Show resolved Hide resolved
pub(crate) struct PackagingToolVersions {
pub pip_version: String,
Expand Down
6 changes: 3 additions & 3 deletions src/python_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ impl PythonVersion {
}

pub fn url(&self, stack_id: &StackId) -> String {
Malax marked this conversation as resolved.
Show resolved Hide resolved
// TODO: (W-11474658) Switch to tracking versions/URLs via a manifest file.
format!(
"https://heroku-buildpack-python.s3.us-east-1.amazonaws.com/{}/runtimes/python-{}.{}.{}.tar.gz",
stack_id, self.major, self.minor, self.patch
Expand Down Expand Up @@ -77,9 +78,8 @@ pub(crate) enum PythonVersionError {

#[cfg(test)]
mod tests {
use libcnb::data::stack_id;

use super::*;
use libcnb::data::stack_id;

#[test]
fn python_version_url() {
Expand All @@ -98,7 +98,7 @@ mod tests {
assert_eq!(
determine_python_version(Path::new("tests/fixtures/runtime_txt_non_existent_version"))
.unwrap(),
PythonVersion::new(999, 999, 999)
PythonVersion::new(999, 888, 777)
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/runtime_txt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ mod tests {
);
assert_eq!(
read_version(Path::new("tests/fixtures/runtime_txt_non_existent_version")).unwrap(),
Some(PythonVersion::new(999, 999, 999))
Some(PythonVersion::new(999, 888, 777))
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python-999.999.999
python-999.888.777
4 changes: 1 addition & 3 deletions tests/integration/python_version.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// runtime.txt parsing

use crate::integration_tests::{
builder, DEFAULT_PYTHON_VERSION, LATEST_PYTHON_3_10, LATEST_PYTHON_3_11, LATEST_PYTHON_3_7,
Malax marked this conversation as resolved.
Show resolved Hide resolved
LATEST_PYTHON_3_8, LATEST_PYTHON_3_9,
Expand Down Expand Up @@ -125,7 +123,7 @@ fn runtime_txt_invalid_version() {
fn runtime_txt_non_existent_version() {
rejects_non_existent_python_version(
"tests/fixtures/runtime_txt_non_existent_version",
"999.999.999",
"999.888.777",
);
}

Expand Down