Skip to content

Commit 401b4c6

Browse files
Fix path issue
1 parent 19f458a commit 401b4c6

File tree

4 files changed

+155
-6
lines changed

4 files changed

+155
-6
lines changed

.devcontainer/devcontainer.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@
6161
},
6262
"containerEnv": {
6363
"PYTHONPATH": "/workspaces/Apim-Samples/shared/python:/workspaces/Apim-Samples",
64-
"VIRTUAL_ENV": "/opt/venv",
65-
"PATH": "/opt/venv/bin:${containerEnv:PATH}"
64+
"VIRTUAL_ENV": "/opt/venv"
6665
},
67-
"postCreateCommand": "bash .devcontainer/setup-prebuild.sh",
66+
"initializeCommand": "echo 'Initializing dev container...'",
67+
"postCreateCommand": "bash .devcontainer/setup-simple.sh",
6868
"postStartCommand": "bash .devcontainer/post-start.sh",
6969
"forwardPorts": [
7070
8000,
@@ -92,5 +92,8 @@
9292
},
9393
"remoteUser": "vscode",
9494
"workspaceFolder": "/workspaces/Apim-Samples",
95-
"mounts": []
95+
"mounts": [],
96+
"runArgs": [
97+
"--init"
98+
]
9699
}

.devcontainer/post-start.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,13 @@ fi
4242
# ------------------------------
4343

4444
echo "✅ Verifying Python environment..."
45-
source /opt/venv/bin/activate
46-
python --version
45+
if [ -f "/opt/venv/bin/activate" ]; then
46+
source /opt/venv/bin/activate
47+
python --version
48+
else
49+
echo "⚠️ Virtual environment not found, using system Python"
50+
python --version
51+
fi
4752

4853
echo ""
4954
echo "✅ Verifying Azure CLI..."

.devcontainer/setup-prebuild.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,16 @@ sudo chown vscode:vscode /opt/venv
2323
# Switch to vscode user for virtual environment creation
2424
sudo -u vscode bash << 'VENV_SETUP'
2525
set -e
26+
echo "Creating virtual environment as vscode user..."
2627
python -m venv /opt/venv
28+
29+
echo "Activating virtual environment..."
2730
source /opt/venv/bin/activate
2831
32+
echo "Verifying virtual environment activation..."
33+
which python
34+
python --version
35+
2936
echo "📦 Installing Python dependencies in virtual environment..."
3037
pip install --upgrade pip setuptools wheel
3138
pip install -r requirements.txt
@@ -34,13 +41,17 @@ pip install -r requirements.txt
3441
pip install pytest pytest-cov coverage
3542
3643
echo "✅ Virtual environment setup complete"
44+
echo "Python location: $(which python)"
45+
echo "Pip location: $(which pip)"
3746
VENV_SETUP
3847

3948
# Activate virtual environment for the rest of the setup
4049
source /opt/venv/bin/activate
4150

4251
# Make virtual environment available system-wide for the vscode user
52+
echo 'export PATH="/opt/venv/bin:$PATH"' >> /home/vscode/.bashrc
4353
echo 'source /opt/venv/bin/activate' >> /home/vscode/.bashrc
54+
echo 'export PATH="/opt/venv/bin:$PATH"' >> /home/vscode/.zshrc
4455
echo 'source /opt/venv/bin/activate' >> /home/vscode/.zshrc
4556

4657
# Set ownership to vscode user (just to be sure)

