justfile 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 unit tests
  11. test: test-core
  12. {{commonenv}} go test ./... -coverprofile=coverage.out
  13. {{commonenv}} go tool cover -html=coverage.out -o coverage.html
  14. {{commonenv}} go vet ./...
  15. # Run unit tests and integration tests
  16. test-integration:
  17. {{commonenv}} INTEGRATION=true go test ./... -coverprofile=coverage.out
  18. # Compile a local binary
  19. build-local:
  20. cd ./cmd/costmodel && \
  21. {{commonenv}} go build \
  22. -ldflags \
  23. "-X github.com/opencost/opencost/core/pkg/version.Version={{version}} \
  24. -X github.com/opencost/opencost/core/pkg/version.GitCommit={{commit}}" \
  25. -o ./costmodel
  26. # Build multiarch binaries
  27. build-binary VERSION=version:
  28. cd ./cmd/costmodel && \
  29. {{commonenv}} GOOS=linux GOARCH=amd64 go build \
  30. -ldflags \
  31. "-X github.com/opencost/opencost/core/pkg/version.Version={{VERSION}} \
  32. -X github.com/opencost/opencost/core/pkg/version.GitCommit={{commit}}" \
  33. -o ./costmodel-amd64
  34. cd ./cmd/costmodel && \
  35. {{commonenv}} GOOS=linux GOARCH=arm64 go build \
  36. -ldflags \
  37. "-X github.com/opencost/opencost/core/pkg/version.Version={{VERSION}} \
  38. -X github.com/opencost/opencost/core/pkg/version.GitCommit={{commit}}" \
  39. -o ./costmodel-arm64
  40. # Build and push a multi-arch Docker image
  41. build IMAGE_TAG RELEASE_VERSION: test (build-binary RELEASE_VERSION)
  42. docker buildx build \
  43. --rm \
  44. --platform "linux/amd64" \
  45. -f 'Dockerfile.cross' \
  46. --build-arg binarypath=./cmd/costmodel/costmodel-amd64 \
  47. --build-arg version={{RELEASE_VERSION}} \
  48. --build-arg commit={{commit}} \
  49. --provenance=false \
  50. -t {{IMAGE_TAG}}-amd64 \
  51. --push \
  52. .
  53. docker buildx build \
  54. --rm \
  55. --platform "linux/arm64" \
  56. -f 'Dockerfile.cross' \
  57. --build-arg binarypath=./cmd/costmodel/costmodel-arm64 \
  58. --build-arg version={{RELEASE_VERSION}} \
  59. --build-arg commit={{commit}} \
  60. --provenance=false \
  61. -t {{IMAGE_TAG}}-arm64 \
  62. --push \
  63. .
  64. manifest-tool push from-args \
  65. --platforms "linux/amd64,linux/arm64" \
  66. --template {{IMAGE_TAG}}-ARCH \
  67. --target {{IMAGE_TAG}}
  68. validate-protobuf:
  69. ./generate.sh
  70. git diff --exit-code