# syntax=docker/dockerfile:experimental # Stage: prepare go test and build FROM golang:1.12 AS prepare RUN go get github.com/golang/dep/cmd/dep && \ go get golang.org/x/lint/golint RUN mkdir -p /app ADD Gopkg.toml Gopkg.lock /app WORKDIR /app RUN --mount=type=cache,target=/go/pkg/dep \ dep ensure --vendor-only ADD . /app # Stage: build go application FROM prepare AS build RUN go build -ldflags=$(BUILD_LDFLAGS) -o ./app # Stage: build container image FROM debian:stretch-slim RUN apt-get update -yq && \ apt-get install -yq ca-certificates && \ rm -rfv /var/lib/apt RUN mkdir -p /app COPY --from=build /app/app /