Skip to content

Instantly share code, notes, and snippets.

@joebew42
Last active June 22, 2017 18:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joebew42/3e37e50404c66d36356e13d60a72e65d to your computer and use it in GitHub Desktop.
Save joebew42/3e37e50404c66d36356e13d60a72e65d to your computer and use it in GitHub Desktop.

Tiller example

What is tiller? here

Useful tutorials:

Configure a simple java application

requirements

  • Java 8
  • Maven 3

The example code can be found here. It is a simple application written in java that exposes an api for read and create notes. It is configured in order to write on a MySQL Database.

$ git clone https://github.com/joebew42/dropwizard-sample-app.git
$ cd dropwizard-sample-app/
$ git checkout tiller

For practicality reason I've already created and pushed a Docker image with Tiller and OpenJDK8-JRE that you can find here, the Dockerfile used is this:

Dockerfile-openjdk8-jre-tiller

FROM alpine:edge

RUN apk add --update alpine-sdk \
    && apk add --update openjdk8-jre-base \
    && apk add --update ruby \
    && apk add --update ruby-dev \
    && gem install --no-ri --no-rdoc json tiller \
    && rm -rf /var/cache/apk/* \
    && mkdir /app

ONBUILD ADD tiller /etc/tiller

CMD ["/usr/bin/tiller" , "-v"]

The Dockerfile of our application

Dockerfile

FROM joebew42/openjdk8-jre-tiller

COPY target/sample-app-1.0-SNAPSHOT.jar /app
WORKDIR /app

EXPOSE 8080

We simply copy the generated artefact! It is just an example.

Generate the artefact

$ mvn package

Build the docker image

$ docker build -t joebew42/dropwizard-sample-app:latest --rm=true .

Run a MySQL server and the create database

For this we use the official MySQL Docker image

$ docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root --name=database mysql
$ docker exec -it database sh -c "mysql -uroot -proot -e 'create database db_notes;'"

Run migrations

$ docker run -it -e environment=production -e tiller_json='{"db_name":"db_notes","db_host":"10.0.0.50","db_port":"3306"}' --rm=true joebew42/dropwizard-sample-app:latest tiller -x "java -jar sample-app-1.0-SNAPSHOT.jar db migrate configuration.yml"

Run the application

$ docker run -it -e environment=production -e tiller_json='{"db_name":"db_notes","db_host":"10.0.0.50","db_port":"3306"}' -p 80:8080 joebew42/dropwizard-sample-app:latest

Take a look at tiller folder to understand how the configuration file is generated:

tiller/

tiller/
├── common.yaml
└── templates
    └── configuration.yml.erb

Make some requests :)

$ curl http://localhost/notes
$ curl -X POST --data "hello world" http://localhost/notes/
$ curl -X POST --data "another hello world" http://localhost/notes/
$ curl http://localhost/notes
$ curl http://localhost/notes/1
$ curl http://localhost/notes/2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment