Skip to content

Commit

Permalink
Remove old compiled spt3g/so3g layers from Docker image (#397)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
BrianJKoopman authored Aug 2, 2024
1 parent 0de9c72 commit b6cbd88
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
23 changes: 18 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,26 +26,35 @@ 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
# downloading all the requirements again
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 /
Expand Down
13 changes: 9 additions & 4 deletions docs/developer/docker.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ OCS Agent via ``ocs-agent-cli``. See the `Dockerfile reference
<https://docs.docker.com/engine/reference/builder/>`_ 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
----------------------------

Expand All @@ -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"]
Expand Down

0 comments on commit b6cbd88

Please sign in to comment.