Skip to content

Commit 50aac0c

Browse files
chore: bump dependencies, migrate to uv
1 parent bbffbb4 commit 50aac0c

File tree

4 files changed

+60
-52
lines changed

4 files changed

+60
-52
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ on:
1414

1515
env:
1616
# Common versions
17-
PYTHON_VERSION: '3.11'
18-
HATCH_VERSION: '1.12.0'
19-
DOCKER_BUILDX_VERSION: 'v0.24.0'
17+
PYTHON_VERSION: '3.13'
18+
HATCH_VERSION: '1.15.1'
19+
DOCKER_BUILDX_VERSION: 'v0.29.1'
2020

2121
# These environment variables are important to the Crossplane CLI install.sh
2222
# script. They determine what version it installs.
2323
XP_CHANNEL: stable
24-
XP_VERSION: v1.20.0
24+
XP_VERSION: v2.1.0
2525

2626
# The package to push, without a version tag. The default matches GitHub. For
2727
# example xpkg.crossplane.io/crossplane/function-template-go. Note that
@@ -37,10 +37,10 @@ jobs:
3737
runs-on: ubuntu-24.04
3838
steps:
3939
- name: Checkout
40-
uses: actions/checkout@v5
40+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
4141

4242
- name: Setup Python
43-
uses: actions/setup-python@v6
43+
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6
4444
with:
4545
python-version: ${{ env.PYTHON_VERSION }}
4646

@@ -54,10 +54,10 @@ jobs:
5454
runs-on: ubuntu-24.04
5555
steps:
5656
- name: Checkout
57-
uses: actions/checkout@v5
57+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
5858

5959
- name: Setup Python
60-
uses: actions/setup-python@v6
60+
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6
6161
with:
6262
python-version: ${{ env.PYTHON_VERSION }}
6363

@@ -81,24 +81,24 @@ jobs:
8181
- arm64
8282
steps:
8383
- name: Setup QEMU
84-
uses: docker/setup-qemu-action@v3
84+
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3
8585
with:
8686
platforms: all
8787

8888
- name: Setup Docker Buildx
89-
uses: docker/setup-buildx-action@v3
89+
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3
9090
with:
9191
version: ${{ env.DOCKER_BUILDX_VERSION }}
9292
install: true
9393

9494
- name: Checkout
95-
uses: actions/checkout@v5
95+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
9696

9797
# We ask Docker to use GitHub Action's native caching support to speed up
9898
# the build, per https://docs.docker.com/build/cache/backends/gha/.
9999
- name: Build Runtime
100100
id: image
101-
uses: docker/build-push-action@v6
101+
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6
102102
with:
103103
context: .
104104
platforms: linux/${{ matrix.arch }}
@@ -116,7 +116,7 @@ jobs:
116116
run: ./crossplane xpkg build --package-file=${{ matrix.arch }}.xpkg --package-root=package/ --embed-runtime-image-tarball=runtime-${{ matrix.arch }}.tar
117117

118118
- name: Upload Single-Platform Package
119-
uses: actions/upload-artifact@v5
119+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5
120120
with:
121121
name: package-${{ matrix.arch }}
122122
path: "*.xpkg"
@@ -131,10 +131,10 @@ jobs:
131131
- build
132132
steps:
133133
- name: Checkout
134-
uses: actions/checkout@v5
134+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
135135

136136
- name: Download Single-Platform Packages
137-
uses: actions/download-artifact@v6
137+
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6
138138
with:
139139
# See https://github.com/docker/build-push-action/blob/263435/README.md#summaries
140140
pattern: "!*.dockerbuild"
@@ -145,7 +145,7 @@ jobs:
145145
run: "curl -sL https://raw.githubusercontent.com/crossplane/crossplane/master/install.sh | sh"
146146

147147
- name: Login to GitHub Container Registry
148-
uses: docker/login-action@v3
148+
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3
149149
with:
150150
registry: ghcr.io
151151
username: ${{ github.repository_owner }}

Dockerfile

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,34 @@
11
# syntax=docker/dockerfile:1
22

3+
ARG UV_VERSION=0.9.7
4+
FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv
5+
36
# It's important that this is Debian 12 to match the distroless image.
47
FROM --platform=${BUILDPLATFORM} debian:12-slim AS build
58

6-
RUN --mount=type=cache,target=/var/lib/apt/lists \
7-
--mount=type=cache,target=/var/cache/apt \
8-
rm -f /etc/apt/apt.conf.d/docker-clean \
9-
&& apt-get update \
10-
&& apt-get install --no-install-recommends --yes python3-venv git
11-
129
# Don't write .pyc bytecode files. These speed up imports when the program is
1310
# loaded. There's no point doing that in a container where they'll never be
1411
# persisted across restarts.
15-
ENV PYTHONDONTWRITEBYTECODE=true
12+
ENV UV_PYTHON_INSTALL_DIR=/python PYTHONDONTWRITEBYTECODE=true
13+
COPY --from=uv /uv /uvx /bin/
1614

