|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +if [ ! -z "$(which apt-get)" ]; then |
| 4 | +# Install for debian |
| 5 | + # gcc for cgo |
| 6 | + apt-get update && apt-get install -y --no-install-recommends \ |
| 7 | + g++ \ |
| 8 | + gcc \ |
| 9 | + libc6-dev \ |
| 10 | + make \ |
| 11 | + pkg-config \ |
| 12 | + wget \ |
| 13 | + procps \ |
| 14 | + && rm -rf /var/lib/apt/lists/* |
| 15 | + |
| 16 | + set -eux; \ |
| 17 | + \ |
| 18 | + # this "case" statement is generated via "update.sh" |
| 19 | + dpkgArch="$(dpkg --print-architecture)"; \ |
| 20 | + case "${dpkgArch##*-}" in \ |
| 21 | + amd64) goRelArch='linux-amd64'; goRelSha256='72d820dec546752e5a8303b33b009079c15c2390ce76d67cf514991646c6127b' ;; \ |
| 22 | + armhf) goRelArch='linux-armv6l'; goRelSha256='feca4e920d5ca25001dc0823390df79bc7ea5b5b8c03483e5a2c54f164654936' ;; \ |
| 23 | + arm64) goRelArch='linux-arm64'; goRelSha256='1e07a159414b5090d31166d1a06ee501762076ef21140dcd54cdcbe4e68a9c9b' ;; \ |
| 24 | + i386) goRelArch='linux-386'; goRelSha256='acbe19d56123549faf747b4f61b730008b185a0e2145d220527d2383627dfe69' ;; \ |
| 25 | + ppc64el) goRelArch='linux-ppc64le'; goRelSha256='91d0026bbed601c4aad332473ed02f9a460b31437cbc6f2a37a88c0376fc3a65' ;; \ |
| 26 | + s390x) goRelArch='linux-s390x'; goRelSha256='e211a5abdacf843e16ac33a309d554403beb63959f96f9db70051f303035434b' ;; \ |
| 27 | + *) goRelArch='src'; goRelSha256='589449ff6c3ccbff1d391d4e7ab5bb5d5643a5a41a04c99315e55c16bbf73ddc'; \ |
| 28 | + echo >&2; echo >&2 "warning: current architecture ($dpkgArch) does not have a corresponding Go binary release; will be building from source"; echo >&2 ;; \ |
| 29 | + esac; \ |
| 30 | + \ |
| 31 | + url="https://golang.org/dl/go${GOLANG_VERSION}.${goRelArch}.tar.gz"; \ |
| 32 | + wget -O go.tgz "$url"; \ |
| 33 | + echo "${goRelSha256} *go.tgz" | sha256sum -c -; \ |
| 34 | + tar -C /usr/local -xzf go.tgz; \ |
| 35 | + rm go.tgz; \ |
| 36 | + \ |
| 37 | + if [ "$goRelArch" = 'src' ]; then \ |
| 38 | + echo >&2; \ |
| 39 | + echo >&2 'error: UNIMPLEMENTED'; \ |
| 40 | + echo >&2 'TODO install golang-any from jessie-backports for GOROOT_BOOTSTRAP (and uninstall after build)'; \ |
| 41 | + echo >&2; \ |
| 42 | + exit 1; \ |
| 43 | + fi; \ |
| 44 | + \ |
| 45 | + export PATH="/usr/local/go/bin:$PATH"; \ |
| 46 | + go version |
| 47 | +else |
| 48 | +# Install for alpine |
| 49 | + set -eux; \ |
| 50 | + apk add --no-cache --virtual .build-deps \ |
| 51 | + bash \ |
| 52 | + gcc \ |
| 53 | + musl-dev \ |
| 54 | + openssl \ |
| 55 | + go \ |
| 56 | + ; \ |
| 57 | + export \ |
| 58 | + # set GOROOT_BOOTSTRAP such that we can actually build Go |
| 59 | + GOROOT_BOOTSTRAP="$(go env GOROOT)" \ |
| 60 | + # ... and set "cross-building" related vars to the installed system's values so that we create a build targeting the proper arch |
| 61 | + # (for example, if our build host is GOARCH=amd64, but our build env/image is GOARCH=386, our build needs GOARCH=386) |
| 62 | + GOOS="$(go env GOOS)" \ |
| 63 | + GOARCH="$(go env GOARCH)" \ |
| 64 | + GOHOSTOS="$(go env GOHOSTOS)" \ |
| 65 | + GOHOSTARCH="$(go env GOHOSTARCH)" \ |
| 66 | + ; \ |
| 67 | + # also explicitly set GO386 and GOARM if appropriate |
| 68 | + # https://github.com/docker-library/golang/issues/184 |
| 69 | + apkArch="$(apk --print-arch)"; \ |
| 70 | + case "$apkArch" in \ |
| 71 | + armhf) export GOARM='6' ;; \ |
| 72 | + x86) export GO386='387' ;; \ |
| 73 | + esac; \ |
| 74 | + \ |
| 75 | + wget -O go.tgz "https://golang.org/dl/go$GOLANG_VERSION.src.tar.gz"; \ |
| 76 | + echo '589449ff6c3ccbff1d391d4e7ab5bb5d5643a5a41a04c99315e55c16bbf73ddc *go.tgz' | sha256sum -c -; \ |
| 77 | + tar -C /usr/local -xzf go.tgz; \ |
| 78 | + rm go.tgz; \ |
| 79 | + \ |
| 80 | + cd /usr/local/go/src; \ |
| 81 | + for p in /go-alpine-patches/*.patch; do \ |
| 82 | + [ -f "$p" ] || continue; \ |
| 83 | + patch -p2 -i "$p"; \ |
| 84 | + done; \ |
| 85 | + ./make.bash; \ |
| 86 | + \ |
| 87 | + rm -rf /go-alpine-patches; \ |
| 88 | + apk del .build-deps; \ |
| 89 | + \ |
| 90 | + export PATH="/usr/local/go/bin:$PATH"; \ |
| 91 | + go version |
| 92 | +fi |
0 commit comments