Skip to content

Commit 2e47bb0

Browse files
Optimize dockerfiles to dicreasy amount image layers. (#55)
Signed-off-by: Oleksandr Andriienko <[email protected]>
1 parent 6eb9e8e commit 2e47bb0

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

dockerfiles/ci/Dockerfile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ RUN CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-w -s' -a -installsuffix cgo
1919
RUN apk add --no-cache ca-certificates
2020

2121
RUN adduser -D -g '' unprivilegeduser && \
22-
mkdir -p /rootfs/tmp && chmod 1777 /rootfs/tmp
22+
mkdir -p /rootfs/tmp /rootfs/etc /rootfs/etc/ssl/certs /rootfs/go/bin && \
23+
# In the `scratch` you can't use Dockerfile#RUN, because there is no shell and no standard commands (mkdir and so on).
24+
# That's why prepare absent in the scratch /tmp folder.
25+
chmod 1777 /rootfs/tmp && \
26+
cp -rf /etc/passwd /rootfs/etc && \
27+
cp -rf /etc/ssl/certs/ca-certificates.crt /rootfs/etc/ssl/certs && \
28+
cp -rf /go/src/github.com/eclipse/che-machine-exec/che-machine-exec /rootfs/go/bin
2329

2430
FROM scratch
2531

26-
# In the scratch you can't use Dockerfile#RUN, because there is no shell and no standard commands (mkdir and so on).
27-
# Add absent in the scratch /tmp folder.
2832
COPY --from=builder /rootfs /
29-
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
30-
COPY --from=builder /etc/passwd /etc/passwd
31-
COPY --from=builder /go/src/github.com/eclipse/che-machine-exec/che-machine-exec /go/bin/che-machine-exec
3233

3334
USER unprivilegeduser
3435

rhel.Dockerfile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@ WORKDIR /go/src/github.com/eclipse/che-machine-exec/
1818
COPY . .
1919
RUN adduser unprivilegeduser && \
2020
CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-w -s' -a -installsuffix cgo -o che-machine-exec . && \
21-
mkdir -p /rootfs/tmp && chmod 1777 /rootfs/tmp
21+
mkdir -p /rootfs/tmp /rootfs/etc /rootfs/go/bin && \
22+
# In the `scratch` you can't use Dockerfile#RUN, because there is no shell and no standard commands (mkdir and so on).
23+
# That's why prepare absent in the scratch /tmp folder.
24+
chmod 1777 /rootfs/tmp && \
25+
cp -rf /etc/passwd /rootfs/etc && \
26+
cp -rf /go/src/github.com/eclipse/che-machine-exec/che-machine-exec /rootfs/go/bin
2227

2328
FROM scratch
2429

25-
# In the scratch you can't use Dockerfile#RUN, because there is no shell and no standard commands (mkdir and so on).
26-
# Add absent in the scratch /tmp folder.
2730
COPY --from=builder /rootfs /
28-
COPY --from=builder /etc/passwd /etc/passwd
29-
COPY --from=builder /go/src/github.com/eclipse/che-machine-exec/che-machine-exec /go/bin/che-machine-exec
31+
3032
USER unprivilegeduser
3133
ENTRYPOINT ["/go/bin/che-machine-exec"]
3234

0 commit comments

Comments
 (0)