Skip to content

Commit 50e11ac

Browse files
Merge pull request #319 from atheo89/vscode-ubi9
Rebase VSCode to UBI9 instead on C9S
2 parents ffdce99 + 9851293 commit 50e11ac

File tree

16 files changed

+464
-4
lines changed

16 files changed

+464
-4
lines changed

Makefile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ runtime-pytorch-ubi9-python-3.9: base-ubi9-python-3.9
183183
runtime-cuda-tensorflow-ubi9-python-3.9: cuda-ubi9-python-3.9
184184
$(call image,$@,runtimes/tensorflow/ubi9-python-3.9,$<)
185185

186+
.PHONY: codeserver-ubi9-python-3.9
187+
codeserver-ubi9-python-3.9: base-ubi9-python-3.9
188+
$(call image,$@,codeserver/ubi9-python-3.9,$<)
189+
190+
186191
####################################### Buildchain for Python 3.9 using C9S #######################################
187192

188193
# Build and push base-c9s-python-3.9 image to the registry
@@ -194,10 +199,6 @@ base-c9s-python-3.9:
194199
cuda-c9s-python-3.9: base-c9s-python-3.9
195200
$(call image,$@,cuda/c9s-python-3.9,$<)
196201

197-
.PHONY: codeserver-c9s-python-3.9
198-
codeserver-c9s-python-3.9: base-c9s-python-3.9
199-
$(call image,$@,codeserver/c9s-python-3.9,$<)
200-
201202
.PHONY: rstudio-c9s-python-3.9
202203
rstudio-c9s-python-3.9: base-c9s-python-3.9
203204
$(call image,$@,rstudio/c9s-python-3.9,$<)

