Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Dockerfile, use scratch as base image, make static binary #46

Merged
merged 2 commits into from
Feb 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 24 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,41 +1,47 @@
ARG HOMEDIR=/opt/gatekeeper

#
# Builder image
# Builder
#

FROM golang:1.14.4 AS build-env
p53 marked this conversation as resolved.
Show resolved Hide resolved
ARG SOURCE=*
ARG HOMEDIR

ADD $SOURCE /src/
WORKDIR /src/

# Unpack any tars, then try to execute a Makefile, but if the SOURCE url is
# just a tar of binaries, then there probably won't be one. Using multiple RUN
# commands to ensure any errors are caught.
RUN find . -name '*.tar.gz' -type f | xargs -rn1 tar -xzf
RUN if [ -f Makefile ]; then make; fi
RUN cp "$(find . -name 'gatekeeper' -type f -print -quit)" /gatekeeper
RUN make static

WORKDIR ${HOMEDIR}

RUN cp /src/bin/gatekeeper .
COPY templates ./templates

RUN echo "gatekeeper:x:1000:gatekeeper" >> /etc/group && \
echo "gatekeeper:x:1000:1000:gatekeeper user:${HOMEDIR}:/sbin/nologin" >> /etc/passwd && \
chown -R gatekeeper:gatekeeper ${HOMEDIR} && \
chmod -R g+rw ${HOMEDIR} && \
chmod +x gatekeeper

#
# Actual image
#

FROM registry.access.redhat.com/ubi8/ubi-minimal:8.3
FROM scratch
ARG HOMEDIR

LABEL Name=gatekeeper \
Release=https://github.com/gogatekeeper/gatekeeper \
Url=https://github.com/gogatekeeper/gatekeeper \
Help=https://github.com/gogatekeeper/gatekeeper/issues

WORKDIR "/opt/gatekeeper"

RUN echo "gatekeeper:x:1000:gatekeeper" >> /etc/group && \
echo "gatekeeper:x:1000:1000:gatekeeper user:/opt/gatekeeper:/sbin/nologin" >> /etc/passwd && \
chown -R gatekeeper:gatekeeper /opt/gatekeeper && \
chmod -R g+rw /opt/gatekeeper

COPY templates ./templates
COPY --from=build-env /gatekeeper ./
RUN chmod +x gatekeeper
COPY --from=build-env ${HOMEDIR} ${HOMEDIR}
COPY --from=build-env /etc/passwd /etc/passwd
COPY --from=build-env /etc/group /etc/group
p53 marked this conversation as resolved.
Show resolved Hide resolved
COPY --from=build-env /usr/share/ca-certificates /usr/share/ca-certificates
COPY --from=build-env /etc/ssl/certs /etc/ssl/certs

WORKDIR ${HOMEDIR}
USER 1000
p53 marked this conversation as resolved.
Show resolved Hide resolved
ENTRYPOINT [ "/opt/gatekeeper/gatekeeper" ]