17-
# Use Hatch to build a wheel. The build stage must do this in a venv because
18-
# Debian doesn't have a hatch package, and it won't let you install one globally
19-
# using pip.
20-
WORKDIR /build
21-
RUN --mount=target=. \
22-
--mount=type=cache,target=/root/.cache/pip \
23-
python3 -m venv /venv/build \
24-
&& /venv/build/bin/pip install hatch \
25-
&& /venv/build/bin/hatch build -t wheel /whl
26-
27-
# Create a fresh venv and install only the function wheel into it.
28-
RUN --mount=type=cache,target=/root/.cache/pip \
29-
python3 -m venv /venv/fn \
30-
&& /venv/fn/bin/pip install /whl/*.whl
15+
WORKDIR /app
16+
ADD . .
17+
# Create a fresh venv and install the dependencies.
18+
RUN --mount=type=cache,target=/root/.cache/uv \
19+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
20+
uv sync --no-dev --no-cache --no-editable --python-preference=only-managed
3121

3222
# Copy the function venv to our runtime stage. It's important that the path be
33-
# the same as in the build stage, to avoid shebang paths and symlinks breaking.
34-
FROM gcr.io/distroless/python3-debian12 AS image
35-
WORKDIR /
36-
COPY --from=build /venv/fn /venv/fn
23+
# the same as in the build stage, to avoid shebang paths and symlinks breaking.
24+
FROM gcr.io/distroless/cc-debian12:nonroot AS image
25+
LABEL org.opencontainers.image.description="A Crossplane composition function template in Python"
26+
WORKDIR /app
27+
28+
# Copy python interpreter and the application from the builder
29+
COPY --from=build --chown=python:python /python /python
30+
COPY --from=build --chown=nonroot:nonroot /app/.venv /app/.venv
31+
ENV PATH="/app/.venv/bin:${PATH}"
3732
EXPOSE 9443
3833
USER nonroot:nonroot
39-
ENTRYPOINT ["/venv/fn/bin/function"]
34+
ENTRYPOINT ["function"]

function/fn.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class FunctionRunner(grpcv1.FunctionRunnerService):
1212
def __init__(self):
1313
"""Create a new FunctionRunner."""
1414
self.log = logging.get_logger()
15+
self.log.info("Starting function-template-python")
1516

1617
async def RunFunction(
1718
self, req: fnv1.RunFunctionRequest, _: grpc.aio.ServicerContext

pyproject.toml

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ build-backend = "hatchling.build"
66
name = "function"
77
description = 'A composition function'
88
readme = "README.md"
9-
requires-python = ">=3.11,<3.12"
9+
requires-python = ">=3.12,<3.14"
1010
license = "Apache-2.0"
1111
keywords = []
1212
authors = [{ name = "Crossplane Maintainers", email = "[email protected]" }]
1313
classifiers = [
1414
"Development Status :: 4 - Beta",
1515
"Programming Language :: Python",
16-
"Programming Language :: Python :: 3.11",
16+
"Programming Language :: Python :: 3.12",
17+
"Programming Language :: Python :: 3.13",
1718
]
1819

1920
dependencies = [
20-
"crossplane-function-sdk-python==0.8.0",
21+
"crossplane-function-sdk-python==0.9.0",
2122
"click==8.3.0",
22-
"grpcio==1.73.1",
2323
]
2424

2525
dynamic = ["version"]
@@ -42,21 +42,33 @@ validate-bump = false # Allow going from 0.0.0.dev0+x to 0.0.0.dev0+y
4242
[tool.hatch.envs.default]
4343
type = "virtual"
4444
path = ".venv-default"
45-
dependencies = ["ipython==9.4.0"]
45+
dependencies = ["ipython==9.7.0"]
4646

4747
[tool.hatch.envs.default.scripts]
4848
development = "python function/main.py --insecure --debug"
4949

50-
# This special environment is used by hatch fmt.
51-
[tool.hatch.envs.hatch-static-analysis]
52-
dependencies = ["ruff==0.12.7"]
53-
config-path = "none" # Disable Hatch's default Ruff config.
50+
[tool.hatch.envs.lint]
51+
type = "virtual"
52+
detached = true
53+
path = ".venv-lint"
54+
dependencies = ["ruff==0.14.3"]
55+
56+
[tool.hatch.envs.lint.scripts]
57+
check = "ruff check function tests --fix && ruff format --diff function tests"
58+
59+
[tool.hatch.envs.test]
60+
type = "virtual"
61+
path = ".venv-test"
62+
63+
[tool.hatch.envs.test.scripts]
64+
unit = "python -m unittest tests/*.py"
5465

5566
[tool.ruff]
56-
target-version = "py311"
67+
target-version = "py313"
5768
exclude = ["function/proto/*"]
5869

5970
[tool.ruff.lint]
71+
preview = true
6072
select = [
6173
"A",
6274
"ARG",

0 commit comments

Comments
 (0)