Dockerfile 1019 B

12345678910111213141516171819202122232425262728293031323334
  1. FROM golang:latest as build-env
  2. RUN mkdir /app
  3. WORKDIR /app
  4. COPY go.mod .
  5. COPY go.sum .
  6. # Get dependencies - will also be cached if we won't change mod/sum
  7. RUN go mod download
  8. # COPY the source code as the last step
  9. COPY . .
  10. # Build the binary
  11. RUN set -e ;\
  12. GIT_COMMIT=`git rev-parse HEAD` ;\
  13. GIT_DIRTY='' ;\
  14. # for our purposes, we only care about dirty .go files ;\
  15. if test -n "`git status --porcelain --untracked-files=no | grep '\.go'`"; then \
  16. GIT_DIRTY='+dirty' ;\
  17. fi ;\
  18. cd cmd/costmodel;\
  19. CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
  20. go build -a -installsuffix cgo \
  21. -ldflags "-X main.gitCommit=${GIT_COMMIT}${GIT_DIRTY}" \
  22. -o /go/bin/app
  23. FROM alpine:3.10.2
  24. RUN apk add --update --no-cache ca-certificates
  25. COPY --from=build-env /go/bin/app /go/bin/app
  26. ADD ./configs/default.json /models/default.json
  27. ADD ./configs/azure.json /models/azure.json
  28. ADD ./configs/aws.json /models/aws.json
  29. ADD ./configs/gcp.json /models/gcp.json
  30. USER 1001
  31. ENTRYPOINT ["/go/bin/app"]