From b302c4d962e0685174d1ffde39272f9469bf394b Mon Sep 17 00:00:00 2001 From: MDW Date: Sun, 11 May 2025 13:52:47 +0200 Subject: [PATCH] build: update Dockerfile to avoid long rebuilds for code updated, add docker-compose.yml - Avoid rebuilding all the steps by installing requirements depending on the requirement files only first. Use actual application code as a reference in the last Dockerfile layer. - Add docker-compose.yml to make running easier. --- docker-compose.yml | 21 ++++++ docker/Dockerfile | 176 ++++++++++++++++++++++++--------------------- 2 files changed, 117 insertions(+), 80 deletions(-) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..d719f315d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,21 @@ +services: + # Run this using `docker compose run --rm aider-base` on the CLI + # To run with forced build: `docker compose run --build --rm aider-base` on the CLI + aider-base: + build: + context: . + args: [--rm] + dockerfile: docker/Dockerfile + container_name: aider + #volumes: + # - .:/app + #working_dir: /app + command: /bin/bash + + # Run this using `docker compose run --rm aider` on the CLI + # You can add arguments: `docker compose run --rm aider --architect -m "Do this task"` + # And you can request to update the build: `docker compose run --build --rm aider` on the CLI + aider: + extends: aider-base + command: aider + diff --git a/docker/Dockerfile b/docker/Dockerfile index 05932a58d..ca5197501 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,80 +1,96 @@ -FROM python:3.10-slim AS base - -# Install system dependencies -RUN apt-get update && \ - apt-get install --no-install-recommends -y build-essential git libportaudio2 pandoc && \ - rm -rf /var/lib/apt/lists/* - -# Create app user with UID 1000 -RUN useradd -m -u 1000 -s /bin/bash appuser - -WORKDIR /app - -# Create virtual environment -RUN python -m venv /venv -ENV PATH="/venv/bin:$PATH" - -# Playwright browser settings -ENV PLAYWRIGHT_BROWSERS_PATH=/home/appuser/pw-browsers -ENV PLAYWRIGHT_SKIP_BROWSER_GC=1 - -# Create directories with proper permissions -RUN mkdir -p /home/appuser/.aider /home/appuser/.cache /home/appuser/pw-browsers && \ - chown -R appuser:appuser /home/appuser /app /venv && \ - chmod -R 777 /home/appuser/.aider /home/appuser/.cache /home/appuser/pw-browsers - -# So git doesn't complain about unusual permissions -RUN git config --system --add safe.directory /app - -# This puts the container's ~/.aider into the host's project directory (usually host's cwd). -# That way caches, version checks, etc get stored in the host filesystem not -# simply discarded every time the container exits. -ENV HOME=/app - -######################### -FROM base AS aider-full - -ENV AIDER_DOCKER_IMAGE=paulgauthier/aider-full - -COPY . /tmp/aider - -# Install dependencies as root -RUN /venv/bin/python -m pip install --upgrade --no-cache-dir pip && \ - /venv/bin/python -m pip install --no-cache-dir /tmp/aider[help,browser,playwright] boto3 \ - --extra-index-url https://download.pytorch.org/whl/cpu && \ - rm -rf /tmp/aider - -# Install playwright browsers -RUN /venv/bin/python -m playwright install --with-deps chromium - -# Fix site-packages permissions -RUN find /venv/lib/python3.10/site-packages \( -type d -exec chmod a+rwx {} + \) -o \( -type f -exec chmod a+rw {} + \) - -# Switch to appuser -USER appuser - -ENTRYPOINT ["/venv/bin/aider"] - -######################### -FROM base AS aider - -ENV AIDER_DOCKER_IMAGE=paulgauthier/aider - -COPY . /tmp/aider - -# Install dependencies as root -RUN /venv/bin/python -m pip install --upgrade --no-cache-dir pip && \ - /venv/bin/python -m pip install --no-cache-dir /tmp/aider[playwright] boto3 google-cloud-aiplatform \ - --extra-index-url https://download.pytorch.org/whl/cpu && \ - rm -rf /tmp/aider - -# Install playwright browsers -RUN /venv/bin/python -m playwright install --with-deps chromium - -# Fix site-packages permissions -RUN find /venv/lib/python3.10/site-packages \( -type d -exec chmod a+rwx {} + \) -o \( -type f -exec chmod a+rw {} + \) - -# Switch to appuser -USER appuser - -ENTRYPOINT ["/venv/bin/aider"] +FROM python:3.10-slim AS base + +# Install system dependencies +RUN apt-get update && \ + apt-get install --no-install-recommends -y build-essential git libportaudio2 pandoc && \ + rm -rf /var/lib/apt/lists/* + +# Create app user with UID 1000 +RUN useradd -m -u 1000 -s /bin/bash appuser + +WORKDIR /app + +# Create virtual environment +RUN python -m venv /venv +ENV PATH="/venv/bin:$PATH" + +# Playwright browser settings +ENV PLAYWRIGHT_BROWSERS_PATH=/home/appuser/pw-browsers +ENV PLAYWRIGHT_SKIP_BROWSER_GC=1 + +# Create directories with proper permissions +RUN mkdir -p /home/appuser/.aider /home/appuser/.cache /home/appuser/pw-browsers && \ + chown -R appuser:appuser /home/appuser /app /venv && \ + chmod -R 777 /home/appuser/.aider /home/appuser/.cache /home/appuser/pw-browsers + +# So git doesn't complain about unusual permissions +RUN git config --system --add safe.directory /app + +# This puts the container's ~/.aider into the host's project directory (usually host's cwd). +# That way caches, version checks, etc get stored in the host filesystem not +# simply discarded every time the container exits. +ENV HOME=/app + +######################### +FROM base AS aider-full + +ENV AIDER_DOCKER_IMAGE=paulgauthier/aider-full + +# Copy requirements files +COPY requirements.txt /tmp/aider/ +COPY requirements/ /tmp/aider/requirements/ + +# Install dependencies as root +RUN /venv/bin/python -m pip install --upgrade --no-cache-dir pip && \ + /venv/bin/python -m pip install --no-cache-dir -r /tmp/aider/requirements.txt && \ + rm -rf /tmp/aider + +# Install playwright browsers +RUN /venv/bin/python -m pip install --no-cache-dir playwright && \ + /venv/bin/python -m playwright install --with-deps chromium + +# Fix site-packages permissions +RUN find /venv/lib/python3.10/site-packages \( -type d -exec chmod a+rwx {} + \) -o \( -type f -exec chmod a+rw {} + \) + +# Copy the rest of the application code +COPY . /app/ + +# Install the application as a package +RUN /venv/bin/python -m pip install . + +# Switch to appuser +USER appuser + +ENTRYPOINT ["/venv/bin/aider"] + +######################### +FROM base AS aider + +ENV AIDER_DOCKER_IMAGE=paulgauthier/aider + +# Copy requirements files +COPY requirements.txt /tmp/aider/ +COPY requirements/ /tmp/aider/requirements/ + +# Install dependencies as root +RUN /venv/bin/python -m pip install --upgrade --no-cache-dir pip && \ + /venv/bin/python -m pip install --no-cache-dir -r /tmp/aider/requirements.txt && \ + rm -rf /tmp/aider + +# Install playwright browsers +RUN /venv/bin/python -m pip install --no-cache-dir playwright && \ + /venv/bin/python -m playwright install --with-deps chromium + +# Fix site-packages permissions +RUN find /venv/lib/python3.10/site-packages \( -type d -exec chmod a+rwx {} + \) -o \( -type f -exec chmod a+rw {} + \) + +# Copy the rest of the application code +COPY . /app/ + +# Install the application as a package +RUN /venv/bin/python -m pip install . + +# Switch to appuser +USER appuser + +ENTRYPOINT ["/venv/bin/aider"]