justfile 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. commonenv := "CGO_ENABLED=0"
  2. version := `./tools/image-tag`
  3. commit := `git rev-parse --short HEAD`
  4. default:
  5. just --list
  6. # run core unit tests
  7. test-core:
  8. {{commonenv}} cd ./core && go test ./... -coverprofile=coverage.out
  9. {{commonenv}} cd ./core && go vet ./...
  10. # run prometheus-source unit tests
  11. test-prometheus-source:
  12. {{commonenv}} cd ./modules/prometheus-source && go test ./... -coverprofile=coverage.out
  13. {{commonenv}} cd ./modules/prometheus-source && go vet ./...
  14. # run collector-source unit tests
  15. test-collector-source:
  16. {{commonenv}} cd ./modules/collector-source && go test ./... -coverprofile=coverage.out
  17. {{commonenv}} cd ./modules/collector-source && go vet ./...
  18. # Run unit tests
  19. test: test-core test-prometheus-source test-collector-source
  20. {{commonenv}} go test ./... -coverprofile=coverage.out
  21. {{commonenv}} go vet ./...
  22. # Run unit tests and integration tests
  23. test-integration:
  24. {{commonenv}} INTEGRATION=true go test ./... -coverprofile=coverage.out
  25. # Compile a local binary
  26. build-local:
  27. cd ./cmd/costmodel && \
  28. {{commonenv}} go build \
  29. -ldflags \
  30. "-X github.com/opencost/opencost/core/pkg/version.Version={{version}} \
  31. -X github.com/opencost/opencost/core/pkg/version.GitCommit={{commit}}" \
  32. -o ./costmodel
  33. # Build multiarch binaries
  34. build-binary VERSION=version:
  35. cd ./cmd/costmodel && \
  36. {{commonenv}} GOOS=linux GOARCH=amd64 go build \
  37. -ldflags \
  38. "-X github.com/opencost/opencost/core/pkg/version.Version={{VERSION}} \
  39. -X github.com/opencost/opencost/core/pkg/version.GitCommit={{commit}}" \
  40. -o ./costmodel-amd64
  41. cd ./cmd/costmodel && \
  42. {{commonenv}} GOOS=linux GOARCH=arm64 go build \
  43. -ldflags \
  44. "-X github.com/opencost/opencost/core/pkg/version.Version={{VERSION}} \
  45. -X github.com/opencost/opencost/core/pkg/version.GitCommit={{commit}}" \
  46. -o ./costmodel-arm64
  47. # Build and push a multi-arch Docker image
  48. build IMAGE_TAG RELEASE_VERSION: (build-binary RELEASE_VERSION)
  49. docker buildx build \
  50. --rm \
  51. --platform "linux/amd64" \
  52. -f 'Dockerfile.cross' \
  53. --build-arg binarypath=./cmd/costmodel/costmodel-amd64 \
  54. --build-arg version={{RELEASE_VERSION}} \
  55. --build-arg commit={{commit}} \
  56. --provenance=false \
  57. -t {{IMAGE_TAG}}-amd64 \
  58. --push \
  59. .
  60. docker buildx build \
  61. --rm \
  62. --platform "linux/arm64" \
  63. -f 'Dockerfile.cross' \
  64. --build-arg binarypath=./cmd/costmodel/costmodel-arm64 \
  65. --build-arg version={{RELEASE_VERSION}} \
  66. --build-arg commit={{commit}} \
  67. --provenance=false \
  68. -t {{IMAGE_TAG}}-arm64 \
  69. --push \
  70. .
  71. manifest-tool push from-args \
  72. --platforms "linux/amd64,linux/arm64" \
  73. --template {{IMAGE_TAG}}-ARCH \
  74. --target {{IMAGE_TAG}}
  75. validate-protobuf:
  76. ./generate.sh
  77. git diff --exit-code