Dockerfile 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  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. # Get dependencies - will also be cached if we won't change mod/sum
  12. RUN go mod download
  13. # COPY the source code as the last step
  14. COPY . .
  15. # Build the binary
  16. RUN set -e ;\
  17. go test ./test/*.go;\
  18. go test ./pkg/*;\
  19. cd cmd/costmodel;\
  20. GOOS=linux \
  21. go build -a -installsuffix cgo -o /go/bin/app
  22. FROM alpine:latest
  23. RUN apk add --update --no-cache ca-certificates
  24. COPY --from=build-env /go/bin/app /go/bin/app
  25. ADD ./configs/default.json /models/default.json
  26. ADD ./configs/azure.json /models/azure.json
  27. ADD ./configs/aws.json /models/aws.json
  28. ADD ./configs/gcp.json /models/gcp.json
  29. USER 1001
  30. ENTRYPOINT ["/go/bin/app"]