codeserver/ubi9-python-3.9/Dockerfile

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
ARG BASE_IMAGE
2+
FROM ${BASE_IMAGE}
3+
4+
ARG CODESERVER_VERSION=v4.16.1
5+
6+
LABEL name="odh-notebook-code-server-ubi9-python-3.9" \
7+
summary="Code Server (VS Code) image with python 3.9 based on UBI 9" \
8+
description="Code Server (VS Code) image with python 3.9 based on UBI9" \
9+
io.k8s.display-name="Code Server (VS Code) image with python 3.9 based on UBI9" \
10+
io.k8s.description="Code Server (VS Code) image with python 3.9 based on UBI9" \
11+
authoritative-source-url="https://github.com/opendatahub-io/notebooks" \
12+
io.openshift.build.commit.ref="main" \
13+
io.openshift.build.source-location="https://github.com/opendatahub-io/notebooks/tree/main/codeserver/ubi9-python-3.9" \
14+
io.openshift.build.image="quay.io/opendatahub/workbench-images:codeserver-ubi9-python-3.9"
15+
16+
USER 0
17+
18+
WORKDIR /opt/app-root/bin
19+
20+
# Install Code Server
21+
RUN yum install -y "https://github.com/coder/code-server/releases/download/${CODESERVER_VERSION}/code-server-${CODESERVER_VERSION/v/}-amd64.rpm" && \
22+
yum -y clean all --enablerepo='*'
23+
24+
# Install NGINX to proxy VSCode and pass probes check
25+
ENV NGINX_VERSION=1.22 \
26+
NGINX_SHORT_VER=122 \
27+
NGINX_CONFIGURATION_PATH=${APP_ROOT}/etc/nginx.d \
28+
NGINX_CONF_PATH=/etc/nginx/nginx.conf \
29+
NGINX_DEFAULT_CONF_PATH=${APP_ROOT}/etc/nginx.default.d \
30+
NGINX_CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/nginx \
31+
NGINX_APP_ROOT=${APP_ROOT} \
32+
NGINX_LOG_PATH=/var/log/nginx \
33+
NGINX_PERL_MODULE_PATH=${APP_ROOT}/etc/perl
34+
35+
# Modules does not exist
36+
RUN yum install -y https://download.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm && \
37+
INSTALL_PKGS="bind-utils nginx nginx-mod-stream nginx-mod-http-perl fcgiwrap initscripts chkconfig" && \
38+
yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \
39+
rpm -V $INSTALL_PKGS && \
40+
# spawn-fcgi is not in epel9 \
41+
rpm -i --nodocs https://www.rpmfind.net/linux/fedora/linux/releases/37/Everything/x86_64/os/Packages/s/spawn-fcgi-1.6.3-23.fc37.x86_64.rpm && \
42+
yum -y clean all --enablerepo='*'
43+
44+
# Copy extra files to the image.
45+
COPY nginx/root/ /
46+
47+
# Changing ownership and user rights to support following use-cases:
48+
# 1) running container on OpenShift, whose default security model
49+
# is to run the container under random UID, but GID=0
50+
# 2) for working root-less container with UID=1001, which does not have
51+
# to have GID=0
52+
# 3) for default use-case, that is running container directly on operating system,
53+
# with default UID and GID (1001:0)
54+
# Supported combinations of UID:GID are thus following:
55+
# UID=1001 && GID=0
56+
# UID=<any>&& GID=0
57+
# UID=1001 && GID=<any>
58+
RUN sed -i -f ${NGINX_APP_ROOT}/nginxconf.sed ${NGINX_CONF_PATH} && \
59+
mkdir -p ${NGINX_APP_ROOT}/etc/nginx.d/ && \
60+
mkdir -p ${NGINX_APP_ROOT}/etc/nginx.default.d/ && \
61+
mkdir -p ${NGINX_APP_ROOT}/api/ && \
62+
mkdir -p ${NGINX_CONTAINER_SCRIPTS_PATH}/nginx-start && \
63+
mkdir -p ${NGINX_LOG_PATH} && \
64+
mkdir -p ${NGINX_PERL_MODULE_PATH} && \
65+
chown -R 1001:0 ${NGINX_CONF_PATH} && \
66+
chown -R 1001:0 ${NGINX_APP_ROOT}/etc && \
67+
chown -R 1001:0 ${NGINX_CONTAINER_SCRIPTS_PATH}/nginx-start && \
68+
chown -R 1001:0 /var/lib/nginx /var/log/nginx /run && \
69+
chmod ug+rw ${NGINX_CONF_PATH} && \
70+
chmod -R ug+rwX ${NGINX_APP_ROOT}/etc && \
71+
chmod -R ug+rwX ${NGINX_CONTAINER_SCRIPTS_PATH}/nginx-start && \
72+
chmod -R ug+rwX /var/lib/nginx /var/log/nginx /run && \
73+
rpm-file-permissions
74+
75+
## Configure nginx
76+
COPY nginx/serverconf/ /opt/app-root/etc/nginx.default.d/
77+
COPY nginx/httpconf/ /opt/app-root/etc/nginx.d/
78+
COPY nginx/api/ /opt/app-root/api/
79+
80+
# Launcher
81+
COPY utils utils/
82+
COPY run-code-server.sh run-nginx.sh ./
83+
84+
ENV SHELL /bin/bash
85+
86+
WORKDIR /opt/app-root/src
87+
88+
USER 1001
89+
90+
CMD /opt/app-root/bin/run-code-server.sh
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
apiVersion: kustomize.config.k8s.io/v1beta1
3+
kind: Kustomization
4+
namePrefix: codeserver-
5+
resources:
6+
- pod.yaml
7+
images:
8+
- name: codeserver-workbench
9+
newName: quay.io/opendatahub/workbench-images
10+
newTag: codeserver-ubi9-python-3.9
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
apiVersion: v1
3+
kind: Pod
4+
metadata:
5+
name: pod
6+
labels:
7+
app: codeserver-image
8+
spec:
9+
containers:
10+
- name: codeserver
11+
image: codeserver-workbench
12+
command: ["/bin/sh", "-c", "while true ; do date; sleep 5; done;"]
13+
imagePullPolicy: Always
14+
ports:
15+
- containerPort: 8585
16+
resources:
17+
limits:
18+
cpu: 500m
19+
memory: 500Mi
20+
requests:
21+
cpu: 500m
22+
memory: 500Mi
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
echo "Status: 200"
3+
echo "Content-type: application/json"
4+
echo
5+
# Query the heartbeat endpoint
6+
HEALTHZ=$(curl -s http://127.0.0.1:8888/vscode/healthz)
7+
# Extract last_activity | remove milliseconds
8+
LAST_ACTIVITY_EPOCH=$(echo $HEALTHZ | grep -Po 'lastHeartbeat":\K.*?(?=})' | awk '{ print substr( $0, 1, length($0)-3 ) }')
9+
# Convert to ISO8601 date format
10+
LAST_ACTIVITY=$(date -d @$LAST_ACTIVITY_EPOCH -Iseconds)
11+
# Extract status and replace with terms expected by culler
12+
STATUS=$(sed 's/alive/busy/;s/expired/idle/' <<< $(echo $HEALTHZ | grep -Po 'status":"\K.*?(?=")'))
13+
# Export in format expected by the culling engine
14+
echo '[{"id":"code-server","name":"code-server","last_activity":"'$LAST_ACTIVITY'","execution_state":"'$STATUS'","connections":1}]'
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Make WebSockets working
2+
map $http_upgrade $connection_upgrade {
3+
default upgrade;
4+
'' close;
5+
}
6+
7+
###
8+
# Custom logging for direct last_activity based culling, brace yourself!
9+
###
10+
11+
# Exclude heartbeat from logging for culling purposes
12+
map $request $loggable {
13+
~\/vscode\/healthz 0;
14+
default 1;
15+
}
16+
17+
# iso8601 with millisecond precision transformer (mimicking Jupyter output)
18+
map $time_iso8601 $time_iso8601_p1 {
19+
~([^+]+) $1;
20+
}
21+
map $time_iso8601 $time_iso8601_p2 {
22+
~\+([0-9:]+)$ $1;
23+
}
24+
map $msec $millisec {
25+
~\.([0-9]+)$ $1;
26+
}
27+
28+
log_format json escape=json '[{'
29+
'"id":"code-server",'
30+
'"name":"code-server",'
31+
'"last_activity":"$time_iso8601_p1.$millisec+$time_iso8601_p2",'
32+
'"execution_state":"busy",'
33+
'"connections": 1'
34+
'}]';
35+
36+
map $http_x_forwarded_proto $custom_scheme {
37+
default $scheme;
38+
https https;
39+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Set current user in nss_wrapper
2+
PASSWD_DIR="/opt/app-root/etc"
3+
4+
export USER_ID=$(id -u)
5+
export GROUP_ID=$(id -g)
6+
envsubst < ${PASSWD_DIR}/passwd.template > ${PASSWD_DIR}/passwd
7+
export LD_PRELOAD=libnss_wrapper.so
8+
export NSS_WRAPPER_PASSWD=${PASSWD_DIR}/passwd
9+
export NSS_WRAPPER_GROUP=/etc/group
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root:x:0:0:root:/root:/bin/bash
2+
bin:x:1:1:bin:/bin:/sbin/nologin
3+
daemon:x:2:2:daemon:/sbin:/sbin/nologin
4+
adm:x:3:4:adm:/var/adm:/sbin/nologin
5+
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
6+
sync:x:5:0:sync:/sbin:/bin/sync
7+
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
8+
halt:x:7:0:halt:/sbin:/sbin/halt
9+
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
10+
operator:x:11:0:operator:/root:/sbin/nologin
11+
games:x:12:100:games:/usr/games:/sbin/nologin
12+
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
13+
nobody:x:99:99:Nobody:/:/sbin/nologin
14+
default:x:${USER_ID}:${GROUP_ID}:Default Application User:${HOME}:/sbin/nologin
15+
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# This will make scl collection binaries work out of box.
2+
unset BASH_ENV PROMPT_COMMAND ENV
3+
source scl_source enable rh-nginx$NGINX_SHORT_VER
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Change port
2+
/listen/s%80%8888 default_server%
3+
4+
# Remove listening on IPv6
5+
/\[::\]/d
6+
7+
# One worker only
8+
/worker_processes/s%auto%1%
9+
10+
s/^user *nginx;//
11+
s%/etc/nginx/conf.d/%/opt/app-root/etc/nginx.d/%
12+
s%/etc/nginx/default.d/%/opt/app-root/etc/nginx.default.d/%
13+
s%/usr/share/nginx/html%/opt/app-root/src%
14+
15+
# See: https://github.com/sclorg/nginx-container/pull/69
16+
/error_page/d
17+
/40x.html/,+1d
18+
/50x.html/,+1d
19+
20+
# Addition for RStudio
21+
/server_name/s%server_name _%server_name ${BASE_URL}%

0 commit comments

Comments
 (0)