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

Improve Dockerfile #135

Merged
merged 4 commits into from
Nov 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 75 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,95 @@ FROM python:3.10.1-alpine

ARG VERSION

###
# For a list of pre-defined annotation keys and value types see:
# https://github.com/opencontainers/image-spec/blob/master/annotations.md
#
# Note: Additional labels are added by the build workflow.
###
LABEL org.opencontainers.image.authors="[email protected]"
mcdonnnj marked this conversation as resolved.
Show resolved Hide resolved
LABEL org.opencontainers.image.vendor="Cybersecurity and Infrastructure Security Agency"

ARG CISA_UID=421
###
# Unprivileged user setup variables
###
ARG CISA_GID=421
ARG CISA_UID=${CISA_GID}
ENV CISA_USER="cisa"
ENV CISA_GROUP=${CISA_USER}
ENV CISA_HOME="/home/cisa"
jsf9k marked this conversation as resolved.
Show resolved Hide resolved
ENV ECHO_MESSAGE="Hello World from Dockerfile"

RUN addgroup --system --gid ${CISA_UID} cisa \
&& adduser --system --uid ${CISA_UID} --ingroup cisa cisa
###
# Unprivileged user setup dependencies
#
# Install shadow, so we have adduser and addgroup.
#
# Note that we use apk --no-cache to avoid writing to a local cache.
# This results in a smaller final image, at the cost of slightly
# longer install times.
#
# Setup user dependencies are only needed for setting up the user and
# will be removed at the end of that process.
###
ENV SETUP_USER_DEPS \
shadow
RUN apk --update --no-cache --quiet upgrade
RUN apk --no-cache --quiet add ${SETUP_USER_DEPS}

###
# Create unprivileged user
###
RUN addgroup --system --gid ${CISA_UID} ${CISA_GROUP} \
&& adduser --system --uid ${CISA_UID} --ingroup ${CISA_GROUP} ${CISA_USER}

###
# Remove build dependencies for unprivileged user
###
RUN apk --no-cache --quiet del ${SETUP_USER_DEPS}
mcdonnnj marked this conversation as resolved.
Show resolved Hide resolved

RUN apk --update --no-cache add \
ca-certificates \
openssl \
py-pip
###
# Dependencies
#
# Note that we use apk --no-cache to avoid writing to a local cache.
# This results in a smaller final image, at the cost of slightly
# longer install times.
###
ENV DEPS \
ca-certificates \
openssl \
py-pip
RUN apk --no-cache --quiet add ${DEPS}

###
# Make sure pip and setuptools are the latest versions
#
# Note that we use pip --no-cache-dir to avoid writing to a local
# cache. This results in a smaller final image, at the cost of
# slightly longer install times.
###
RUN pip install --no-cache-dir --upgrade pip setuptools

WORKDIR ${CISA_HOME}

RUN wget -O sourcecode.tgz https://github.com/cisagov/skeleton-python-library/archive/v${VERSION}.tar.gz && \
tar xzf sourcecode.tgz --strip-components=1 && \
pip install --requirement requirements.txt && \
ln -snf /run/secrets/quote.txt src/example/data/secret.txt && \
rm sourcecode.tgz
###
# Install Python dependencies
#
# Note that we use pip --no-cache-dir to avoid writing to a local
# cache. This results in a smaller final image, at the cost of
# slightly longer install times.
###
RUN wget --output-document sourcecode.tgz \
https://github.com/cisagov/skeleton-python-library/archive/v${VERSION}.tar.gz && \
tar --extract --gzip --file sourcecode.tgz --strip-components=1 && \
pip install --no-cache-dir --requirement requirements.txt && \
ln -snf /run/secrets/quote.txt src/example/data/secret.txt && \
rm sourcecode.tgz
jsf9k marked this conversation as resolved.
Show resolved Hide resolved

###
# Prepare to run
###
ENV ECHO_MESSAGE="Hello World from Dockerfile"
USER cisa

EXPOSE 8080/TCP
VOLUME ["/var/log"]
ENTRYPOINT ["example"]
Expand Down