Skip to content

Commit 1a228e1

Browse files
authored
feat: update runtime versions, use uv in docker builds (#208)
1 parent 498e813 commit 1a228e1

File tree

38 files changed

+5914
-282
lines changed

38 files changed

+5914
-282
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ lib/**/*.d.ts
66
dist
77
docs
88
__pycache__
9-
.venv
9+
/.venv
1010
.tox
1111
tests/*.egg*
1212
tests/*venv*

integration_tests/cdk/package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/stac-api/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class PgStacApiLambdaRuntime extends Construct {
4141
constructor(
4242
scope: Construct,
4343
id: string,
44-
props: PgStacApiLambdaRuntimeProps
44+
props: PgStacApiLambdaRuntimeProps,
4545
) {
4646
super(scope, id);
4747

@@ -60,8 +60,8 @@ export class PgStacApiLambdaRuntime extends Construct {
6060
if (!isValidExtension(ext)) {
6161
throw new Error(
6262
`Invalid extension: "${ext}". Must be one of: ${Object.values(
63-
EXTENSIONS
64-
).join(", ")}`
63+
EXTENSIONS,
64+
).join(", ")}`,
6565
);
6666
}
6767
}
@@ -75,7 +75,7 @@ export class PgStacApiLambdaRuntime extends Construct {
7575
this.lambdaFunction = new lambda.Function(this, "lambda", {
7676
// defaults
7777
runtime: lambda.Runtime.PYTHON_3_12,
78-
handler: "handler.handler",
78+
handler: "stac_api.handler.handler",
7979
memorySize: 8192,
8080
logRetention: aws_logs.RetentionDays.ONE_WEEK,
8181
timeout: Duration.seconds(30),
@@ -106,7 +106,7 @@ export class PgStacApiLambdaRuntime extends Construct {
106106
this.lambdaFunction.connections.allowTo(
107107
props.db,
108108
ec2.Port.tcp(5432),
109-
"allow connections from stac-fastapi-pgstac"
109+
"allow connections from stac-fastapi-pgstac",
110110
);
111111
}
112112
}

lib/stac-api/runtime/Dockerfile

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
11
ARG PYTHON_VERSION
22
FROM --platform=linux/amd64 public.ecr.aws/lambda/python:${PYTHON_VERSION}
3+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
34

45
WORKDIR /tmp
5-
RUN python -m pip install pip -U
6+
COPY stac-api/runtime/uv.lock stac-api/runtime/pyproject.toml ./
7+
COPY stac-api/runtime/src/ ./src/
8+
COPY utils/utils.py /asset/
69

7-
COPY stac-api/runtime/requirements.txt requirements.txt
8-
RUN python -m pip install -r requirements.txt -t /asset --no-binary pydantic
10+
RUN <<EOF
11+
uv export --locked --no-editable --no-dev --format requirements.txt -o requirements.txt
12+
uv pip install \
13+
--compile-bytecode \
14+
--no-binary pydantic \
15+
--target /asset \
16+
--no-cache-dir \
17+
--disable-pip-version-check \
18+
-r requirements.txt
19+
EOF
920

10-
RUN mkdir -p /asset/src
11-
COPY stac-api/runtime/src/*.py /asset/
12-
COPY utils/utils.py /asset/
21+
# Reduce package size and remove useless files
22+
WORKDIR /asset
23+
RUN <<EOF
24+
dnf install -y findutils && \
25+
dnf clean all && \
26+
rm -rf /var/cache/dnf
27+
find . -type f -name '*.pyc' | while read f; do n=$(echo $f | sed 's/__pycache__\///' | sed 's/.cpython-[0-9]*//'); cp $f $n; done;
28+
find . -type d -a -name '__pycache__' -print0 | xargs -0 rm -rf
29+
find . -type f -a -name '*.py' -print0 | xargs -0 rm -f
30+
find . -type d -a -name 'tests' -print0 | xargs -0 rm -rf
31+
EOF
1332

1433
CMD ["echo", "hello world"]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[project]
2+
name = "stac-api"
3+
version = "0.0.0"
4+
description = "stac-api runtime"
5+
authors = [{ name = "hrodmn", email = "[email protected]" }]
6+
requires-python = ">=3.12"
7+
dependencies = [
8+
"stac-fastapi-pgstac[awslambda]>=6.0,<6.1",
9+
"starlette-cramjam>=0.4,<0.5",
10+
]
11+
12+
[build-system]
13+
requires = ["hatchling"]
14+
build-backend = "hatchling.build"

lib/stac-api/runtime/requirements.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.
File renamed without changes.

lib/stac-api/runtime/uv.lock

Lines changed: 855 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/stac-auth-proxy/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class StacAuthProxyLambdaRuntime extends Construct {
1313
constructor(
1414
scope: Construct,
1515
id: string,
16-
props: StacAuthProxyLambdaRuntimeProps
16+
props: StacAuthProxyLambdaRuntimeProps,
1717
) {
1818
super(scope, id);
1919

@@ -22,7 +22,7 @@ export class StacAuthProxyLambdaRuntime extends Construct {
2222

2323
this.lambdaFunction = new lambda.Function(this, "lambda", {
2424
runtime: lambda.Runtime.PYTHON_3_13,
25-
handler: "handler.handler",
25+
handler: "stac_auth_proxy_api.handler.handler",
2626
memorySize: 8192,
2727
logRetention: cdk.aws_logs.RetentionDays.ONE_WEEK,
2828
timeout: cdk.Duration.seconds(30),
@@ -114,7 +114,7 @@ export class StacAuthProxyLambda extends Construct {
114114
const runtime = new StacAuthProxyLambdaRuntime(
115115
this,
116116
"runtime",
117-
runtimeProps
117+
runtimeProps,
118118
);
119119
this.lambdaFunction = runtime.lambdaFunction;
120120

0 commit comments

Comments
 (0)