Skip to content

Commit eb6e3dc

Browse files
authored
Ship StepFunction JSONata dependency by default (#12110)
1 parent fad716d commit eb6e3dc

File tree

5 files changed

+25
-7
lines changed

5 files changed

+25
-7
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ RUN --mount=type=cache,target=/root/.cache \
153153
source .venv/bin/activate && \
154154
python -m localstack.cli.lpm install \
155155
lambda-runtime \
156+
jpype-jsonata \
156157
dynamodb-local && \
157158
chown -R localstack:localstack /usr/lib/localstack && \
158159
chmod -R 777 /usr/lib/localstack

localstack-core/localstack/dev/run/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
type=str,
3737
required=False,
3838
help="Overwrite the container image to be used (defaults to localstack/localstack or "
39-
"localstack/localstack-pro.",
39+
"localstack/localstack-pro).",
4040
)
4141
@click.option(
4242
"--volume-dir",
@@ -66,7 +66,7 @@
6666
"--mount-source/--no-mount-source",
6767
is_flag=True,
6868
default=True,
69-
help="Mount source files from localstack, localstack-ext, and moto into the container.",
69+
help="Mount source files from localstack and localstack-ext. Use --local-packages for optional dependencies such as moto.",
7070
)
7171
@click.option(
7272
"--mount-dependencies/--no-mount-dependencies",

localstack-core/localstack/services/stepfunctions/asl/jsonata/jsonata.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import jpype
99
import jpype.imports
1010

11-
from localstack.services.stepfunctions.asl.jsonata.packages import jsonata_package
1211
from localstack.services.stepfunctions.asl.utils.encoding import to_json_str
12+
from localstack.services.stepfunctions.packages import jpype_jsonata_package
1313
from localstack.utils.objects import singleton_factory
1414

1515
JSONataExpression = str
@@ -40,17 +40,19 @@ class _JSONataJVMBridge:
4040
_java_JSONATA: "com.dashjoin.jsonata.Jsonata.jsonata" # noqa
4141

4242
def __init__(self):
43-
installer = jsonata_package.get_installer()
43+
installer = jpype_jsonata_package.get_installer()
4444
installer.install()
4545

4646
from jpype import config as jpype_config
4747

4848
jpype_config.destroy_jvm = False
4949

50+
# Limitation: We can only start one JVM instance within LocalStack and using JPype for another purpose
51+
# (e.g., event-ruler) fails unless we change the way we load/reload the classpath.
5052
jvm_path = installer.get_java_lib_path()
5153
jsonata_libs_path = Path(installer.get_installed_dir())
52-
event_ruler_libs_pattern = jsonata_libs_path.joinpath("*")
53-
jpype.startJVM(jvm_path, classpath=[event_ruler_libs_pattern], interrupt=False)
54+
jsonata_libs_pattern = jsonata_libs_path.joinpath("*")
55+
jpype.startJVM(jvm_path, classpath=[jsonata_libs_pattern], interrupt=False)
5456

5557
from com.fasterxml.jackson.databind import ObjectMapper # noqa
5658
from com.dashjoin.jsonata.Jsonata import jsonata # noqa

localstack-core/localstack/services/stepfunctions/asl/jsonata/packages.py renamed to localstack-core/localstack/services/stepfunctions/packages.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ class JSONataPackage(Package):
1212
def __init__(self):
1313
super().__init__("JSONataLibs", JSONATA_DEFAULT_VERSION)
1414

15+
# Match the dynamodb-local JRE version to reduce the LocalStack image size by sharing the same JRE version
16+
self.java_version = "21"
17+
1518
def get_versions(self) -> list[str]:
1619
return list(JSONATA_JACKSON_VERSION_STORE.keys())
1720

@@ -24,10 +27,13 @@ def __init__(self, version: str):
2427
jackson_version = JSONATA_JACKSON_VERSION_STORE[version]
2528
super().__init__(
2629
f"pkg:maven/com.dashjoin/jsonata@{version}",
30+
# jackson-databind is imported in jsonata.py as "from com.fasterxml.jackson.databind import ObjectMapper"
31+
# jackson-annotations and jackson-core are dependencies of jackson-databind:
32+
# https://central.sonatype.com/artifact/com.fasterxml.jackson.core/jackson-databind/dependencies
2733
f"pkg:maven/com.fasterxml.jackson.core/jackson-core@{jackson_version}",
2834
f"pkg:maven/com.fasterxml.jackson.core/jackson-annotations@{jackson_version}",
2935
f"pkg:maven/com.fasterxml.jackson.core/jackson-databind@{jackson_version}",
3036
)
3137

3238

33-
jsonata_package = JSONataPackage()
39+
jpype_jsonata_package = JSONataPackage()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from localstack.packages import Package, package
2+
3+
4+
@package(name="jpype-jsonata")
5+
def jpype_jsonata_package() -> Package:
6+
"""The Java-based jsonata library uses JPype and depends on a JVM installation."""
7+
from localstack.services.stepfunctions.packages import jpype_jsonata_package
8+
9+
return jpype_jsonata_package

0 commit comments

Comments
 (0)