Blog

Recently I stumbled upon GitPod, a Web based IDE for GitHub projects. GitPod is based on Theia, an extensible, VS Code-powered IDE for browser and desktop. While playing around with GitPod, I got the feeling: This is awesome! For me there are several use cases, but the most important one was: Could I use GitPod as tool for giving workshops with lots of coding exercises. As an example I tried out my Web App Tutorial that I regularly give at conferences. Usually I prepare a VM using Vagrant, containing all the labs, the tooling, etc., but those VMs are around 6 GB of data and need a decent notebook so that everything runs smoothly. And in every training there are notebook configurations having trouble running these VMs. What if I just could say: Bring your favorite Web browser, we will do all labs and running all tests in the browser? That’s what I wanted to try out with GitPod. Here is my setup: During the workshop we develop a small microservice with an Angular 7 based frontend and a Spring Boot 2.0.6 based backend. How easy would it be to compile and start the backend in GitPod, start the frontend, see the result, making a change to the frontend Typescript code and immediately see the result in a browser window? Additionally I wanted to run Headless-Chrome based tests on the frontend code. This was actually pretty easy with GitPod. I only had to create a GitPod configuration file in my Git repo:

The first statement tells GitPod to run npm install which is needed to install all Node.js modules. To run the tests in Chrome I had to set the CHROME_BIN environment variable to point to Chromium. The last thing was to expose the ports 8080 for the backend, to browse the REST API and 4200 for the frontend development server to have fast turnarounds during frontend development. The picture shows how this looks in GitPod:

Now the new frontend should immediately re-compile and you should see the change in the UI

All in all, I see great potential to run labs with coding exercises completely in the browser using GitPod. Once the debugging server protocols are in place I hope that I could both debug the frontend as well the backend also directly in GitPod.

Last Friday I gave a presentation for the Java User Group Thüringen that included a live deployment to Heroku using Docker. The deployment did not work and I found out about it one day later: Heroku has changed the workflow, Docker push to the Heroku registry does not release the app anymore. The reason for that change is explained here. In my Travis-CI builds, I added a small bash script using the Heroku API to trigger a release. Here is an example script that I use in my microservice in 60 minutes demo.

Spring Boot creates fat jars as a result. It is very easy to run them in containers, just create an image that contains the appropriate Java version, copy the jar, start java => that’s basically it. Most likely you want to push this image to a Docker registry and here one disadvantage of this method becomes obvious: If you just change one line in one of your own Java classes, you create a layer in the Docker image, which contains not only your own stuff bat also all dependencies. So when you push an image after a small change, you are probably pushing between 30 and 60 MB, depending on your dependencies. This block post explains how you can optimize your Docker images so that you only push your stuff, which in the best case is only KB or a few MB.

The first step is to separate your own stuff and your dependencies. For that, you can use extra Gradle or Maven build steps. I will show how this is done using Gradle. The idea is that after Gradle has created the Spring Boot fat jar, unzip it, and copy the result to 2 separate directories: docker/lib for the external dependencies and docker/app for your very own stuff. Then create a Dockerfile including 2 lines: One line copies docker/lib to /app/BOOT-INF/lib/ in one Docker image layer and the second line copies docker/app/ to /app/ in another Docker image layer.

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:

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

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.

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.

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.

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

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>

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 :).

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.

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 :).

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.

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?

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:

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’:

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.

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.

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 :).