Dockerfile 1.1 KB

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