Skip to content

Commit 6aa302e

Browse files
committed
Add another test case for venv detection where python is removed
1 parent 4c11e4b commit 6aa302e

File tree

5 files changed

+106
-2
lines changed

5 files changed

+106
-2
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# README
2+
3+
## Origin
4+
5+
Origin of this test was a comment by Arne:
6+
<https://github.com/green-coding-solutions/green-metrics-tool/pull/1297#issuecomment-3302240294>
7+
8+
This is my Dockerfile:
9+
10+
```dockerfile
11+
FROM greencoding/gcb_playwright:v20
12+
13+
RUN cd /root && \
14+
python3 -m virtualenv venv && \
15+
/root/venv/bin/pip install psutils
16+
17+
CMD ["tail", "-f", "/dev/null"]
18+
```
19+
20+
psutils is not found
21+
22+
## Test
23+
24+
The test script validates that the issue was resolved.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/bin/bash
22

3-
# Build Playwright container and verify psutils is detected in /root/venv/ by dependency_resolver
3+
# Build container and verify psutils is detected in /root/venv/ by dependency_resolver
44

55
set -e
66

77
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
88
DOCKERFILE_PATH="$SCRIPT_DIR"
99
DEPENDENCY_RESOLVER_PATH="$SCRIPT_DIR/../../.."
10-
CONTAINER_NAME="test-playwright-$(date +%s)"
10+
CONTAINER_NAME="test-pip-root-venv-detection-$(date +%s)"
1111

1212
echo "Building Docker image from $DOCKERFILE_PATH..."
1313
docker build -t "$CONTAINER_NAME" -f "$DOCKERFILE_PATH/Dockerfile" "$DOCKERFILE_PATH"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM greencoding/gcb_playwright:v20
2+
3+
RUN cd /root && \
4+
python3 -m virtualenv venv && \
5+
/root/venv/bin/pip install psutils
6+
7+
RUN rm /usr/bin/apt
8+
RUN rm /usr/bin/dpkg
9+
RUN rm /usr/bin/dpkg-query
10+
RUN rm /usr/bin/python3
11+
12+
CMD ["tail", "-f", "/dev/null"]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# README
2+
3+
## Origin
4+
5+
Origin of this test was a comment by Arne:
6+
<https://github.com/green-coding-solutions/green-metrics-tool/pull/1297#issuecomment-3302325317>
7+
8+
My Dockerfile:
9+
10+
```dockerfile
11+
FROM greencoding/gcb_playwright:v20
12+
13+
RUN cd /root && \
14+
python3 -m virtualenv venv && \
15+
/root/venv/bin/pip install psutils
16+
17+
RUN rm /usr/bin/apt
18+
RUN rm /usr/bin/dpkg
19+
RUN rm /usr/bin/dpkg-query
20+
RUN rm /usr/bin/python3
21+
22+
CMD ["tail", "-f", "/dev/null"]
23+
```
24+
25+
Our tool finds nothing.
26+
27+
## Test
28+
29+
The test fails. The dependency resolver can't resolve the dependencies, because pip can't be executed:
30+
31+
```sh
32+
/usr/local/bin/pip: cannot execute: required file not found
33+
```
34+
35+
pip is missing python3.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
# Build container and verify psutils is detected in /root/venv/ by dependency_resolver
4+
5+
set -e
6+
7+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
DOCKERFILE_PATH="$SCRIPT_DIR"
9+
DEPENDENCY_RESOLVER_PATH="$SCRIPT_DIR/../../.."
10+
CONTAINER_NAME="test-pip-root-venv-detection-2-$(date +%s)"
11+
12+
echo "Building Docker image from $DOCKERFILE_PATH..."
13+
docker build -t "$CONTAINER_NAME" -f "$DOCKERFILE_PATH/Dockerfile" "$DOCKERFILE_PATH"
14+
15+
echo "Starting container..."
16+
docker run --rm -d --name "$CONTAINER_NAME" "$CONTAINER_NAME"
17+
18+
echo "Running dependency_resolver on container $CONTAINER_NAME..."
19+
cd "$DEPENDENCY_RESOLVER_PATH"
20+
source venv/bin/activate
21+
22+
echo "Checking for psutils in output..."
23+
if python3 -m dependency_resolver docker "$CONTAINER_NAME" | grep -q "psutils"; then
24+
echo "✓ psutils found in dependency output"
25+
else
26+
echo "✗ psutils NOT found in dependency output"
27+
fi
28+
29+
echo "Cleaning up..."
30+
docker stop "$CONTAINER_NAME"
31+
docker rmi "$CONTAINER_NAME"
32+
33+
echo "Test complete!"

0 commit comments

Comments
 (0)