Browse code

Dockerfile: use tmpfs for building registry, go-swagger

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2020/01/10 22:07:01
Showing 1 changed files
... ...
@@ -37,6 +37,7 @@ RUN mkdir -p /usr/src/criu \
37 37
     && make PREFIX=/build/ install-criu
38 38
 
39 39
 FROM base AS registry
40
+WORKDIR /go/src/github.com/docker/distribution
40 41
 # Install two versions of the registry. The first one is a recent version that
41 42
 # supports both schema 1 and 2 manifests. The second one is an older version that
42 43
 # only supports schema1 manifests. This allows integration-cli tests to cover
... ...
@@ -47,34 +48,33 @@ ENV REGISTRY_COMMIT_SCHEMA1 ec87e9b6971d831f0eff752ddb54fb64693e51cd
47 47
 ENV REGISTRY_COMMIT 47a064d4195a9b56133891bbb13620c3ac83a827
48 48
 RUN --mount=type=cache,target=/root/.cache/go-build \
49 49
     --mount=type=cache,target=/go/pkg/mod \
50
+    --mount=type=tmpfs,target=/go/src/ \
50 51
         set -x \
51
-        && export GOPATH="$(mktemp -d)" \
52
-        && git clone https://github.com/docker/distribution.git "$GOPATH/src/github.com/docker/distribution" \
53
-        && (cd "$GOPATH/src/github.com/docker/distribution" && git checkout -q "$REGISTRY_COMMIT") \
54
-        && GOPATH="$GOPATH/src/github.com/docker/distribution/Godeps/_workspace:$GOPATH" \
52
+        && git clone https://github.com/docker/distribution.git . \
53
+        && git checkout -q "$REGISTRY_COMMIT" \
54
+        && GOPATH="/go/src/github.com/docker/distribution/Godeps/_workspace:$GOPATH" \
55 55
            go build -buildmode=pie -o /build/registry-v2 github.com/docker/distribution/cmd/registry \
56 56
         && case $(dpkg --print-architecture) in \
57 57
                amd64|armhf|ppc64*|s390x) \
58
-               (cd "$GOPATH/src/github.com/docker/distribution" && git checkout -q "$REGISTRY_COMMIT_SCHEMA1"); \
59
-               GOPATH="$GOPATH/src/github.com/docker/distribution/Godeps/_workspace:$GOPATH"; \
58
+               git checkout -q "$REGISTRY_COMMIT_SCHEMA1"; \
59
+               GOPATH="/go/src/github.com/docker/distribution/Godeps/_workspace:$GOPATH"; \
60 60
                    go build -buildmode=pie -o /build/registry-v2-schema1 github.com/docker/distribution/cmd/registry; \
61 61
                 ;; \
62
-           esac \
63
-        && rm -rf "$GOPATH"
62
+           esac
64 63
 
65 64
 FROM base AS swagger
65
+WORKDIR $GOPATH/src/github.com/go-swagger/go-swagger
66 66
 # Install go-swagger for validating swagger.yaml
67 67
 # This is https://github.com/kolyshkin/go-swagger/tree/golang-1.13-fix
68 68
 # TODO: move to under moby/ or fix upstream go-swagger to work for us.
69 69
 ENV GO_SWAGGER_COMMIT 5793aa66d4b4112c2602c716516e24710e4adbb5
70 70
 RUN --mount=type=cache,target=/root/.cache/go-build \
71 71
     --mount=type=cache,target=/go/pkg/mod \
72
+    --mount=type=tmpfs,target=/go/src/ \
72 73
         set -x \
73
-        && export GOPATH="$(mktemp -d)" \
74
-        && git clone https://github.com/kolyshkin/go-swagger.git "$GOPATH/src/github.com/go-swagger/go-swagger" \
75
-        && (cd "$GOPATH/src/github.com/go-swagger/go-swagger" && git checkout -q "$GO_SWAGGER_COMMIT") \
76
-        && go build -o /build/swagger github.com/go-swagger/go-swagger/cmd/swagger \
77
-        && rm -rf "$GOPATH"
74
+        && git clone https://github.com/kolyshkin/go-swagger.git . \
75
+        && git checkout -q "$GO_SWAGGER_COMMIT" \
76
+        && go build -o /build/swagger github.com/go-swagger/go-swagger/cmd/swagger
78 77
 
79 78
 FROM base AS frozen-images
80 79
 ARG DEBIAN_FRONTEND