Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ FROM python:3.9-slim
WORKDIR /app

# install required packages for system
RUN apt-get update \
RUN sed -i 's|http://deb.debian.org|https://deb.debian.org|g' /etc/apt/sources.list.d/debian.sources \
&& apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y gcc default-libmysqlclient-dev pkg-config \
Comment on lines +8 to 11
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

sed path can break the build; consolidate the RUN layer for robustness & smaller images

The build will fail on any Debian-based image that does not ship /etc/apt/sources.list.d/debian.sources (e.g. older slim tags) because sed exits non-zero when the file is missing.
While you are touching this layer, you can also:

  1. Skip the unnecessary apt-get upgrade –y (bloats the image, hurts reproducibility).
  2. Install with --no-install-recommends to keep the image lean.
  3. Collapse commands into a single RUN to reduce layers and make the cleanup unconditional.

Proposed patch:

-RUN sed -i 's|http://deb.debian.org|https://deb.debian.org|g' /etc/apt/sources.list.d/debian.sources \
-    && apt-get update \
-    && apt-get upgrade -y \
-    && apt-get install -y gcc default-libmysqlclient-dev pkg-config \
-    && rm -rf /var/lib/apt/lists/*
+RUN set -eux; \
+    # Switch any Debian mirrors to HTTPS if the file exists (works on older & newer images)
+    for f in /etc/apt/sources.list /etc/apt/sources.list.d/debian.sources; do \
+        [ -f "$f" ] && sed -i 's|http://deb.debian.org|https://deb.debian.org|g' "$f"; \
+    done; \
+    apt-get update; \
+    apt-get install -y --no-install-recommends gcc default-libmysqlclient-dev pkg-config; \
+    rm -rf /var/lib/apt/lists/*

This keeps the build portable, reproducible, and slimmer without changing functionality.

🤖 Prompt for AI Agents
In Dockerfile lines 8 to 11, the sed command targets a file that may not exist,
causing build failures on some Debian images. To fix this, remove the sed
command or conditionally handle the file's absence, skip the apt-get upgrade to
reduce image size, add --no-install-recommends to apt-get install for a leaner
image, and combine all apt-get commands into a single RUN statement to reduce
layers and ensure cleanup runs unconditionally.

&& rm -rf /var/lib/apt/lists/*
Expand Down