Skip to content

Commit c225b44

Browse files
committed
refactor: Update code-server image for easier use of docker in exercise
1 parent 4588600 commit c225b44

File tree

5 files changed

+109
-42
lines changed

5 files changed

+109
-42
lines changed

docker/code-server/.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12

docker/code-server/Dockerfile

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,54 @@
1-
# syntax=docker/dockerfile:1
2-
3-
# Based on https://gist.githubusercontent.com/usr-ein/c42d98abca3cb4632ab0c2c6aff8c88a/raw/19dcc899f68d0b08c2c137d3fd01715b0c84bac9/Dockerfile
4-
5-
################################
6-
# PYTHON-BASE
7-
# Sets up all our shared environment variables
8-
################################
9-
FROM --platform=$TARGETPLATFORM linuxserver/code-server:latest AS python-base
10-
11-
ARG TARGETPLATFORM
12-
13-
# python
14-
ENV PYTHONUNBUFFERED=1 \
15-
# prevents python creating .pyc files
16-
PYTHONDONTWRITEBYTECODE=1 \
17-
\
18-
# pip
19-
PIP_DISABLE_PIP_VERSION_CHECK=on \
20-
PIP_DEFAULT_TIMEOUT=100 \
21-
\
22-
# paths
23-
# this is where our requirements + virtual environment will live
24-
PYSETUP_PATH="/opt/pysetup" \
25-
VENV_PATH="/opt/pysetup/.venv"
26-
27-
28-
################################
29-
# BUILDER-BASE
30-
# Used to build deps + create our virtual environment
31-
################################
32-
FROM python-base AS builder-base
1+
# Start from the linuxserver/code-server image.
2+
FROM --platform=$TARGETPLATFORM linuxserver/code-server:latest
333
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
344

5+
ENV PUID=0
6+
ENV PGID=0
7+
ENV DEFAULT_WORKSPACE=/workspace
8+
9+
# Switch to root to install additional packages.
10+
USER root
11+
12+
# Install Docker engine (docker.io).
3513
RUN apt-get update && \
36-
apt-get install -y curl bash-completion \
37-
software-properties-common \
38-
build-essential && \
39-
add-apt-repository ppa:deadsnakes/ppa && \
40-
apt-get update && \
41-
apt-get install -y python3.12 python3.12-venv python3.12-dev && \
42-
apt-get clean && \
14+
apt-get install -y docker.io \
15+
build-essential \
16+
gcc \
17+
g++ \
18+
clang \
19+
make \
20+
meson \
21+
ninja-build && \
22+
apt-get clean &&\
4323
rm -rf /var/lib/apt/lists/*
4424

45-
RUN curl -fsSL https://get.docker.com | sh
25+
# Create the Docker daemon socket directory, if needed.
26+
RUN mkdir -p /var/run
4627

47-
# Expose the port used by code-server
28+
# Expose only the code-server port (adjust based on your configuration).
4829
EXPOSE 8443
4930

31+
# Copy the custom entrypoint script.
32+
COPY docker-entrypoint.sh /docker-entrypoint.sh
33+
RUN chmod +x /docker-entrypoint.sh
34+
35+
SHELL ["/bin/bash", "-c"]
36+
WORKDIR /workspace
37+
ENV PATH="/app/code-server/bin:${PATH}"
38+
39+
RUN code-server --install-extension ms-python.python
40+
41+
42+
ADD pyproject.toml .
43+
ADD settings.json .vscode/settings.json
44+
45+
RUN uv venv .venv
46+
RUN source .venv/bin/activate
47+
RUN uv sync --active
48+
49+
50+
# Use our entrypoint script to launch Docker daemon and then code-server.
51+
ENTRYPOINT ["/docker-entrypoint.sh"]
5052

51-
RUN /app/code-server/bin/code-server --install-extension ms-python.python
53+
# The default command provided by linuxserver initiates code-server.
54+
CMD ["/init"]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "Starting Docker daemon (without TCP exposure)..."
5+
6+
# Launch dockerd in the background. Docker will listen on its default Unix socket (/var/run/docker.sock).
7+
dockerd > /var/log/dockerd.log 2>&1 &
8+
9+
# Wait until the Docker daemon is ready.
10+
until docker info > /dev/null 2>&1; do
11+
echo "Waiting for Docker daemon..."
12+
sleep 1
13+
done
14+
15+
echo "Docker daemon is running."
16+
17+
18+
19+
20+
# Execute the default command (typically code-server via linuxserver's /init script).
21+
exec "$@"

docker/code-server/pyproject.toml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[project]
2+
name = "titanicsurvivors"
3+
version = "0.1.0"
4+
description = "Example project for the creation of a machine learning platform with ZenML.This project creates a model to predict would survive the titanic disaster."
5+
requires-python = ">=3.12"
6+
dependencies = [
7+
"numpy<2.0",
8+
"pandas>=2.2.3",
9+
"pyarrow>=19.0.1",
10+
"python-dotenv>=1.1.0",
11+
"xgboost>=3.0.0",
12+
"zenml>=0.80.1",
13+
]
14+
15+
[project.optional-dependencies]
16+
k8s = [
17+
"kubernetes>=32.0.1",
18+
]
19+
azure = [
20+
"adlfs>=2024.12.0",
21+
"azure-identity>=1.21.0",
22+
"azure-keyvault-keys>=4.10.0",
23+
"azure-keyvault-secrets>=4.9.0",
24+
"azure-mgmt-containerservice>=20.0.0",
25+
"azure-storage-blob>=12.17.0",
26+
"azureml-core>=1.56.0",
27+
"azure-ai-ml>=1.23.1"
28+
]
29+
mlflow = [
30+
"mlflow>=2.21.3",
31+
"pydantic>=2.8.2",
32+
"python-rapidjson>=1.20",
33+
]
34+
bento = [
35+
"bentoml>=1.4.7",
36+
]

docker/code-server/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"defaultInterpreterPath": "${workspaceFolder}/.venv",
3+
"envFile": "${workspaceFolder}/.env",
4+
"terminal.activateEnvironment": true
5+
6+
}

0 commit comments

Comments
 (0)