Skip to content

Commit

Permalink
Update and refactor Dockerfiles
Browse files Browse the repository at this point in the history
Signed-off-by: jamshale <[email protected]>
  • Loading branch information
jamshale committed Dec 2, 2024
1 parent cdabab6 commit fdb66e8
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 63 deletions.
54 changes: 23 additions & 31 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ FROM python:${python_version}-slim-bullseye AS build

WORKDIR /src

ADD . .
COPY . .

RUN pip install --no-cache-dir poetry
RUN poetry build
RUN pip install --no-cache-dir poetry && \
poetry build

FROM python:${python_version}-slim-bullseye AS main

ARG uid=1001
ARG user=aries
ARG acapy_name="aries-cloudagent"
ARG acapy_name="acapy"
ARG acapy_version
ARG acapy_reqs=[askar,didcommv2]
ARG acapy_reqs=[didcommv2]

ENV HOME="/home/$user" \
APP_ROOT="$HOME" \
Expand All @@ -26,7 +26,7 @@ ENV HOME="/home/$user" \
RUST_LOG=warn \
SHELL=/bin/bash \
SUMMARY="$acapy_name image" \
DESCRIPTION="$acapy_name provides a base image for running Hyperledger Aries agents in Docker. \
DESCRIPTION="$acapy_name provides a base image for running ACA-Py agents in Docker. \
This image layers the python implementation of $acapy_name $acapy_version. Based on Debian Buster."

LABEL summary="$SUMMARY" \
Expand All @@ -38,15 +38,14 @@ LABEL summary="$SUMMARY" \
maintainer=""

# Add aries user
RUN useradd -U -ms /bin/bash -u $uid $user

# Install environment
RUN apt-get update -y && \
# Add aries user and install environment
RUN useradd -U -ms /bin/bash -u "$uid" "$user" && \
apt-get update -y && \
apt-get install -y --no-install-recommends \
apt-transport-https \
ca-certificates \
build-essential \
bzip2 \
ca-certificates \
curl \
git \
less \
Expand All @@ -71,24 +70,17 @@ ENV PATH="$HOME/.local/bin:$PATH"
# - In order to drop the root user, we have to make some directories writable
# to the root group as OpenShift default security model is to run the container
# under random UID.
RUN usermod -a -G 0 $user

# Create standard directories to allow volume mounting and set permissions
# Note: PIP_NO_CACHE_DIR environment variable should be cleared to allow caching
RUN mkdir -p \
$HOME/.acapy_agent \
$HOME/.cache/pip/http \
$HOME/.indy_client \
$HOME/ledger/sandbox/data \
$HOME/log

# The root group needs access the directories under $HOME/.indy_client and $HOME/.acapy_agent for the container to function in OpenShift.
RUN chown -R $user:root $HOME/.indy_client $HOME/.acapy_agent && \
chmod -R ug+rw $HOME/log $HOME/ledger $HOME/.acapy_agent $HOME/.cache $HOME/.indy_client

# Create /home/indy and symlink .indy_client folder for backwards compatibility with artifacts created on older indy-based images.
RUN mkdir -p /home/indy
RUN ln -s /home/aries/.indy_client /home/indy/.indy_client
RUN usermod -a -G 0 "$user" && \
mkdir -p \
"$HOME"/.acapy_agent \
"$HOME"/.cache/pip/http \
"$HOME"/.indy_client \
"$HOME"/ledger/sandbox/data \
"$HOME"/log && \
chown -R "$user":root "$HOME"/.indy_client "$HOME"/.acapy_agent && \
chmod -R ug+rw "$HOME"/log "$HOME"/ledger "$HOME"/.acapy_agent "$HOME"/.cache "$HOME"/.indy_client && \
mkdir -p /home/indy && \
ln -s /home/aries/.indy_client /home/indy/.indy_client

# Install ACA-py from the wheel as $user,
# and ensure the permissions on the python 'site-packages' and $HOME/.local folders are set correctly.
Expand All @@ -98,9 +90,9 @@ RUN acapy_agent_package=$(find ./ -name "acapy_agent*.whl" | head -n 1) && \
echo "Installing ${acapy_agent_package} ..." && \
pip install --no-cache-dir --find-links=. ${acapy_agent_package}${acapy_reqs} && \
rm acapy_agent*.whl && \
chmod +rx $(python -m site --user-site) $HOME/.local
chmod +rx $(python -m site --user-site) "$HOME"/.local

# Clean-up unneccessary build dependencies and reduce final image size
# Clean-up unnecessary build dependencies and reduce final image size
USER root
RUN apt-get purge -y --auto-remove build-essential

Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile.bdd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM faber-alice-demo
# Install bdd dependencies
RUN pip3 install --no-cache-dir -r demo/requirements.behave.txt

