2020-05-10 11:15:35 +00:00
|
|
|
FROM golang:1.14-alpine as build
|
2020-04-01 02:08:21 +00:00
|
|
|
|
|
|
|
# Create appuser.
|
|
|
|
ARG USER=inetmock
|
|
|
|
ARG USER_ID=10001
|
|
|
|
|
|
|
|
ENV CGO_ENABLED=0
|
|
|
|
|
|
|
|
# Prepare build stage - can be cached
|
|
|
|
WORKDIR /work
|
2020-05-10 11:15:35 +00:00
|
|
|
RUN apk add -U --no-cache \
|
|
|
|
make protoc gcc musl-dev && \
|
2020-04-01 02:08:21 +00:00
|
|
|
adduser \
|
|
|
|
--disabled-password \
|
|
|
|
--gecos "" \
|
|
|
|
--home "/nonexistent" \
|
|
|
|
--shell "/sbin/nologin" \
|
|
|
|
--no-create-home \
|
|
|
|
--uid "${USER_ID}" \
|
|
|
|
"${USER}"
|
|
|
|
|
|
|
|
# Fetch dependencies
|
|
|
|
COPY Makefile go.mod go.sum ./
|
2020-05-10 11:15:35 +00:00
|
|
|
RUN go mod download && \
|
|
|
|
go get -u github.com/golang/mock/mockgen@latest && \
|
|
|
|
go install github.com/golang/protobuf/protoc-gen-go
|
2020-04-01 02:08:21 +00:00
|
|
|
|
|
|
|
COPY ./ ./
|
|
|
|
|
|
|
|
# Build binary and plugins
|
|
|
|
RUN make CONTAINER=yes
|
|
|
|
|
|
|
|
# Runtime layer
|
|
|
|
|
|
|
|
FROM scratch
|
|
|
|
|
2020-04-01 22:58:44 +00:00
|
|
|
ENV INETMOCK_PLUGINS_DIRECTORY=/app/plugins/
|
|
|
|
|
2020-04-01 02:08:21 +00:00
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
COPY --from=build /etc/passwd /etc/group /etc/
|
|
|
|
COPY --from=build --chown=$USER /work/inetmock ./
|
2020-04-25 22:22:45 +00:00
|
|
|
COPY --from=build --chown=$USER /work/*.so ./plugins/
|
2020-04-01 02:08:21 +00:00
|
|
|
|
|
|
|
USER $USER:$USER
|
|
|
|
|
2020-04-25 22:22:45 +00:00
|
|
|
ENTRYPOINT ["/app/inetmock"]
|