justfile 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 the opencost unit tests
  19. test-opencost:
  20. {{commonenv}} go test ./... -coverprofile=coverage.out
  21. {{commonenv}} go vet ./...
  22. # Run unit tests, merge coverage reports, remove old reports
  23. test: test-core test-prometheus-source test-collector-source test-opencost
  24. find . -name "coverage.out" -print0 | xargs -0 cat > coverage.new
  25. find . -name "coverage.out" -delete
  26. mv coverage.new coverage.out
  27. # Run unit tests and integration tests
  28. test-integration:
  29. {{commonenv}} INTEGRATION=true go test ./... -coverprofile=coverage.out
  30. # Compile a local binary
  31. build-local:
  32. cd ./cmd/costmodel && \
  33. {{commonenv}} go build \
  34. -ldflags \
  35. "-X github.com/opencost/opencost/core/pkg/version.Version={{version}} \
  36. -X github.com/opencost/opencost/core/pkg/version.GitCommit={{commit}}" \
  37. -o ./costmodel
  38. # Build multiarch binaries
  39. build-binary VERSION=version:
  40. cd ./cmd/costmodel && \
  41. {{commonenv}} GOOS=linux GOARCH=amd64 go build \
  42. -ldflags \
  43. "-X github.com/opencost/opencost/core/pkg/version.Version={{VERSION}} \
  44. -X github.com/opencost/opencost/core/pkg/version.GitCommit={{commit}}" \
  45. -o ./costmodel-amd64
  46. cd ./cmd/costmodel && \
  47. {{commonenv}} GOOS=linux GOARCH=arm64 go build \
  48. -ldflags \
  49. "-X github.com/opencost/opencost/core/pkg/version.Version={{VERSION}} \
  50. -X github.com/opencost/opencost/core/pkg/version.GitCommit={{commit}}" \
  51. -o ./costmodel-arm64
  52. # Build and push a multi-arch Docker image
  53. build IMAGE_TAG RELEASE_VERSION: (build-binary RELEASE_VERSION)
  54. docker buildx build \
  55. --rm \
  56. --platform "linux/amd64" \
  57. -f 'Dockerfile.cross' \
  58. --build-arg binarypath=./cmd/costmodel/costmodel-amd64 \
  59. --build-arg version={{RELEASE_VERSION}} \
  60. --build-arg commit={{commit}} \
  61. --provenance=false \
  62. -t {{IMAGE_TAG}}-amd64 \
  63. --push \
  64. .
  65. docker buildx build \
  66. --rm \
  67. --platform "linux/arm64" \
  68. -f 'Dockerfile.cross' \
  69. --build-arg binarypath=./cmd/costmodel/costmodel-arm64 \
  70. --build-arg version={{RELEASE_VERSION}} \
  71. --build-arg commit={{commit}} \
  72. --provenance=false \
  73. -t {{IMAGE_TAG}}-arm64 \
  74. --push \
  75. .
  76. manifest-tool push from-args \
  77. --platforms "linux/amd64,linux/arm64" \
  78. --template {{IMAGE_TAG}}-ARCH \
  79. --target {{IMAGE_TAG}}
  80. validate-protobuf:
  81. ./generate.sh
  82. git diff --exit-code