-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile.students
More file actions
139 lines (117 loc) · 3.9 KB
/
Dockerfile.students
File metadata and controls
139 lines (117 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
ARG ARCH=
FROM ${ARCH}ubuntu:22.04 as packages
# Setup workspace directory
RUN mkdir /workspace
WORKDIR /workspace
# Install dependencies
ENV TZ=America/New_York
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install --yes \
apt-transport-https \
ca-certificates \
cmake \
curl \
debian-keyring \
debian-archive-keyring \
git \
gnupg \
libcairo2 \
libpq-dev \
locales \
software-properties-common \
sudo \
tzdata \
unzip \
wget \
zip \
zsh \
&& rm -rf /var/lib/apt/lists/*
# Install Python 3.12
RUN add-apt-repository ppa:deadsnakes/ppa \
&& apt update \
&& apt install --yes \
python3.12 \
python3.12-dev \
python3.12-distutils \
python3-pip \
&& rm -rf /var/lib/apt/lists* \
&& unlink /usr/bin/python3 \
&& ln -s /usr/bin/python3.12 /usr/bin/python3
# Update PIP for 3.12 / Ubuntu compatibility (https://ubuntuhandbook.org/index.php/2023/10/fix-broken-pip-python-312-ubuntu/)
RUN wget -O /tmp/get-pip.py https://bootstrap.pypa.io/get-pip.py && \
python3 /tmp/get-pip.py && \
rm /tmp/get-pip.py
# Use a non-root user per https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID
# Add non-root user and add to sudoers
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME
# Configure zsh
USER $USERNAME
ENV HOME /home/$USERNAME
# Install Python requirements.txt
COPY server/requirements.txt /workspace/requirements.txt
WORKDIR /workspace
RUN echo 'export PYTHONPATH=/workspace' >>~/.zshrc && \
python3 -m pip install --user -r requirements.txt && \
python3 -m pip cache purge
# === Stage 2 ===
# Restart with more minimal setup
FROM ${ARCH}python:3.12-slim-bookworm as target
# Setup workspace directory
RUN mkdir /workspace
WORKDIR /workspace
# Install dependencies
ENV TZ=America/New_York
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install --yes \
curl \
git \
locales \
sudo \
tzdata \
unzip \
wget \
zip \
zsh \
&& rm -rf /var/lib/apt/lists/*
# Use a non-root user per https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID
# Add non-root user and add to sudoers
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME -s /usr/bin/zsh \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME
# Set code to default git commit editor
RUN git config --system core.editor "code --wait"
# Set Safe Directory
RUN git config --system safe.directory '/workspace'
# Set Merge as default pull resolution
RUN git config --system pull.rebase false
# Set Locale for Functional Autocompletion in zsh
RUN locale-gen en_US.UTF-8
# Link from deadsnakes install of python3 to python3.12:slim-bookworm
RUN ln -s /usr/local/bin/python3 /usr/bin/python3
# Configure zsh
USER $USERNAME
ENV HOME /home/$USERNAME
# Add zsh theme with niceties
RUN curl https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh | bash - \
&& sed -i 's/robbyrussell/kennethreitz/g' ~/.zshrc \
&& echo 'export PATH=$PATH:$HOME/.local/bin' >>~/.zshrc
# Copy in built Python Packages
COPY --from=packages /home/${USERNAME}/.local /home/${USERNAME}/.local
COPY server/requirements.txt /tmp/requirements.txt
WORKDIR /tmp
RUN python3 -m pip install --user -r requirements.txt && \
pip install --upgrade pip && \
python3 -m pip cache purge
# Install Trailhead (until an official PyPI package)
COPY bin/trailhead /home/$USERNAME/.local/bin/trailhead
COPY dist/trailhead /home/$USERNAME/.local/lib/python3.12/site-packages/trailhead