Category Archive for: ‘Java’

Deploying Spring Boot Apps to Heroku using Docker

0

I am using Heroku for a long time now. The usual deployment method for me was to push a Git repository to Heroku, then build and run the software in their cloud. Since a long time, Heroku supports also Docker deployment, but in the past I found it a bit to restrictive. Now it is possible to deploy web applications as Docker images very easily. As an example I have a continuous delivery pipeline (using Travis CI) up and running that deploys the same docker image to both DockerHub and Heroku. As base I take my Open Source Playground Chatty. In this blog I explain how this is done.

One restriction of the Heroku Docker deployment is that the web server has to run on a port specified by the environment variable PORT. In Spring there are many ways for doing this. I decided to manually override Springs’s server.port property, when the application finds out at run-time that it is running in an Heroku environment, checking the environment variables DYNO and PORT:

public static void main(String[] args) throws Exception {

    String ENV_PORT = System.getenv().get("PORT");
    String ENV_DYNO = System.getenv().get("DYNO");
    if(ENV_PORT != null && ENV_DYNO != null) {
        System.getProperties().put("server.port", ENV_PORT);
    }

    SpringApplication.run(Chatty.class, args);
}

To do a Docker deployment, you have to login into the Heroku registry first. For that you need to know the your Heroku auth token. The easiest way to get it is to login to Heroku using the CLI and then type

heroku auth:token

This will return a token like ea405d9e-76ff-4881-acbd-327c28efa3be. Now you can login to the Heroku Docker registry with

docker login --email=_ --username=_ --password="ea405d9e-76ff-4881-acbd-327c28efa3be" registry.heroku.com

Then you have to tag your Docker image like

docker tag <image> registry.heroku.com/<app>/<process-type>, e.g.
docker tag kaitoedter/chatty registry.heroku.com/chatty42/web

You could simply put the scripting in a .travis.yml file and hide the Heroku auth token in an environment variable, like

  - docker login --email=_ --username=_ --password="$HEROKU_AUTH_TOKEN" registry.heroku.com
  - docker tag kaitoedter/chatty registry.heroku.com/chatty42/web
  - docker push registry.heroku.com/chatty42/web

You find the Chatty .travis.yml here.
A running container is always available at https://chatty42.herokuapp.com
Since Heroku is shutting down the service when there are no users, please give it a bit of time to start up.

As conclusion I find the deployment of custom Docker images to Heroku even easier than the previous git deployment.

Creating colorful Banners for Spring Boot Applications

5

Often it is nice if a service provides its own banner. Then you can easily recognize the start of the service, even when you just take a quick glimpse. Its even nicer if the banner could provide colors, just in case you have a log or a terminal that supports colored output. With the release 1.3.0 of Spring Boot it is possible to display colorful banners.

For my Chatty demo, I quickly created a banner using an ASCII art generator, like http://patorjk.com/software/taag/#p=display&f=Graffiti&t=Chatty. if you save it in a file named banner.txt and put it under src/main/resources, it would be displayed like:

chatty-banner1

With a little bit of ANSI colors I got

chatty-banner2

You find the current Chatty banner.txt here.

If you want to have it really colorful, you could create a banner like

chatty-banner3

You find the source for the above banner.txt here.

All in all, it was fun creating a new banner for my Spring Boot based demo service.

 

Docker on Windows behind a Firewall

17

Working with Docker under Windows becomes easier and easier. I am often ask by co-workers how to run Docker behind a firewall, this blog gives a little recipe, how to set up the whole Windows/Docker/Firewall environment.

  1. Install Virtual Box
  2. Download Docker Machine to manage your docker hosts
    • You find the Windows versions (32 and 64 bit) at above link
    • Rename the exe to docker-machine.exe
    • I would recommend putting the machine in a dedicated docker directory and update your PATH env variable
  3. Install the Docker Windows client
  4. Create a Docker host named ‘dev’ with docker machine
    • docker-machine create --driver virtualbox dev
  5. Connect the Docker client with the docker vm
    • Saving the environment to a .bat file: docker-machine env -shell cmd dev > docker-env.bat
    • You will get something like
      SET DOCKER_TLS_VERIFY=1
      SET DOCKER_HOST=tcp://192.168.99.2:2376
      SET DOCKER_CERT_PATH=C:\Users\toedter_k\.docker\machine\machines\dev
      SET DOCKER_MACHINE_NAME=dev
      REM Run this command to configure your shell:
      REM FOR /f “tokens=*” %i IN (‘docker-machine env -shell cmd dev’) DO %i
    • Run the bat file (or, like docker-machine tells you, you could run the code in the last line without the REM 🙂 )
    • Check if the client is working:
      • Run docker ps in a Windows cmd
  6. Prepare the proxy settings
    • SSH into the docker dev host: docker-machine ssh dev
    • Add the following lines to /var/lib/boot2docker/profile (this file is read-only, use sudo)
      export HTTP_PROXY=http://<proxy>:<port>
      export HTTPS_PROXY=http://<proxy>:<port>
    • Exit the ssh session and restart the docker machine: docker-machine restart dev

