justfile 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. commonenv := "CGO_ENABLED=0"
  2. version := `./tools/image-tag`
  3. commit := `git rev-parse --short HEAD`
  4. default:
  5. just --list
  6. # Run unit tests
  7. test:
  8. {{commonenv}} go test ./... -coverprofile=coverage.out
  9. {{commonenv}} go vet ./...
  10. # Compile a local binary
  11. build-local:
  12. cd ./cmd/costmodel && \
  13. {{commonenv}} go build \
  14. -ldflags \
  15. "-X github.com/opencost/opencost/pkg/version.Version={{version}} \
  16. -X github.com/opencost/opencost/pkg/version.GitCommit={{commit}}" \
  17. -o ./costmodel
  18. # Build multiarch binaries
  19. build-binary VERSION=version:
  20. cd ./cmd/costmodel && \
  21. {{commonenv}} GOOS=linux GOARCH=amd64 go build \
  22. -ldflags \
  23. "-X github.com/opencost/opencost/pkg/version.Version={{VERSION}} \
  24. -X github.com/opencost/opencost/pkg/version.GitCommit={{commit}}" \
  25. -o ./costmodel-amd64
  26. cd ./cmd/costmodel && \
  27. {{commonenv}} GOOS=linux GOARCH=arm64 go build \
  28. -ldflags \
  29. "-X github.com/opencost/opencost/pkg/version.Version={{VERSION}} \
  30. -X github.com/opencost/opencost/pkg/version.GitCommit={{commit}}" \
  31. -o ./costmodel-arm64
  32. # Build and push a multi-arch Docker image
  33. build IMAGETAG VERSION=version: test (build-binary VERSION)
  34. docker buildx build \
  35. --rm \
  36. --platform "linux/amd64" \
  37. -f 'Dockerfile.cross' \
  38. --build-arg binarypath=./cmd/costmodel/costmodel-amd64 \
  39. --provenance=false \
  40. -t {{IMAGETAG}}-amd64 \
  41. --push \
  42. .
  43. docker buildx build \
  44. --rm \
  45. --platform "linux/arm64" \
  46. -f 'Dockerfile.cross' \
  47. --build-arg binarypath=./cmd/costmodel/costmodel-arm64 \
  48. --provenance=false \
  49. -t {{IMAGETAG}}-arm64 \
  50. --push \
  51. .
  52. manifest-tool push from-args \
  53. --platforms "linux/amd64,linux/arm64" \
  54. --template {{IMAGETAG}}-ARCH \
  55. --target {{IMAGETAG}}