Skip to content

Commit 0bebc47

Browse files
committed
Support local db
1 parent 594b4d6 commit 0bebc47

7 files changed

Lines changed: 97 additions & 9 deletions

File tree

.github/workflows/deploy-on-release.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Deploy Website on Release
1+
name: Deploy Website
22

33
on:
44
push:
@@ -41,12 +41,10 @@ jobs:
4141
run: cp sample.env .env && npm run b
4242
env:
4343
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44-
44+
4545
- name: Deploy to Vercel
4646
run: |
4747
npx vercel --prod --token "${{ secrets.VERCEL_TOKEN }}" --yes
4848
env:
4949
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
50-
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
51-
GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }}
52-
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
50+
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,7 @@ dist
133133
.vercel
134134
/public
135135
.DS_Store
136+
bin/DynamoDBLocal_lib
137+
dynamodb-local-metadata.json
138+
shared-local-instance.db
139+
bin/DynamoDBLocal.jar

bin/init-local-dynamodb.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/bash
2+
3+
# Script to initialize and run local DynamoDB
4+
# Checks for required dependencies and downloads/runs DynamoDB Local
5+
6+
set -e
7+
8+
DYNAMODB_DIR="$(dirname "$0")"
9+
DYNAMODB_TAR="$DYNAMODB_DIR/dynamodb_local_latest.tar.gz"
10+
DYNAMODB_JAR="$DYNAMODB_DIR/DynamoDBLocal.jar"
11+
DYNAMODB_LIB="$DYNAMODB_DIR/DynamoDBLocal_lib"
12+
13+
# Check for Java
14+
if ! java -version >/dev/null 2>&1; then
15+
echo "Error: Java is not properly installed or not in PATH."
16+
echo "Please install Java 8 or later from https://adoptium.net/ or using Homebrew: 'brew install openjdk'"
17+
exit 1
18+
fi
19+
20+
# Check Java version (optional, but informative)
21+
JAVA_VERSION=$(java -version 2>&1 | head -n 1)
22+
echo "Java found: $JAVA_VERSION"
23+
24+
# Check if DynamoDB Local is already downloaded
25+
if [ ! -f "$DYNAMODB_JAR" ]; then
26+
echo "DynamoDB Local not found. Downloading..."
27+
28+
# Download the latest DynamoDB Local
29+
if ! curl -L -o "$DYNAMODB_TAR" "https://s3.us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_latest.tar.gz"; then
30+
echo "Error: Failed to download DynamoDB Local."
31+
exit 1
32+
fi
33+
34+
# Extract the archive
35+
if ! tar -xzf "$DYNAMODB_TAR" -C "$DYNAMODB_DIR"; then
36+
echo "Error: Failed to extract DynamoDB Local archive."
37+
exit 1
38+
fi
39+
40+
# Clean up the tar file
41+
rm "$DYNAMODB_TAR"
42+
43+
echo "DynamoDB Local downloaded and extracted successfully."
44+
else
45+
echo "DynamoDB Local is already downloaded."
46+
fi
47+
48+
# Check if DynamoDB Local is already running (on default port 8000)
49+
if lsof -Pi :8000 -sTCP:LISTEN -t >/dev/null 2>&1; then
50+
echo "DynamoDB Local is already running on port 8000."
51+
else
52+
echo "Starting DynamoDB Local..."
53+
54+
# Start DynamoDB Local in the background
55+
java -Djava.library.path="$DYNAMODB_LIB" -jar "$DYNAMODB_JAR" -sharedDb &
56+
57+
# Wait for it to start (DynamoDB Local may take a few seconds)
58+
echo "Waiting for DynamoDB Local to start..."
59+
sleep 5
60+
61+
# Verify it's running
62+
if lsof -Pi :8000 -sTCP:LISTEN -t >/dev/null 2>&1; then
63+
echo "DynamoDB Local started successfully on port 8000."
64+
else
65+
echo "Warning: DynamoDB Local may not have started properly. Check for errors above."
66+
fi
67+
fi
68+
69+
echo "Local DynamoDB initialization complete."

bin/stop-local-dynamodb.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
# Script to stop local DynamoDB
4+
5+
echo "Stopping DynamoDB Local..."
6+
7+
# Find and kill the DynamoDB Local process
8+
if pgrep -f "DynamoDBLocal.jar" >/dev/null; then
9+
pkill -f "DynamoDBLocal.jar"
10+
echo "DynamoDB Local stopped."
11+
else
12+
echo "DynamoDB Local is not running."
13+
fi

sample.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ CLIENT_SECRET=xxx
1010
AWS_ACCESS_KEY_ID=xxx
1111
AWS_SECRET_ACCESS_KEY=xxx
1212
AWS_REGION=us-east-1
13+
# Set DYNAMODB_ENDPOINT to http://localhost:8000 for local DynamoDB
14+
# Comment out or remove for AWS DynamoDB
15+
# DYNAMODB_ENDPOINT=http://localhost:8000
1316

1417
JWT_SECRET=xxx
1518
DYNAMO_TABLE_PREFIX=xxx

src/client/common/links.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ export default function Links (): JSX.Element {
4545
{
4646
url: 'https://electerm.html5beta.com/sponsor-electerm.html',
4747
title: 'Sponsor Electerm'
48-
},
49-
{
50-
url: 'https://github.com/mbadolato/iTerm2-Color-Schemes/tree/master/electerm',
51-
title: 'Themes'
5248
}
5349
]
5450
return (

src/server/models/db.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import { Token, tokenSchema } from './token-model'
77
import { Data, dataSchema } from './data-model'
88
import { Statics, staticsSchema } from './statics-model'
99

10+
// Configure DynamoDB
11+
if (process.env.DYNAMODB_ENDPOINT !== undefined) {
12+
dynamoose.aws.ddb.local(process.env.DYNAMODB_ENDPOINT)
13+
}
14+
1015
// Common schema options
1116
const commonSchemaOptions = {
1217
timestamps: true

0 commit comments

Comments
 (0)