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

Use alpine base #21

Closed
wants to merge 3 commits into from
Closed
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
17 changes: 12 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
# for details on how to run DynamoDB locally. This Dockerfile essentially
# replicates those instructions.

# Use JDK 7. I tried alpine, but all calls to dynamo then fail silently...
# FROM openjdk:7-jre-alpine
FROM openjdk:7
FROM openjdk:8-jre-alpine

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could not make it work locally but it worked using slim tags

Image sizes:

  • regular ~510 mb
  • slim ~240 mb
  • alpine ~120 mb

Slim will not optimize the image size but it could be already considered an improvement

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fell off my radar, I'll take a look now and try either getting it to work reliably or else use the slim tags.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you give an example of what you ran to get the above error?
I also found this which may explain why: uber/h3-java#25

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 @jukie I was getting this kind of message

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's go for slim then, still an improvement and I love the build arg so want to get the changes in!


# Specify dynamodb version with a build argument. (i.e. docker build . --build-arg DYNAMODB_VERSION=latest)
ARG DYNAMODB_VERSION

# Some metadata.
MAINTAINER Dave Kerr <github.com/dwmkerr>
Expand All @@ -20,8 +21,14 @@ WORKDIR /opt/dynamodb

# Download and unpack dynamodb.
# Links are from: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html
RUN wget https://s3-us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_latest.tar.gz -q -O - | tar -xz


RUN wget https://s3-us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_${DYNAMODB_VERSION}.tar.gz \
&& wget https://s3-us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_${DYNAMODB_VERSION}.tar.gz.sha256 \
&& sha256sum -c dynamodb_local_${DYNAMODB_VERSION}.tar.gz.sha256 \
&& tar zxvf dynamodb_local_${DYNAMODB_VERSION}.tar.gz \
&& rm dynamodb_local_${DYNAMODB_VERSION}.tar.gz dynamodb_local_${DYNAMODB_VERSION}.tar.gz.sha256


# The entrypoint is the dynamodb jar. Default port is 8000.
EXPOSE 8000
ENTRYPOINT ["java", "-jar", "DynamoDBLocal.jar"]
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ tests/ # bash scripts to test how the container works

The Dockerfile is based on [OpenJDK](https://hub.docker.com/_/openjdk/) and essentially just runs a jar file in a JRSE 7 environment.

When building the image, it will expect to have the desired dynamodb version set with a build argument of "DYNAMODB_VERSION".
Example:
```bash
docker build --build-arg DYNAMODB_VERSION=latest .
```


## The Makefile

The makefile contains commands to build, test and deploy. Parameters can be passed as environment variables or through the commandline.
Expand Down
5 changes: 3 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Create the docker images locally. If a BUILD_NUM is provided, we will also
# create an image with the tag BUILD_NUM.
# Specify a specific dynamodb version by changing the DYNAMODB_VERSION=latest build flag as desired
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a trick we can use here is this:

DYNAMODB_VERSION ?= latest
build:
    docker build -t dwmkerr/dynamodb:latest --build-arg DYNAMODB_VERSION=$(DYNAMODB_VERSION)
    # etc...

This way there's not even any need to change the makefile, the caller can just do:

DYNAMODB_VERSION=1.2.3 make build

Or even:

make build DYNAMODB_VERSION=1.2.3 

It's a really nice syntax - if the variable is not specified, the default latest is use. This is an excellent approach for CI systems - if you have a specific version in mind you can just set it as an env var and the makefile will just pick it up automatically.

(Nice reference here: https://adamcod.es/2016/11/15/makefile-variables.html)

build:
docker build -t dwmkerr/dynamodb:latest .
docker build -t dwmkerr/dynamodb:latest --build-arg DYNAMODB_VERSION=latest .
ifndef BUILD_NUM
$(warning No build number is defined, skipping build number tag.)
else
docker build -t dwmkerr/dynamodb:$(BUILD_NUM) .
docker build -t dwmkerr/dynamodb:$(BUILD_NUM) --build-arg DYNAMODB_VERSION=latest .
endif

# Run the tests. These do things like kill containers, so run with caution.
Expand Down