From b6cbd885191b627d64ba0db61f8bd3886cf9b708 Mon Sep 17 00:00:00 2001 From: Brian Koopman Date: Fri, 2 Aug 2024 15:50:47 -0400 Subject: [PATCH] Remove old compiled spt3g/so3g layers from Docker image (#397) * Switch to directly using ubuntu:22.04 base image This cuts out the spt3g-docker and so3g layers in the image build. ocs will pull in so3g from pip, these extra layers were from when we needed to compile spt3g_software and so3g prior to so3g becoming pip installable. * Setup and use virtualenv within image * Update pip within venv * Document use of virtualenv in developers page about Docker * Replace lingering python3 with python --- Dockerfile | 23 ++++++++++++++++++----- docs/developer/docker.rst | 13 +++++++++---- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6c82e097..7aa5423e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,11 @@ # A container setup with an installation of ocs. # Use ubuntu base image -FROM simonsobs/so3g:v0.1.3-13-g5471f0d +FROM ubuntu:22.04 + +# Set timezone to UTC +ENV TZ=Etc/UTC +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone # Set locale ENV LANG C.UTF-8 @@ -22,12 +26,21 @@ ENV OCS_CONFIG_DIR=/config ENV PYTHONUNBUFFERED=1 # Install python and pip -RUN apt-get update && apt-get install -y python3 \ +RUN apt-get update && apt-get install -y \ + git \ + python3 \ python3-pip \ + python3-virtualenv \ + python-is-python3 \ vim +# Setup virtualenv +RUN python -m virtualenv /opt/venv/ +ENV PATH="/opt/venv/bin:$PATH" +RUN python -m pip install -U pip + # Install init system -RUN pip3 install dumb-init +RUN python -m pip install dumb-init # Copy in and install requirements # This will leverage the cache for rebuilds when modifying OCS, avoiding @@ -35,13 +48,13 @@ RUN pip3 install dumb-init COPY requirements/ /app/ocs/requirements COPY requirements.txt /app/ocs/requirements.txt WORKDIR /app/ocs/ -RUN pip3 install -r requirements.txt +RUN python -m pip install -r requirements.txt # Copy the current directory contents into the container at /app COPY . /app/ocs/ # Install ocs -RUN pip3 install . +RUN python -m pip install . # Reset workdir to avoid local imports WORKDIR / diff --git a/docs/developer/docker.rst b/docs/developer/docker.rst index 9d17a462..fb4d7521 100644 --- a/docs/developer/docker.rst +++ b/docs/developer/docker.rst @@ -26,6 +26,12 @@ OCS Agent via ``ocs-agent-cli``. See the `Dockerfile reference `_ in the Docker documentation for more information about how to write a Dockerfile. +.. note:: + + ``ocs`` and its dependencies are installed into a ``virutualenv`` kept in + ``/opt/venv/``. This is enabled by putting ``/opt/venv/bin/`` at the front of + the PATH. This is in place to isolate the installation from the system Python. + Building Upon the Base Image ---------------------------- @@ -43,19 +49,18 @@ that looks something like: # Install required dependencies RUN apt-get update && apt-get install -y rsync \ - wget \ - python3-pip + wget # Copy in and install requirements COPY requirements.txt /app/my-ocs-agent/requirements.txt WORKDIR /app/my-ocs-agent/ - RUN pip3 install -r requirements.txt + RUN python -m pip install -r requirements.txt # Copy the current directory contents into the container at /app COPY . /app/my-ocs-agent/ # Install my-ocs-agent - RUN pip3 install . + RUN python -m pip install . # Run agent on container startup ENTRYPOINT ["dumb-init", "ocs-agent-cli"]