Dockerfile 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. 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/pkg/version.Version=${version} \
  26. -X github.com/opencost/opencost/pkg/version.GitCommit=${commit}" \
  27. -o /go/bin/app
  28. FROM alpine:latest
  29. RUN apk add --update --no-cache ca-certificates
  30. COPY --from=build-env /go/bin/app /go/bin/app
  31. ADD ./configs/default.json /models/default.json
  32. ADD ./configs/azure.json /models/azure.json
  33. ADD ./configs/aws.json /models/aws.json
  34. ADD ./configs/gcp.json /models/gcp.json
  35. USER 1001
  36. ENTRYPOINT ["/go/bin/app"]