Skip to content

Commit 82adc31

Browse files
author
7908837174
committed
1024
1 parent b951d41 commit 82adc31

File tree

7 files changed

+147
-20
lines changed

7 files changed

+147
-20
lines changed

.devcontainer/Dockerfile

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ RUN useradd -m -s /bin/bash vscode
77

88
WORKDIR /workspace
99

10-
RUN export DEBIAN_FRONTEND=noninteractive
10+
# Configure apt proxy settings if proxy environment variables are set
11+
RUN if [ -n "$http_proxy" ] || [ -n "$https_proxy" ]; then \
12+
echo "Acquire::http::Proxy \"$http_proxy\";" > /etc/apt/apt.conf.d/01proxy; \
13+
echo "Acquire::https::Proxy \"$https_proxy\";" >> /etc/apt/apt.conf.d/01proxy; \
14+
fi
1115

1216
# please keep pkgs sorted
1317
RUN \
@@ -42,15 +46,34 @@ RUN \
4246
ruby-dev \
4347
shellcheck
4448

45-
# Create a virtual environment and install Python requirements
49+
# Configure pip proxy settings
50+
RUN if [ -n "$http_proxy" ] || [ -n "$https_proxy" ]; then \
51+
echo "[global]" > /etc/pip.conf; \
52+
if [ -n "$http_proxy" ]; then echo "proxy = $http_proxy" >> /etc/pip.conf; fi; \
53+
if [ -n "$https_proxy" ]; then echo "trusted-host = pypi.org" >> /etc/pip.conf; \
54+
echo "trusted-host = pypi.python.org" >> /etc/pip.conf; \
55+
echo "trusted-host = files.pythonhosted.org" >> /etc/pip.conf; fi; \
56+
fi
57+
58+
# Configure npm proxy settings
59+
RUN if [ -n "$http_proxy" ]; then npm config set proxy $http_proxy; fi
60+
RUN if [ -n "$https_proxy" ]; then npm config set https-proxy $https_proxy; fi
61+
62+
# Configure bundler proxy settings
63+
RUN if [ -n "$http_proxy" ]; then bundle config http_proxy $http_proxy; fi
64+
RUN if [ -n "$https_proxy" ]; then bundle config https_proxy $https_proxy; fi
65+
66+
# Create a virtual environment for Python packages
4667
RUN python3 -m venv /opt/venv
4768
ENV PATH="/opt/venv/bin:$PATH"
48-
RUN pip install -r /workspace/requirements.txt
69+
70+
# Note: requirements.txt will be installed in the updateContentCommand.sh or onCreateCommand.sh scripts
71+
# This avoids issues with trying to install requirements before the workspace is mounted
4972

