-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
254 lines (215 loc) · 7.08 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# https://www.gnu.org/software/make/manual/make.html
BASE=alpine_base
# TOP_DIR=$(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
TOP_DIR=$(shell dirname $(abspath $(firstword $(MAKEFILE_LIST))))
PROJECT=$(notdir $(TOP_DIR))
REPO=$(BASE)/$(PROJECT)
# Dockerfile | SDK.Dockerfile | SDKMAN.Dockerfile
DOCKER_FILE=Dockerfile
# docker-compose.yml | docker-compose.yaml
DOCKER_COMPOSE_FILE=docker-compose.yml
# alpine_network | <docker-compose-project>_alpine_network
DOCKER_NETWORK=alpine_network
OFFICIAL_PROJECT=$(shell echo $(PROJECT) | cut -d'_' -f2)
ifneq ("$(wildcard VERSION.txt)", "")
TAG=$(shell grep -i version VERSION.txt | cut -d '=' -f 2 | tr -d '[:space:]')
OFFICIAL_TAG=latest
else ifdef LATEST
TAG=latest
OFFICIAL_TAG=latest
else
TAG=latest
OFFICIAL_TAG=latest
endif
# COMMAND=docker run --rm -ti -v $(TOP_DIR)/$(SRC_FOLDER):$(PROJECT_FOLDER) -h $(PROJECT) --name $(PROJECT) $(REPO):$(TAG)
COMMAND=
ifneq ("$(wildcard ${HOME}/.env)", "")
include ${HOME}/.env
else ifneq ("$(wildcard env)", "")
include env
else
GIT_USER=cclhsu
GIT_USER_PASSWORD=
GIT_USER_EMAIL=cclhsu@yahoo.com
DOCKER_ID_USER=cclhsu
DOCKER_PASSWORD=
endif
# project | HelloWorld
PROJECT_FOLDER=/HelloWorld
# . | src | example
SRC_FOLDER=.
##### HOWTO #####
# make package; make build_docker; make run_docker
# make package; make run_package
# make package; make run
##### ##### #####
.DEFAULT_GOAL := help
.PHONY: help
help:
@make -rpn | sed -n -e '/^$$/ { n ; /^[^ .#][^ ]*:/ { s/:.*$$// ; p ; } ; }' | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@#make -rpn | sed -n -e '/^$/ { n ; /^[^ ]*:/p ; }' | egrep --color '^[^ .]*:' | sort
@#grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: all
all: compile
.PHONY: project_init
project_init:
go mod init ${PROJECT} && \
mkdir ${TOP_DIR}/bin && \
mkdir ${TOP_DIR}/cmd && \
mkdir ${TOP_DIR}/pb && \
mkdir ${TOP_DIR}/proto
.PHONY: install_dependency_packages
install_dependency_packages:
export GOPATH=${HOME}/go && \
export PATH="${PATH}:$(shell go env GOPATH)/bin" && \
go get -u <URL>
# .PHONY: build
# build:
# # export GOPATH=${TOP_DIR}
# export GOBIN=${TOP_DIR}/bin && \
# go env && \
# $(COMMAND) go build -o ${TOP_DIR}/bin/hello ${TOP_DIR}/src/hello.go
# .PHONY: build
# build:
# # export GOPATH=${TOP_DIR}
# export GOBIN=${TOP_DIR}/bin && \
# go env && \
# $(COMMAND) go build -o ${TOP_DIR}/bin/app app
# .PHONY: compile_linux
# compile_linux:
# # export GOPATH=${TOP_DIR}
# export GOBIN=${TOP_DIR}/bin && \
# export GOOS=linux && \
# export GOARCH=amd64 && \
# go env && \
# $(COMMAND) go install ${TOP_DIR}/src/hello.go
.PHONY: compile
compile:
# export GOPATH=${TOP_DIR}
export GOBIN=${TOP_DIR}/bin && \
go env && \
$(COMMAND) go install ${TOP_DIR}/cmd/crd-controller
.PHONY: install
install:
# export GOPATH=${TOP_DIR}
export GOBIN=${TOP_DIR}/bin && \
go env && \
$(COMMAND) go install ${TOP_DIR}/cmd/crd-controller
.PHONY: run
run:
# $(COMMAND) ./bin/hello || :
# $(COMMAND) ./bin/app || :
$(COMMAND) ./bin/crd-controller || :
.PHONY: script
script:
@# ./hello.sh
# $(COMMAND) go run ${TOP_DIR}/src/hello.go
$(COMMAND) go run ${TOP_DIR}/cmd/crd-controller/crud.go
.PHONY: package
package:
make clean
make compile
@# make compile_linux
.PHONY: run_package
run_package:
$(COMMAND) go ${TOP_DIR}/bin/hello
.PHONY: clean
clean:
@# $(COMMAND) gradle clean
rm -rf ${TOP_DIR}/bin/*
rm -rf ${TOP_DIR}/api/pb
rm -rf ${TOP_DIR}/api/swagger
.PHONY: bash
bash:
$(COMMAND) /bin/bash
.PHONY: build_docker
build_docker:
make clean_docker
# docker build -f ${DOCKER_FILE} -t $(REPO):$(TAG) .
docker build --rm -f ${DOCKER_FILE} -t $(REPO):$(TAG) .
.PHONY: clean_docker
clean_docker:
docker rm -f $(PROJECT) 2>/dev/null; true
docker rmi $(REPO):$(TAG) 2>/dev/null; true
docker rm $(shell docker ps -a -q) 2>/dev/null; true
docker rmi $(shell docker images -f "dangling=true" -q) 2>/dev/null; true
docker volume prune -f 2>/dev/null; true
rm -rf tmp
.PHONY: run_docker
run_docker:
@# $(COMMAND)
docker run --rm -ti -v $(TOP_DIR):$(PROJECT_FOLDER) -v $(TOP_DIR)/entrypoint.sh:/usr/bin/entrypoint.sh -h $(PROJECT) --name $(PROJECT) $(REPO):$(TAG)
.PHONY: run_docker_with_mount_volume
run_docker_with_mount_volume:
@# docker run --rm -ti -v $(TOP_DIR)/$(SRC_FOLDER):$(PROJECT_FOLDER) -h $(PROJECT) --name $(PROJECT) $(REPO):$(TAG) <command>
docker run --rm -ti -v $(TOP_DIR):$(PROJECT_FOLDER) -h $(PROJECT) --name $(PROJECT) $(REPO):$(TAG)
.PHONY: run_docker_with_mount_entrypoint
run_docker_with_mount_entrypoint:
@# docker run --rm -ti -v $(TOP_DIR)/entrypoint.sh:/usr/bin/entrypoint.sh -h $(PROJECT) --name $(PROJECT) $(REPO):$(TAG) <command>
docker run --rm -ti -v $(TOP_DIR)/entrypoint.sh:/usr/bin/entrypoint.sh -h $(PROJECT) --name $(PROJECT) $(REPO):$(TAG)
.PHONY: bash_docker
bash_docker:
@# $(COMMAND) /bin/bash
docker run --rm -ti -h $(PROJECT) --name $(PROJECT) $(REPO):$(TAG) /bin/bash
.PHONY: bash_container
bash_container:
bash -c "clear && docker exec -it $(PROJECT) /bin/bash"
.PHONY: list_docker
list_docker:
docker ps -a
docker volume ls
docker images
.PHONY: publish
publish:
@# https://docs.docker.com/docker-cloud/builds/push-images/
@# docker login -u $(DOCKER_ID_USER) -p $(DOCKER_PASSWORD)
docker tag $(REPO):$(TAG) $(DOCKER_ID_USER)/$(PROJECT)
docker push $(DOCKER_ID_USER)/$(PROJECT)
.PHONY: untag_publish
untag_publish:
docker rmi $(DOCKER_ID_USER)/$(PROJECT):$(TAG)
.PHONY: dockerhub
dockerhub:
open https://hub.docker.com/u/${DOCKER_ID_USER}/
.PHONY: publish_to_registry
publish_to_registry:
@# https://docs.docker.com/docker-cloud/builds/push-images/
@# docker login -u $(DOCKER_ID_USER) -p $(DOCKER_PASSWORD)
# docker tag $(REPO):$(TAG) $(DOCKER_ID_USER)/$(PROJECT)
# docker push $(DOCKER_ID_USER)/$(PROJECT)
docker tag alpine:latest 0.0.0.0:5000/alpine/alpine:latest
docker push 0.0.0.0:5000/alpine/alpine:latest
curl -X GET http://0.0.0.0:5000/v2/_catalog
curl -X GET http://0.0.0.0:5000/v2/alpine/alpine/tags/list
.PHONY: untag_publish_to_registry
untag_publish_to_registry:
docker rmi $(DOCKER_ID_USER)/$(PROJECT):$(TAG)
.PHONY: git_init
git_init:
git config --global user.name ${GIT_USER}
git config --global user.email ${GIT_USER_EMAIL}
curl -u ${GIT_USER}:${GIT_USER_PASSWORD} https://api.github.com/user/repos -d "{\"name\":\"${PROJECT}\"}"
touch README.md
touch .gitignore
git init
git checkout -b develop
git add .gitignore
git commit -m "first commit"
git add *
git rm -r --cached Makefile
git commit -m "add project skeleton"
git checkout -b master
git merge develop
git flow init -fd
# git remote add origin git@github.com:${GIT_USER}/${PROJECT}.git
git remote add origin https://github.com/${GIT_USER}/${PROJECT}.git
echo ${GIT_USER_PASSWORD} | git push -u origin master
git remote set-head origin master
git remote set-head origin -a
echo ${GIT_USER_PASSWORD} | git push --all
.PHONY: git_push
git_push:
git push
.PHONY: git_delete_github_repository
git_delete_github_repository:
curl -u ${GIT_USER}:${GIT_USER_PASSWORD} -X DELETE https://api.github.com/repos/${GIT_USER}/${PROJECT}