Multistage Docker build with scratch container

This commit is contained in:
Josh Komoroske 2018-03-06 10:54:08 -08:00
parent 6c0b475c15
commit 76c0b2925f
2 changed files with 18 additions and 7 deletions

3
.dockerignore Normal file
View File

@ -0,0 +1,3 @@
.git/
tests/
screenshot/

View File

@ -1,10 +1,15 @@
FROM alpine:3.4
# Define build image which compiles binary
FROM golang:1.9.2-alpine as build
RUN apk update && \
apk add -U --no-cache \
ca-certificates \
openssh-client && \
rm -rf /var/cache/apk/*
WORKDIR /go/src/github.com/appleboy/drone-ssh
COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags netgo \
&& cp drone-ssh /bin
# Define final image which consumes final artifact
FROM scratch
LABEL org.label-schema.version=latest
LABEL org.label-schema.vcs-url="https://github.com/appleboy/drone-ssh.git"
@ -12,5 +17,8 @@ LABEL org.label-schema.name="drone-ssh"
LABEL org.label-schema.vendor="Bo-Yi Wu"
LABEL org.label-schema.schema-version="1.0"
ADD release/linux/amd64/drone-ssh /bin/
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=build /bin/drone-ssh /bin/
ENTRYPOINT ["/bin/drone-ssh"]