Skip to content

Commit

Permalink
Allow build with specific Go version
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugues Bruant committed Feb 5, 2018
1 parent 9497bbe commit 9bf1ae1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
8 changes: 0 additions & 8 deletions Dockerfile
Expand Up @@ -12,14 +12,6 @@ RUN apt-get update &&\
RUN curl -L --fail https://get.docker.com/builds/Linux/x86_64/docker-1.10.3 -o /usr/local/bin/docker &&\
chmod +x /usr/local/bin/docker

# Installing from official packages makes it easier to bump Go version when distro lags
# behind. For instance Debian is taking too long to upgrade to 1.5.3 which includes an
# important security fix.
RUN curl https://storage.googleapis.com/golang/go1.5.3.linux-amd64.tar.gz -o go.tar.gz &&\
tar -C /usr/local -xzf go.tar.gz &&\
rm -rf go.tar.gz &&\
mkdir /gopath

ENV GOPATH /gopath

ENV PATH $PATH:/usr/local/go/bin:/gopath/bin
Expand Down
6 changes: 4 additions & 2 deletions README.md
Expand Up @@ -84,8 +84,10 @@ dependencies from github and other public repositories supported by default,
however, vendored dependencies should be preferred as they ensure repeatable
build.

gockerize uses Go 1.5.3 and enables [GOVENDOREXPERIMENT](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo).

By default, gockerize uses Go 1.5.3 and enables [GOVENDOREXPERIMENT](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo).
However, it is possible to use any desired version of Go by setting the `GOVERSION`
environment variable appropriately, for instance `GOVERSION=1.9.2` to build with
Go 1.9.2

Patching standard lib
---------------------
Expand Down
22 changes: 18 additions & 4 deletions gockerize
@@ -1,6 +1,6 @@
#!/bin/bash
#
# Copyright (c) 2015, Air Computing Inc. <oss@aerofs.com>
# Copyright (c) 2015-2017, Air Computing Inc. <oss@aerofs.com>
# All rights reserved.

set -e
Expand Down Expand Up @@ -33,7 +33,12 @@ else
fi
DOCKERFILE=${5:-/dev/null}

BUILDER=aerofs/gockerize
# TODO: auto-detect latest stable golang release
# NB: stick to 1.5.3 by default for backwards compatibility
GOVERSION=${GOVERSION:-1.5.3}
BUILDER_PREFIX=aerofs/gockerize
BUILDER_BASE=${BUILDER_PREFIX}.base
BUILDER=${BUILDER_PREFIX}-${GOVERSION}
THIS_DIR="$( cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"

source "$THIS_DIR/img_fresh.sh"
Expand All @@ -45,7 +50,16 @@ fi

echo "Building $BUILDER ..."
# build base builder container
docker build -t $BUILDER "$THIS_DIR"
docker build -t ${BUILDER_BASE} "$THIS_DIR"

# build builder with specific go version
docker build -t ${BUILDER} - <<EOF
FROM ${BUILDER_BASE}
RUN curl https://storage.googleapis.com/golang/go${GOVERSION}.linux-amd64.tar.gz -o go.tar.gz &&\
tar -C /usr/local -xzf go.tar.gz &&\
rm -rf go.tar.gz &&\
mkdir /gopath
EOF

tmpimg="${BUILDER}-$(echo "$IMAGE" | sed 's/\//./g')"
echo "Building $tmpimg ..."
Expand All @@ -54,7 +68,7 @@ echo "Building $tmpimg ..."
tmpfile="${SRC_DIR}/.gockerize.dockerfile"

cat - > "$tmpfile" <<EOF
FROM $BUILDER
FROM ${BUILDER}
COPY . /gopath/src/$DST_DIR
EOF

Expand Down
10 changes: 4 additions & 6 deletions root/run.sh
@@ -1,5 +1,4 @@
#!/bin/bash

set -e

IMAGE=$1
Expand All @@ -15,13 +14,12 @@ fi

# apply optional stdlib patches
if [ -d "${GOPATH}/src/${SERVICE}/patches" ] ; then
pushd /usr/local/go/
pushd /usr/local/go/ >>/dev/null
for p in ${GOPATH}/src/${SERVICE}/patches/*.patch ; do
patch -p1 < $p
done
popd
popd >>/dev/null
fi

CGO_ENABLED=0 GO15VENDOREXPERIMENT=1 go get $GOARGS -a -x -installsuffix cgo -ldflags '-d -s -w' ${SERVICE}
docker build --no-cache -t ${IMAGE} -f ${DOCKERFILE} ${GOPATH}

CGO_ENABLED=0 GO15VENDOREXPERIMENT=1 go get $GOARGS -a -installsuffix cgo -ldflags '-d -s -w' ${SERVICE}
docker build -t ${IMAGE} -f ${DOCKERFILE} ${GOPATH}

0 comments on commit 9bf1ae1

Please sign in to comment.