Skip to content
Merged
Show file tree
Hide file tree
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 .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
```bash
ddev add-on get https://github.com/stasadev/ddev-python2/tarball/refs/pull/REPLACE_ME_WITH_THIS_PR_NUMBER/head
ddev restart
ddev exec python -V
ddev exec python --version
ddev exec pip --version
```

## Automated Testing Overview
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ After installation, make sure to commit the `.ddev` directory to version control

| Command | Description |
| ------- | ----------- |
| `ddev exec python2.7` | Run Python 2.7.18 inside the `web` container.<br>Installed at `/usr/bin/python2.7` |
| `ddev exec python` | Run Python 2.7.18 inside the `web` container.<br>Symlink at `/usr/local/bin/python` |
| `ddev exec python` | Run Python 2.7.18 inside the `web` container.<br>Installed at `/usr/local/bin/python` |
| `ddev exec pip` | Run pip 20.0.2 inside the `web` container.<br>Installed at `/usr/local/bin/pip` |

This add-on also installs the `build-essential` package, which is usually required for the `npm build`, see [config.python2.yaml](./config.python2.yaml). Remove or replace the contents of this file if you only need Python 2.

Expand Down
7 changes: 7 additions & 0 deletions docker-compose.python2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ddev-generated
services:
# This service is only used to pull the Docker image for offline use.
python2:
image: python:2.7-slim-${DDEV_SITENAME}-built
profiles:
- python2
3 changes: 2 additions & 1 deletion install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: python2

project_files:
- config.python2.yaml
- docker-compose.python2.yaml
- web-build/Dockerfile.python2

ddev_version_constraint: '>= v1.23.5'
ddev_version_constraint: '>= v1.24.10'
28 changes: 26 additions & 2 deletions tests/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,37 @@ setup() {
}

health_checks() {
run ddev exec python -V
run ddev exec python --version
assert_success
assert_output "Python 2.7.18"

run ddev exec python2.7 -V
run ddev exec python2 --version
assert_success
assert_output "Python 2.7.18"

run ddev exec python2.7 --version
assert_success
assert_output "Python 2.7.18"

run ddev exec pip --version
assert_success
assert_output "pip 20.0.2 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)"

run ddev exec pip2 --version
assert_success
assert_output "pip 20.0.2 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)"

run ddev exec pip2.7 --version
assert_success
assert_output "pip 20.0.2 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)"

run ddev exec python -c "import hashlib; print('MD5:', hashlib.md5('test').hexdigest())"
assert_success
assert_output "('MD5:', '098f6bcd4621d373cade4e832627b4f6')"

run ddev exec python -c "import ssl; print('SSL:', ssl.OPENSSL_VERSION)"
assert_success
assert_output "('SSL:', 'OpenSSL 1.1.1d 10 Sep 2019')"
}

teardown() {
Expand Down
24 changes: 15 additions & 9 deletions web-build/Dockerfile.python2
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
#ddev-generated
# Adapted from https://web.archive.org/web/20250223192706/https://www.fadedbee.com/2024/01/18/installing-python2-on-debian-12-bookworm/
COPY --from=python:2.7-slim /usr/local /usr/local
COPY --from=python:2.7-slim /usr/lib /tmp/python2-libs
ARG TARGETARCH
RUN mkdir -p /tmp/python2 && \
wget -O /tmp/python2/python2.7.tar.gz https://github.com/stasadev/ddev-python2/releases/download/v1.0.1/python2.7_${TARGETARCH}.tar.gz && \
tar -xzf /tmp/python2/python2.7.tar.gz -C /tmp/python2 && \
source /etc/os-release && \
if [ "$VERSION_CODENAME" = "bookworm" ]; then rm -f /tmp/python2/libnsl2*.deb /tmp/python2/libtirpc3t64*.deb; fi && \
dpkg -i /tmp/python2/*.deb && \
rm -rf /tmp/python2 && \
ln -s /usr/bin/python2.7 /usr/local/bin/python
RUN if [ "$TARGETARCH" = "amd64" ]; then \
LIB_ARCH="x86_64-linux-gnu"; \
elif [ "$TARGETARCH" = "arm64" ]; then \
LIB_ARCH="aarch64-linux-gnu"; \
else \
echo "Unsupported architecture: $TARGETARCH"; exit 1; \
fi && \
echo "Detected architecture: $TARGETARCH ($LIB_ARCH)" && \
mkdir -p /usr/lib/$LIB_ARCH && \
cp /tmp/python2-libs/*/libssl.so.1.1 /usr/lib/$LIB_ARCH/ && \
cp /tmp/python2-libs/*/libcrypto.so.1.1 /usr/lib/$LIB_ARCH/ && \
rm -rf /tmp/python2-libs && \
ldconfig