-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
openkbs
committed
Jul 20, 2020
1 parent
3f85a72
commit eabc7d4
Showing
9 changed files
with
123 additions
and
401 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,113 @@ | ||
SHELL := /bin/bash | ||
|
||
VERSION := 1.0.0 | ||
# ------------------------------------------------------------------------------------------------------- | ||
# login first (Registry: e.g., hub.docker.io, registry.localhost:5000, etc.) | ||
# a.) docker login | ||
# or | ||
# b.) sudo docker login -p FpXM6Qy9vVL5kPeoefzxwA-oaYb-Wpej2iXTwV7UHYs -e unused -u unused docker-registry-default.openkbs.org | ||
# e.g. (using Openshift) | ||
# oc process -f ./files/deployments/template.yml -v API_NAME=$(REGISTRY_IMAGE) > template.active | ||
# | ||
# to run: | ||
# make <verb> [ APP_VERSION=<...> DOCKER_NAME=<...> REGISTRY_HOST=<...> ] | ||
# example: | ||
# make build | ||
# make up | ||
# make down | ||
# ------------------------------------------------------------------------------------------------------- | ||
|
||
DOCKER_REPO := openkbs | ||
SHELL := /bin/bash | ||
|
||
## == Default is Ubuntu:20.04 as Docker base image == | ||
BASE_IMAGE := $(BASE_IMAGE) | ||
|
||
## -- To Check syntax: | ||
# cat -e -t -v Makefile | ||
|
||
# The name of the executable (default is current directory name) | ||
# DOCKER := json-server-docker | ||
DOCKER := $(shell echo $${PWD\#\#*/}) | ||
# The name of the container (default is current directory name) | ||
#DOCKER_NAME := $(shell echo $${PWD\#\#*/}) | ||
DOCKER_NAME := $(shell echo $${PWD\#\#*/}|tr '[:upper:]' '[:lower:]'|tr "/: " "_" ) | ||
|
||
ORGANIZATION=$(shell echo $${ORGANIZATION:-openkbs}) | ||
APP_VERSION=$(shell echo $${APP_VERSION:-latest}) | ||
imageTag=$(ORGANIZATION)/$(DOCKER_NAME) | ||
|
||
## Docker Registry (Private Server) | ||
REGISTRY_HOST= | ||
#REGISTRY_HOST=$(shell echo $${REGISTRY_HOST:-localhost:5000}) | ||
REGISTRY_IMAGE=$(REGISTRY_HOST)/$(ORGANIZATION)/$(DOCKER_NAME) | ||
|
||
#VERSION?="$(APP_VERSION)-$$(date +%Y%m%d)" | ||
VERSION?="$(APP_VERSION)" | ||
|
||
NAME := $(DOCKER) | ||
## -- Uncomment this to use local Registry Host -- | ||
DOCKER_IMAGE := $(ORGANIZATION)/$(DOCKER_NAME) | ||
|
||
## -- To Check syntax: | ||
# cat -e -t -v Makefile | ||
|
||
# -- example -- | ||
#VOLUME_MAP := "-v $${PWD}/json:/project-json -v $${PWD}/data:/data" | ||
#VOLUME_MAP := "-v $${PWD}/data:/home/developer/data -v $${PWD}/workspace:/home/developer/workspace" | ||
VOLUME_MAP := | ||
|
||
# -- Local SAVE of image -- | ||
IMAGE_EXPORT_PATH := "$${PWD}/archive" | ||
|
||
# { no, on-failure, unless-stopped, always } | ||
RESTART_OPTION := no | ||
RESTART_OPTION := always | ||
|
||
SHA := $(shell git describe --match=NeVeRmAtCh --always --abbrev=40 --dirty=*) | ||
|
||
.PHONY : clean | ||
.PHONY: clean rmi build push pull up down run stop exec | ||
|
||
clean : | ||
echo $(NAME) $(DOCKER_REPO)/$(DOCKER):$(VERSION) | ||
clean: | ||
echo $(DOCKER_NAME) $(DOCKER_IMAGE):$(VERSION) | ||
|
||
default: docker_build | ||
default: build | ||
|
||
docker_build: | ||
@docker build \ | ||
--build-arg VCS_REF=`git rev-parse --short HEAD` \ | ||
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` . | ||
build: | ||
docker build \ | ||
--build-arg BASE_IMAGE="$(BASE_IMAGE)" \ | ||
--build-arg CIRCLE_SHA1="$(SHA)" \ | ||
--build-arg version=$(VERSION) \ | ||
--build-arg VCS_REF=`git rev-parse --short HEAD` \ | ||
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \ | ||
-t $(DOCKER_REPO)/$(DOCKER):$(VERSION) . | ||
sudo docker build \ | ||
--build-arg BASE_IMAGE="$(BASE_IMAGE)" \ | ||
--build-arg CIRCLE_SHA1="$(SHA)" \ | ||
--build-arg version=$(VERSION) \ | ||
--build-arg VCS_REF=`git rev-parse --short HEAD` \ | ||
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \ | ||
-t $(DOCKER_IMAGE):$(VERSION) . | ||
|
||
push: build | ||
docker push $(DOCKER_REPO)/$(DOCKER):$(VERSION) | ||
|
||
sudo docker commit -m "$comment" ${containerID} ${imageTag}:$(VERSION) | ||
sudo docker push $(DOCKER_IMAGE):$(VERSION) | ||
|
||
docker tag $(imageTag):$(VERSION) $(REGISTRY_IMAGE):$(VERSION) | ||
#sudo docker tag $(imageTag):latest $(REGISTRY_IMAGE):latest | ||
docker push $(REGISTRY_IMAGE):$(VERSION) | ||
#sudo docker push $(REGISTRY_IMAGE):latest | ||
@if [ ! "$(IMAGE_EXPORT_PATH)" = "" ]; then \ | ||
mkdir -p $(IMAGE_EXPORT_PATH); \ | ||
sudo docker save $(REGISTRY_IMAGE):$(VERSION) | gzip > $(IMAGE_EXPORT_PATH)/$(DOCKER_NAME)_$(VERSION).tar.gz; \ | ||
fi | ||
pull: | ||
docker pull $(DOCKER_REPO)/$(DOCKER):$(VERSION) | ||
@if [ "$(REGISTRY_HOST)" = "" ]; then \ | ||
sudo docker pull $(DOCKER_IMAGE):$(VERSION) ; \ | ||
else \ | ||
sudo docker pull $(REGISTRY_IMAGE):$(VERSION) ; \ | ||
fi | ||
|
||
|
||
up: build | ||
docker-compose up -d | ||
sudo docker-compose up -d | ||
|
||
down: | ||
docker-compose down | ||
sudo docker-compose down | ||
|
||
run: | ||
docker run --name=$(NAME) --restart=$(RESTART_OPTION) $(VOLUME_MAP) $(DOCKER_REPO)/$(DOCKER):$(VERSION) | ||
sudo docker run --name=$(DOCKER_NAME) --restart=$(RESTART_OPTION) $(VOLUME_MAP) $(DOCKER_IMAGE):$(VERSION) | ||
|
||
stop: run | ||
docker stop --name=$(NAME) | ||
sudo docker stop --name=$(DOCKER_NAME) | ||
|
||
status: | ||
sudo docker ps | ||
|
||
rmi: | ||
docker rmi $$(docker images -f dangling=true -q) | ||
sudo docker rmi $$(docker images -f dangling=true -q) | ||
|
||
exec: up | ||
docker-compose exec $(DOCKER) /bin/bash | ||
sudo docker-compose exec $(DOCKER_NAME) /bin/bash |
Oops, something went wrong.