Skip to content

Commit a04f7ad

Browse files
authored
support docker and update scripts, docs (#9)
1 parent da85a37 commit a04f7ad

File tree

5 files changed

+186
-10
lines changed

5 files changed

+186
-10
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Makefile and scripts for simply and uni dev-ops, current include go, docker
55
## feature
66

77
- [x] go
8-
- [ ] docker
8+
- [x] docker
99

1010
## requirements
1111

@@ -50,11 +50,11 @@ You can easily install by `install.sh`, **but** only support into the `root dir
5050
>**better clone into your project root dir**
5151
5252
- `git clone https://github.com/v8fg/uni-deploy.git -b <branch> [path]`
53-
- `bash all.sh`
53+
- `bash all.sh -h`
5454

55-
>more usage: `bash all.sh help`
55+
>more usage: `bash all.sh -h`
5656
5757
## uninstall uni-deploy
5858

59-
- `bash uni-deploy/all.sh uninstall`
59+
- `bash uni-deploy/all.sh -c uninstall`
6060
- the submodule `uni-deploy` **must in the root dir for your project**

docker/Makefile

Lines changed: 110 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
# This Makefile doesn't consider Windows Environment. If you use it in Windows, please be careful.
33
SHELL := /bin/sh
44

5+
define NEWLINE
6+
7+
endef
8+
59
# -------- color constant start -------
610
RED=\033[31;01m
711
GREEN=\033[32;01m
@@ -38,7 +42,8 @@ _compose_version=""
3842

3943
# The params will be override if specified by input
4044
# SHOW_TIP whether or not show the init info
41-
SHOW_TIP?=true
45+
SHOW_TIP?=false
46+
override CURRENT_SCRIPT_DIR=${_current_script_dir}
4247

4348
# PROJECT_ROOT the project root dir
4449
PROJECT_ROOT?=${_default_project_root}
@@ -52,8 +57,28 @@ REGISTRY_PASSWORD?=
5257
REPOSITORY?=${_default_repository}
5358
TAG?=${_default_tag}
5459

60+
# image id
5561
IMAGE_ID?=
62+
# container id
5663
CONTAINER_ID?=
64+
# display logs count, default 200
65+
LOGS_COUNT?=200
66+
67+
# for image list filter, format: -f reference=""
68+
IMAGE_LIST_PARAMS?=-f reference=""
69+
70+
CONTAINER_LIST_PARAMS?=
71+
72+
COMPOSE_RUN_PARAMS?="-d"
73+
74+
# for run container, the image(name or id) use
75+
CONTAINER_IMAGE?=${REPOSITORY}:${TAG}
76+
# for run container, container name, format: --name <container_name>
77+
CONTAINER_NAME_PARAM?=
78+
# for run container, format like: -d daemon -v v1:v1 ... -p p1:p2 ... -e k1=v1 ...
79+
CONTAINER_PARAMS?=
80+
# for run container, params for app need, container CMD need
81+
CONTAINER_CMD_PARAMS?=
5782

5883
# check or override: SHOW_TIP
5984
ifeq (,$(strip ${SHOW_TIP}))
@@ -128,14 +153,16 @@ $(info [init] vcs: [git=${_git_version}, commit_short=${gitCommitShort}, comm
128153
$(info [init] env: [docker=${_docker_version}, compose=${_compose_version}])
129154
$(info [init] base: [ docker_file=${DOCKER_FILE}])
130155
$(info [init] base: [compose_file=${DOCKER_COMPOSE_FILE}])
156+
$(info ${NEWLINE})
131157
endif
132158

133159

134160
# ----------- Makefile commands -----------
135161
.PHONY: default help env cp-ignore \
136-
login login-auth build tag push list-image run run-daemon stop list-docker \
137-
rmi image-prune rm docker-prune compose-run compose-daemon compose-stop
138-
prune remove
162+
login login-auth build tag push list-image list-docker\
163+
run stop \
164+
rmi image-prune rm docker-prune compose-run compose-stop \
165+
logs
139166

140167
default: help
141168

@@ -150,6 +177,11 @@ env:
150177
@echo -e "${COLOR_INFO}$(shell docker-compose --version)${COLOR_RESET}"
151178
@echo -e "[command-env] ${GREEN}execute success${COLOR_RESET}"
152179

180+
## cp-ignore: copy the default '.dockerignore' file to the root dir of your project, pls rename it manually
181+
cp-ignore:
182+
cp ${CURRENT_SCRIPT_DIR}/.dockerignore-example ${PROJECT_ROOT}
183+
@echo -e "[command-cp-ignore] ${GREEN}execute success${COLOR_RESET}"
184+
153185
## login: login docker-hub
154186
login:
155187
docker login
@@ -159,3 +191,77 @@ login:
159191
login-auth:
160192
docker login -u "${REGISTRY_ACCOUNT}" "${REGISTRY}" -p "${REGISTRY_PASSWORD}"
161193
@echo -e "[command-login-auth] ${GREEN}execute success${COLOR_RESET}"
194+
195+
## build: docker build with REPOSITORY(default your dir name) and TAG(default latest)
196+
build:
197+
@echo -e "building image with name:[${REPOSITORY}:${TAG}], use Dockerfile:${DOCKER_FILE}"
198+
@cd ${PROJECT_ROOT} && docker build -t ${REPOSITORY}:${TAG} -f ${DOCKER_FILE} .
199+
@echo -e "build image with name:[${REPOSITORY}:${TAG}], use Dockerfile:${DOCKER_FILE}"
200+
@echo -e "[command-build] ${GREEN}execute success${COLOR_RESET}"
201+
202+
## tag: docker tag, only support rename tag by image id
203+
tag:
204+
@docker tag ${IMAGE_ID} ${REPOSITORY}:${TAG}
205+
@echo -e "[command-tag] ${GREEN}image with ID [${IMAGE_ID}], rename to [${REPOSITORY}:${TAG}${COLOR_RESET}]"
206+
@echo -e "[command-tag] ${GREEN}execute success${COLOR_RESET}"
207+
208+
## push: push docker images to docker hub or others. shall login before push!
209+
push:
210+
docker push ${REPOSITORY}:${TAG}
211+
@echo -e "[command-push] ${GREEN}push ${REPOSITORY}:${TAG} over${COLOR_RESET}"
212+
213+
## list-image: list docker images, can with filter, -f reference="", ref 'docker images --help'
214+
list-image:
215+
@docker images ${IMAGE_LIST_PARAMS}
216+
@echo -e "[command-list-image] ${GREEN}list all images, with params:[${IMAGE_LIST_PARAMS}]${COLOR_RESET}"
217+
218+
## list-docker: list docker container, can with filter, ref 'docker ps --help' or 'docker container ls --help'
219+
list-docker:
220+
@docker ps ${CONTAINER_LIST_PARAMS}
221+
@echo -e "[command-list-docker] ${GREEN}list containers with params:[${CONTAINER_LIST_PARAMS}]${COLOR_RESET}"
222+
223+
## run: docker run with specified params, must set 'CONTAINER_IMAGE', format(image name or id)
224+
run:
225+
@echo -e "[command-run] ${GREEN}run docker, with container image:[${CONTAINER_IMAGE}]${COLOR_RESET}"
226+
docker run -it ${CONTAINER_NAME_PARAM} --rm ${CONTAINER_PARAMS} ${CONTAINER_IMAGE} ${CONTAINER_CMD_PARAMS}
227+
228+
## stop: stop the running containers with container ids
229+
stop:
230+
docker stop ${CONTAINER_ID}
231+
@echo -e "[command-stop] ${GREEN}stop container, with container id:[${CONTAINER_ID}]${COLOR_RESET}"
232+
233+
## rmi: remove the images with image ids
234+
rmi:
235+
docker rmi ${IMAGE_ID}
236+
@echo -e "[command-rmi] ${GREEN}remove images :[${IMAGE_ID}]${COLOR_RESET}"
237+
238+
## image-prune: remove all unused images, ref docker image --help
239+
image-prune:
240+
docker image prune
241+
@echo -e "[command-image-prune] ${GREEN}remove all unused images${COLOR_RESET}"
242+
243+
## rm: remove the containers with container ids
244+
rm:
245+
docker rm ${CONTAIN_ID}
246+
@echo -e "[command-rm] ${GREEN}remove containers :[${CONTAIN_ID}]${COLOR_RESET}"
247+
248+
## docker-prune: remove all stopped containers, ref docker container --help
249+
docker-prune:
250+
docker image prune
251+
@echo -e "[command-docker-prune] ${GREEN}remove all stopped containers${COLOR_RESET}"
252+
253+
compose-run:
254+
@echo -e "[command-compose-run] ${GREEN}docker-compose run with file:[${DOCKER_COMPOSE_FILE}]${COLOR_RESET}"
255+
docker-compose -f ${DOCKER_COMPOSE_FILE} up ${COMPOSE_RUN_PARAMS}
256+
257+
compose-stop:
258+
@echo -e "[command-compose-stop] ${GREEN}docker-compose stop with file:[${DOCKER_COMPOSE_FILE}]${COLOR_RESET}"
259+
docker-compose -f ${DOCKER_COMPOSE_FILE} stop
260+
261+
logs:
262+
docker logs -fn ${LOGS_COUNT} ${CONTAINER_ID}
263+
@echo -e "[command-logs] ${GREEN}the latest ${LOGS_COUNT} logs, for container_id:${CONTAINER_ID}${COLOR_RESET}"
264+
265+
compose-logs:
266+
docker-compose logs
267+
@echo -e "[command-compose-logs] ${GREEN}execute success${COLOR_RESET}"

docker/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# uni-deploy docker
2+
3+
## requirements
4+
5+
>pls ref: [docker requirements](../README.md)
6+
7+
## usage
8+
9+
- `make help` _if already in the `uni-deploy/docker`_
10+
- `cd {PROJECT_ROOT}/uni-deploy/docker && make [command]`
11+
- `make -C {PROJECT_ROOT}/uni-deploy/docker [command]`
12+
13+
## variables notices
14+
15+
- `SHOW_TIP?=false` _default not show base tip, if you want show, pls set SHOW_TIP=true or others, but not empty._
16+
17+
## links
18+
19+
- [docker engine](https://docs.docker.com/engine/)
20+
- [docker-compose](https://docs.docker.com/compose/)
21+
- [docker hub](https://hub.docker.com/)
22+
23+
## examples
24+
25+
- **help** `make -C uni-deploy/docker help`
26+
- **env** `make -C uni-deploy/docker env`
27+
- **cp-ignore** `make -C uni-deploy/docker cp-ignore` **pls rename it manually**
28+
- **docker login** `make -C uni-deploy/docker login`
29+
- **build image** `make -C uni-deploy/docker build DOCKER_FILE=<DOCKER_FILE> [REPOSITORY=<REPOSITORY>] [TAG=<TAG>]`
30+
- **image tag** `make -C uni-deploy/docker tag IMAGE_ID=<image_id> [REPOSITORY=<REPOSITORY>] [TAG=<TAG>]`
31+
- **push image** `make -C uni-deploy/docker push REPOSITORY=<REPOSITORY> [TAG=<TAG>]`
32+
- ***list images** `make -C uni-deploy/docker list-image [IMAGE_LIST_PARAMS=<IMAGE_LIST_PARAMS>]`
33+
- ***list containers** `make -C uni-deploy/docker list-docker [CONTAINER_LIST_PARAMS=<CONTAINER_LIST_PARAMS>]`

go/Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
# This Makefile doesn't consider Windows Environment. If you use it in Windows, please be careful.
33
SHELL := /bin/sh
44

5+
define NEWLINE
6+
7+
endef
8+
59
# -------- color constant start -------
610
RED=\033[31;01m
711
GREEN=\033[32;01m
@@ -36,7 +40,7 @@ CGO_ENABLED?=0
3640

3741
# The params will be override if specified by input
3842
# SHOW_TIP whether or not show the init info
39-
SHOW_TIP?=true
43+
SHOW_TIP?=false
4044

4145
# PROJECT_ROOT the project root dir
4246
PROJECT_ROOT?=${_default_project_root}
@@ -115,6 +119,7 @@ $(info [init] env: [go_verion=${_go_version}, CGO_ENABLED=${CGO_ENABLED}])
115119
$(info [init] output: [build_out_dir=${BUILD_DIR_OUT}])
116120
$(info [init] output: [binary_name=${BINARY_NAME}, binary_output=${binary_file})
117121
$(info [init] output: [conf_output=${build_dir_out_conf}])
122+
$(info ${NEWLINE})
118123
endif
119124

120125
# ----------- go pkg and files -----------
@@ -364,7 +369,7 @@ clean-binary:
364369
## clean-conf: only clean the build conf
365370
clean-conf:
366371
@cd ${BUILD_DIR_OUT} && \
367-
if [ -f ${build_dir_out_conf} ] ; then rm ${build_dir_out_conf} ; fi
372+
if [ -d ${build_dir_out_conf} ] ; then rm ${build_dir_out_conf} ; fi
368373
@echo -e "[command-clean-conf] ${GREEN}clean ${build_dir_out_conf} success"
369374

370375
## version: print the binary app version, need third pkg

go/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,39 @@
1010
- `cd {PROJECT_ROOT}/uni-deploy/go && make [command]`
1111
- `make -C {PROJECT_ROOT}/uni-deploy/go [command]`
1212

13+
## variables notices
14+
15+
- `SHOW_TIP?=false` _default not show base tip, if you want show, pls set SHOW_TIP=true or others, but not empty._
16+
- `BUILD_DIR_OUT=${PROJECT_ROOT}/build`
17+
- `binary_file=${BUILD_DIR_OUT}/bin/${BINARY_NAME}`
18+
- `build_dir_out_binary=${BUILD_DIR_OUT}/bin`
19+
- `build_dir_out_conf=${BUILD_DIR_OUT}/conf`
20+
- `build_dir_out_coverage=${BUILD_DIR_OUT}/coverage`
21+
1322
## links
1423

1524
- [go link](https://pkg.go.dev/cmd/link)
1625
- [golangci-lint](https://golangci-lint.run)
26+
27+
## examples
28+
29+
- **help** `make -C uni-deploy/go help`
30+
- **env** `make -C uni-deploy/go env`
31+
- **list** `make -C uni-deploy/go list`
32+
- **tidy** `make -C uni-deploy/go tidy`
33+
- **vendor** `make -C uni-deploy/go vendor`
34+
- **go-version** `make -C uni-deploy/go go-version`
35+
- **fmt** `make -C uni-deploy/go fmt`
36+
- **fmt-check-files** `make -C uni-deploy/go fmt-check-files`
37+
- **build** `make -C uni-deploy/go build [BINARY_NAME=<BINARY_NAME>]`
38+
- **release** `make -C uni-deploy/go release [BINARY_NAME=<BINARY_NAME>]`
39+
- **release-vendor** `make -C uni-deploy/go release-vendor [BINARY_NAME=<BINARY_NAME>]`
40+
- **list-build** `make -C uni-deploy/go list-build`
41+
- **upx** `make -C uni-deploy/go upx [BINARY_NAME=<BINARY_NAME>]`
42+
- **upx-bak** `make -C uni-deploy/go upx-bak`
43+
- **version** `make -C uni-deploy/go version [BINARY_NAME=<BINARY_NAME>]`
44+
- **run** `make -C uni-deploy/go run`
45+
- **run-binary** `make -C uni-deploy/go run-binary [BINARY_NAME=<BINARY_NAME>]`
46+
- **clean** `make -C uni-deploy/go clean`
47+
- **clean-binary** `make -C uni-deploy/go clean-binary [BINARY_NAME=<BINARY_NAME>]`
48+
- **clean-conf** `make -C uni-deploy/go clean-conf`

0 commit comments

Comments
 (0)