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.
This commit is contained in:
Pall Valmundsson 2018-05-30 12:01:23 +00:00 committed by Ludovic Fernandez
parent 86f1721281
commit 1d9b0906b1
2 changed files with 16 additions and 8 deletions

View file

@ -1,15 +1,16 @@
FROM alpine:3.6 FROM golang:alpine3.7 as builder
ENV GOPATH /go ARG LEGO_VERSION=master
ENV LEGO_VERSION tags/v0.4.1
RUN apk update && apk add --no-cache --virtual run-dependencies ca-certificates && \ RUN apk update && \
apk add --no-cache --virtual build-dependencies go git musl-dev && \ apk add --no-cache --virtual git && \
go get -u github.com/xenolf/lego && \ go get -u github.com/xenolf/lego && \
cd ${GOPATH}/src/github.com/xenolf/lego && \ cd ${GOPATH}/src/github.com/xenolf/lego && \
git checkout ${LEGO_VERSION} && \ git checkout ${LEGO_VERSION} && \
go build -o /usr/bin/lego . && \ go build -o /usr/bin/lego .
apk del build-dependencies && \
rm -rf ${GOPATH} 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" ] ENTRYPOINT [ "/usr/bin/lego" ]

View file

@ -24,6 +24,13 @@ To build lego inside a Docker container, just run
``` ```
docker build -t lego . 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 ##### From the package manager
- [ArchLinux (AUR)](https://aur.archlinux.org/packages/lego-git): - [ArchLinux (AUR)](https://aur.archlinux.org/packages/lego-git):
``` ```