Now you should be able to use Docker on Windows behind a firewall. To test it, open a Windows cmd and run
docker run busybox echo hello world

After docker has downloaded the busybox image you should see

hello world

That’s it 🙂
Now you can easily use all Eclipse or IntelliJ IDEA plugins that require a local Docker installation.

JavaLand 2015

0

Last week I attended the JavaLand conference (March 23-24, 2015) and this is a short personal blog about it.

The Venue

The conference took place at Phantasialand, a great theme park in Brühl, close to Cologne. I really liked the atmosphere there, it reminded me a lot of Disneyland, which I visited 6 months ago. The sessions were held both in the Quantum conference center, as well as the movie theater and the main stage. At the end of the first conference day, 11 attractions of the park were opened just for the conference attendees. I took the advice of some friends very seriously: Don’t drink a beer until you have finished all the rides! When I was younger, I was a big roller coaster fan, so I tried Black Mamba, Colorado Adventure and Temple of the Night Hawk. Then I had enough of roller coasters :).

javaland-panorama

The Sessions

For many conference attendees the sessions are the most important part of a conference. In my point of view the sessions were a good mix of technical and non-technical topics. Since I am a Java veteran for 20 years, I usually only attend sessions about content that is either totally new for me or I have very little knowledge about. My personal highlights were:

  • Coding Culture (by Sven Peters)
  • Effective Asciidoc (by Dan Allen and Sarah White)
  • Use Cases for Elasticsearch (by Florian Hopf)

Of course there were many more great talks but these 3 gave me new insights and made me think most. My own session about TypeScript went well, hopefully I could transport my excitement about TypeScript to the audience. I really appreciated that other programming languages got some attention at the conference.

session-panorama

The Community

I really liked the atmosphere at the conference. It was very easy for me to talk to people I did not know before. In the community area there were lots of interesting booths, playgrounds, open spaces, katas, workshops and more. It was fun to experience a few Oculus Rift demos that I did not know before. It was also very nice to meet old friends like Wayne Beaton and Lars Vogel from the Eclipse community, as well as many people I know from my JCP work or other conferences.

The Food

While many developers are happy if they get pizza or fast food, I appreciate good catering at conferences. I was invited to the community dinner on Monday, hosted in the restaurant of one of the theme hotels. This dinner was the start of great catering during the whole conference, so JavaLand easily made it into my all-time top 5 conference caterings.

The Band

I have to admit that I did not expect anything when I heard a band was playing Tuesday night. To make it short: The Band (Sonnabend) was awesome! After enjoying few songs I could not resist to dance for more than one hour. 20 years ago I played keyboards in my Band DC Robertson (see MultiMedia) so I had a special eye on the awesome keyboarder :).

band-panorama

Opportunities

There were a few things that I was missing: Reliable Wifi and a conference app. Another thing: When I attended sessions in the theater, it was pretty chilly. So, as always, there is room for improvements :).

Summary

All in all I liked the conference a lot and looking forward to JavaLand 2016.

Deploy Multi-Language Projects to Heroku

0

In my current technology playground chatty I use Java, TypeScript and JavaScript as programming languages. For the TypeScript/HTML based Web UI I use a node/grunt based build, for the Java parts I use Gradle. Heroku is a great cloud platform, deploying software is done using a git push. Using the predefined build-packs, it is pretty easy to deploy Java OR Node based applications, but how to deploy a multi-language project that uses both?

Here the heroku-buildpack-multi helps a lot. Simply invoke

$ heroku config:add BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-multi.git

and add all buildpacks to a top-level .buildpack file, that’s it. Then, each build is done sequentially as specified in the .buildpack file. The .buildpack for chatty looks like

https://github.com/mbuchetics/heroku-buildpack-nodejs-grunt.git
https://github.com/heroku/heroku-buildpack-gradle.git

