From 1d9b0906b1033b3d4d20cbd280369adb0d3c5cd4 Mon Sep 17 00:00:00 2001 From: Pall Valmundsson <3846899+pall-valmundsson@users.noreply.github.com> Date: Wed, 30 May 2018 12:01:23 +0000 Subject: [PATCH] Update Dockerfile (#484) This updates the Dockerfile to use multi-stage builds and enables a build argument to specify which version or SHA is built. --- Dockerfile | 17 +++++++++-------- README.md | 7 +++++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 511e403c..a67dac0a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,16 @@ -FROM alpine:3.6 +FROM golang:alpine3.7 as builder -ENV GOPATH /go -ENV LEGO_VERSION tags/v0.4.1 +ARG LEGO_VERSION=master -RUN apk update && apk add --no-cache --virtual run-dependencies ca-certificates && \ - apk add --no-cache --virtual build-dependencies go git musl-dev && \ +RUN apk update && \ + apk add --no-cache --virtual git && \ go get -u github.com/xenolf/lego && \ cd ${GOPATH}/src/github.com/xenolf/lego && \ git checkout ${LEGO_VERSION} && \ - go build -o /usr/bin/lego . && \ - apk del build-dependencies && \ - rm -rf ${GOPATH} + go build -o /usr/bin/lego . + +FROM alpine:3.7 +RUN apk update && apk add --no-cache --virtual ca-certificates +COPY --from=builder /usr/bin/lego /usr/bin/lego ENTRYPOINT [ "/usr/bin/lego" ] diff --git a/README.md b/README.md index 9ec7e1f3..fde4b531 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,13 @@ To build lego inside a Docker container, just run ``` docker build -t lego . ``` + +The container is, by default, built from `master`. +This can be overridden by supplying a build argument containing a git SHA or reference. +```bash +docker build --build-arg LEGO_VERSION=tags/v0.5.0 -t lego . +``` + ##### From the package manager - [ArchLinux (AUR)](https://aur.archlinux.org/packages/lego-git): ```