Skip to content

Instantly share code, notes, and snippets.

@rosscdh
Last active May 28, 2021 11:28
Show Gist options
  • Select an option

  • Save rosscdh/88244fcb3fc75b6ebb5d399640178e2b to your computer and use it in GitHub Desktop.

Select an option

Save rosscdh/88244fcb3fc75b6ebb5d399640178e2b to your computer and use it in GitHub Desktop.
docker makefile
.PHONY: all build login push run
NAME := rosscdh/my-project
TAG := $$(git log -1 --pretty=%h)
VERSION := ${NAME}:${TAG}
LATEST := ${NAME}:latest
BUILD_REPO_ORIGIN=$$(git config --get remote.origin.url)
BUILD_COMMIT_SHA1:=$$(git rev-parse --short HEAD)
BUILD_COMMIT_DATE:=$$(git log -1 --date=short --pretty=format:%ct)
BUILD_BRANCH:=$$(git symbolic-ref --short HEAD)
BUILD_DATE:=$$(date -u +"%Y-%m-%dT%H:%M:%SZ")
export
all: build login push
build:
docker build -t ${LATEST} -t ${VERSION} \
--build-arg BUILD_COMMIT_SHA1=${BUILD_COMMIT_SHA1} \
--build-arg BUILD_COMMIT_DATE=${BUILD_COMMIT_DATE} \
--build-arg BUILD_BRANCH=${BUILD_BRANCH} \
--build-arg BUILD_DATE=${BUILD_DATE} \
--build-arg BUILD_REPO_ORIGIN=${BUILD_REPO_ORIGIN} \
.
push:
docker push ${TAG}
docker push ${LATEST}
run:
docker run -p8090:8080 ${LATEST}
@rosscdh

rosscdh commented May 22, 2018

Copy link
Copy Markdown
Author

and the Dockerfile should contain the following to make the build info part of the env and easily displayable

FROM

#
# Handle the env info
#
ARG BUILD_COMMIT_SHA1
ARG BUILD_COMMIT_DATE
ARG BUILD_BRANCH
ARG BUILD_DATE
ARG BUILD_REPO_ORIGIN
 
ENV BUILD_COMMIT_SHA1=$BUILD_COMMIT_SHA1
ENV BUILD_COMMIT_DATE=$BUILD_COMMIT_DATE
ENV BUILD_BRANCH=$BUILD_BRANCH
ENV BUILD_DATE=$BUILD_DATE
ENV BUILD_REPO_ORIGIN=$BUILD_REPO_ORIGIN

ENTRYPOINT []
CMD []

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment