Skip to content

Instantly share code, notes, and snippets.

@fbueno
Last active March 7, 2016 21:56
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fbueno/0a717fd1f591f071d01f to your computer and use it in GitHub Desktop.
Save fbueno/0a717fd1f591f071d01f to your computer and use it in GitHub Desktop.
Docker Makefile to easily build and push container images
BASEREPO = fbueno
TAG = $(shell date +%Y-%m-%d-%H%M%S)
IMAGE = $(shell baseneme `pwd`)
help:
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
git-pull: ## Pull the latest changes from the remote GIT repository
git-pull:
git pull
build: ## same as build-no-cache
build: test
docker build --pull=true -t $(BASEREPO)/$(IMAGE):$(TAG) .
echo $(TAG) > .last_tag.$(IMAGE)
build-no-pull: ## git-pull build using local cache not to pulling a fresh image from docker repository
build-no-pull: test git-pull
docker build -f -t $(BASEREPO)/$(IMAGE):$(TAG) .
echo $(TAG) > .last_tag.$(IMAGE)
build-no-cache: ## git-pull and build IGNORING local cache and force to pull a fresh image from docker repository
build-no-cache: test git-pull
docker build --no-cache --pull=true -t $(BASEREPO)/$(IMAGE):$(TAG) .
echo $(TAG) > .last_tag.$(IMAGE)
push: ## Push last generated build
push: test
test -s .last_tag.$(IMAGE) || (echo You need to build first ; exit 1)
docker push $(BASEREPO)/$(IMAGE):`cat .last_tag.$(IMAGE)` && \
rm -f .last_tag.$(IMAGE)
push-latest: ## Push local latest tag
push-latest: test
docker push $(BASEREPO)/$(IMAGE):latest
latest: ## Link last build (tag) to the tag latest
latest: test
test -s .last_tag.$(IMAGE) || (echo You need to build first ; exit 1)
docker tag -f $(BASEREPO)/$(IMAGE):`cat .last_tag.$(IMAGE)` $(BASEREPO)/$(IMAGE):latest
test: ## Run necessary tests
@test -n "$(IMAGE)" || (echo TEST ERROR: You MUST specify IMAGE variable, type make help ; exit 1)
@test -f ./Dockerfile || (echo TEST ERROR: There is no Dockerfile.$(IMAGE) in this directory. ; exit 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment