Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for dockerized DynamoDBLocal #64

Merged
merged 1 commit into from
Jan 21, 2022

Conversation

henhal
Copy link
Contributor

@henhal henhal commented Jan 13, 2022

This adds a new option which if true starts DynamoDB using docker.
Enabling support for docker resolves some issues with running the DynamoDB Java server on incompatible
architectures such as Apple M1.

If the option docker is truthy, instead of spawning a java process, a docker process is spawned, such as

docker run -d -p 8000:8000 amazon/dynamodb-local -jar DynamoDBLocal.jar -port 8000 -sharedDb -inMemory

The same arguments are supported as when running DynamoDBLocal using java on the localhost.

Customization:

The following environment variables may be used to customize the docker behaviour:

  • DOCKER_PATH - the path to the docker executable. Default: 'docker'
  • DOCKER_IMAGE - the name of the docker image. Default: 'amazon/dynamodb-local'

This adds a new option  which if true starts DynamoDB
using docker, e.g.
docker run -d -p 8000:8000 amazon/dynamodb-local -jar DynamoDBLocal.jar -port 8000 -sharedDb -inMemory

The docker executable may be customized using process.env.DOCKER_PATH, and the docker image through
provess.env.DOCKER_IMAGE.

Enabling support for docker resolves some issues with running the DynamoDB Java server on incompatible
architectures such as Apple M1.
@henhal
Copy link
Contributor Author

henhal commented Jan 13, 2022

Fixes #63.
Whipped together for feedback and discussion. Works fine for me to start on MacBook Pro M1 2021 after installing Docker Desktop.
No tests created (if applicable).

@henhal
Copy link
Contributor Author

henhal commented Jan 13, 2022

If this is accepted, I intend to make a PR on https://github.com/99x/serverless-dynamodb-local/blob/v1/index.js to support docker as an argument for the SLS plugin as well.

Would it be more desirable to have the option as an object, such as

docker: {
   enabled: true,
   image: 'amazon/dynamodb-local', // optional
   path: '/usr/bin/local/docker' // optional
}

... or are you find with a simple docker: true and advanced options through environment variables? It occurred to me that envs are not ideal to use from the SLS plugin, it would be clearer if those options could be passed as part of the options object passed to dynamodb-localhost.

Updates to README.md are also needed, happy to append that once discussion topics are settled. :)

@ixartz
Copy link

ixartz commented Jan 21, 2022

I'm also interested by this PR. It could be great if it can be merged.

Maybe we should tag here the maintainer. They also put an email adresss in the README file?

@henhal
Copy link
Contributor Author

henhal commented Jan 21, 2022

@AshanFernando

@AshanFernando AshanFernando merged commit d88f777 into 99x:master Jan 21, 2022
@henhal
Copy link
Contributor Author

henhal commented Feb 7, 2022

@AshanFernando In order to proceed with 99x/serverless-dynamodb-local#279 I need a new released version of dynamodb-localhost. Could you please publish e.g. 0.1.0?

@AshanFernando
Copy link
Collaborator

@henhal Can you approve the below version bump
#65

@henhal henhal deleted the docker-support branch February 7, 2022 08:46
@lsalazarm99
Copy link

Hello. I know that the new versions of this plugin and dynamodb-localhost are not released in NPM yet, so I installed both of them directly from their git repositories.

I tried serverless dynamodb start --docker, as the docs states, but it says it doesn't recognize the docker argument. It works if I set the docker parameter in my serverless config.

@henhal
Copy link
Contributor Author

henhal commented Mar 2, 2022

@lsalazarm99 Sorry if a stupid suggestion, but did you confirm that the unreleased version was in use? I mean, did serverless-dynamodb-local's package.json also reference the unreleased "pre-version"?

I did try this use-case successfully using npm link during development, which ensures my local version was used both from my test package and transitively from serverless-dynamodb-local. Just thinking your temporary setup might have had two versions in node_modules like this?

node_modules
|- serverless-dynamodb-local <- unreleased version directly from git
   |- node_modules
      |- dynamodb-localhost <-- official version referenced by package.json
|- dynamodb-localhost <- unreleased version directly from git

@henhal
Copy link
Contributor Author

henhal commented Mar 2, 2022

Doh, I missed the part about how it worked from serverless.yml but not from the CLI, then my suggestion makes no sense. Sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants