Skip to content

Commit 156968d

Browse files
author
Christopher D. Gokey
committed
KMS-649: Consolidated Redis cache/client logic into redisCacheStore and remove legacy cache wrappers
1 parent b913c36 commit 156968d

30 files changed

Lines changed: 1454 additions & 1519 deletions

README.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ npm run start-local:watch
3939

4040
### Optional: Enable Redis cache in local SAM/LocalStack
4141

42-
By default, local `start-local` does not provision Redis in CDK. You can still test Redis caching by running Redis in Docker and using environment variables from your shell.
42+
By default, local `start-local` does not provision Redis in CDK. You can still test Redis caching by running Redis in Docker.
43+
Local defaults are centralized in `bin/env/local_env.sh`.
4344

4445
1. Ensure the docker network exists:
4546
```
@@ -51,11 +52,9 @@ npm run rdf4j:create-network
5152
npm run redis:start
5253
```
5354

54-
3. (Optional) override defaults if needed:
55+
3. (Optional) override defaults in `bin/env/local_env.sh` or per-command, for example:
5556
```
56-
export REDIS_ENABLED=true
57-
export REDIS_HOST=kms-redis-local
58-
export REDIS_PORT=6379
57+
REDIS_ENABLED=true REDIS_HOST=kms-redis-local REDIS_PORT=6379 npm run start-local
5958
```
6059

6160
4. Start local API:
@@ -90,7 +89,7 @@ https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/CacheNodes.SupportedType
9089

9190
To disable local Redis cache again:
9291
```
93-
export REDIS_ENABLED=false
92+
REDIS_ENABLED=false npm run start-local
9493
```
9594

