-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
181 lines (150 loc) · 7.1 KB
/
Dockerfile
File metadata and controls
181 lines (150 loc) · 7.1 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# Variant for Haskell in CPSC 312, based on https://github.com/PrairieLearnUBC/workspace_cpsc210
# Enhanced code-server workspace template for PrairieLearn.
# As discussed here: https://github.com/PrairieLearn/PrairieLearn/issues/3170
# Based on the original Dockerfiles for code-server.
# 20210630 Eric Huber - updating to 3.10.2, simplifying, fixing local testing
# It seems like the bug has been fixed, so let's try the more recent version.
# (Some extensions are broken with older versions.)
# https://github.com/PrairieLearn/PrairieLearn/issues/4036
FROM --platform=linux/amd64 codercom/code-server:4.20.0-bookworm
# On PL, we want to standardize on using 1001:1001 for the user. We change the
# "coder" account's UID and GID here so that fixuid has no work to do later.
# This speeds up container loading time drastically and avoids timeouts.
USER root
RUN export OLD_UID=$(id -u coder) && \
export OLD_GID=$(id -g coder) && \
export NEW_UID=1001 && \
export NEW_GID=1001 && \
groupmod -g 1001 coder && \
usermod -u 1001 -g 1001 coder && \
find /home -user $OLD_UID -execdir chown -h $NEW_UID {} + && \
find /home -group $OLD_GID -execdir chgrp -h $NEW_GID {} + && \
unset OLD_UID OLD_GID NEW_UID NEW_GID
# Cleaning up the cache in the same step when we install is important if you
# want to minimize the image size.
USER coder
####################################################
## Install Haskell
RUN sudo apt-get update -y
RUN sudo apt-get install -y \
build-essential \
curl \
libffi-dev \
libffi8 \
libgmp-dev \
libgmp10 \
libncurses-dev \
libncurses5 \
libtinfo5 \
pkg-config
# Install with HLS and set up the PATH properly.
# (Trying to run HLS with recommended is failing!)
ENV BOOTSTRAP_HASKELL_NONINTERACTIVE=1
ENV BOOTSTRAP_HASKELL_INSTALL_HLS=1
ENV BOOTSTRAP_HASKELL_GHC_VERSION=latest
ENV BOOTSTRAP_HASKELL_CABAL_VERSION=latest
ENV BOOTSTRAP_HASKELL_STACK_VERSION=latest
ENV BOOTSTRAP_HASKELL_HLS_VERSION=latest
# NOT currently getting me the path I need.
ENV BOOTSTRAP_HASKELL_ADJUST_BASHRC=1
RUN curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
# Reduce image size by deleting unnecessary files
# TODO: delete all ~/.ghcup/ghc/**/*_p.a files
# TODO: delete all files like ~/.ghcup/hls/2.9.0.1/lib/haskell-language-server-2.9.0.1/lib/*
# that are not for this version of ghc
# # UPDATE LTS HERE
# # Review https://www.stackage.org/ to compare ghc versions to what's available.
# ENV LTS=lts-22.31
RUN ( code-server --disable-telemetry --force \
# Install only one extension per line.
--install-extension haskell.haskell \
--install-extension ms-vscode.live-server \
) && \
rm -rf /home/coder/.local/share/code-server/CachedExtensionVSIXs
# Prepare the entrypoints. The entrypoint.sh part is based on what code-server
# originally had, so it may need to be updated when code-server is updated. We
# avoid running fixuid if the user is root (for local testing in PL). We also
# disable auth as PL handles it.
USER root
RUN rm -f /run/fixuid.ran && \
echo "" > /usr/bin/entrypoint.sh && chmod 0755 /usr/bin/entrypoint.sh && \
/usr/bin/env echo -e '#!/usr/bin/env bash \n' \
'set -eu \n' \
'# We do this first to ensure sudo works below when renaming the user. \n' \
'# Otherwise the current container UID may not exist in the passwd database. \n' \
'[ $(id -u) -ne 0 ] && eval "$(fixuid -q)" \n' \
' \n' \
'if [ "${DOCKER_USER-}" ]; then \n' \
' USER="$DOCKER_USER" \n' \
' if [ "$DOCKER_USER" != "$(whoami)" ]; then \n' \
' echo "$DOCKER_USER ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers.d/nopasswd > /dev/null \n' \
' # Unfortunately we cannot change $HOME as we cannot move any bind mounts \n' \
' # nor can we bind mount $HOME into a new home as that requires a privileged container. \n' \
' sudo usermod --login "$DOCKER_USER" coder \n' \
' sudo groupmod -n "$DOCKER_USER" coder \n' \
' \n' \
' sudo sed -i "/coder/d" /etc/sudoers.d/nopasswd \n' \
' fi \n' \
'else \n' \
' sudo rm /etc/sudoers.d/nopasswd \n' \
'fi \n' \
'\n' \
'dumb-init /usr/bin/code-server --auth none "$@" \n' >> /usr/bin/entrypoint.sh
EXPOSE 8080
RUN /bin/sh -c echo "**** install runtime dependencies ****" && \
sudo apt-get update && \
sudo apt-get install -y \
software-properties-common \
jq \
libatomic1 \
net-tools \
netcat-traditional
COPY --chmod=0700 haskell_cleanup.sh /home/coder/haskell_cleanup.sh
RUN echo "**** clean up ****" && \
sudo apt-get clean && \
sudo rm -rf \
/config/* \
/tmp/* \
/var/lib/apt/lists/* \
/var/tmp/* && \
/home/coder/haskell_cleanup.sh && \
rm /home/coder/haskell_cleanup.sh
# TODO: Maybe customize the preferences to set the theme to auto-adjust to the
# browser, turn off more telemetry, etc.
# Please read the note here carefully to avoid wiping out what you installed
# in ~/.local:
# EDITOR_FOCUS_DIR should be set to the directory you want the editor to start
# up in. This is not necessarily the same as the "home" setting in the
# question's info.json file. The "home" setting determines the mount point for
# the persistent cloud storage, which will hide any contents your image
# originally had at the same path. You might want to set both EDITOR_FOCUS_DIR
# and "home" to a deeper directory than /home/coder if you want to keep the
# default home contents from the workspace image (~/.local, etc.). For
# example, using /home/coder/question will copy the question's workspace
# folder contents into an empty mount at /home/coder/question and save it for
# the student, while always reusing the initial contents of /home/coder that
# you prepared in the image. (However, if students try to customize their
# editor settings, those will get reset in between sessions this way.)
USER coder
ENV PROJECT_DIR="/home/coder/prairielearn/project"
ENV EDITOR_FOCUS_DIR="${PROJECT_DIR}/app"
ENV PATH="${PATH}:/home/coder/.ghcup/bin"
RUN mkdir -p "${EDITOR_FOCUS_DIR}"
RUN mkdir -p "${PROJECT_DIR}/src"
WORKDIR "${PROJECT_DIR}"
RUN mkdir -p "/home/coder/.local/share/code-server/User" "/home/coder/prairielearn/project"
COPY --chmod=0444 settings.json /home/coder/.local/share/code-server/User/settings.json
COPY --chmod=0666 keybindings.json /home/coder/.local/share/code-server/User/keybindings.json
COPY --chmod=0444 coder.json /home/coder/.local/share/code-server/coder.json
COPY --chmod=0444 settingsEmpty.json /home/coder/.local/share/code-server/Machine/settings.json
COPY --chmod=0555 workspaceTemplate/.scripts "${PROJECT_DIR}/.scripts"
COPY --chmod=0444 workspaceTemplate/.vscode "${PROJECT_DIR}/.vscode"
COPY --chmod=0444 workspaceTemplate/.lib "${PROJECT_DIR}/.lib"
# This DOES work to update the path for the user within the Docker image.
RUN echo 'export PATH=$PATH:/home/coder/.ghcup/bin' >> ~/.bashrc
# Initialize the project and do an initial download of packages.
COPY --chmod=0666 workspaceTemplate/Main.hs "${PROJECT_DIR}/app/Main.hs"
COPY --chmod=0666 workspaceTemplate/Lib.hs "${PROJECT_DIR}/src/Lib.hs"
RUN cabal init . -n -p project --libandexe --application-dir=app --source-dir=src -d base,random --main-is="Main.hs"
RUN cabal build
ENTRYPOINT ["/usr/bin/env", "sh", "/usr/bin/entrypoint.sh", "--bind-addr", "0.0.0.0:8080", "."]