Another important thing to know about these buildpacks assume that the corresponding project is located at top-level. So the node build expects a package.json in the root directory. Since chatty is a multi-project build, the web part is located in subprojects/com.toedter.chatty.client.web. For me, the easiest solution was to copy the package json to the root directory, and the provide a grunt file, that copies all node_modules to the subproject. Additionally I use the grunt contribution grunt-hub to invoke the gruntfile located in the subproject with target distBoot (to provide a distribution of the JacaScript/HTML/CSS/libs that can be deployed together with the Spring Boot based server part. The last thing is to define a grunt task named ‘heroku’ that is invoked by the buildpack. The whole top-level grunt file looks like:

module.exports = function (grunt) {
    'use strict';

    grunt.initConfig({
        hub: {
            all: {
                src: ['subprojects/com.toedter.chatty.client.web/Gruntfile.js'],
                tasks: ['distBoot']
            }
        },
        copy: {
            node_modules: {
                expand: true,
                src: 'node_modules/**/*',
                dest: 'subprojects/com.toedter.chatty.client.web/'
            }
        }
    });

    grunt.loadNpmTasks('grunt-hub');
    grunt.loadNpmTasks('grunt-contrib-copy');

    grunt.registerTask('heroku', ['copy:node_modules', 'hub']);
}

The Java part is pretty straight forward since gradle is the master build system of chatty. The only subproject I want to deploy to heroku is the Spring Boot based server, located in subprojects/com.toedter.chatty.server.boot. In the gradle.build file I just added a new gradle task ‘stage’:

task stage(dependsOn: ['jar', 'bootRepackage'])

that creates the fat jar for the chatty spring boot application. The resulting web application demo is then deployed to Heroku, you can check it out at https://chatty42.herokuapp.com/chatty/chatty.html.

Regarding IDE integration there are Heroku plugins for IntelliJ IDEA and Eclipse. In the next blog of this series, I will explain how to use Travis-CI for a continuous delivery, including the automatic deployment to Heroku after a successful build.

Eclipse 4 Application Platform Tutorial Update

1

Recently I worked a bit on my Eclipse 4 Application Platform Tutorial. The good news for you: The slides are now licensed under a Creative Commons Attribution 4.0 International License.

cc-88x31

If you find useful stuff in the slides that you would like to re-use for talks, trainings or even for commercial use, you could do that now. You find the current slide deck either on my Web site or directly at SpeakerDeck. The corresponding source code is hosted at my GitHub repository and licensed under EPL. Here is a screenshot of the little app developed in the tutorial.

e4-tutorial-thumb

The slides as the sources are valid for both Kepler and Luna.

If you find outdated/strange/wrong things in the slides, please let me know :).

Continuous Integration with Travis CI

2

Travis CI is a cloud-based continuous integration service that supports many different programming languages and environments. If you have projects at GitHub, Travis CI might be interesting for you. I currently use it for a few of my open source projects at GitHub. Setup is quite easy, you can log in with your GitHub credentials and then you get a lit of all repos you have administration rights. Then you can configure, when Travis should run a build, e.g. on every push or pull request. The only thing you have to do is to provide a .travis.yml file at the root of your GitHub project that contains configuration info.

A few examples: my current pet project chatty has a Java back-end and a HTML/JavaScript based front-end (actually mostly written in TypeScript). For the JavaScript/TypeScript part I need node.js installed, as well as grunt, bower and tsd (TypeScript Definition Manager). The yml file looks like:

language: java
jdk:
  - oraclejdk8

before_script:
  - npm install -g grunt-cli
  - npm install -g bower
  - npm install -g tsd

script: ./gradlew test

This makes sure that the node modules grunt-cli, bower and tsd is installed before the build is run. Gradle is supported out of the box but the default is the check task. In my chatty project I have integration tests that I don’t want to run on Travis CI, that’s why I explicitly use ‘gradlew test’ as script. Make sure that the build scripts are executable. While this is a no-brainer on most operating systems, on Windows it is not so easy. But even on Windows you could use git to do the job, e.g.:

git update-index --chmod=+x gradlew

When the Travis CI build is set up, you can include a build indicator icon directory in the readme of your GitHub project. If you use markdown, the code snipped (for chatty) looks like

