From a372dea1d0dbe9225e75ea523369af745b323657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gre=CC=81goire=20Compagnon?= Date: Mon, 19 Aug 2024 10:03:20 +0200 Subject: [PATCH 1/3] feat(docker): enhance Dockerfile with caching and environment configurations This update introduces several improvements to the Dockerfile: - Add comments - Utilizes Dockerfile syntax version 1.5 for enhanced features. - Configures DEBIAN_FRONTEND to noninteractive to suppress prompts during package installation. - Disables automatic clean-up of apt cache to retain downloaded packages. - Implements caching for apt and pip to improve build efficiency. These changes aim to optimize the build process and provide better control over the container environment. --- Dockerfile | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2dc99b78..94eedfca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,46 @@ +# Use the Dockerfile syntax version 1.5 for enhanced features +# syntax=docker/dockerfile:1.5 + +# Start from a lightweight Python 3 image FROM python:3-slim +# Set environment variables to control shell interaction and markdown formatting +# Disable shell interaction by default (not possible in docker) ENV SHELL_INTERACTION=false + +# Disable markdown prettification by default ENV PRETTIFY_MARKDOWN=false + +# Automatically detect the operating system name ENV OS_NAME=auto + +# Automatically detect the shell name ENV SHELL_NAME=auto +# Set the DEBIAN_FRONTEND environment variable to noninteractive to suppress prompts during package installation +ENV DEBIAN_FRONTEND=noninteractive + +# Disable automatic clean-up of apt cache to retain downloaded packages +RUN rm /etc/apt/apt.conf.d/docker-clean && \ + echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache + +# Update package lists and install the gcc compiler while caching the apt data +RUN --mount=type=cache,target=/var/cache/apt \ + --mount=type=cache,target=/var/lib/apt \ + apt-get update && apt-get install -y gcc + +# Set the working directory to /app WORKDIR /app -COPY . /app -RUN apt-get update && apt-get install -y gcc -RUN pip install --no-cache /app && mkdir -p /tmp/shell_gpt +# Copy the current directory contents into the /app directory in the container +COPY . . + +# Install Python dependencies using pip while caching the pip data +RUN --mount=type=cache,target=/root/.cache/pip \ + pip install /app +# Define a mount point for temporary files VOLUME /tmp/shell_gpt +# Set the default command to run when the container starts ENTRYPOINT ["sgpt"] From b9efdaaba8c7571d455908e720444986ccd883b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gre=CC=81goire=20Compagnon?= Date: Mon, 19 Aug 2024 10:08:23 +0200 Subject: [PATCH 2/3] chore(docker): update base image to Python 3.12-slim This is to ensure sgpt will build, even if a new incompatible python came out --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 94eedfca..1218867e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ # Use the Dockerfile syntax version 1.5 for enhanced features # syntax=docker/dockerfile:1.5 -# Start from a lightweight Python 3 image -FROM python:3-slim +# Start from a lightweight Python 3.12 image +FROM python:3.12-slim # Set environment variables to control shell interaction and markdown formatting # Disable shell interaction by default (not possible in docker) From a685cd829eeefec1446f33f5d496e16d55e53aca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gre=CC=81goire=20Compagnon?= Date: Mon, 19 Aug 2024 10:15:44 +0200 Subject: [PATCH 3/3] chore(docker): add .dockerignore file to exclude unnecessary directories --- .dockerignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..293e8b43 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +/.devcontainer +/.github +/tests