Browse Source

Provide an updated Dockerfile where Gogs is build with Go 1.8 (#4151)

In order to have an up to date Docker image based on alpine 3.5
  and having Gogs built with Go 1.8

Refs: [ #4145 ]
pull/4153/head
yaourt 8 years ago committed by 无闻
parent
commit
1841316f18
  1. 14
      Dockerfile
  2. 32
      docker/build-go.sh
  3. 8
      docker/build.sh
  4. 22
      docker/finalize.sh
  5. 16
      docker/no-pic.patch

14
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/"]

32
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

8
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"

22
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

16
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 {
Loading…
Cancel
Save