diff --git a/Dockerfile b/Dockerfile index 21c60a7..c668646 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,7 +31,7 @@ RUN --mount=type=cache,target=/root/.cache/pip \ # Copy the function venv to our runtime stage. It's important that the path be # the same as in the build stage, to avoid shebang paths and symlinks breaking. -FROM gcr.io/distroless/python3-debian12 AS image +FROM gcr.io/distroless/python3-debian13 AS image WORKDIR / COPY --from=build /venv/fn /venv/fn EXPOSE 9443 diff --git a/function/main.py b/function/main.py index 7ea1197..1b049a4 100644 --- a/function/main.py +++ b/function/main.py @@ -1,50 +1,16 @@ """The composition function's main CLI.""" import click -from crossplane.function import logging, runtime +from crossplane.function import cli as sdkcli from function import fn @click.command() -@click.option( - "--debug", - "-d", - is_flag=True, - help="Emit debug logs.", -) -@click.option( - "--address", - default="0.0.0.0:9443", - show_default=True, - help="Address at which to listen for gRPC connections", -) -@click.option( - "--tls-certs-dir", - help="Serve using mTLS certificates.", - envvar="TLS_SERVER_CERTS_DIR", -) -@click.option( - "--insecure", - is_flag=True, - help="Run without mTLS credentials. " - "If you supply this flag --tls-certs-dir will be ignored.", -) -def cli(debug: bool, address: str, tls_certs_dir: str, insecure: bool) -> None: # noqa:FBT001 # We only expect callers via the CLI. +@sdkcli.standard_options +def cli(**kwargs): """A Crossplane composition function.""" - try: - level = logging.Level.INFO - if debug: - level = logging.Level.DEBUG - logging.configure(level=level) - runtime.serve( - fn.FunctionRunner(), - address, - creds=runtime.load_credentials(tls_certs_dir), - insecure=insecure, - ) - except Exception as e: - click.echo(f"Cannot run function: {e}") + sdkcli.run(fn.FunctionRunner(), **kwargs) if __name__ == "__main__": diff --git a/pyproject.toml b/pyproject.toml index 0c04510..e6b1d75 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,7 @@ classifiers = [ ] dependencies = [ - "crossplane-function-sdk-python==0.14.0", + "crossplane-function-sdk-python==0.15.0", "click==8.5.0", "grpcio>=1.73.1", ]