Dockerfile 1.9 KB

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