justfile 2.3 KB

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