2
0

Dockerfile 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. FROM --platform=$BUILDPLATFORM golang:1.24-alpine3.20 AS build-env
  2. WORKDIR /app
  3. # This ensures that CGO is disabled for go test running AND for the build
  4. # step. This prevents a build failure when building an ARM64 image with
  5. # docker buildx. I believe this is because the ARM64 version of the
  6. # golang:latest image does not contain GCC, while the AMD64 version does.
  7. ARG CGO_ENABLED=0
  8. # Get dependencies - will also be cached if we won't change mod/sum
  9. COPY go.* .
  10. COPY core/go.* core/
  11. COPY modules/collector-source/go.* modules/collector-source/
  12. COPY modules/prometheus-source/go.* modules/prometheus-source/
  13. RUN go mod download
  14. ARG version=dev
  15. ARG commit=HEAD
  16. ARG TARGETOS
  17. ARG TARGETARCH
  18. ENV GOOS=$TARGETOS
  19. ENV GOARCH=$TARGETARCH
  20. # COPY the source code as the last step
  21. COPY . .
  22. # Build the binary
  23. RUN set -e ;\
  24. cd cmd/costmodel;\
  25. go build -a -installsuffix cgo \
  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 /go/bin/app
  30. FROM alpine:latest
  31. LABEL org.opencontainers.image.description="Cross-cloud cost allocation models for Kubernetes workloads"
  32. LABEL org.opencontainers.image.documentation=https://opencost.io/docs/
  33. LABEL org.opencontainers.image.licenses=Apache-2.0
  34. LABEL org.opencontainers.image.source=https://github.com/opencost/opencost
  35. LABEL org.opencontainers.image.title=kubecost-cost-model
  36. LABEL org.opencontainers.image.url=https://opencost.io
  37. RUN apk add --update --no-cache ca-certificates
  38. COPY --from=build-env /go/bin/app /go/bin/app
  39. ADD --chmod=400 ./THIRD_PARTY_LICENSES.txt /THIRD_PARTY_LICENSES.txt
  40. ADD --chmod=500 ./configs/default.json /models/default.json
  41. ADD --chmod=500 ./configs/azure.json /models/azure.json
  42. ADD --chmod=500 ./configs/aws.json /models/aws.json
  43. ADD --chmod=500 ./configs/gcp.json /models/gcp.json
  44. ADD --chmod=500 ./configs/alibaba.json /models/alibaba.json
  45. ADD --chmod=500 ./configs/oracle.json /models/oracle.json
  46. ADD --chmod=500 ./configs/otc.json /models/otc.json
  47. RUN chown -R 1001:1001 /models
  48. USER 1001
  49. ENTRYPOINT ["/go/bin/app"]