Skip to content

Instantly share code, notes, and snippets.

@werwolfby
Created December 28, 2016 21:35
Show Gist options
  • Save werwolfby/fd0e53d8ed33d5e8ed91a709b4eea298 to your computer and use it in GitHub Desktop.
Save werwolfby/fd0e53d8ed33d5e8ed91a709b4eea298 to your computer and use it in GitHub Desktop.
Dockerfile helper with Makefile
-include env
IMAGENAME := $(shell basename `git rev-parse --show-toplevel`)
NAMESPACE := user
SHA := $(shell git rev-parse --short HEAD)
timestamp := $(shell date +"%Y%m%d%H%M")
.PHONY: download echo build run stop start rmf rmi
download:
# download example
wget https://github.com/user/repository/releases/download/$(REPOSITORY_VERSION)/repository-$(repository_VERSION).zip -O repository.zip
rm -R repository || true
mkdir repository
unzip repository.zip -d repository
echo:
@echo "You can run 'build' to build image from the scratch"
@echo ""
@echo "Or you can copy 'env.template' to your 'env' and "
@echo "change variables to values suitable for your system"
build:
docker rmi -f $(NAMESPACE)/$(IMAGENAME):bak || true
docker tag $(NAMESPACE)/$(IMAGENAME) $(NAMESPACE)/$(IMAGENAME):bak || true
docker rmi -f $(NAMESPACE)/$(IMAGENAME) || true
docker build -t $(NAMESPACE)/$(IMAGENAME) .
run:
docker rm $(CONTAINER_NAME) || true
docker run -d --name $(CONTAINER_NAME) $(PORTS) $(VOLUMES) $(NAMESPACE)/$(IMAGENAME)
stop:
docker stop $(CONTAINER_NAME)
start:
docker start $(CONTAINER_NAME)
rmf:
docker rm -f $(CONTAINER_NAME)
rmi:
docker rmi $(NAMESPACE)/$(IMAGENAME)
rmibak:
docker rmi $(NAMESPACE)/$(IMAGENAME):bak
tag:
docker tag $(NAMESPACE)/$(IMAGENAME) $(NAMESPACE)/$(IMAGENAME):$(repository_VERSION)
push:
docker push $(NAMESPACE)/$(IMAGENAME)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment