Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion .github/workflows/scheduled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,37 @@ jobs:
- name: cargo update
if: hashFiles('server/Cargo.lock') != ''
run: cargo update
- name: Download DynamoDB Local
Comment thread
jonhoo marked this conversation as resolved.
if: hashFiles('server/Cargo.lock') != ''
run: |
wget https://d1ni2b6xgvw0s0.cloudfront.net/v2.x/dynamodb_local_latest.tar.gz
wget https://d1ni2b6xgvw0s0.cloudfront.net/v2.x/dynamodb_local_latest.tar.gz.sha256
Comment thread
jonhoo marked this conversation as resolved.
sha256sum --check dynamodb_local_latest.tar.gz.sha256
mkdir dynamodb-local
tar xfv dynamodb_local_latest.tar.gz --directory=dynamodb-local
ls -lah dynamodb-local
- name: Install Java SDK
if: hashFiles('server/Cargo.lock') != ''
uses: actions/setup-java@v4
with:
distribution: 'oracle'
java-version: '21'
- name: Launch DynamoDB Local
if: hashFiles('server/Cargo.lock') != ''
run: |
cd dynamodb-local
java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb &
- name: Create tables and indexes in DynamoDb Local
if: hashFiles('server/Cargo.lock') != ''
run: ./run-migrations.sh http://localhost:8000
env:
AWS_ACCESS_KEY_ID: carpe
AWS_SECRET_ACCESS_KEY: diem
AWS_DEFAULT_REGION: dead-poets-society-eu-east-1
Comment thread
jonhoo marked this conversation as resolved.
# https://twitter.com/jonhoo/status/1571290371124260865
- name: cargo test
if: hashFiles('server/Cargo.lock') != ''
run: cargo test --locked --all-features --all-targets
run: cargo test --locked --all-features --all-targets -- --include-ignored
env:
RUSTFLAGS: -D deprecated
USE_DYNAMODB: local
27 changes: 26 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,31 @@ jobs:
# enable this ci template to run regardless of whether the lockfile is checked in or not
if: hashFiles('server/Cargo.lock') == ''
run: cargo generate-lockfile
- name: Download DynamoDB Local
run: |
wget https://d1ni2b6xgvw0s0.cloudfront.net/v2.x/dynamodb_local_latest.tar.gz
wget https://d1ni2b6xgvw0s0.cloudfront.net/v2.x/dynamodb_local_latest.tar.gz.sha256
sha256sum --check dynamodb_local_latest.tar.gz.sha256
mkdir dynamodb-local
tar xfv dynamodb_local_latest.tar.gz --directory=dynamodb-local
ls -lah dynamodb-local
- name: Install Java SDK
uses: actions/setup-java@v4
with:
distribution: 'oracle'
java-version: '21'
- name: Launch DynamoDB Local
run: |
cd dynamodb-local
java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb &
- name: Create tables and indexes in DynamoDb Local
run: ./run-migrations.sh http://localhost:8000
env:
AWS_ACCESS_KEY_ID: carpe
AWS_SECRET_ACCESS_KEY: diem
AWS_DEFAULT_REGION: dead-poets-society-eu-east-1
# https://twitter.com/jonhoo/status/1571290371124260865
- name: cargo test --locked
run: cargo test --locked --all-features --all-targets
run: cargo test --locked --all-features --all-targets -- --include-ignored
env:
USE_DYNAMODB: local
2 changes: 2 additions & 0 deletions server/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/target
/dynamodb-data
/dynamodb-local
dynamodb_local_latest.tar.gz*
Makefile
29 changes: 1 addition & 28 deletions server/run-dynamodb-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,34 +45,7 @@ while ! (aws dynamodb list-tables --endpoint-url ${ENDPOINT_URL} >/dev/null); do
echo "⏳ Waiting for the database to start accepting connections..."
done

echo "🗒️ Creating 'events' table..."
aws dynamodb create-table \
--table-name events \
--attribute-definitions AttributeName=id,AttributeType=S \
--key-schema AttributeName=id,KeyType=HASH \
--billing-mode PAY_PER_REQUEST \
--endpoint-url ${ENDPOINT_URL} >/dev/null

aws dynamodb update-time-to-live \
--table-name events \
--time-to-live-specification Enabled=true,AttributeName=expire \
--endpoint-url ${ENDPOINT_URL} >/dev/null

echo "🗒️ Creating 'questions' table and 🚄 GSI..."
aws dynamodb create-table \
--table-name questions \
--attribute-definitions AttributeName=id,AttributeType=S \
AttributeName=eid,AttributeType=S \
AttributeName=votes,AttributeType=N \
--key-schema AttributeName=id,KeyType=HASH \
--global-secondary-indexes 'IndexName=top,KeySchema=[{AttributeName=eid,KeyType=HASH},{AttributeName=votes,KeyType=RANGE}],Projection={ProjectionType=INCLUDE,NonKeyAttributes=[answered,hidden]}' \
--billing-mode PAY_PER_REQUEST \
--endpoint-url ${ENDPOINT_URL} >/dev/null

aws dynamodb update-time-to-live \
--table-name questions \
--time-to-live-specification Enabled=true,AttributeName=expire \
--endpoint-url ${ENDPOINT_URL} >/dev/null
./run-migrations.sh "${ENDPOINT_URL}"

echo "✅ Container \"${DYNAMODB_CONTAINER_NAME}\" with DynamoDB Local is ready!"

Expand Down
50 changes: 50 additions & 0 deletions server/run-migrations.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bash

if ! [ -x "$(command -v aws)" ]; then
echo '❌ Error: please make sure AWS CLI is installed and is in the PATH' >&2
exit 1
fi

if [ "$1" = "" ]; then
echo "
❌ Please provide DynamoDB endpoint url.

Usage: $0 <endpoint_url>
e.g.: $0 http://localhost:8000

Also make sure 'AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY', and 'AWS_DEFAULT_REGION'
are available in the environment or your '~/.aws' configuration files.
"
exit 1
fi

ENDPOINT_URL="$1"

echo "🗒️ Creating 'events' table..."
aws dynamodb create-table \
--table-name events \
--attribute-definitions AttributeName=id,AttributeType=S \
--key-schema AttributeName=id,KeyType=HASH \
--billing-mode PAY_PER_REQUEST \
--endpoint-url ${ENDPOINT_URL} >/dev/null

aws dynamodb update-time-to-live \
--table-name events \
--time-to-live-specification Enabled=true,AttributeName=expire \
--endpoint-url ${ENDPOINT_URL} >/dev/null

echo "🗒️ Creating 'questions' table and 🚄 GSI..."
aws dynamodb create-table \
--table-name questions \
--attribute-definitions AttributeName=id,AttributeType=S \
AttributeName=eid,AttributeType=S \
AttributeName=votes,AttributeType=N \
--key-schema AttributeName=id,KeyType=HASH \
--global-secondary-indexes 'IndexName=top,KeySchema=[{AttributeName=eid,KeyType=HASH},{AttributeName=votes,KeyType=RANGE}],Projection={ProjectionType=INCLUDE,NonKeyAttributes=[answered,hidden]}' \
--billing-mode PAY_PER_REQUEST \
--endpoint-url ${ENDPOINT_URL} >/dev/null

aws dynamodb update-time-to-live \
--table-name questions \
--time-to-live-specification Enabled=true,AttributeName=expire \
--endpoint-url ${ENDPOINT_URL} >/dev/null