From fd70aaaf0579b263629921c97a048f4df10dcb06 Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Mon, 1 Jul 2019 15:37:55 +0200 Subject: [PATCH] Git commit reference mechanism changed - Git commit is passed as a build argument as explained in README.md - `.git` directory is ignored by Docker for a quicker build and smaller context - the build arg VCS_REF is used both to tag the image and the Go program --- .dockerignore | 1 + Dockerfile | 5 +++-- README.md | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.dockerignore b/.dockerignore index 1865f29..af55e3c 100644 --- a/.dockerignore +++ b/.dockerignore @@ -9,3 +9,4 @@ coverage.txt Dockerfile LICENSE test.sh +.git diff --git a/Dockerfile b/Dockerfile index 351e334..8e57d6b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,16 +7,17 @@ FROM ${BASE_IMAGE_BUILDER}:${GO_VERSION}-alpine${ALPINE_VERSION} AS builder ARG GOARCH=amd64 ARG GOARM ARG VERSION=0.2.4 -RUN apk --update add -q --progress git +ARG VCS_REF= WORKDIR /go/src/github.com/jesseduffield/lazydocker/ COPY ./ . RUN CGO_ENABLED=0 GOOS=linux GOARCH=${GOARCH} GOARM=${GOARM} go build -a -installsuffix cgo -ldflags="-s -w \ - -X main.commit=$(git rev-parse HEAD) \ + -X main.commit=${VCS_REF} \ -X main.version=${VERSION} \ -X main.buildSource=Docker" FROM ${BASE_IMAGE}:${ALPINE_VERSION} ARG VERSION=0.2.4 +ARG VCS_REF= LABEL org.label-schema.schema-version="1.0.0-rc1" \ maintainer="jessedduffield@gmail.com" \ org.label-schema.vcs-ref=$VCS_REF \ diff --git a/README.md b/README.md index c651f8f..3ebf97e 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,8 @@ go get github.com/jesseduffield/lazydocker https://github.com/jesseduffield/lazydocker.git ``` + You can also add `--build-arg VCS_REF=$(git rev-parse HEAD)` so that the go build and the container contain the commit used. +

1. Run it