„Übersicht“ Tool for OS X

Today i stumbled over a really nice little desktop widget tool called Übersicht. It’s from the developer Felix Hageloh. Übersicht is like the good old GeekTool and displays information aggregated from system commands or internet services directly onto you desktop background. Thereby Übersicht is much easier to modify, because all widgets are written in JavaScript or CoffeeScript and use HTML5 and CSS.

You will find a lot of widgets on his site too.

 

Share

How to: Install and remote debug a java application in Docker with IDEA IntelliJ

IDEA IntelliJ has a plugin for docker integration which supports docker container creation, configuration and deployment.

This article will guide you how to use the docker integration plugin and remote debug a simple java application running in a docker container.

What is used: IDEA IntelliJ 15.0.1, Docker 1.9.0, JDK 1.8, Maven 3.3, Docker integration plugin 1.7.4

Step 1 – Install Docker integration plugin

Go to Plugins under IntelliJ preferences and look for Docker integration plugin and install it.

Docker integration plugin

Docker integration plugin

 

Step 2 – Create a project

After restart of IntelliJ, create a new maven based project or clone and open my simple spring-boot example from Github.

 

Step 3 – The magic (part 1): Dockerfile

One important part is the Dockerfile. This file describes the image for all containers.

Create a new file in the root directory of your project with name „Dockerfile“ and insert this: (for the different Dockerfile commands, take a look at the Dockerfile reference)

# get latest debian docker base image
FROM debian:latest
# make sure wget and tar are installed
RUN apt-get update && apt-get install wget tar -y
# create and set working directory
RUN mkdir /opt/jdk18
WORKDIR /opt/jdk18
# tricky download of oracle jdk 1.8
RUN wget --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u66-b17/jdk-8u66-linux-x64.tar.gz" -O jdk.tar.gz
# unpack jdk to actual folder (ignoring root folder from archive)
RUN tar xvf jdk.tar.gz --strip 1
# clean up
RUN rm jdk.tar.gz
# set up environment for jdk
ENV JAVA_HOME=/opt/jdk18
ENV PATH=$PATH:$JAVA_HOME/bin
# set working dir
WORKDIR /root

# deploy the app (jar)
ADD target/spring-docker-app-1.0-SNAPSHOT.jar /root

The Dockerfile is based on latest debian image for docker. It installs wget and tar, downloads and installs JDK 1.8 and sets up the environment variables for the JDK.

Pay attention to the last line of your Dockerfile – it copies/deploys the application .jar-file into the container image. – Modify this line to your needs.

 

Step 4 – The magic (part 2): Docker run configuration

Create a new Run configuration based on „Docker Deployment“ template in IntelliJ and give it a speaking name like „Run in docker“.

Next, configure your new Run configuration:

Tab „Deployment“:

In the „Server“ entry, create a new Server configuration that points to your remote docker host and confirm the dialog with „OK“.

IntelliJ docker server

Docker server configuration dialog

Back in the deployment tab, select „Dockerfile“ as deployment type.

Give the container and image a name. Every docker container is based on an image. The image will be generated once, from the Dockerfile we created before and its name is mandatory.

The container name is optional. If it is left blank, every container will get a random name after startup.

Now select a debug port for java remote debugging. I use: 14096.

Under the debug port option the command line parameters for remote debugging are shown by IntelliJ – containing our debug port 14096. Please copy this line, we will need it later.

Add a maven package goal for the application in the „Before launch“ part. This is important, because before every deployment a new application jar is created and injected into a new container image.

Take a look at all settings on the following screenshot:

IntelliJ docker deployment

Deployment configuration overview

Now change to the „Container“ tab:

Click on the green arrow to create a new JSON file with container settings. This file contains all properties of a container, f.i.: mapped ports, mounted volumes etc.

We will edit the new JSON file later.

Every container needs an entry point. This is a command that will be executed when the container starts up. In our case we start a new java vm with our app in JAR format and the remote debugging options we copied earlier. The line for this command should look like this: (again: Change the application name to your needs)

java -agentlib:jdwp=transport=dt_socket,address=14096,suspend=n,server=y -jar spring-docker-app-1.0-SNAPSHOT.jar

Overview of all container options:

Intellij docker container

Container configuration overview

Confirm the dialog with „OK“ and navigate to the container_settings.json file.

The insider tip: Because of a bug or incompatibility problem between the Docker integration plugin in version 1.7.x and the newer Docker version 1.9 we need to modify the file like the one shown below:

{
  "_comment": "FOR DETAILED FORMAT LOOK AT https://docs.docker.com/reference/api/docker_remote_api_v1.16/#create-a-container",
  "AttachStdin": true,
  "OpenStdin": true,
  "ExposedPorts": {
    "8080/tcp": {},
    "14096/tcp": {}
  },
  "HostConfig": {
    "PortBindings":{
      "8080/tcp": [{ "HostPort": "8080", "HostIp":"0.0.0.0" }],
      "14096/tcp": [{ "HostPort": "14096", "HostIp":"0.0.0.0" }]
    }
  }
}

