Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d41e2fa

Browse files
committed
Update Dockerfile to bundle Python dependencies in the Debian package
1 parent 7d59520 commit d41e2fa

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

Dockerfile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
3434
python3 \
3535
python3-pip \
3636
python3-setuptools \
37+
python3-venv \
3738
build-essential \
3839
&& rm -rf /var/lib/apt/lists/*
3940

@@ -46,20 +47,22 @@ COPY . .
4647
# Create directories for packaging
4748
RUN mkdir -p /app/package/usr/lib/k8sh
4849
RUN mkdir -p /app/package/usr/bin
50+
RUN mkdir -p /app/package/usr/lib/k8sh/venv
51+
52+
# Create a virtual environment and install dependencies
53+
RUN python3 -m venv /app/package/usr/lib/k8sh/venv
54+
RUN /app/package/usr/lib/k8sh/venv/bin/pip install --no-cache-dir -r requirements.txt
4955

5056
# Copy application files to the package structure
5157
RUN cp -r command k8s_client state utils main.py requirements.txt /app/package/usr/lib/k8sh/
5258

53-
# Create the launcher script
59+
# Create the launcher script that uses the bundled virtual environment
5460
RUN echo '#!/bin/bash' > /app/package/usr/bin/k8sh && \
5561
echo 'cd /usr/lib/k8sh' >> /app/package/usr/bin/k8sh && \
56-
echo 'python3 main.py "$@"' >> /app/package/usr/bin/k8sh && \
62+
echo 'PYTHONPATH=/usr/lib/k8sh /usr/lib/k8sh/venv/bin/python main.py "$@"' >> /app/package/usr/bin/k8sh && \
5763
chmod +x /app/package/usr/bin/k8sh
5864

59-
# Create an after-install script to install Python dependencies
60-
RUN echo '#!/bin/bash' > /app/after-install.sh && \
61-
echo 'pip3 install --no-cache-dir -r /usr/lib/k8sh/requirements.txt' >> /app/after-install.sh && \
62-
chmod +x /app/after-install.sh
65+
# No need for an after-install script as dependencies are bundled
6366

6467
# Build the package with FPM
6568
RUN fpm \
@@ -69,10 +72,8 @@ RUN fpm \
6972
--version 1.0.0 \
7073
--architecture all \
7174
--depends python3 \
72-
--depends python3-pip \
7375
--maintainer "K8sh Team <[email protected]>" \
7476
--description "Kubernetes Terminal Emulator - A shell-like interface to Kubernetes" \
75-
--after-install /app/after-install.sh \
7677
--chdir /app/package \
7778
--package /app/k8sh.deb \
7879
.

0 commit comments

Comments
 (0)