Skip to content

Commit 6c5f299

Browse files
committed
Add an explicit Alpine 3.5 variant of Go 1.7
1 parent 4d3c44d commit 6c5f299

File tree

7 files changed

+192
-3
lines changed

7 files changed

+192
-3
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ env:
88
- VERSION=1.7 VARIANT=
99
- VERSION=1.7 VARIANT=wheezy
1010
- VERSION=1.7 VARIANT=alpine
11+
- VERSION=1.7 VARIANT=alpine3.5
1112
- VERSION=1.6 VARIANT=
1213
- VERSION=1.6 VARIANT=wheezy
1314
- VERSION=1.6 VARIANT=alpine

1.7/alpine3.5/17847.patch

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go
2+
index 14f4fa9..bf2de57 100644
3+
--- a/src/cmd/link/internal/ld/lib.go
4+
+++ b/src/cmd/link/internal/ld/lib.go
5+
@@ -1251,6 +1251,28 @@ func hostlink() {
6+
}
7+
}
8+
9+
+ // When building a program with the default -buildmode=exe the
10+
+ // gc compiler generates code requires DT_TEXTREL in a
11+
+ // position independent executable (PIE). On systems where the
12+
+ // toolchain creates PIEs by default, and where DT_TEXTREL
13+
+ // does not work, the resulting programs will not run. See
14+
+ // issue #17847. To avoid this problem pass -no-pie to the
15+
+ // toolchain if it is supported.
16+
+ if Buildmode == BuildmodeExe {
17+
+ src := filepath.Join(tmpdir, "trivial.c")
18+
+ if err := ioutil.WriteFile(src, []byte{}, 0666); err != nil {
19+
+ Ctxt.Diag("WriteFile trivial.c failed: %v", err)
20+
+ }
21+
+ cmd := exec.Command(argv[0], "-c", "-no-pie", "trivial.c")
22+
+ cmd.Dir = tmpdir
23+
+ cmd.Env = append([]string{"LC_ALL=C"}, os.Environ()...)
24+
+ out, err := cmd.CombinedOutput()
25+
+ supported := err == nil && !bytes.Contains(out, []byte("unrecognized"))
26+
+ if supported {
27+
+ argv = append(argv, "-no-pie")
28+
+ }
29+
+ }
30+
+
31+
for _, p := range strings.Fields(extldflags) {
32+
argv = append(argv, p)
33+

1.7/alpine3.5/Dockerfile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
FROM alpine:3.5
2+
3+
RUN apk add --no-cache ca-certificates
4+
5+
ENV GOLANG_VERSION 1.7.4
6+
ENV GOLANG_SRC_URL https://golang.org/dl/go$GOLANG_VERSION.src.tar.gz
7+
ENV GOLANG_SRC_SHA256 4c189111e9ba651a2bb3ee868aa881fab36b2f2da3409e80885ca758a6b614cc
8+
9+
# https://golang.org/issue/14851
10+
COPY no-pic.patch /
11+
# https://golang.org/issue/17847
12+
COPY 17847.patch /
13+
14+
RUN set -ex \
15+
&& apk add --no-cache --virtual .build-deps \
16+
bash \
17+
gcc \
18+
musl-dev \
19+
openssl \
20+
go \
21+
\
22+
&& export GOROOT_BOOTSTRAP="$(go env GOROOT)" \
23+
\
24+
&& wget -q "$GOLANG_SRC_URL" -O golang.tar.gz \
25+
&& echo "$GOLANG_SRC_SHA256 golang.tar.gz" | sha256sum -c - \
26+
&& tar -C /usr/local -xzf golang.tar.gz \
27+
&& rm golang.tar.gz \
28+
&& cd /usr/local/go/src \
29+
&& patch -p2 -i /no-pic.patch \
30+
&& patch -p2 -i /17847.patch \
31+
&& ./make.bash \
32+
\
33+
&& rm -rf /*.patch \
34+
&& apk del .build-deps
35+
36+
ENV GOPATH /go
37+
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
38+
39+
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"
40+
WORKDIR $GOPATH
41+
42+
COPY go-wrapper /usr/local/bin/

1.7/alpine3.5/go-wrapper

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/bin/sh
2+
set -e
3+
4+
usage() {
5+
base="$(basename "$0")"
6+
cat <<EOUSAGE
7+
8+
usage: $base command [args]
9+
10+
This script assumes that is is run from the root of your Go package (for
11+
example, "/go/src/app" if your GOPATH is set to "/go").
12+
13+
In Go 1.4, a feature was introduced to supply the canonical "import path" for a
14+
given package in a comment attached to a package statement
15+
(https://golang.org/s/go14customimport).
16+
17+
This script allows us to take a generic directory of Go source files such as
18+
"/go/src/app" and determine that the canonical "import path" of where that code
19+
expects to live and reference itself is "github.com/jsmith/my-cool-app". It
20+
will then ensure that "/go/src/github.com/jsmith/my-cool-app" is a symlink to
21+
"/go/src/app", which allows us to build and run it under the proper package
22+
name.
23+
24+
For compatibility with versions of Go older than 1.4, the "import path" may also
25+
be placed in a file named ".godir".
26+
27+
Available Commands:
28+
29+
$base download
30+
$base download -u
31+
(equivalent to "go get -d [args] [godir]")
32+
33+
$base install
34+
$base install -race
35+
(equivalent to "go install [args] [godir]")
36+
37+
$base run
38+
$base run -app -specific -arguments
39+
(assumes "GOPATH/bin" is in "PATH")
40+
41+
EOUSAGE
42+
}
43+
44+
# make sure there is a subcommand specified
45+
if [ "$#" -eq 0 ]; then
46+
usage >&2
47+
exit 1
48+
fi
49+
# "shift" so that "$@" becomes the remaining arguments and can be passed along to other "go" subcommands easily
50+
cmd="$1"
51+
shift
52+
53+
goDir="$(go list -e -f '{{.ImportComment}}' 2>/dev/null || true)"
54+
55+
if [ -z "$goDir" -a -s .godir ]; then
56+
goDir="$(cat .godir)"
57+
fi
58+
59+
dir="$(pwd -P)"
60+
if [ "$goDir" ]; then
61+
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)
62+
goDirPath="$goPath/src/$goDir"
63+
mkdir -p "$(dirname "$goDirPath")"
64+
if [ ! -e "$goDirPath" ]; then
65+
ln -sfv "$dir" "$goDirPath"
66+
elif [ ! -L "$goDirPath" ]; then
67+
echo >&2 "error: $goDirPath already exists but is unexpectedly not a symlink!"
68+
exit 1
69+
fi
70+
goBin="$goPath/bin/$(basename "$goDir")"
71+
else
72+
goBin="$(basename "$dir")" # likely "app"
73+
fi
74+
75+
case "$cmd" in
76+
download)
77+
set -- go get -v -d "$@"
78+
if [ "$goDir" ]; then set -- "$@" "$goDir"; fi
79+
set -x; exec "$@"
80+
;;
81+
82+
install)
83+
set -- go install -v "$@"
84+
if [ "$goDir" ]; then set -- "$@" "$goDir"; fi
85+
set -x; exec "$@"
86+
;;
87+
88+
run)
89+
set -x; exec "$goBin" "$@"
90+
;;
91+
92+
*)
93+
echo >&2 'error: unknown command:' "$cmd"
94+
usage >&2
95+
exit 1
96+
;;
97+
esac

1.7/alpine3.5/no-pic.patch

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go
2+
index 14f4fa9..5599307 100644
3+
--- a/src/cmd/link/internal/ld/lib.go
4+
+++ b/src/cmd/link/internal/ld/lib.go
5+
@@ -1272,6 +1272,11 @@ func hostlink() {
6+
argv = append(argv, peimporteddlls()...)
7+
}
8+
9+
+ // The Go linker does not currently support building PIE
10+
+ // executables when using the external linker. See:
11+
+ // https://github.com/golang/go/issues/6940
12+
+ argv = append(argv, "-fno-PIC")
13+
+
14+
if Debug['v'] != 0 {
15+
fmt.Fprintf(Bso, "host link:")
16+
for _, v := range argv {

generate-stackbrew-library.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ for version in "${versions[@]}"; do
6969
EOE
7070

7171
for v in \
72-
onbuild wheezy alpine \
72+
onbuild wheezy alpine alpine3.5 \
7373
windows/windowsservercore windows/nanoserver \
7474
; do
7575
dir="$version/$v"

update.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ for version in "${versions[@]}"; do
4949
"$version/"*"/Dockerfile"
5050
cp go-wrapper "$version/"
5151
)
52-
for variant in alpine wheezy; do
52+
for variant in alpine3.5 alpine wheezy; do
5353
if [ -d "$version/$variant" ]; then
54-
if [ "$variant" != 'alpine' ]; then
54+
if [[ "$variant" != 'alpine'* ]]; then
5555
(
5656
set -x
5757
sed 's/^FROM .*/FROM buildpack-deps:'"$variant"'-scm/' "$version/Dockerfile" > "$version/$variant/Dockerfile"

0 commit comments

Comments
 (0)