Last active
March 7, 2016 21:56
-
-
Save fbueno/0a717fd1f591f071d01f to your computer and use it in GitHub Desktop.
Docker Makefile to easily build and push container images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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