Skip to content

Commit 3b777fe

Browse files
Update python.md
1 parent ef0dd91 commit 3b777fe

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

python.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# INSTALL SERVER
99
pip install pypiserver
1010

11-
# CREATE/DOWNLOADING
11+
# CREATE/DOWNLOADING / # OPTION1: DOWNLOAD PIP PACKAGES MANUALY
1212
mkdir ~/packages
1313
pip download requests -d ~/packages
1414
pip download picker==2.3.0 -d ~/packages
@@ -20,6 +20,50 @@ pypi-server run -p 8080 ~/package
2020
pip install --index-url http://localhost:8080/simple picker
2121
```
2222

23+
```bash
24+
# OPTION2: DOWNLOAD PIP PACKAGES w/ DOCKER
25+
26+
cat <<EOF > pip-schleuser.sh
27+
#!/bin/sh
28+
set -eux
29+
30+
BASE_IMAGE=$1
31+
PIP_PACKAGES=$2
32+
33+
# Local directory on host
34+
WHEELHOUSE="$(pwd)/wheelhouse"
35+
mkdir -p "$WHEELHOUSE"
36+
37+
# Run container to build offline wheelhouse
38+
docker run --rm -it \
39+
-v "$WHEELHOUSE:/wheelhouse" \
40+
"$BASE_IMAGE" sh -euxc "
41+
42+
# 1. Create and activate venv
43+
python3 -m venv /venv
44+
. /venv/bin/activate
45+
46+
# 2. Upgrade pip tooling
47+
pip install --upgrade pip setuptools wheel
48+
49+
# 3. Download requested packages into /wheelhouse
50+
pip download -d /wheelhouse $PIP_PACKAGES
51+
52+
# 4. Optional: install them (from wheelhouse, offline style)
53+
pip install --no-index --find-links=/wheelhouse $PIP_PACKAGES
54+
55+
# 5. Record installed packages
56+
pip freeze > /wheelhouse/installed-packages.txt
57+
"
58+
59+
echo "[INFO] pip packages and wheelhouse saved under: $WHEELHOUSE"
60+
61+
zip -r ./pip-packages.zip wheelhouse
62+
EOF
63+
64+
sh pip-schleuser.sh python:3.10.0-alpine "requests flask"
65+
```
66+
2367
```yaml
2468
# DEPLOY ON KUBERNETES
2569
---

0 commit comments

Comments
 (0)