2
0

justfile 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. commonenv := "CGO_ENABLED=0"
  2. version := `./tools/image-tag`
  3. commit := `git rev-parse --short HEAD`
  4. default:
  5. just --list
  6. # format all Go code
  7. fmt:
  8. go fmt ./...
  9. # check if code is formatted
  10. fmt-check:
  11. #!/bin/sh
  12. echo "Checking code formatting..."
  13. unformatted="$(gofmt -l .)"
  14. if [ -n "$unformatted" ]; then \
  15. echo "The following files are not formatted:"; \
  16. echo "$unformatted"; \
  17. echo ""; \
  18. echo "Run 'just fmt' to format your code"; \
  19. exit 1; \
  20. fi
  21. echo "All files are properly formatted"
  22. # run core unit tests
  23. test-core:
  24. {{commonenv}} cd ./core && go test ./... -coverprofile=coverage.out
  25. {{commonenv}} cd ./core && go vet ./...
  26. # run prometheus-source unit tests
  27. test-prometheus-source:
  28. {{commonenv}} cd ./modules/prometheus-source && go test ./... -coverprofile=coverage.out
  29. {{commonenv}} cd ./modules/prometheus-source && go vet ./...
  30. # run collector-source unit tests
  31. test-collector-source:
  32. {{commonenv}} cd ./modules/collector-source && go test ./... -coverprofile=coverage.out
  33. {{commonenv}} cd ./modules/collector-source && go vet ./...
  34. # run the opencost unit tests
  35. test-opencost:
  36. {{commonenv}} go test ./... -coverprofile=coverage.out
  37. {{commonenv}} go tool cover -html=coverage.out -o coverage.html
  38. {{commonenv}} go vet ./...
  39. # Run unit tests, merge coverage reports, remove old reports
  40. test: test-core test-prometheus-source test-collector-source test-opencost
  41. find . -name "coverage.out" -print0 | xargs -0 cat > coverage.new
  42. find . -name "coverage.out" -delete
  43. mv coverage.new coverage.out
  44. # Run unit tests and integration tests
  45. test-integration:
  46. {{commonenv}} INTEGRATION=true go test ./... -coverprofile=coverage.out
  47. # Compile a local binary
  48. build-local:
  49. cd ./cmd/costmodel && \
  50. {{commonenv}} go build \
  51. -ldflags \
  52. "-X github.com/opencost/opencost/core/pkg/version.Version={{version}} \
  53. -X github.com/opencost/opencost/core/pkg/version.GitCommit={{commit}}" \
  54. -o ./costmodel
  55. # Build multiarch binaries
  56. build-binary VERSION=version:
  57. cd ./cmd/costmodel && \
  58. {{commonenv}} GOOS=linux GOARCH=amd64 go build \
  59. -ldflags \
  60. "-X github.com/opencost/opencost/core/pkg/version.Version={{VERSION}} \
  61. -X github.com/opencost/opencost/core/pkg/version.GitCommit={{commit}}" \
  62. -o ./costmodel-amd64
  63. cd ./cmd/costmodel && \
  64. {{commonenv}} GOOS=linux GOARCH=arm64 go build \
  65. -ldflags \
  66. "-X github.com/opencost/opencost/core/pkg/version.Version={{VERSION}} \
  67. -X github.com/opencost/opencost/core/pkg/version.GitCommit={{commit}}" \
  68. -o ./costmodel-arm64
  69. # Build and push a multi-arch Docker image
  70. build IMAGE_TAG RELEASE_VERSION: (build-binary RELEASE_VERSION)
  71. docker buildx build \
  72. --rm \
  73. --platform "linux/amd64" \
  74. -f 'Dockerfile.cross' \
  75. --build-arg binarypath=./cmd/costmodel/costmodel-amd64 \
  76. --build-arg version={{RELEASE_VERSION}} \
  77. --build-arg commit={{commit}} \
  78. --provenance=false \
  79. -t {{IMAGE_TAG}}-amd64 \
  80. --push \
  81. .
  82. docker buildx build \
  83. --rm \
  84. --platform "linux/arm64" \
  85. -f 'Dockerfile.cross' \
  86. --build-arg binarypath=./cmd/costmodel/costmodel-arm64 \
  87. --build-arg version={{RELEASE_VERSION}} \
  88. --build-arg commit={{commit}} \
  89. --provenance=false \
  90. -t {{IMAGE_TAG}}-arm64 \
  91. --push \
  92. .
  93. manifest-tool push from-args \
  94. --platforms "linux/amd64,linux/arm64" \
  95. --template {{IMAGE_TAG}}-ARCH \
  96. --target {{IMAGE_TAG}}
  97. validate-protobuf:
  98. ./generate.sh
  99. git diff --exit-code