diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b876c06 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.git/ +tests/ +screenshot/ diff --git a/Dockerfile b/Dockerfile index 213707a..a19808f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/README.md b/README.md index 918129a..bc2de34 100644 --- a/README.md +++ b/README.md @@ -24,18 +24,9 @@ go test Build the docker image with the following commands: ``` -CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags netgo docker build -t appleboy/drone-ssh . ``` -Please note incorrectly building the image for the correct x64 linux and with -GCO disabled will result in an error when running the Docker image: - -``` -docker: Error response from daemon: Container command -'/bin/drone-ssh' not found or does not exist.. -``` - ## Usage Execute from the working directory: