diff --git a/Dockerfile b/Dockerfile index 3a3c4051..f424ef43 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,4 @@ -FROM alpine:3.3 -MAINTAINER jp@roemer.im +FROM alpine:3.5 # Install system utils & Gogs runtime dependencies ADD https://github.com/tianon/gosu/releases/download/1.9/gosu-amd64 /usr/sbin/gosu @@ -8,9 +7,12 @@ RUN chmod +x /usr/sbin/gosu \ ENV GOGS_CUSTOM /data/gogs -COPY . /app/gogs/ -WORKDIR /app/gogs/ -RUN ./docker/build.sh +COPY . /app/gogs/build +WORKDIR /app/gogs/build + +RUN ./docker/build-go.sh \ + && ./docker/build.sh \ + && ./docker/finalize.sh # Configure LibC Name Service COPY docker/nsswitch.conf /etc/nsswitch.conf @@ -18,5 +20,5 @@ COPY docker/nsswitch.conf /etc/nsswitch.conf # Configure Docker Container VOLUME ["/data"] EXPOSE 22 3000 -ENTRYPOINT ["docker/start.sh"] +ENTRYPOINT ["/app/gogs/docker/start.sh"] CMD ["/bin/s6-svscan", "/app/gogs/docker/s6/"] diff --git a/docker/build-go.sh b/docker/build-go.sh new file mode 100755 index 00000000..22e3724d --- /dev/null +++ b/docker/build-go.sh @@ -0,0 +1,32 @@ +#!/bin/sh +# Build GO version as specified in Dockerfile + +set -x +set -e + +# Components versions +export GOLANG_VERSION="1.8" +export GOLANG_SRC_URL="https://golang.org/dl/go$GOLANG_VERSION.src.tar.gz" +export GOLANG_SRC_SHA256="406865f587b44be7092f206d73fc1de252600b79b3cacc587b74b5ef5c623596" + + +# Install build tools +apk add --no-cache --no-progress --virtual build-deps-go gcc musl-dev openssl go + +export GOROOT_BOOTSTRAP="$(go env GOROOT)" + +# Download Go +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 + +# Build +cd /usr/local/go/src +# see https://golang.org/issue/14851 +patch -p2 -i /app/gogs/build/docker/no-pic.patch +./make.bash + +# Clean +rm /app/gogs/build/docker/*.patch +apk del build-deps-go diff --git a/docker/build.sh b/docker/build.sh index cb442d6e..2cc188d5 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -4,16 +4,18 @@ set -e # Set temp environment vars export GOPATH=/tmp/go -export PATH=${PATH}:${GOPATH}/bin +export PATH=/usr/local/go/bin:${PATH}:${GOPATH}/bin export GO15VENDOREXPERIMENT=1 # Install build deps -apk --no-cache --no-progress add --virtual build-deps build-base linux-pam-dev go +apk --no-cache --no-progress add --virtual build-deps build-base linux-pam-dev # Build Gogs mkdir -p ${GOPATH}/src/github.com/gogits/ -ln -s /app/gogs/ ${GOPATH}/src/github.com/gogits/gogs +ln -s /app/gogs/build ${GOPATH}/src/github.com/gogits/gogs cd ${GOPATH}/src/github.com/gogits/gogs +# Needed since git 2.9.3 or 2.9.4 +git config --global http.https://gopkg.in.followRedirects true go get -v -tags "sqlite cert pam" ./... make build TAGS="sqlite cert pam" diff --git a/docker/finalize.sh b/docker/finalize.sh new file mode 100755 index 00000000..afd18e73 --- /dev/null +++ b/docker/finalize.sh @@ -0,0 +1,22 @@ +#!/bin/sh +# Finalize the build + +set -x +set -e + +# Move to final place +mv /app/gogs/build/gogs /app/gogs/ +mv /app/gogs/build/templates /app/gogs/ +mv /app/gogs/build/public /app/gogs/ +mv /app/gogs/build/docker /app/gogs/ + +# Final cleaning +rm -rf /app/gogs/build +rm /app/gogs/docker/build.sh +rm /app/gogs/docker/build-go.sh +rm /app/gogs/docker/finalize.sh +rm /app/gogs/docker/nsswitch.conf +rm /app/gogs/docker/README.md + +rm -rf /tmp/go +rm -rf /usr/local/go \ No newline at end of file diff --git a/docker/no-pic.patch b/docker/no-pic.patch new file mode 100644 index 00000000..74d30270 --- /dev/null +++ b/docker/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 l.Debugvlog != 0 { + l.Logf("%5.2f host link:", obj.Cputime()) + for _, v := range argv { \ No newline at end of file