Browse Source

docker: add new Dockerfile.docker-ce for docker-ce(>=v17.06) to build docker image (#5322)

* add new Dockerfile.docker-ce for docker-ce(>=v17.06) to  build docker image

* change default Dockerfile to support docker-ce(>=v17.06) multi-stage build
Michael Li 5 years ago
parent
commit
cc95d251d6
4 changed files with 24 additions and 21 deletions
  1. 0 2
      .dockerignore
  2. 14 10
      Dockerfile
  3. 6 4
      docker/build.sh
  4. 4 5
      docker/finalize.sh

+ 0 - 2
.dockerignore

@@ -1,5 +1,3 @@
-.git
-.git/**
 packager
 packager/**
 scripts

+ 14 - 10
Dockerfile

@@ -1,7 +1,13 @@
-FROM alpine:3.5
+FROM golang:alpine AS binarybuilder
+# Install build deps
+RUN apk --no-cache --no-progress add --virtual build-deps build-base git linux-pam-dev
+WORKDIR /go/src/github.com/gogs/gogs
+COPY . .
+RUN make build TAGS="sqlite cert pam"
 
+FROM alpine:latest
 # Install system utils & Gogs runtime dependencies
-ADD https://github.com/tianon/gosu/releases/download/1.9/gosu-amd64 /usr/sbin/gosu
+ADD https://github.com/tianon/gosu/releases/download/1.10/gosu-amd64 /usr/sbin/gosu
 RUN chmod +x /usr/sbin/gosu \
   && echo http://dl-2.alpinelinux.org/alpine/edge/community/ >> /etc/apk/repositories \
   && apk --no-cache --no-progress add \
@@ -20,16 +26,14 @@ ENV GOGS_CUSTOM /data/gogs
 
 # Configure LibC Name Service
 COPY docker/nsswitch.conf /etc/nsswitch.conf
-COPY docker /app/gogs/docker
-COPY templates /app/gogs/templates
-COPY public /app/gogs/public
 
-WORKDIR /app/gogs/build
-COPY . .
+WORKDIR /app/gogs
+COPY docker ./docker
+COPY templates ./templates
+COPY public ./public
+COPY --from=binarybuilder /go/src/github.com/gogs/gogs/gogs .
 
-RUN    ./docker/build-go.sh \
-    && ./docker/build.sh \
-    && ./docker/finalize.sh
+RUN ./docker/finalize.sh
 
 # Configure Docker Container
 VOLUME ["/data"]

+ 6 - 4
docker/build.sh

@@ -23,7 +23,9 @@ rm -r $GOPATH
 # Remove build deps
 apk --no-progress del build-deps
 
-# Create git user for Gogs
-addgroup -S git
-adduser -G git -H -D -g 'Gogs Git User' git -h /data/git -s /bin/bash && usermod -p '*' git && passwd -u git
-echo "export GOGS_CUSTOM=${GOGS_CUSTOM}" >> /etc/profile
+# Move to final place
+mv /app/gogs/build/gogs /app/gogs/
+
+# Cleanup go
+rm -rf /tmp/go
+rm -rf /usr/local/go

+ 4 - 5
docker/finalize.sh

@@ -4,8 +4,10 @@
 set -x
 set -e
 
-# Move to final place
-mv /app/gogs/build/gogs /app/gogs/
+# Create git user for Gogs
+addgroup -S git
+adduser -G git -H -D -g 'Gogs Git User' git -h /data/git -s /bin/bash && usermod -p '*' git && passwd -u git
+echo "export GOGS_CUSTOM=${GOGS_CUSTOM}" >> /etc/profile
 
 # Final cleaning
 rm -rf /app/gogs/build
@@ -14,6 +16,3 @@ 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