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

Add Docker build target for container that doesn't run as root #174

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
33 changes: 25 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ RUN echo "cloning ${BRANCH}" && \
/bin/sh ./install.sh

# IMAGE BUILD
FROM python:3.9-slim
FROM python:3.9-slim AS no-root

ARG UID=1000
ARG GID=1000

EXPOSE 8555 8444

ENV CHIA_ROOT=/root/.chia/mainnet
ENV CHIA_ROOT=/home/chia/.chia/mainnet
ENV keys="generate"
ENV service="farmer"
ENV plots_dir="/plots"
Expand All @@ -43,22 +46,36 @@ ENV farmer="false"
# tzdata: Setting the timezone
# curl: Health-checks
RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y sudo tzdata curl && \
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y tzdata curl && \
rm -rf /var/lib/apt/lists/* && \
ln -snf "/usr/share/zoneinfo/$TZ" /etc/localtime && echo "$TZ" > /etc/timezone && \
dpkg-reconfigure -f noninteractive tzdata
dpkg-reconfigure -f noninteractive tzdata && \
groupadd -g "${GID}" chia && \
useradd -m -u "${UID}" -g "${GID}" chia && \
mkdir /plots && \
chown -R chia:chia /home/chia /plots

COPY --from=chia_build /chia-blockchain /chia-blockchain
COPY --chown=chia:chia --from=chia_build /chia-blockchain /chia-blockchain

ENV PATH=/chia-blockchain/venv/bin:$PATH
WORKDIR /chia-blockchain

COPY docker-start.sh /usr/local/bin/
COPY docker-entrypoint.sh /usr/local/bin/
COPY docker-healthcheck.sh /usr/local/bin/
COPY docker-start.sh docker-entrypoint.sh docker-healthcheck.sh /usr/local/bin/

HEALTHCHECK --interval=1m --timeout=10s --start-period=20m \
CMD /bin/bash /usr/local/bin/docker-healthcheck.sh || exit 1

USER chia:chia

ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["docker-start.sh"]

FROM no-root

USER root:root

ENV CHIA_ROOT=/root/.chia/mainnet

RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y sudo && \
rm -rf /var/lib/apt/lists/*
6 changes: 0 additions & 6 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
#!/usr/bin/env bash

# shellcheck disable=SC2154
if [[ -n "${TZ}" ]]; then
echo "Setting timezone to ${TZ}"
ln -snf "/usr/share/zoneinfo/$TZ" /etc/localtime && echo "$TZ" > /etc/timezone
fi

cd /chia-blockchain || exit 1

# shellcheck disable=SC1091
Expand Down