| 1 |
FROM golang:1.15 as build |
| 2 |
|
| 3 |
# Create appuser. |
| 4 |
# See https://stackoverflow.com/a/55757473/12429735 |
| 5 |
ENV USER=appuser |
| 6 |
ENV UID=10001 |
| 7 |
RUN adduser \ |
| 8 |
--disabled-password \ |
| 9 |
--gecos "" \ |
| 10 |
--home "/nonexistent" \ |
| 11 |
--shell "/sbin/nologin" \ |
| 12 |
--no-create-home \ |
| 13 |
--uid "${UID}" \ |
| 14 |
"${USER}" |
| 15 |
|
| 16 |
RUN apt-get update && apt-get install -y ca-certificates |
| 17 |
RUN go get github.com/rakyll/hey |
| 18 |
|
| 19 |
# Build |
| 20 |
WORKDIR /go/src/github.com/rakyll/hey |
| 21 |
RUN go mod download |
| 22 |
RUN CGO_ENABLED=0 GOOS=linux go build -o /go/bin/hey hey.go |
| 23 |
|
| 24 |
############################################################################### |
| 25 |
# final stage |
| 26 |
FROM scratch |
| 27 |
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ |
| 28 |
COPY --from=build /etc/passwd /etc/passwd |
| 29 |
COPY --from=build /etc/group /etc/group |
| 30 |
USER appuser:appuser |
| 31 |
|
| 32 |
ARG APPLICATION="hey" |
| 33 |
ARG DESCRIPTION="HTTP load generator, ApacheBench (ab) replacement, formerly known as rakyll/boom" |
| 34 |
ARG PACKAGE="rakyll/hey" |
| 35 |
|
| 36 |
LABEL org.opencontainers.image.ref.name="${PACKAGE}" \ |
| 37 |
org.opencontainers.image.authors="Jaana Dogan <@rakyll>" \ |
| 38 |
org.opencontainers.image.documentation="https://github.com/${PACKAGE}/README.md" \ |
| 39 |
org.opencontainers.image.description="${DESCRIPTION}" \ |
| 40 |
org.opencontainers.image.licenses="Apache 2.0" \ |
| 41 |
org.opencontainers.image.source="https://github.com/${PACKAGE}" |
| 42 |
|
| 43 |
COPY --from=build /go/bin/${APPLICATION} /hey |
| 44 |
ENTRYPOINT ["/hey"] |