build.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/sh
  2. set -e
  3. # Automatically get the current environment's GOARCH; if not defined, use the detected system architecture
  4. GOARCH=${GOARCH:-$(go env GOARCH)}
  5. DOCS="true"
  6. # Safely remove the old release directory
  7. rm -rf release
  8. # Set Go environment variables
  9. go env -w GO111MODULE=on
  10. go env -w GOPROXY=https://goproxy.cn,direct
  11. go env -w CGO_ENABLED=1
  12. go env -w GOOS=linux
  13. go env -w GOARCH=${GOARCH}
  14. # Generate Swagger documentation if DOCS is not empty
  15. if [ -n "${DOCS}" ]; then
  16. # Check if swag is installed
  17. if ! command -v swag &> /dev/null; then
  18. echo "swag command not found. Please install it using:"
  19. echo "go install github.com/swaggo/swag/cmd/swag@latest"
  20. echo "Skipping Swagger documentation generation due to missing swag tool."
  21. else
  22. echo "Generating Swagger documentation..."
  23. swag init -g cmd/apimain.go --output docs/api --instanceName api --exclude http/controller/admin
  24. swag init -g cmd/apimain.go --output docs/admin --instanceName admin --exclude http/controller/api
  25. fi
  26. else
  27. echo "Skipping Swagger documentation generation due to DOCS is empty."
  28. fi
  29. # Compile the Go code and output it to the release directory
  30. go build -o release/apimain cmd/apimain.go
  31. # Copy resource files to the release directory
  32. cp -ar resources release/
  33. cp -ar docs release/
  34. cp -ar conf release/
  35. # Create necessary directory structures
  36. mkdir -p release/data
  37. mkdir -p release/runtime
  38. echo "Build and setup completed successfully."