Makefile 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. SHELL = /bin/bash
  2. #SCRIPT_DIR = $(shell pwd)/etc/script
  3. #请选择golang版本
  4. BUILD_IMAGE_SERVER = golang:1.18
  5. #请选择node版本
  6. BUILD_IMAGE_WEB = node:16
  7. #项目名称
  8. PROJECT_NAME = github.com/flipped-aurora/gin-vue-admin/server
  9. #配置文件目录
  10. CONFIG_FILE = config.yaml
  11. #镜像仓库命名空间
  12. IMAGE_NAME = gva
  13. #镜像地址
  14. REPOSITORY = registry.cn-hangzhou.aliyuncs.com/${IMAGE_NAME}
  15. ifeq ($(TAGS_OPT),)
  16. TAGS_OPT = latest
  17. else
  18. endif
  19. ifeq ($(PLUGIN),)
  20. PLUGIN = email
  21. else
  22. endif
  23. #容器环境前后端共同打包
  24. build: build-web build-server
  25. docker run --name build-local --rm -v $(shell pwd):/go/src/${PROJECT_NAME} -w /go/src/${PROJECT_NAME} ${BUILD_IMAGE_SERVER} make build-local
  26. #容器环境打包前端
  27. build-web:
  28. docker run --name build-web-local --rm -v $(shell pwd):/go/src/${PROJECT_NAME} -w /go/src/${PROJECT_NAME} ${BUILD_IMAGE_WEB} make build-web-local
  29. #容器环境打包后端
  30. build-server:
  31. docker run --name build-server-local --rm -v $(shell pwd):/go/src/${PROJECT_NAME} -w /go/src/${PROJECT_NAME} ${BUILD_IMAGE_SERVER} make build-server-local
  32. #构建web镜像
  33. build-image-web:
  34. @cd web/ && docker build -t ${REPOSITORY}/web:${TAGS_OPT} .
  35. #构建server镜像
  36. build-image-server:
  37. @cd server/ && docker build -t ${REPOSITORY}/server:${TAGS_OPT} .
  38. #本地环境打包前后端
  39. build-local:
  40. if [ -d "build" ];then rm -rf build; else echo "OK!"; fi \
  41. && if [ -f "/.dockerenv" ];then echo "OK!"; else make build-web-local && make build-server-local; fi \
  42. && mkdir build && cp -r web/dist build/ && cp server/server build/ && cp -r server/resource build/resource
  43. #本地环境打包前端
  44. build-web-local:
  45. @cd web/ && if [ -d "dist" ];then rm -rf dist; else echo "OK!"; fi \
  46. && yarn config set registry http://mirrors.cloud.tencent.com/npm/ && yarn install && yarn build
  47. #本地环境打包后端
  48. build-server-local:
  49. @cd server/ && if [ -f "server" ];then rm -rf server; else echo "OK!"; fi \
  50. && go env -w GO111MODULE=on && go env -w GOPROXY=https://goproxy.cn,direct \
  51. && go env -w CGO_ENABLED=0 && go env && go mod tidy \
  52. && go build -ldflags "-B 0x$(shell head -c20 /dev/urandom|od -An -tx1|tr -d ' \n') -X main.Version=${TAGS_OPT}" -v
  53. #打包前后端二合一镜像
  54. image: build
  55. docker build -t ${REPOSITORY}/gin-vue-admin:${TAGS_OPT} -f deploy/docker/Dockerfile .
  56. #尝鲜版
  57. images: build build-image-web build-image-server
  58. docker build -t ${REPOSITORY}/all:${TAGS_OPT} -f deploy/docker/Dockerfile .
  59. #插件快捷打包: make plugin PLUGIN="这里是插件文件夹名称,默认为email"
  60. plugin:
  61. if [ -d ".plugin" ];then rm -rf .plugin ; else echo "OK!"; fi && mkdir -p .plugin/${PLUGIN}/{server/plugin,web/plugin} \
  62. && if [ -d "server/plugin/${PLUGIN}" ];then cp -r server/plugin/${PLUGIN} .plugin/${PLUGIN}/server/plugin/ ; else echo "OK!"; fi \
  63. && if [ -d "web/src/plugin/${PLUGIN}" ];then cp -r web/src/plugin/${PLUGIN} .plugin/${PLUGIN}/web/plugin/ ; else echo "OK!"; fi \
  64. && cd .plugin && zip -r ${PLUGIN}.zip ${PLUGIN} && mv ${PLUGIN}.zip ../ && cd ..