-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 29c53d9
Showing
14 changed files
with
13,059 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module.exports = { | ||
extends: ['@commitlint/config-conventional'], | ||
rules: { | ||
'type-enum': [ | ||
2, | ||
'always', | ||
[ | ||
'build', | ||
'chore', | ||
'ci', | ||
'docs', | ||
'feat', | ||
'fix', | ||
'perf', | ||
'refactor', | ||
'revert', | ||
'style', | ||
'test', | ||
'wip', | ||
], | ||
], | ||
'subject-case': [ | ||
2, | ||
'always', | ||
[ | ||
'lower-case', | ||
'upper-case', | ||
'camel-case', | ||
'kebab-case', | ||
'pascal-case', | ||
'sentence-case', | ||
'snake-case', | ||
'start-case', | ||
], | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!dynamodb-local/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: Build | ||
|
||
on: | ||
release: | ||
types: [released] | ||
branches: | ||
- master | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
if: github.repository == 'twentyfourg/dynamodb-local' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Get VERSION | ||
id: version | ||
uses: notiz-dev/github-action-json-property@release | ||
with: | ||
path: ./package.json | ||
prop_path: version | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v1 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
- name: Cache Docker layers | ||
uses: actions/cache@v2 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: ${{ runner.os }}-buildx-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-buildx- | ||
- name: Docker Login | ||
uses: docker/login-action@v1 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
- name: Docker Buildx (push) | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
file: ./Dockerfile | ||
platforms: linux/amd64,linux/arm64 | ||
push: true | ||
tags: twentyfourg/dynamodb-local:latest,twentyfourg/dynamodb-local:${{steps.version.outputs.prop}} | ||
cache-from: type=local,src=/tmp/.buildx-cache | ||
cache-to: type=local,dest=/tmp/.buildx-cache-new | ||
- # Temp fix | ||
# https://github.com/docker/build-push-action/issues/252 | ||
# https://github.com/moby/buildkit/issues/1896 | ||
name: Move cache | ||
run: | | ||
rm -rf /tmp/.buildx-cache | ||
mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
jobs: | ||
release: | ||
name: Release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 16 | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
GIT_AUTHOR_NAME: ${{ github.event.head_commit.author.name }} | ||
GIT_AUTHOR_EMAIL: ${{ github.event.head_commit.author.email }} | ||
GIT_COMMITTER_NAME: ${{ github.event.head_commit.author.name }} | ||
GIT_COMMITTER_EMAIL: ${{ github.event.head_commit.author.email }} | ||
run: npx semantic-release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
FROM amazonlinux:2 | ||
COPY dynamodb-local /opt/dynamodb-local | ||
|
||
# Determine which build platform so we know what binaries to install | ||
ARG TARGETPLATFORM | ||
|
||
# Fake credentials required to work with local endpoint | ||
ENV AWS_ACCESS_KEY_ID=local | ||
ENV AWS_SECRET_ACCESS_KEY=local | ||
|
||
# Set default value for features | ||
ENV DYNAMODB_ADMIN_ENABLED=true | ||
ENV DYNAMODB_CREATE_TABLES=true | ||
ENV DYNAMODB_TABLE_SCHEMA_PATH=./tableSchema.json | ||
|
||
# Set environment variables for NodeJs install | ||
ENV NVM_DIR /usr/local/nvm | ||
ENV NODE_VERSION 16.13.2 | ||
ENV NVM_INSTALL_PATH $NVM_DIR/versions/node/v$NODE_VERSION | ||
|
||
# Install required linux utilities | ||
RUN yum update --assumeyes --quiet --errorlevel=0 && \ | ||
yum upgrade --assumeyes --quiet --errorlevel=0 && \ | ||
yum install --assumeyes --quiet --errorlevel=0 less unzip gzip tar jq && \ | ||
amazon-linux-extras install java-openjdk11 -y | ||
|
||
# Install NodeJS and npm | ||
RUN mkdir $NVM_DIR | ||
RUN rm /bin/sh && ln -s /bin/bash /bin/sh | ||
RUN curl --silent -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash | ||
RUN source $NVM_DIR/nvm.sh \ | ||
&& nvm install $NODE_VERSION \ | ||
&& nvm alias default $NODE_VERSION \ | ||
&& nvm use default | ||
ENV NODE_PATH $NVM_INSTALL_PATH/lib/node_modules | ||
ENV PATH $NVM_INSTALL_PATH/bin:$PATH | ||
|
||
# Install AWS CLI | ||
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then curl "https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip" -o "/tmp/awscliv2.zip"; else curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "/tmp/awscliv2.zip"; fi | ||
RUN unzip /tmp/awscliv2.zip -d /tmp/ && bash /tmp/aws/install | ||
|
||
# Install dynamodb-admin GUI | ||
RUN npm install -g dynamodb-admin | ||
|
||
WORKDIR /opt/dynamodb-local | ||
|
||
# Install dynamodb-local | ||
RUN curl "https://s3.us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_latest.tar.gz" -o /opt/dynamodb-local/dynamodb_local_latest.tar.gz && \ | ||
tar -xvzf dynamodb_local_latest.tar.gz | ||
|
||
EXPOSE 8000 8001 | ||
|
||
CMD ./entrypoint.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# DynamoDB Local | ||
|
||
Run DynamoDB locally inside a Docker container. | ||
|
||
The container comes shipped with [DynamoDB-local](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.UsageNotes.html) and [DynamoDB Admin](https://www.npmjs.com/package/dynamodb-admin) for easy GUI access. You can also set default table(s) to be created on start up. | ||
|
||
## Usage | ||
|
||
```bash | ||
docker run -d -p 8000:8000 -p 8001:8001 twentyfourg/dynamodb-local | ||
``` | ||
|
||
## Configuration | ||
|
||
You can enable/disable features or change configuration by using environment variables. | ||
|
||
| Environment Variable | Description | Default | | ||
| ---------------------------- | ------------------------------------------------------------------------------------------------------- | -------------------- | | ||
| `DYNAMODB_ADMIN_ENABLED` | Enable or disable DynamoDB Admin | `true` | | ||
| `DYNAMODB_CREATE_TABLES` | Whether to create default DynamoDB tables | `true` | | ||
| `DYNAMODB_TABLE_SCHEMA_PATH` | Where the DynamoDB table schema JSON is stored. Only does something if `DYNAMODB_CREATE_TABLES` is set. | `./tableSchema.json` | | ||
|
||
## Default Tables | ||
|
||
Default tables are created using a [JSON schema](). You can define custom tables to create by mounting a schema file into the container and altering the `DYNAMODB_TABLE_SCHEMA_PATH` environment variable. | ||
|
||
The schema file must be a JSON array so even if you have one table, enclose your table in `[]`. | ||
|
||
One Table | ||
|
||
```json | ||
[ | ||
{ | ||
"TableName": "cache", | ||
"KeySchema": [ | ||
{ "AttributeName": "key", "KeyType": "HASH" } | ||
], | ||
"AttributeDefinitions": [ | ||
{ "AttributeName": "key", "AttributeType": "S" } | ||
], | ||
"BillingMode": "PAY_PER_REQUEST" | ||
} | ||
``` | ||
|
||
Multiple Tables | ||
|
||
```json | ||
[ | ||
{ | ||
"TableName": "cache", | ||
"KeySchema": [{ "AttributeName": "key", "KeyType": "HASH" }], | ||
"AttributeDefinitions": [{ "AttributeName": "key", "AttributeType": "S" }], | ||
"BillingMode": "PAY_PER_REQUEST" | ||
}, | ||
{ | ||
"TableName": "rate-limit", | ||
"KeySchema": [{ "AttributeName": "rate-limit", "KeyType": "HASH" }], | ||
"AttributeDefinitions": [ | ||
{ "AttributeName": "rate-limit", "AttributeType": "S" } | ||
], | ||
"BillingMode": "PAY_PER_REQUEST" | ||
} | ||
] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#! /bin/bash | ||
|
||
if [ ! -z "$DYNAMODB_CREATE_TABLES" ] | ||
then | ||
echo "Creating DynamoDB tables." | ||
if [ -z "$DYNAMODB_TABLE_SCHEMA_PATH" ] | ||
then | ||
echo "DYNAMODB_TABLE_SCHEMA_PATH environment variable is empty. Defaulting to ./tableSchema.json." | ||
export DYNAMODB_TABLE_SCHEMA_PATH="./tableSchema.json" | ||
fi | ||
|
||
jq -c '.[]' $DYNAMODB_TABLE_SCHEMA_PATH | while read i; do | ||
TABLE_NAME=$(echo "$i" | jq '.TableName') | ||
echo "Attempting to create table $TABLE_NAME" | ||
aws dynamodb create-table --cli-input-json $i --endpoint-url http://localhost:8000 --region us-east-1 1> /dev/null | ||
done | ||
else | ||
echo "Not creating DynamoDB tables." | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#! /bin/bash | ||
java -jar DynamoDBLocal.jar -inMemory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#! /bin/bash | ||
if [ ! -z "$DYNAMODB_ADMIN_ENABLED" ] | ||
then | ||
echo "Starting DynamoDB Admin" | ||
dynamodb-admin | ||
else | ||
echo "DynamoDB Admin disabled. Not starting DynamoDB Admin" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#! /bin/bash | ||
|
||
# https://docs.docker.com/config/containers/multi-service_container/ | ||
|
||
# turn on bash's job control | ||
set -m | ||
set -e | ||
|
||
# Start the primary dynamoDB process in the background | ||
./dynamodb.sh & | ||
|
||
# Try to start dynamodb-admin | ||
./dynamodbAdmin.sh & | ||
|
||
# Try to create tables in DynamoDB | ||
./createTables.sh | ||
|
||
# now we bring the primary process back into the foreground | ||
# and leave it there | ||
fg %1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[ | ||
{ | ||
"TableName": "cache", | ||
"KeySchema": [ | ||
{ "AttributeName": "key", "KeyType": "HASH" } | ||
], | ||
"AttributeDefinitions": [ | ||
{ "AttributeName": "key", "AttributeType": "S" } | ||
], | ||
"BillingMode": "PAY_PER_REQUEST" | ||
}, | ||
{ | ||
"TableName": "rate-limit", | ||
"KeySchema": [ | ||
{ "AttributeName": "rate-limit", "KeyType": "HASH" } | ||
], | ||
"AttributeDefinitions": [ | ||
{ "AttributeName": "rate-limit", "AttributeType": "S" } | ||
], | ||
"BillingMode": "PAY_PER_REQUEST" | ||
} | ||
] |
Oops, something went wrong.