9695
### Invoke cache-prime cron locally
@@ -112,11 +111,8 @@ npm run test
112111
## Setting up the RDF Database for local development
113112
In order to run KMS locally, you first need to setup a RDF database.
114113
### Prerequisites
115-
#### Set the RDFDB user name and password
116-
```
117-
export RDF4J_USER_NAME=[user name]
118-
export RDF4J_PASSWORD=[password]
119-
```
114+
RDF4J local defaults are in `bin/env/local_env.sh`.
115+
If needed, override per command (for example: `RDF4J_USER_NAME=... RDF4J_PASSWORD=... npm run rdf4j:setup`).
120116
### Building and Running the RDF Database
121117
#### Build the docker image
122118
```

bin/env/local_env.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
# Shared defaults for local SAM/CDK workflows.
4+
export RDF4J_SERVICE_URL="${RDF4J_SERVICE_URL:-http://rdf4j-server:8080}"
5+
export REDIS_ENABLED="${REDIS_ENABLED:-true}"
6+
export REDIS_HOST="${REDIS_HOST:-kms-redis-local}"
7+
export REDIS_PORT="${REDIS_PORT:-6379}"
8+
export KMS_DOCKER_NETWORK="${KMS_DOCKER_NETWORK:-kms-network}"
9+
export SAM_WARM_CONTAINERS="${SAM_WARM_CONTAINERS:-EAGER}"
10+
export SAM_LOCAL_WATCH="${SAM_LOCAL_WATCH:-false}"

bin/rdf4j/create-network.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
NETWORK_NAME="${RDF4J_DOCKER_NETWORK:-kms-network}"
4+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
# shellcheck source=bin/env/local_env.sh
6+
source "${SCRIPT_DIR}/../env/local_env.sh"
7+
8+
NETWORK_NAME="${RDF4J_DOCKER_NETWORK:-${KMS_DOCKER_NETWORK:-kms-network}}"
59

610
if docker network inspect "$NETWORK_NAME" >/dev/null 2>&1; then
711
echo "Docker network '${NETWORK_NAME}' already exists"

bin/rdf4j/setup.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
# shellcheck source=bin/env/local_env.sh
6+
source "${SCRIPT_DIR}/../env/local_env.sh"
7+
8+
RDF4J_CONTAINER_NAME="${RDF4J_CONTAINER_NAME:-rdf4j-server}"
9+
RDF4J_USER_NAME="${RDF4J_USER_NAME:-rdf4j}"
10+
RDF4J_PASSWORD="${RDF4J_PASSWORD:-rdf4j}"
11+
RDF4J_REPOSITORY_ID="${RDF4J_REPOSITORY_ID:-kms}"
12+
# Setup runs from host machine against mapped port by default.
13+
export RDF4J_SERVICE_URL="${RDF4J_SETUP_SERVICE_URL:-http://127.0.0.1:8081}"
14+
export RDF4J_CONTAINER_NAME RDF4J_USER_NAME RDF4J_PASSWORD RDF4J_REPOSITORY_ID
15+
16+
echo "Running RDF4J setup against ${RDF4J_SERVICE_URL}/rdf4j-server (repo=${RDF4J_REPOSITORY_ID})"
17+
418
node setup/setupRdf4j.js

bin/rdf4j/start.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
NETWORK_NAME="${RDF4J_DOCKER_NETWORK:-kms-network}"
4+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
# shellcheck source=bin/env/local_env.sh
6+
source "${SCRIPT_DIR}/../env/local_env.sh"
7+
8+
NETWORK_NAME="${RDF4J_DOCKER_NETWORK:-${KMS_DOCKER_NETWORK:-kms-network}}"
59
CONTAINER_NAME="${RDF4J_CONTAINER_NAME:-rdf4j-server}"
610
RDF4J_USER_NAME="${RDF4J_USER_NAME:-rdf4j}"
711
RDF4J_PASSWORD="${RDF4J_PASSWORD:-rdf4j}"

bin/start-local.sh

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/bin/bash
22

3+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4+
# shellcheck source=bin/env/local_env.sh
5+
source "${SCRIPT_DIR}/env/local_env.sh"
6+
37
# Function to clean up processes and containers
48
cleanup() {
59
echo "Cleaning up..."
@@ -9,14 +13,6 @@ cleanup() {
913
# Set up trap to call cleanup function on Ctrl+C
1014
trap cleanup SIGINT
1115

12-
# Set environment variables for local development
13-
export RDF4J_SERVICE_URL=http://rdf4j-server:8080
14-
export REDIS_ENABLED="${REDIS_ENABLED:-true}"
15-
export REDIS_HOST="${REDIS_HOST:-kms-redis-local}"
16-
export REDIS_PORT="${REDIS_PORT:-6379}"
17-
SAM_WARM_CONTAINERS=${SAM_WARM_CONTAINERS:-EAGER}
18-
SAM_LOCAL_WATCH=${SAM_LOCAL_WATCH:-false}
19-
2016
SAM_WATCH_ARGS=()
2117
if [ "$SAM_LOCAL_WATCH" = "true" ]; then
2218
SAM_WATCH_ARGS+=(--beta-features --watch)
@@ -31,7 +27,7 @@ sam local start-api \
3127
--template-file ./cdk.out/KmsStack.template.json \
3228
--warm-containers "${SAM_WARM_CONTAINERS}" \
3329
--port 3013 \
34-
--docker-network kms-network \
30+
--docker-network "${KMS_DOCKER_NETWORK}" \
3531
"${SAM_WATCH_ARGS[@]}"
3632

3733
# Wait for the SAM process

scripts/local/invoke_prime_concepts_cache.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
set -euo pipefail
44

55
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
6+
# shellcheck source=bin/env/local_env.sh
7+
source "${ROOT_DIR}/bin/env/local_env.sh"
8+
69
TEMPLATE_FILE="${TEMPLATE_FILE:-${ROOT_DIR}/cdk/cdk.out/KmsStack.template.json}"
710
EVENT_FILE="${EVENT_FILE:-/tmp/prime-concepts-cache-event.json}"
811
LOG_FILE="${LOG_FILE:-/tmp/prime-concepts-cache.log}"
912
SAM_INVOKE_IMAGE="${SAM_INVOKE_IMAGE:-public.ecr.aws/lambda/nodejs:22-rapid-x86_64}"
10-
REDIS_ENABLED="${REDIS_ENABLED:-true}"
11-
REDIS_HOST="${REDIS_HOST:-kms-redis-local}"
12-
REDIS_PORT="${REDIS_PORT:-6379}"
13-
RDF4J_SERVICE_URL="${RDF4J_SERVICE_URL:-http://rdf4j-server:8080}"
1413

1514
echo "Synthesizing local template with REDIS_ENABLED=${REDIS_ENABLED}, REDIS_HOST=${REDIS_HOST}, REDIS_PORT=${REDIS_PORT}"
1615
(
@@ -63,7 +62,7 @@ trap cleanup EXIT
6362

6463
sam local invoke \
6564
-t "${TEMPLATE_FILE}" \
66-
--docker-network kms-network \
65+
--docker-network "${KMS_DOCKER_NETWORK}" \
6766
--skip-pull-image \
6867
--invoke-image "${SAM_INVOKE_IMAGE}" \
6968
--log-file "${LOG_FILE}" \

0 commit comments

Comments
 (0)