[![Build Status](https://travis-ci.org/toedter/chatty.svg?branch=master)](https://travis-ci.org/toedter/chatty)

Then a nice icon build status is displayed in your project description.

Eclipse based Builds
When you want to run Tycho based builds for Eclipse based projects, you only have to make sure to change to the directory of the parent pom. The yml file for my Eclipse 4 Application Platform Tutorial looks like:

language: java
jdk:
  - oraclejdk8

before_script:
  - cd org.eclipse.e4.tutorial.contacts.build.tycho

script: mvn clean install -DskipTests

I had some trouble running tests on Travis CI that involve SWT, that’s why I skip the tests.

Grails based Builds
Travis CI does not support Grails out of the box (like Gradle) but this is no problem at all since Grails provides its own Wrapper. So make sure that the wrapper is part of your project. One of our Siemens OSS projects, the REST API doc for Grails has the following yml file:

language: groovy
script: ./grailsw refresh-dependencies
     && ./grailsw test-app --echoOut

I am a big fan of Travis CI and recommend to give it a try!

Eclipse Demo Camp Munich 2013: Impressions

0

Yesterday we had the Eclipse Demo Camp Munich 2013 at the Siemens campus. Around 150 attendees showed up, and from the feedback I got do far, the event was a great success.

democamp-munich

I would like to thank

  • All speakers: Ralph Müller, Tom Schindl, Gerrit Grunwald, Eike Stepper, Marcel Bruch, Jonas Helming, Eugen Nefeld, Matthias Zimmerman, Jérémie Bresson, and Matthias Sohn!
  • Our sponsors: Siemens AG, EclipseSource Munich,  Eclipse Magazin (S&S Media GmbH) and EclipseScout (BSI Business Systems Integration AG)
  • All attendees

You all made the demo camp a great event. My personal highlight in terms of fun factor was the release of the EMF Client Platform, when Jonas and the EMF Client Platform team pushed the BIG RED RELEASE BUTTON

and we could follow the release build live. Here is a short video:

Today I felt so good about the demo camp that I have booked the location again for next year, so stay tuned for Eclipse Demo Camp Munich 2014 🙂

Kai

You find me on Twitter and Google+.
Interested in Eclipse 4 Application Platform trainings?

Eclipse Democamp Munich 2013 @ Siemens : Update 2

0

There are only 10 days left and the Eclipse Democamp Munich 2013 (June 12th, 2013)  is almost sold out. As of today, there are only 11 tickets left out of 200. So hurry up, if you want to attend and haven’t registered yet. This year we will again have a great speaker lineup with interesting sessions and demos. Here is a photo of last year’s demo camp:

democamp

You can register and take a look at the agenda at http://democampmunich2013.eventbrite.com. After the sessions we will have great networking opportunities, a warm buffet and drinks.

CU next week at the Demo Camp

Kai

Eclipse Demo Camp 2013 @ Siemens (Update 1)

0

Update 1: All sessions are confirmed, Ralph Müller is going to give an intro and 107 tickets are already taken 🙂

I am happy to announce the Kepler Eclipse Demo Camp 2013 @ Siemens in Munich, Germany. Again, excellent speakers with interesting demos/talks will make this demo camp an Eclipse fest! In the last years we had between 150 and 175 attendees, this is the mark to top this year. The latest event details and agenda you always find at the Wiki page and the registration page.

Location
Location: Siemens AG, Forum 1, Otto-Hahn-Ring 6, 81739 Munich, Germany
PDF with directions: Siemens Munich MCH_P campus
Google Maps: Siemens Munich MCH_P campus

Date and Time
Wednesday, June 12, 2013 from 5:00 PM – 11:00 PM (GMT+0100)

Agenda

  • 05:00pm – 05:30pm Meet and Greet
  • 05:30pm – 05:40pm Welcome/Intro,
    Ralph Müller (Eclipse Foundation) + Kai Tödter (Siemens Corporate Technology)
  • 05:40pm – 06:00pm JavaFX/Swing Renderers for the Eclipse 4 Application Platform
    Kai Tödter (Siemens Corporate Technology)
  • 06:00pm – 06:20pm Extended JavaFX
    Tom Schindl (BestSolution)
  • 06:20pm – 06:40pm Cool Stuff with JavaFX and Raspberry Pi
    Gerrit Grunwald (Canoo)
  • 06:40pm – 07:00pm The CDO Model Repository
    Eike Stepper (ES-Computersysteme)
  • 07:00pm – 07:30pm BREAK (with soft drinks & snacks)
  • 07:30pm – 07:50pm Down the Rabbithole with Code Recommenders
    Marcel Bruch (Codetrails)
  • 07:50pm – 08:10pm How to build a Tool based on EMF in 20 Minutes
    Maximilian Kögel + Jonas Helming (EclipseSource)
  • 08:10pm – 08:30pm Mobile Business Applications with Eclipse Scout
    Matthias Zimmermann (BSI Business Systems Integration AG)
  • 08:30pm – 08:50pm Cool new Stuff in EGit and JGit
    Matthias Sohn (SAP AG)
  • 08.50pm – 11:00pm Networking (with beer, soft drinks and warm buffet)

Registration
At democampmunich2013.eventbrite.com you find the current list of attendees and you can register. Registration is free: beer, soft drinks and (warm) buffet is sponsored by Siemens AG, EclipseSource, Eclipse Magazin (S&S Media GmbH) and EclipseScout (BSI Business Systems Integration AG).

Let’s make this demo camp great!

See you all in Munich…

Kai

You find me on Twitter and Google+.
Interested in Eclipse 4 Application Platform trainings?

Page 1 of 1112345»10...Last »