2
0

justfile 3.2 KB

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