Dockerfile 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. # Get dependencies - will also be cached if we won't change mod/sum
  14. RUN go mod download
  15. # COPY the source code as the last step
  16. COPY . .
  17. # Build the binary
  18. RUN set -e ;\
  19. cd cmd/costmodel;\
  20. GOOS=linux \
  21. go build -a -installsuffix cgo \
  22. -ldflags \
  23. "-X github.com/opencost/opencost/pkg/version.Version=${version} \
  24. -X github.com/opencost/opencost/pkg/version.GitCommit=${commit}" \
  25. -o /go/bin/app
  26. FROM alpine:latest
  27. RUN apk add --update --no-cache ca-certificates
  28. COPY --from=build-env /go/bin/app /go/bin/app
  29. ADD --chmod=644 ./configs/default.json /models/default.json
  30. ADD --chmod=644 ./configs/azure.json /models/azure.json
  31. ADD --chmod=644 ./configs/aws.json /models/aws.json
  32. ADD --chmod=644 ./configs/gcp.json /models/gcp.json
  33. ADD --chmod=644 ./configs/alibaba.json /models/alibaba.json
  34. USER 1001
  35. ENTRYPOINT ["/go/bin/app"]