Dockerfile 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. FROM golang:latest 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 ./test/*.go;\
  20. go test ./pkg/*;\
  21. cd cmd/costmodel;\
  22. GOOS=linux \
  23. go build -a -installsuffix cgo \
  24. -ldflags \
  25. "-X github.com/opencost/opencost/core/pkg/version.Version=${version} \
  26. -X github.com/opencost/opencost/core/pkg/version.GitCommit=${commit}" \
  27. -o /go/bin/app
  28. FROM alpine:latest
  29. LABEL org.opencontainers.image.description="Cross-cloud cost allocation models for Kubernetes workloads"
  30. LABEL org.opencontainers.image.documentation=https://opencost.io/docs/
  31. LABEL org.opencontainers.image.licenses=Apache-2.0
  32. LABEL org.opencontainers.image.source=https://github.com/opencost/opencost
  33. LABEL org.opencontainers.image.title=kubecost-cost-model
  34. LABEL org.opencontainers.image.url=https://github.com/opencost/opencost
  35. RUN apk add --update --no-cache ca-certificates
  36. COPY --from=build-env /go/bin/app /go/bin/app
  37. ADD --chmod=644 ./configs/default.json /models/default.json
  38. ADD --chmod=644 ./configs/azure.json /models/azure.json
  39. ADD --chmod=644 ./configs/aws.json /models/aws.json
  40. ADD --chmod=644 ./configs/gcp.json /models/gcp.json
  41. ADD --chmod=644 ./configs/alibaba.json /models/alibaba.json
  42. ADD --chmod=644 ./configs/oracle.json /models/oracle.json
  43. USER 1001
  44. ENTRYPOINT ["/go/bin/app"]