-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
executable file
·113 lines (86 loc) · 3.31 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# -------------------------------------------------------------------------------------------------------
# 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
# -------------------------------------------------------------------------------------------------------
SHELL := /bin/bash
BASE_IMAGE := $(BASE_IMAGE)
## -- To Check syntax:
# cat -e -t -v Makefile
# 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)"
## -- 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}/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 := always
SHA := $(shell git describe --match=NeVeRmAtCh --always --abbrev=40 --dirty=*)
.PHONY: clean rmi build push pull up down run stop exec
clean:
echo $(DOCKER_NAME) $(DOCKER_IMAGE):$(VERSION)
default: build
build:
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
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:
@if [ "$(REGISTRY_HOST)" = "" ]; then \
sudo docker pull $(DOCKER_IMAGE):$(VERSION) ; \
else \
sudo docker pull $(REGISTRY_IMAGE):$(VERSION) ; \
fi
up: build
sudo docker-compose up -d
down:
sudo docker-compose down
run:
sudo docker run --name=$(DOCKER_NAME) --restart=$(RESTART_OPTION) $(VOLUME_MAP) $(DOCKER_IMAGE):$(VERSION)
stop: run
sudo docker stop --name=$(DOCKER_NAME)
status:
sudo docker ps
rmi:
sudo docker rmi $$(docker images -f dangling=true -q)
exec: up
sudo docker-compose exec $(DOCKER_NAME) /bin/bash