.devcontainer/setup-simple.sh

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#!/bin/bash
2+
3+
# ------------------------------
4+
# SIMPLE PREBUILD SETUP
5+
# ------------------------------
6+
7+
set -e
8+
echo "🔧 Running simplified prebuild setup..."
9+
10+
# Basic environment setup
11+
export DEBIAN_FRONTEND=noninteractive
12+
13+
# ------------------------------
14+
# PYTHON VIRTUAL ENVIRONMENT
15+
# ------------------------------
16+
17+
echo "📦 Creating Python virtual environment..."
18+
19+
# Create venv directory with proper permissions
20+
if [ ! -d "/opt/venv" ]; then
21+
sudo mkdir -p /opt/venv
22+
sudo chown -R vscode:vscode /opt/venv
23+
fi
24+
25+
# Create virtual environment as vscode user
26+
sudo -u vscode python3 -m venv /opt/venv
27+
28+
# Install packages in virtual environment
29+
echo "📦 Installing Python packages..."
30+
sudo -u vscode /opt/venv/bin/pip install --upgrade pip setuptools wheel
31+
sudo -u vscode /opt/venv/bin/pip install -r requirements.txt
32+
sudo -u vscode /opt/venv/bin/pip install pytest pytest-cov coverage
33+
34+
# Ensure ownership is correct
35+
sudo chown -R vscode:vscode /opt/venv
36+
37+
# ------------------------------
38+
# SHELL CONFIGURATION
39+
# ------------------------------
40+
41+
echo "🔧 Configuring shell environment..."
42+
43+
# Create bashrc additions for vscode user
44+
sudo -u vscode bash -c 'cat >> ~/.bashrc << "EOF"
45+
46+
# Virtual environment activation
47+
export VIRTUAL_ENV="/opt/venv"
48+
export PATH="/opt/venv/bin:$PATH"
49+
source /opt/venv/bin/activate
50+
51+
EOF'
52+
53+
# Create zshrc additions for vscode user
54+
sudo -u vscode bash -c 'cat >> ~/.zshrc << "EOF"
55+
56+
# Virtual environment activation
57+
export VIRTUAL_ENV="/opt/venv"
58+
export PATH="/opt/venv/bin:$PATH"
59+
source /opt/venv/bin/activate
60+
61+
EOF'
62+
63+
# ------------------------------
64+
# PYTHON PATH SETUP
65+
# ------------------------------
66+
67+
echo "🔧 Setting up Python path..."
68+
sudo -u vscode /opt/venv/bin/python setup/setup_python_path.py --generate-env || echo "⚠️ Python path setup failed, continuing..."
69+
70+
# ------------------------------
71+
# AZURE CLI SETUP
72+
# ------------------------------
73+
74+
echo "☁️ Configuring Azure CLI..."
75+
az config set core.login_experience_v2=off 2>/dev/null || true
76+
77+
echo "📥 Installing Azure CLI extensions..."
78+
az extension add --name containerapp --only-show-errors 2>/dev/null || true
79+
az extension add --name front-door --only-show-errors 2>/dev/null || true
80+
81+
# ------------------------------
82+
# JUPYTER SETUP
83+
# ------------------------------
84+
85+
echo "📓 Setting up Jupyter..."
86+
sudo -u vscode /opt/venv/bin/python -m ipykernel install --user --name=apim-samples --display-name="APIM Samples Python" || echo "⚠️ Jupyter kernel setup failed, continuing..."
87+
88+
# ------------------------------
89+
# WORKSPACE CONFIGURATION
90+
# ------------------------------
91+
92+
echo "🛠️ Configuring workspace..."
93+
mkdir -p .vscode
94+
95+
cat > .vscode/settings.json << 'EOF'
96+
{
97+
"python.terminal.activateEnvironment": true,
98+
"python.defaultInterpreterPath": "/opt/venv/bin/python",
99+
"python.analysis.extraPaths": [
100+
"/workspaces/Apim-Samples/shared/python"
101+
],
102+
"jupyter.kernels.filter": [
103+
{
104+
"path": "/opt/venv/bin/python",
105+
"type": "pythonEnvironment"
106+
}
107+
],
108+
"files.associations": {
109+
"*.bicep": "bicep"
110+
},
111+
"python.envFile": "${workspaceFolder}/.env"
112+
}
113+
EOF
114+
115+
# ------------------------------
116+
# COMPLETION
117+
# ------------------------------
118+
119+
echo "✅ Creating completion marker..."
120+
echo "$(date): Simplified prebuild setup completed" > .devcontainer/.prebuild-complete
121+
122+
echo "🎉 Prebuild setup complete!"
123+
124+
# Simple verification
125+
echo "✅ Verification:"
126+
echo "Python version: $(/opt/venv/bin/python --version)"
127+
echo "Virtual env location: /opt/venv"
128+
echo "Packages installed: $(/opt/venv/bin/pip list | wc -l) packages"
129+
130+
echo "📋 Setup complete - container should start faster next time!"

0 commit comments

Comments
 (0)