From 6c5f2993c210854b077ad07c9a94334f8c82fbb1 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Mon, 9 Jan 2017 10:10:49 -0800 Subject: [PATCH] Add an explicit Alpine 3.5 variant of Go 1.7 --- .travis.yml | 1 + 1.7/alpine3.5/17847.patch | 33 ++++++++++++ 1.7/alpine3.5/Dockerfile | 42 +++++++++++++++ 1.7/alpine3.5/go-wrapper | 97 +++++++++++++++++++++++++++++++++++ 1.7/alpine3.5/no-pic.patch | 16 ++++++ generate-stackbrew-library.sh | 2 +- update.sh | 4 +- 7 files changed, 192 insertions(+), 3 deletions(-) create mode 100644 1.7/alpine3.5/17847.patch create mode 100644 1.7/alpine3.5/Dockerfile create mode 100755 1.7/alpine3.5/go-wrapper create mode 100644 1.7/alpine3.5/no-pic.patch diff --git a/.travis.yml b/.travis.yml index e632e5e8..9157197f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ env: - VERSION=1.7 VARIANT= - VERSION=1.7 VARIANT=wheezy - VERSION=1.7 VARIANT=alpine + - VERSION=1.7 VARIANT=alpine3.5 - VERSION=1.6 VARIANT= - VERSION=1.6 VARIANT=wheezy - VERSION=1.6 VARIANT=alpine diff --git a/1.7/alpine3.5/17847.patch b/1.7/alpine3.5/17847.patch new file mode 100644 index 00000000..de9c7537 --- /dev/null +++ b/1.7/alpine3.5/17847.patch @@ -0,0 +1,33 @@ +diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go +index 14f4fa9..bf2de57 100644 +--- a/src/cmd/link/internal/ld/lib.go ++++ b/src/cmd/link/internal/ld/lib.go +@@ -1251,6 +1251,28 @@ func hostlink() { + } + } + ++ // When building a program with the default -buildmode=exe the ++ // gc compiler generates code requires DT_TEXTREL in a ++ // position independent executable (PIE). On systems where the ++ // toolchain creates PIEs by default, and where DT_TEXTREL ++ // does not work, the resulting programs will not run. See ++ // issue #17847. To avoid this problem pass -no-pie to the ++ // toolchain if it is supported. ++ if Buildmode == BuildmodeExe { ++ src := filepath.Join(tmpdir, "trivial.c") ++ if err := ioutil.WriteFile(src, []byte{}, 0666); err != nil { ++ Ctxt.Diag("WriteFile trivial.c failed: %v", err) ++ } ++ cmd := exec.Command(argv[0], "-c", "-no-pie", "trivial.c") ++ cmd.Dir = tmpdir ++ cmd.Env = append([]string{"LC_ALL=C"}, os.Environ()...) ++ out, err := cmd.CombinedOutput() ++ supported := err == nil && !bytes.Contains(out, []byte("unrecognized")) ++ if supported { ++ argv = append(argv, "-no-pie") ++ } ++ } ++ + for _, p := range strings.Fields(extldflags) { + argv = append(argv, p) + diff --git a/1.7/alpine3.5/Dockerfile b/1.7/alpine3.5/Dockerfile new file mode 100644 index 00000000..d7dd02a2 --- /dev/null +++ b/1.7/alpine3.5/Dockerfile @@ -0,0 +1,42 @@ +FROM alpine:3.5 + +RUN apk add --no-cache ca-certificates + +ENV GOLANG_VERSION 1.7.4 +ENV GOLANG_SRC_URL https://golang.org/dl/go$GOLANG_VERSION.src.tar.gz +ENV GOLANG_SRC_SHA256 4c189111e9ba651a2bb3ee868aa881fab36b2f2da3409e80885ca758a6b614cc + +# https://golang.org/issue/14851 +COPY no-pic.patch / +# https://golang.org/issue/17847 +COPY 17847.patch / + +RUN set -ex \ + && apk add --no-cache --virtual .build-deps \ + bash \ + gcc \ + musl-dev \ + openssl \ + go \ + \ + && export GOROOT_BOOTSTRAP="$(go env GOROOT)" \ + \ + && wget -q "$GOLANG_SRC_URL" -O golang.tar.gz \ + && echo "$GOLANG_SRC_SHA256 golang.tar.gz" | sha256sum -c - \ + && tar -C /usr/local -xzf golang.tar.gz \ + && rm golang.tar.gz \ + && cd /usr/local/go/src \ + && patch -p2 -i /no-pic.patch \ + && patch -p2 -i /17847.patch \ + && ./make.bash \ + \ + && rm -rf /*.patch \ + && apk del .build-deps + +ENV GOPATH /go +ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH + +RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH" +WORKDIR $GOPATH + +COPY go-wrapper /usr/local/bin/ diff --git a/1.7/alpine3.5/go-wrapper b/1.7/alpine3.5/go-wrapper new file mode 100755 index 00000000..b63e20b4 --- /dev/null +++ b/1.7/alpine3.5/go-wrapper @@ -0,0 +1,97 @@ +#!/bin/sh +set -e + +usage() { + base="$(basename "$0")" + cat <&2 + exit 1 +fi +# "shift" so that "$@" becomes the remaining arguments and can be passed along to other "go" subcommands easily +cmd="$1" +shift + +goDir="$(go list -e -f '{{.ImportComment}}' 2>/dev/null || true)" + +if [ -z "$goDir" -a -s .godir ]; then + goDir="$(cat .godir)" +fi + +dir="$(pwd -P)" +if [ "$goDir" ]; then + goPath="${GOPATH%%:*}" # this just grabs the first path listed in GOPATH, if there are multiple (which is the detection logic "go get" itself uses, too) + goDirPath="$goPath/src/$goDir" + mkdir -p "$(dirname "$goDirPath")" + if [ ! -e "$goDirPath" ]; then + ln -sfv "$dir" "$goDirPath" + elif [ ! -L "$goDirPath" ]; then + echo >&2 "error: $goDirPath already exists but is unexpectedly not a symlink!" + exit 1 + fi + goBin="$goPath/bin/$(basename "$goDir")" +else + goBin="$(basename "$dir")" # likely "app" +fi + +case "$cmd" in + download) + set -- go get -v -d "$@" + if [ "$goDir" ]; then set -- "$@" "$goDir"; fi + set -x; exec "$@" + ;; + + install) + set -- go install -v "$@" + if [ "$goDir" ]; then set -- "$@" "$goDir"; fi + set -x; exec "$@" + ;; + + run) + set -x; exec "$goBin" "$@" + ;; + + *) + echo >&2 'error: unknown command:' "$cmd" + usage >&2 + exit 1 + ;; +esac diff --git a/1.7/alpine3.5/no-pic.patch b/1.7/alpine3.5/no-pic.patch new file mode 100644 index 00000000..b10f2905 --- /dev/null +++ b/1.7/alpine3.5/no-pic.patch @@ -0,0 +1,16 @@ +diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go +index 14f4fa9..5599307 100644 +--- a/src/cmd/link/internal/ld/lib.go ++++ b/src/cmd/link/internal/ld/lib.go +@@ -1272,6 +1272,11 @@ func hostlink() { + argv = append(argv, peimporteddlls()...) + } + ++ // The Go linker does not currently support building PIE ++ // executables when using the external linker. See: ++ // https://github.com/golang/go/issues/6940 ++ argv = append(argv, "-fno-PIC") ++ + if Debug['v'] != 0 { + fmt.Fprintf(Bso, "host link:") + for _, v := range argv { diff --git a/generate-stackbrew-library.sh b/generate-stackbrew-library.sh index 39333688..0763e1ea 100755 --- a/generate-stackbrew-library.sh +++ b/generate-stackbrew-library.sh @@ -69,7 +69,7 @@ for version in "${versions[@]}"; do EOE for v in \ - onbuild wheezy alpine \ + onbuild wheezy alpine alpine3.5 \ windows/windowsservercore windows/nanoserver \ ; do dir="$version/$v" diff --git a/update.sh b/update.sh index 58f3c533..4254ffcc 100755 --- a/update.sh +++ b/update.sh @@ -49,9 +49,9 @@ for version in "${versions[@]}"; do "$version/"*"/Dockerfile" cp go-wrapper "$version/" ) - for variant in alpine wheezy; do + for variant in alpine3.5 alpine wheezy; do if [ -d "$version/$variant" ]; then - if [ "$variant" != 'alpine' ]; then + if [[ "$variant" != 'alpine'* ]]; then ( set -x sed 's/^FROM .*/FROM buildpack-deps:'"$variant"'-scm/' "$version/Dockerfile" > "$version/$variant/Dockerfile"