WORKDIR ./demo
ADD demo/multi_ledger_config_bdd.yml ./demo/multi_ledger_config.yml
WORKDIR /app/demo
COPY demo/multi_ledger_config_bdd.yml ./demo/multi_ledger_config.yml
RUN chmod a+w .
ENTRYPOINT ["behave"]
31 changes: 16 additions & 15 deletions docker/Dockerfile.demo
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,30 @@ ENV ENABLE_PTVSD 0
ENV ENABLE_PYDEVD_PYCHARM 0
ENV PYDEVD_PYCHARM_HOST "host.docker.internal"

RUN mkdir -p bin && curl -L -o bin/jq \
https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 && \
chmod ug+x bin/jq
RUN mkdir -p bin
ADD https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 bin/jq
RUN chmod ug+x bin/jq && \
pip install --no-cache-dir poetry

# Add and install Aries Agent code
RUN pip install --no-cache-dir poetry

ADD README.md pyproject.toml poetry.lock ./
COPY README.md pyproject.toml poetry.lock ./

ARG all_extras=0
RUN if ! [ -z ${all_extras} ]; then poetry install --no-root --no-directory --all-extras; else poetry install --no-root --no-directory -E "askar didcommv2"; fi

ADD acapy_agent ./acapy_agent
ADD scripts ./scripts
RUN if ! [ -z ${all_extras} ]; then \
poetry install --no-root --no-directory --all-extras; \
else \
poetry install --no-root --no-directory -E "didcommv2"; \
fi

RUN pip3 install --no-cache-dir -e .
COPY acapy_agent ./acapy_agent
COPY scripts ./scripts

RUN mkdir demo && chown -R aries:aries demo && chmod -R ug+rw demo
RUN pip3 install --no-cache-dir -e . && \
mkdir demo && chown -R aries:aries demo && chmod -R ug+rw demo

# Add and install demo code
ADD demo/requirements.txt ./demo/requirements.txt
COPY demo/requirements.txt ./demo/requirements.txt
RUN pip3 install --no-cache-dir -r demo/requirements.txt

ADD demo ./demo
COPY demo ./demo

ENTRYPOINT ["bash", "-c", "demo/ngrok-wait.sh \"$@\"", "--"]
19 changes: 8 additions & 11 deletions docker/Dockerfile.run
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,21 @@ FROM python:3.12-slim-bullseye

RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
libsodium23 git curl && \
curl git libsodium23 && \
apt-get install -y curl && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

WORKDIR /usr/src/app

# For consistency with base images, include curl for healthchecks
RUN apt-get update && apt-get install -y curl && apt-get clean

RUN pip install --no-cache-dir poetry

RUN mkdir -p acapy_agent && touch acapy_agent/__init__.py
ADD pyproject.toml poetry.lock README.md ./
RUN mkdir -p log && chmod -R ug+rw log
RUN pip install --no-cache-dir poetry && \
mkdir -p acapy_agent && touch acapy_agent/__init__.py && \
mkdir -p log && chmod -R ug+rw log
COPY pyproject.toml poetry.lock README.md ./

ARG all_extras=0
RUN if ! [ -z ${all_extras} ]; then poetry install --all-extras; else poetry install -E "askar didcommv2"; fi
RUN if ! [ -z ${all_extras} ]; then poetry install --all-extras; else poetry install -E "didcommv2"; fi

ADD . .
COPY . .

ENTRYPOINT ["/bin/bash", "-c", "poetry run aca-py \"$@\"", "--"]
12 changes: 8 additions & 4 deletions docker/Dockerfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@ FROM python:${python_version}-slim-bullseye

RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
libsodium23 git curl && \
curl git libsodium23 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

WORKDIR /usr/src/app

RUN pip install --no-cache-dir poetry

ADD ./README.md pyproject.toml ./poetry.lock ./
COPY ./README.md pyproject.toml ./poetry.lock ./
RUN mkdir acapy_agent && touch acapy_agent/__init__.py

ARG all_extras=0
RUN if ! [ -z ${all_extras} ]; then poetry install --no-directory --all-extras --with=dev; else poetry install --no-directory -E "askar didcommv2" --with=dev; fi
RUN if ! [ -z ${all_extras} ]; then \
poetry install --no-directory --all-extras --with=dev; \
else \
poetry install --no-directory -E "didcommv2" --with=dev; \
fi

ADD . .
COPY . .

ENTRYPOINT ["/bin/bash", "-c", "poetry run pytest \"$@\"", "--"]

0 comments on commit fdb66e8

Please sign in to comment.