5073
RUN apt-get clean autoclean
5174
RUN apt-get autoremove -y
5275
RUN rm -rf /var/lib/{apt,dpkg,cache,log}/*
5376

5477
# Switch to non-root user
5578
USER vscode
56-
WORKDIR /home/vscode
79+
WORKDIR /home/vscode

.devcontainer/onCreateCommand.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
#!/bin/bash
22

3+
# Install npm packages
34
npm i
5+
6+
# Install Ruby gems
47
bundle install --verbose
58

6-
# Create a virtual environment and install Python requirements
7-
python3 -m venv .venv
8-
source .venv/bin/activate
9-
pip install -r requirements.txt
9+
# Install Python packages using virtual environment to avoid PEP 668 error
10+
if [ -f "requirements.txt" ]; then
11+
python3 -m venv .venv
12+
source .venv/bin/activate
13+
pip install -r requirements.txt
14+
fi
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#!/bin/bash
22

3+
# Install Ruby gems
34
bundle install --verbose
45

5-
# Create a virtual environment and install Python requirements
6-
python3 -m venv .venv
7-
source .venv/bin/activate
8-
pip install -r requirements.txt
6+
# Install Python packages using virtual environment to avoid PEP 668 error
7+
if [ -f "requirements.txt" ]; then
8+
python3 -m venv .venv
9+
source .venv/bin/activate
10+
pip install -r requirements.txt
11+
fi

.github/workflows/container-tests.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,27 @@ jobs:
3939
chmod +x tests/container_tests.sh
4040
./tests/container_tests.sh
4141
42+
- name: Test docker-compose with proxy
43+
run: |
44+
if [ "${{ matrix.proxy }}" = "with-proxy" ]; then
45+
echo "Testing docker-compose with proxy"
46+
# Start services with docker-compose
47+
docker-compose up -d
48+
# Wait for services to start
49+
sleep 10
50+
# Check if services are running
51+
docker-compose ps
52+
# Stop services
53+
docker-compose down
54+
else
55+
echo "Testing docker-compose without proxy"
56+
docker-compose up -d
57+
sleep 10
58+
docker-compose ps
59+
docker-compose down
60+
fi
61+
4262
- name: Test VS Code integration
4363
run: |
4464
# Skip this test for now as it's not essential for the build
45-
echo "Skipping VS Code integration test"
65+
echo "Skipping VS Code integration test"

README.adoc

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,47 @@ For convenience, running Rake inside the container is encapsulated in `do`. For
9898
# generate an implementation-specific spec for the 'example_rv64_with_overlay' config
9999
./do gen:arch[example_rv64_with_overlay]
100100
----
101+
102+
== Proxy Support
103+
104+
The development environment now includes comprehensive proxy support for all package managers:
105+
106+
* `apt` (system packages)
107+
* `pip` (Python packages)
108+
* `npm` (Node.js packages)
109+
* `bundler` (Ruby gems)
110+
111+
To use the development environment with a proxy, you can either:
112+
113+
1. Use the provided docker-compose configuration:
114+
+
115+
[source,bash]
116+
----
117+
http_proxy=http://your.proxy:port https_proxy=http://your.proxy:port docker-compose up
118+
----
119+
120+
2. Set proxy environment variables when using the devcontainer directly:
121+
+
122+
[source,bash]
123+
----
124+
docker build -t riscv-unified-db .devcontainer/
125+
docker run -e http_proxy=http://your.proxy:port -e https_proxy=http://your.proxy:port riscv-unified-db
126+
----
127+
128+
The proxy configuration is automatically applied to all supported package managers when the environment variables are present.
129+
130+
== Testing
131+
132+
Container tests are available in `tests/container_tests.sh` and can be run with:
133+
134+
[source,bash]
135+
----
136+
./tests/container_tests.sh
137+
----
138+
139+
These tests validate:
140+
* Container build process
141+
* Basic command functionality
142+
* Package installation in virtual environments
143+
* Non-root user configuration
144+
* Proxy configuration for all package managers

docker-compose.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version: '3.8'
2+
3+
services:
4+
dev:
5+
build:
6+
context: .
7+
dockerfile: .devcontainer/Dockerfile
8+
volumes:
9+
- .:/workspace:cached
10+
network_mode: service:proxy
11+
environment:
12+
- http_proxy=http://proxy:3128
13+
- https_proxy=http://proxy:3128
14+
- HTTP_PROXY=http://proxy:3128
15+
- HTTPS_PROXY=http://proxy:3128
16+
depends_on:
17+
- proxy
18+
19+
proxy:
20+
image: ubuntu/squid:latest
21+
ports:
22+
- "3128:3128"

tests/container_tests.sh

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,22 @@ docker run --rm riscv-unified-db-test id -u vscode
4141

4242
# Test 8: Proxy configuration test
4343
echo "Test 8: Checking proxy configuration..."
44-
if [ -n "$http_proxy" ] || [ -n "$https_proxy" ]; then
45-
echo "Proxy is configured: HTTP_PROXY=$http_proxy, HTTPS_PROXY=$https_proxy"
46-
# Test proxy connectivity if configured
47-
docker run --rm -e http_proxy -e https_proxy riscv-unified-db-test env | grep -i proxy
48-
else
49-
echo "No proxy configured"
50-
fi
44+
docker run --rm -e http_proxy=http://test.proxy:3128 -e https_proxy=http://test.proxy:3128 riscv-unified-db-test bash -c "env | grep -i proxy"
45+
46+
# Test 9: Check apt proxy configuration
47+
echo "Test 9: Checking apt proxy configuration..."
48+
docker run --rm -e http_proxy=http://test.proxy:3128 riscv-unified-db-test bash -c "if [ -f /etc/apt/apt.conf.d/01proxy ]; then cat /etc/apt/apt.conf.d/01proxy; else echo 'No apt proxy configuration found'; fi"
49+
50+
# Test 10: Check pip proxy configuration
51+
echo "Test 10: Checking pip proxy configuration..."
52+
docker run --rm -e http_proxy=http://test.proxy:3128 riscv-unified-db-test bash -c "if [ -f /etc/pip.conf ]; then cat /etc/pip.conf; else echo 'No pip proxy configuration found'; fi"
53+
54+
# Test 11: Check npm proxy configuration
55+
echo "Test 11: Checking npm proxy configuration..."
56+
docker run --rm -e http_proxy=http://test.proxy:3128 riscv-unified-db-test bash -c "npm config get proxy || echo 'No npm proxy configured'"
57+
58+
# Test 12: Check bundler proxy configuration
59+
echo "Test 12: Checking bundler proxy configuration..."
60+
docker run --rm -e http_proxy=http://test.proxy:3128 riscv-unified-db-test bash -c "bundle config http_proxy || echo 'No bundler proxy configured'"
5161

5262
echo "All container tests passed!"

0 commit comments

Comments
 (0)