Skip to content

Commit 74f26fa

Browse files
Updated dockerfile
1 parent a8dc4e8 commit 74f26fa

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed

.devcontainer/Dockerfile

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
# https://github.com/devcontainers/images/tree/main/src/python
2+
13
# syntax=docker/dockerfile:1.4
24

3-
# Build stage for dependencies
5+
# BUILD stage for dependencies - use MAJOR semantic image (1) with Python 3.12
46
FROM mcr.microsoft.com/devcontainers/python:1-3.12-bookworm AS builder
57

68
# Set build arguments for flexibility
@@ -21,20 +23,26 @@ USER vscode
2123
# Create virtual environment with optimized settings
2224
RUN python3 -m venv $VIRTUAL_ENV --copies
2325

26+
# # Ensure pip is at latest version in virtual environment
27+
# RUN . $VIRTUAL_ENV/bin/activate && \
28+
# python -m pip install --upgrade pip setuptools wheel
29+
2430
# Copy only requirements.txt first for better Docker layer caching
2531
COPY --chown=vscode:vscode requirements.txt /tmp/requirements.txt
2632

2733
# Install Python packages with mount cache for pip
2834
RUN --mount=type=cache,target=/home/vscode/.cache/pip,uid=1000,gid=1000 \
2935
set -ex && \
3036
. $VIRTUAL_ENV/bin/activate && \
31-
pip install --upgrade pip setuptools wheel && \
3237
pip install --compile -r /tmp/requirements.txt && \
3338
pip install --compile pytest pytest-cov coverage ipykernel && \
3439
python -m ipykernel install --user --name=apim-samples --display-name="APIM Samples Python" && \
35-
pip list --format=freeze > /tmp/installed-packages.txt
40+
pip list --format=freeze > /tmp/installed-packages.txt && \
41+
echo "✅ Pip version: $(pip --version)" > /tmp/pip-version.txt
42+
43+
###################################################################################################
3644

37-
# Production stage
45+
# PRODUCTION stage - use MAJOR semantic image (1) with Python 3.12
3846
FROM mcr.microsoft.com/devcontainers/python:1-3.12-bookworm AS production
3947

4048
# Set build arguments for flexibility
@@ -55,39 +63,42 @@ ENV PYTHONUNBUFFERED=1 \
5563
USER root
5664
RUN --mount=type=cache,target=/var/cache/apt \
5765
--mount=type=cache,target=/var/lib/apt/lists \
58-
apt-get update && apt-get install -y --no-install-recommends \
59-
curl \
60-
wget \
61-
jq \
62-
tree \
63-
git-lfs \
64-
vim \
65-
nano \
66-
htop \
67-
&& apt-get clean
66+
apt-get update && \
67+
apt-get install -y --no-install-recommends curl wget jq tree git-lfs vim nano htop && \
68+
apt-get clean && \
69+
# Ensure latest pip is installed
70+
python3 -m pip install --upgrade pip setuptools wheel
6871

6972
# Copy the virtual environment from builder stage
7073
COPY --from=builder --chown=vscode:vscode ${VIRTUAL_ENV_PATH} ${VIRTUAL_ENV_PATH}
7174

7275
# Copy Jupyter kernel config from builder
7376
COPY --from=builder --chown=vscode:vscode /home/vscode/.local /home/vscode/.local
7477

78+
# Copy pip version info from builder
79+
COPY --from=builder /tmp/pip-version.txt /tmp/pip-version.txt
80+
7581
# Switch to vscode user for all remaining operations
7682
USER vscode
7783

78-
# Configure shell environment with optimizations
84+
# Verify pip installation and display version info
7985
RUN set -ex && \
86+
. $VIRTUAL_ENV/bin/activate && \
87+
pip --version && \
88+
python -c "import pip; print(f'✅ Pip version: {pip.__version__}')" && \
89+
cat /tmp/pip-version.txt && \
90+
# Configure shell environment with optimizations
91+
set -ex && \
8092
echo "# Virtual environment auto-activation" >> ~/.bashrc && \
8193
echo "export VIRTUAL_ENV=${VIRTUAL_ENV}" >> ~/.bashrc && \
8294
echo "export PATH=\"\${VIRTUAL_ENV}/bin:\$PATH\"" >> ~/.bashrc && \
8395
echo "source \${VIRTUAL_ENV}/bin/activate" >> ~/.bashrc && \
8496
echo "# Virtual environment auto-activation" >> ~/.zshrc && \
8597
echo "export VIRTUAL_ENV=${VIRTUAL_ENV}" >> ~/.zshrc && \
8698
echo "export PATH=\"\${VIRTUAL_ENV}/bin:\$PATH\"" >> ~/.zshrc && \
87-
echo "source \${VIRTUAL_ENV}/bin/activate" >> ~/.zshrc
88-
89-
# Create helpful aliases and functions
90-
RUN set -ex && \
99+
echo "source \${VIRTUAL_ENV}/bin/activate" >> ~/.zshrc && \
100+
# Create helpful aliases and functions
101+
set -ex && \
91102
echo "# APIM Samples helpful aliases" >> ~/.bashrc && \
92103
echo "alias ll='ls -alF'" >> ~/.bashrc && \
93104
echo "alias la='ls -A'" >> ~/.bashrc && \
@@ -101,7 +112,7 @@ WORKDIR /workspaces/Apim-Samples
101112

102113
# Add health check for the virtual environment
103114
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
104-
CMD python -c "import sys; print(f'Python {sys.version}'); import requests, jwt; print('Core packages OK')" || exit 1
115+
CMD python -c "import sys, pip; print(f'Python {sys.version}'); print(f'Pip {pip.__version__}'); import requests, jwt; print('Core packages OK')" || exit 1
105116

106117
# Add labels for better maintainability
107118
LABEL maintainer="APIM Samples Team" \

0 commit comments

Comments
 (0)