diff --git a/Dockerfile b/Dockerfile index 48edd58dc..f74f828e5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,45 +29,8 @@ CMD ["/bin/s6-svscan", "/app/gogs/docker/s6/"] ## Build Golang & Gogs - - -# https://golang.org/issue/14851 -#COPY no-pic.patch / - - COPY docker /app/gogs/docker RUN set -ex \ - && apk add --no-cache --virtual .build-deps \ - bash \ - gcc \ - musl-dev \ - openssl \ - go \ - build-base \ - linux-pam-dev \ - \ - && 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 /app/gogs/docker/no-pic.patch \ - && ./make.bash \ - \ - && rm /app/gogs/docker/*.patch \ - && git config --global http.https://gopkg.in.followRedirects true \ - && cd /app/gogs/docker/ \ - && sh /app/gogs/docker/build.sh \ - && rm /app/gogs/docker/build.sh \ - && rm /app/gogs/docker/nsswitch.conf \ - && rm /app/gogs/docker/README.md \ - && apk del .build-deps \ - && mv /go/src/github.com/gogits/gogs/gogs /app/gogs/ \ - && mv /go/src/github.com/gogits/gogs/templates /app/gogs/ \ - && mv /go/src/github.com/gogits/gogs/scripts /app/gogs/ \ - && mv /go/src/github.com/gogits/gogs/public /app/gogs/ \ - && rm -rf /go \ - && rm -rf /usr/local/go \ No newline at end of file + && sh /app/gogs/docker/build-go.sh \ + && sh /app/gogs/docker/build.sh diff --git a/docker/build-go.sh b/docker/build-go.sh new file mode 100644 index 000000000..46a1fb60d --- /dev/null +++ b/docker/build-go.sh @@ -0,0 +1,22 @@ +#!/bin/sh +# Build GO version as specified in Dockerfile + +# Install build tools +apk add --no-cache --virtual .build-deps bash gcc musl-dev openssl go build-base linux-pam-dev + +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/docker/no-pic.patch +./make.bash + +# Clean +rm /app/gogs/docker/*.patch diff --git a/docker/build.sh b/docker/build.sh index eb264e466..017b3872b 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -15,4 +15,20 @@ make build TAGS="sqlite cert pam" # Create git user for Gogs adduser -H -D -g 'Gogs Git User' git -h /data/git -s /bin/bash && passwd -u git -echo "export GOGS_CUSTOM=${GOGS_CUSTOM}" >> /etc/profile \ No newline at end of file +echo "export GOGS_CUSTOM=${GOGS_CUSTOM}" >> /etc/profile + +# Move to final place +mv /go/src/github.com/gogits/gogs/gogs /app/gogs/ +mv /go/src/github.com/gogits/gogs/templates /app/gogs/ +mv /go/src/github.com/gogits/gogs/scripts /app/gogs/ +mv /go/src/github.com/gogits/gogs/public /app/gogs/ + +# Final cleaning +rm /app/gogs/docker/build.sh +rm /app/gogs/docker/build-go.sh +rm /app/gogs/docker/nsswitch.conf +rm /app/gogs/docker/README.md +rm -rf /go +rm -rf /usr/local/go + +apk del .build-deps \ No newline at end of file