forked from docker-library/mongo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
executable file
·148 lines (112 loc) · 4.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# -------------------------------------------------------------------------------------------------------
# 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\#\#*/}|tr '[:upper:]' '[:lower:]'|tr "/: " "_" )
# The name of the container (default is current directory name)
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
current_dir := $(notdir $(patsubst %/,%,$(dir $(mkfile_path))))
DOCKER_NAME := $(shell echo $(current_dir)|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)"
MONGO_VERSION=6.0
## -- 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=*)
TIME_START := $(shell date +%s)
.PHONY: clean rmi build push pull up down run stop exec
clean:
$(DOCKER_NAME) $(DOCKER_IMAGE):$(MONGO_VERSION)
default: build
build-time:
docker build \
--build-arg BASE_IMAGE="$(BASE_IMAGE)" \
--build-arg CIRCLE_SHA1="$(SHA)" \
--build-arg version=$(MONGO_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):$(MONGO_VERSION) .
copy-dockerfile:
cp $(MONGO_VERSION)/Dockerfile .
cp $(MONGO_VERSION)/docker-entrypoint.sh .
build-rm: copy-dockerfile
cp $(MONGO_VERSION)/Dockerfile .
docker build --force-rm --no-cache \
-t $(DOCKER_IMAGE):$(MONGO_VERSION) .
DOCKER_IMAGE=mongo
build:
cp $(MONGO_VERSION)/docker-entrypoint.sh .
@echo ">>> Pull library/mongo images ... (no local build - recommended)"
docker pull mongo
build-local: copy-dockerfile
cp $(MONGO_VERSION)/Dockerfile .
sed -i '/^ENV JSYAML/r ./Dockerfile-certificate.txt' Dockerfile
docker build \
-t $(DOCKER_IMAGE):$(MONGO_VERSION) .
docker images | grep $(DOCKER_IMAGE)
@echo ">>> Total Dockder images Build using time in seconds: $$(($$(date +%s)-$(TIME_START))) seconds"
push:
docker commit -m "$comment" ${containerID} ${imageTag}:$(MONGO_VERSION)
docker push $(DOCKER_IMAGE):$(MONGO_VERSION)
docker tag $(imageTag):$(MONGO_VERSION) $(REGISTRY_IMAGE):$(MONGO_VERSION)
#docker tag $(imageTag):latest $(REGISTRY_IMAGE):latest
docker push $(REGISTRY_IMAGE):$(MONGO_VERSION)
#docker push $(REGISTRY_IMAGE):latest
@if [ ! "$(IMAGE_EXPORT_PATH)" = "" ]; then \
mkdir -p $(IMAGE_EXPORT_PATH); \
docker save $(REGISTRY_IMAGE):$(MONGO_VERSION) | gzip > $(IMAGE_EXPORT_PATH)/$(DOCKER_NAME)_$(MONGO_VERSION).tar.gz; \
fi
pull:
@if [ "$(REGISTRY_HOST)" = "" ]; then \
docker pull $(DOCKER_IMAGE):$(MONGO_VERSION) ; \
else \
docker pull $(REGISTRY_IMAGE):$(MONGO_VERSION) ; \
fi
up-console:
docker-compose up
up:
docker-compose up -d
down:
docker-compose down
run:
docker run --name=$(DOCKER_NAME) --restart=$(RESTART_OPTION) $(VOLUME_MAP) $(DOCKER_IMAGE):$(MONGO_VERSION)
stop:
docker stop --name=$(DOCKER_NAME)
status:
docker ps
rmi:
docker rmi $$(docker images -f dangling=true -q)
exec:
docker-compose exec $(DOCKER_NAME) /bin/bash