Makefile 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. PROJECT:=go-admin
  2. .PHONY: build version
  3. version?=latest
  4. build:
  5. CGO_ENABLED=0 go build -o bin/observe -ldflags="-w -s" -a -installsuffix .
  6. linux-build:
  7. CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/observe -ldflags="-w -s" -a -installsuffix .
  8. linux-event-build:
  9. CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/observe-event -ldflags="-w -s" -a -installsuffix .
  10. # make build-linux
  11. build-linux:
  12. @docker build -t go-admin:latest .
  13. @echo "build successful"
  14. build-sqlite:
  15. go build -tags sqlite3 -ldflags="-w -s" -a -installsuffix -o bin/observe .
  16. run:
  17. bin/observe server -c config/settings.yml
  18. run-nodeport:
  19. bin/observe server -c config/settings.nodeport.yml
  20. # make run
  21. docker-run:
  22. # delete go-admin-api container
  23. # @if [ $(shell docker ps -aq --filter name=go-admin --filter publish=8000) ]; then docker rm -f go-admin; fi
  24. # 启动方法一 run go-admin-api container docker-compose 启动方式
  25. # 进入到项目根目录 执行 make run 命令
  26. # @docker-compose up -d
  27. # 启动方式二 docker run 这里注意-v挂载的宿主机的地址改为部署时的实际决对路径
  28. #@docker run --name=go-admin -p 8000:8000 -v /home/code/go/src/go-admin/go-admin/config:/go-admin-api/config -v /home/code/go/src/go-admin/go-admin-api/static:/go-admin/static -v /home/code/go/src/go-admin/go-admin/temp:/go-admin-api/temp -d --restart=always go-admin:latest
  29. @echo "go-admin service is running..."
  30. # delete Tag=<none> 的镜像
  31. @docker image prune -f
  32. @docker ps -a | grep "go-admin"
  33. stop:
  34. # delete go-admin-api container
  35. @if [ $(shell docker ps -aq --filter name=go-admin --filter publish=8000) ]; then docker-compose down; fi
  36. #@if [ $(shell docker ps -aq --filter name=go-admin --filter publish=8000) ]; then docker rm -f go-admin; fi
  37. #@echo "go-admin stop success"
  38. DOCKER_IMAGE_NAME=observe-server
  39. DOCKER_REMOTE_IMAGE_NAME=reg.cestong.com.cn/cecf/${DOCKER_IMAGE_NAME}:${version}
  40. create-version:
  41. git rev-parse --short HEAD > version
  42. go mod tidy
  43. docker-build:
  44. docker build . -f Dockerfile -t ${DOCKER_IMAGE_NAME}
  45. docker-push:
  46. docker tag ${DOCKER_IMAGE_NAME} ${DOCKER_REMOTE_IMAGE_NAME}
  47. docker push ${DOCKER_REMOTE_IMAGE_NAME}
  48. docker: create-version linux-build docker-build docker-push
  49. EVENT_IMAGE_NAME=observe-event
  50. EVENT_REMOTE_IMAGE_NAME=reg.cestong.com.cn/cecf/${EVENT_IMAGE_NAME}
  51. event-build:
  52. docker build . -f Dockerfile -t ${EVENT_IMAGE_NAME}
  53. event-push:
  54. docker tag ${EVENT_IMAGE_NAME} ${EVENT_REMOTE_IMAGE_NAME}
  55. docker push ${EVENT_REMOTE_IMAGE_NAME}
  56. event: create-version linux-event-build event-build event-push
  57. #.PHONY: test
  58. #test:
  59. # go test -v ./... -cover
  60. #.PHONY: docker
  61. #docker:
  62. # docker build . -t go-admin:latest
  63. # make deploy
  64. deploy:
  65. #@git checkout master
  66. #@git pull origin master
  67. make build-linux
  68. make run