Skip to content

Commit 11270fc

Browse files
authored
Initial implementation (#3)
The initial implementation of a native (non-shimmed) libcnb.rs-based Python CNB.
1 parent 89a589d commit 11270fc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+4873
-1
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @heroku/languages

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "cargo"
4+
directory: "/"
5+
schedule:
6+
interval: "monthly"
7+
- package-ecosystem: "github-actions"
8+
directory: "/"
9+
schedule:
10+
interval: "monthly"

.github/workflows/check_changelog.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Check Changelog
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, labeled, unlabeled, synchronize]
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
check-changelog:
12+
runs-on: ubuntu-latest
13+
if: |
14+
!contains(github.event.pull_request.labels.*.name, 'skip changelog') &&
15+
!contains(github.event.pull_request.labels.*.name, 'dependencies')
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v3
19+
- name: Check that CHANGELOG is touched
20+
run: |
21+
git fetch origin ${{ github.base_ref }} --depth 1 && \
22+
git diff remotes/origin/${{ github.base_ref }} --name-only | grep CHANGELOG.md

.github/workflows/ci.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
# Avoid duplicate builds on PRs.
6+
branches:
7+
- main
8+
pull_request:
9+
10+
permissions:
11+
contents: read
12+
13+
env:
14+
CARGO_TERM_COLOR: always
15+
16+
jobs:
17+
lint:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v3
22+
- name: Update Rust toolchain
23+
run: rustup update
24+
- name: Rust Cache
25+
uses: Swatinem/[email protected]
26+
- name: Clippy
27+
run: cargo clippy --all-targets --locked -- --deny warnings
28+
- name: rustfmt
29+
run: cargo fmt -- --check
30+
31+
unit-test:
32+
runs-on: ubuntu-latest
33+
steps:
34+
- name: Checkout
35+
uses: actions/checkout@v3
36+
- name: Update Rust toolchain
37+
run: rustup update
38+
- name: Rust Cache
39+
uses: Swatinem/[email protected]
40+
- name: Run unit tests
41+
run: cargo test --locked
42+
43+
integration-test:
44+
runs-on: ubuntu-latest
45+
strategy:
46+
fail-fast: false
47+
matrix:
48+
builder: ["builder:22", "buildpacks:20"]
49+
env:
50+
INTEGRATION_TEST_CNB_BUILDER: heroku/${{ matrix.builder }}
51+
steps:
52+
- name: Checkout
53+
uses: actions/checkout@v3
54+
- name: Install musl-tools
55+
run: sudo apt-get install musl-tools --no-install-recommends
56+
- name: Update Rust toolchain
57+
run: rustup update
58+
- name: Install Rust linux-musl target
59+
run: rustup target add x86_64-unknown-linux-musl
60+
- name: Rust Cache
61+
uses: Swatinem/[email protected]
62+
- name: Install Pack CLI
63+
uses: buildpacks/github-actions/[email protected]
64+
- name: Run integration tests
65+
# Runs only tests annotated with the `ignore` attribute (which in this repo, are the integration tests).
66+
run: cargo test --locked -- --ignored --test-threads 5

.github/workflows/release.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Release Buildpack
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
contents: write
8+
9+
env:
10+
BUILDPACK_DOCKER_REPO: docker.io/heroku/buildpack-python
11+
CARGO_TERM_COLOR: always
12+
13+
jobs:
14+
# Releases the buildpack to Docker Hub and registers it with the CNB Buildpack Registry.
15+
# This release process intentionally does not create a .cnb file release for now, since
16+
# there are currently no use-cases that need it for Python.
17+
release:
18+
name: Release heroku/python
19+
runs-on: ubuntu-latest
20+
steps:
21+
# Setup
22+
- name: Checkout
23+
uses: actions/checkout@v3
24+
- name: Install musl-tools
25+
run: sudo apt-get install musl-tools --no-install-recommends
26+
- name: Update Rust toolchain
27+
run: rustup update
28+
- name: Install Rust linux-musl target
29+
run: rustup target add x86_64-unknown-linux-musl
30+
- name: Rust Cache
31+
uses: Swatinem/[email protected]
32+
- name: Install libcnb-cargo
33+
run: cargo install libcnb-cargo
34+
- name: Install Pack CLI
35+
uses: buildpacks/github-actions/[email protected]
36+
- name: Install yj and crane
37+
uses: buildpacks/github-actions/[email protected]
38+
- name: Login to Docker Hub
39+
uses: docker/login-action@v2
40+
with:
41+
registry: docker.io
42+
username: ${{ secrets.DOCKER_HUB_USER }}
43+
password: ${{ secrets.DOCKER_HUB_TOKEN }}
44+
45+
# Build
46+
- name: Compile the buildpack
47+
run: cargo libcnb package --release
48+
49+
# Publish
50+
- name: Read buildpack metadata
51+
run: |
52+
echo "buildpack_id=$(yj -t < buildpack.toml | jq -r .buildpack.id)" >> $GITHUB_ENV
53+
echo "buildpack_version=$(yj -t < buildpack.toml | jq -r .buildpack.version)" >> $GITHUB_ENV
54+
- name: Check version is unique on Docker Hub
55+
run: |
56+
if docker manifest inspect "${{ env.BUILDPACK_DOCKER_REPO }}:${{ env.buildpack_version }}" > /dev/null; then
57+
echo "Duplicate version found on Docker Hub ${{ env.BUILDPACK_DOCKER_REPO }}:${{ env.buildpack_version }}"
58+
exit 1
59+
fi
60+
- name: Publish the buildpack to Docker Hub
61+
run: pack buildpack package --path target/buildpack/release/heroku_python --publish "${{ env.BUILDPACK_DOCKER_REPO }}:${{ env.buildpack_version }}"
62+
- name: Calculate the buildpack image digest
63+
run: echo "buildpack_digest=$(crane digest ${{ env.BUILDPACK_DOCKER_REPO }}:${{ env.buildpack_version }})" >> $GITHUB_ENV
64+
- name: Register the new version with the CNB Buildpack Registry
65+
uses: docker://ghcr.io/buildpacks/actions/registry/request-add-entry:5.0.1
66+
with:
67+
token: ${{ secrets.CNB_REGISTRY_RELEASE_BOT_GITHUB_TOKEN }}
68+
id: ${{ env.buildpack_id }}
69+
version: ${{ env.buildpack_version }}
70+
address: ${{ env.BUILDPACK_DOCKER_REPO }}@${{ env.buildpack_digest }}
71+
- name: Create GitHub release
72+
uses: actions/create-release@v1
73+
env:
74+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75+
with:
76+
tag_name: v${{ env.buildpack_version }}
77+
release_name: v${{ env.buildpack_version }}
78+
body: |
79+
See the [CHANGELOG](./CHANGELOG.md) for details.
80+
draft: false

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
__pycache__/
2+
target/
3+
.DS_Store

.vscode/extensions.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["rust-lang.rust-analyzer"],
3+
}

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"rust-analyzer.check.command": "clippy",
3+
"rust-analyzer.imports.granularity.enforce": true,
4+
"rust-analyzer.imports.granularity.group": "module",
5+
"rust-analyzer.imports.prefix": "crate",
6+
}

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Added
11+
12+
- Initial implementation.

0 commit comments

Comments
 (0)