justfile 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. --build-arg version={{version}} \
  40. --build-arg commit={{commit}} \
  41. --provenance=false \
  42. -t {{IMAGETAG}}-amd64 \
  43. --push \
  44. .
  45. docker buildx build \
  46. --rm \
  47. --platform "linux/arm64" \
  48. -f 'Dockerfile.cross' \
  49. --build-arg binarypath=./cmd/costmodel/costmodel-arm64 \
  50. --build-arg version={{version}} \
  51. --build-arg commit={{commit}} \
  52. --provenance=false \
  53. -t {{IMAGETAG}}-arm64 \
  54. --push \
  55. .
  56. manifest-tool push from-args \
  57. --platforms "linux/amd64,linux/arm64" \
  58. --template {{IMAGETAG}}-ARCH \
  59. --target {{IMAGETAG}}