Take a look at „ExposedPorts“ and „PortBindings“. ExposedPorts tells docker which ports of the container should be available/exposed. PortBindings map ports between the virtual container network interface and the real host interface of the remote machine.

In the file above we map our debug port (14096) and spring-boot web server port (8080) and make it available outside of the docker container.

That’s all!

Now you can startup your new run configuration with docker deployment. The first start takes a bit longer because a new docker image will be created and the JDK download and installation will take a while.

If you set a breakpoint in App.main() method and start your docker run configuration in debug mode, the app should hit the breakpoint and halts.

With exposing and mapping of port 8080 the app should also be reachable via web browser http://x.x.x.x:8080/.

Hint: You can watch the image and container creation during startup. Docker will be handled as „Application Server“ in IntelliJ. Just show the „Application Servers“ tab with menu View / Tool Windows / Application Servers.

Have fun experimenting with Docker in IntelliJ!

🙂

 

Share

Quick – how to: Remote access your docker machine (Debian example)

If you’ve installed docker on a Debian linux machine following the guide on docker.com, you are able to control your containers only if you SSH into this machine or open some kind of tunnel (e.g. Putty) or configure NAT in case of a local vm.

Reason: the default installation of docker only listens to local sockets.

To access the docker machine from a remote client the docker service needs to be configured differently.

/etc/default/docker is a configuration file with a DOCKER_OPTS environment variable. Normally you would set the option -H tcp://ip-address:port here.

The problem: this option gets ignored with docker on Debian.

On Debian you have to modify the service description docker.service located under /etc/systemd/system/multi-user.target.wants

The key ExecStart should edited like this:

ExecStart=/usr/bin/docker daemon -H tcp://0.0.0.0:2375

(0.0.0.0 are all network interfaces – alternatively you can set another ip address here, f.i. if you have more than one network interface)

After editing the docker.service the systemctl daemon needs to be reloaded with

systemctl daemon-reload

After a restart of docker with

service docker restart

docker should be reachable via remote client.

Remark: if you are logged into your docker machine you need to set global DOCKER_HOST environment variable to tcp://0.0.0.0:2375, otherwise the docker command will not work.

export DOCKER_HOST=tcp://0.0.0.0:2375

On your remote client you also need to set DOCKER_HOST environment variable with ip-address and port of your docker machine:

for Windows: set DOCKER_HOST=tcp://x.x.x.x:2375

for OS X/Linux: export set DOCKER_HOST=tcp://x.x.x.x:2375

Now you can create/delete/control your containers and images of your remote docker machine with your local docker installation.

Hint – Small local docker installation:

On OS X: Just install Docker Toolbox, but don’t install Kinematic and Oracle VM (VirtualBox)! – following this guide: https://docs.docker.com/engine/installation/mac/

On Windows: Use Chocolatey to install a simple and clean docker client without the Oracle VM and Kitematic from Docker Toolbox.

 

Be warned: The docker endpoint has no security at this time and is reachable in your local network without authentication or encryption!

Share

Configuring IntelliJ 14.1 (CE) to work with SonarQube 5.1

The official SonarQube plugin for IntelliJ is not maintained since 2014 and doesn’t show SonarQube results in the IntelliJ IDE. I decided to give the SonarQube Community Plugin a chance. It works but there is one tricky dialog during configuration. I will show you how to install and configure the plugin.

At first make sure that no other SonarQube plugin is installed to avoid side effects.

Next step is to install the actual version of SonarQube Community Plugin using IntelliJ/Preferernces/Plugins dialog. (For Windows: File/Settings/Plugins)
SonarAfter IntelliJ has restarted, configure the plugin using IntelliJ/Preferences/Other Settings/SonarQube (For Windows: File/Settings/Other Settings/SonarQube). Add the connection to your SonarQube server as shown in the following screenshot. (Important: Server must be up and running!)

SonarPlugin1
Now the tricky dialog part: Select the + under SonarQube resources. Select „Download resources“ in the next dialog window. It should show all your SonarQube projects. SonarPlugin2Select the project resources you need and confirm all open dialogs with OK.

You are ready to run Analyze/Inspect code from the IntelliJ menu. In the inspection results tree will be a new branch called „SonarQube“ containing all information from last SonarQube analysis.
Also all analysis results will be presented as tooltips in the IDE – as shown in the next screenshot.
SonarResult

Don’t forget to run Analyze/Inspect code after every SonarQube code analysis to get the actual results from the SonarQube server.

Share

Restart

After a few month with the Ghost-Blog, i’m back to WordPress and decided to rebuild this site. Unfortunately Ghost didn’t develop as much as i expected last year. The markdown editor was the best feature of it, but otherwise Ghost made only small steps ahead. Welcome to the restart!

Share