-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakeDockerRun.mk
110 lines (100 loc) · 4.56 KB
/
MakeDockerRun.mk
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
# this file must use as base Makefile
# use Makefile ROOT_NAME
ROOT_DOCKER_CONTAINER ?= $(ROOT_NAME)
# change this for dockerRun
ROOT_DOCKER_IMAGE_PARENT_NAME ?= golang
ROOT_DOCKER_IMAGE_PARENT_TAG ?= 1.13.3-stretch
# change this for dockerRunLinux or dockerRunDarwin
ROOT_DOCKER_IMAGE_NAME ?= $(ROOT_NAME)
# can change as local set or read Makefile DIST_VERSION
ROOT_DOCKER_IMAGE_TAG ?= $(DIST_VERSION)
# For Docker dev images init
initDockerDevImages:
@echo "~> start init this project in docker"
@echo "-> check version"
go version
@echo "-> check env golang"
go env
@echo "~> you can use [ make help ] see more task"
-GOPROXY="$(ENV_GO_PROXY)" GO111MODULE=on go mod vendor
dockerLocalImageInit:
docker build --tag $(ROOT_DOCKER_IMAGE_NAME):$(DIST_VERSION) .
dockerLocalImageRebuild:
docker image rm $(ROOT_DOCKER_IMAGE_NAME):$(DIST_VERSION)
docker build --tag $(ROOT_DOCKER_IMAGE_NAME):$(DIST_VERSION) .
dockerRunLinux: localIPLinux
@echo "=> check local image as $(ROOT_DOCKER_IMAGE_NAME):$(ROOT_DOCKER_IMAGE_TAG)"
docker image inspect --format='{{ .Created}}' $(ROOT_DOCKER_IMAGE_NAME):$(ROOT_DOCKER_IMAGE_TAG)
ENV_WEB_HOST=$(ROOT_LOCAL_IP_V4_LINUX) \
ROOT_DOCKER_CONTAINER=$(ROOT_DOCKER_CONTAINER) \
ROOT_DOCKER_IMAGE_NAME=$(ROOT_DOCKER_IMAGE_NAME) \
ROOT_DOCKER_IMAGE_TAG=$(ROOT_DOCKER_IMAGE_TAG) \
ENV_WEB_HOST=$(ROOT_LOCAL_IP_V4_LINUX) \
DIST_VERSION=$(DIST_VERSION) \
docker-compose up -d
-sleep 5
@echo "=> container $(ROOT_DOCKER_CONTAINER) now status"
docker inspect --format='{{ .State.Status}}' $(ROOT_DOCKER_CONTAINER)
docker logs $(ROOT_DOCKER_CONTAINER) -f
dockerRunDarwin: localIPDarwin
@echo "=> check local image as $(ROOT_DOCKER_IMAGE_NAME):$(ROOT_DOCKER_IMAGE_TAG)"
docker image inspect --format='{{ .Created}}' $(ROOT_DOCKER_IMAGE_NAME):$(ROOT_DOCKER_IMAGE_TAG)
ENV_WEB_HOST=$(ROOT_LOCAL_IP_V4_LINUX) \
ROOT_DOCKER_CONTAINER=$(ROOT_DOCKER_CONTAINER) \
ROOT_DOCKER_IMAGE_NAME=$(ROOT_DOCKER_IMAGE_NAME) \
ROOT_DOCKER_IMAGE_TAG=$(ROOT_DOCKER_IMAGE_TAG) \
ENV_WEB_HOST=$(ROOT_LOCAL_IP_V4_DARWIN) \
DIST_VERSION=$(DIST_VERSION) \
docker-compose up -d
-sleep 5
@echo "=> container $(ROOT_DOCKER_CONTAINER) now status"
docker inspect --format='{{ .State.Status}}' $(ROOT_DOCKER_CONTAINER)
docker logs $(ROOT_DOCKER_CONTAINER) -f
dockerRun:
@echo "=> Now run as docker ENV"
@echo "-> env ROOT_DOCKER_IMAGE_NAME=$(ROOT_DOCKER_IMAGE_PARENT_NAME)"
@echo "-> env ROOT_DOCKER_IMAGE_TAG=$(ROOT_DOCKER_IMAGE_PARENT_TAG)"
@echo "-> env image: ${ROOT_DOCKER_IMAGE_PARENT_NAME}:${ROOT_DOCKER_IMAGE_PARENT_TAG}"
@echo "-> env container_name: ROOT_DOCKER_CONTAINER=$(ROOT_NAME)"
@echo "-> env DIST_VERSION=$(DIST_VERSION)"
@echo ""
ROOT_DOCKER_CONTAINER=$(ROOT_DOCKER_CONTAINER) \
ROOT_DOCKER_IMAGE_NAME=$(ROOT_DOCKER_IMAGE_PARENT_NAME) \
ROOT_DOCKER_IMAGE_TAG=$(ROOT_DOCKER_IMAGE_PARENT_TAG) \
DIST_VERSION=$(DIST_VERSION) \
docker-compose up -d
-sleep 5
@echo "=> container $(ROOT_DOCKER_CONTAINER) now status"
docker inspect --format='{{ .State.Status}}' $(ROOT_DOCKER_CONTAINER)
docker logs $(ROOT_DOCKER_CONTAINER) -f
dockerStop:
ROOT_DOCKER_CONTAINER=$(ROOT_DOCKER_CONTAINER) \
ROOT_DOCKER_IMAGE_NAME=$(ROOT_DOCKER_IMAGE_NAME) \
ROOT_DOCKER_IMAGE_TAG=$(ROOT_DOCKER_IMAGE_TAG) \
DIST_VERSION=$(DIST_VERSION) \
docker-compose stop
dockerPrune: dockerStop
ROOT_DOCKER_CONTAINER=$(ROOT_DOCKER_CONTAINER) \
ROOT_DOCKER_IMAGE_NAME=$(ROOT_DOCKER_IMAGE_NAME) \
ROOT_DOCKER_IMAGE_TAG=$(ROOT_DOCKER_IMAGE_TAG) \
DIST_VERSION=$(DIST_VERSION) \
docker-compose rm -f $(ROOT_DOCKER_CONTAINER)
-docker rmi -f $(ROOT_DOCKER_IMAGE_NAME):$(ROOT_DOCKER_IMAGE_TAG)
docker network prune
docker volume prune
helpDockerRun:
@echo "Help: MakeDockerRun.mk"
@echo "~> make dockerStop - stop docker-compose container-name at $(ROOT_DOCKER_CONTAINER)"
@echo "~> make dockerPrune - stop docker-compose container-name at $(ROOT_DOCKER_CONTAINER) and try to remove"
@echo "Before run this project in docker must use"
@echo "~> make dockerLocalImageInit to init Docker image"
@echo "or use"
@echo "~> make dockerLocalImageRebuild to rebuild Docker image"
@echo "After build Docker image success"
@echo "~> make dockerRunLinux - run docker-compose server as $(ROOT_DOCKER_IMAGE_NAME):$(DIST_VERSION) \
container-name at $(ROOT_DOCKER_CONTAINER) in dockerRunLinux"
@echo "~> make dockerRunDarwin - run docker-compose server as $(ROOT_DOCKER_IMAGE_NAME):$(DIST_VERSION) \
container-name at $(ROOT_DOCKER_CONTAINER) in macOS"
@echo "~> make dockerRun - run image: $(ROOT_DOCKER_IMAGE_PARENT_NAME):$(ROOT_DOCKER_IMAGE_PARENT_TAG) \
ROOT_DOCKER_CONTAINER=$(ROOT_DOCKER_CONTAINER)"
@echo ""