Friday, July 31, 2015

Portability Series: A Go Environment

Previously we looked at the portability of container setups. One of the observations is that a lot of containers are based on a Go environment -- take swarm or the registry. On x86, that usually means golang, but we have gccgo on s390. Let's see, how we can deal with this difference.



When you check out the Dockerfile of swarm and of the registry, they expect a golang environment. They copy their code into a location in the container. Then they set up some environment variables and invoke the go compiler. Finally, they shape, how the container is invoked.

To sneak in a gccgo, we first have to build one. However, we do this in a container -- by creating a directory, and a Dockerfile in it. The Dockerfile reads:
FROM debian:wheezy
RUN echo deb http://ftp.de.debian.org/debian wheezy-backports main >> /etc/apt/sources.list && \
    apt-get update && \
    apt-get install -y git subversion mercurial libgmp-dev libmpfr-dev libmpc-dev flex byacc gcc cpp g++ make

RUN svn co svn://gcc.gnu.org/svn/gcc/tags/gcc_5_2_0_release && \
    mkdir bld && \
    cd bld && \
    ../gcc_5_2_0_release/configure --enable-threads=posix --enable-shared --enable-__cxa_atexit --enable-languages=c,c++,go --enable-secureplt --enable-checking=yes --with-long-double-128 --enable-decimal-float --disable-bootstrap --disable-alsa --disable-multilib --prefix=/usr/local/gccgo && \
    make && \
    make install && \
    cd .. && \
    rm -fr bld gcc_5_2_0_release

ENV PATH /usr/local/gccgo/bin:/go/bin:$PATH
ENV LD_LIBRARY_PATH /usr/local/gccgo/lib64:$LD_LIBRARY_PATH
ENV CGO_ENABLED 1
ENV GOPATH /go
(Update 8/18: added mercurial to the list of packages to be installed)
So this again uses a debian:wheezy (as described previously -- note it's wheezy, not jessie). Then, a wheezy-backports repository is added (use the mirror of choice), and some packages are installed.

The large RUN section checks out the 5.2.0 release of gcc and builds and installs it with Go support.
Some environment variables are required to make gccgo behave similar enough to golang that most packages work out of the box. The image is built with
docker build -t gccgo:5.2.0 directory
where directory corresponds to the folder containing the Dockerfile. To make use of this, existing Dockerfiles referring to golang have to be changed to refer to gccgo:5.2.0, or we simply tag the image as golang:1.4 (docker tag gccgo:5.2.0 golang:1.4). Note this is not a real golang:1.4, but for most practical purposes, it will do the trick:
git clone https://github.com/docker/distribution.git
docker build -t distribution distribution
docker run distribution
or
git clone https://github.com/docker/swarm.git
docker build -t swarm swarm
docker run swarm
Again, the white spots on the map got smaller.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.