-
Notifications
You must be signed in to change notification settings - Fork 1
/
rockcraft.yaml
176 lines (151 loc) · 5.91 KB
/
rockcraft.yaml
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
name: jupyter-pytorch-full
summary: An image for using Jupyter & PyTorch on CPUs
description: |
This image is used as part of the Charmed Kubeflow product. It is deployed
in a user namespace, and enables users to perform CPU-accelerated tasks
using PyTorch from within a Jupyter Notebook.
Both PyTorch and Jupyter are installed in Conda environment, which is
automatically activated.
version: v1.7.0
license: Apache-2.0
base: ubuntu:22.04
platforms:
amd64:
services:
jupyter:
override: replace
startup: enabled
user: jovyan
command: /opt/conda/bin/jupyter lab --notebook-dir="/home/jovyan" --ip=0.0.0.0 --no-browser --port=8888 --ServerApp.token="" --ServerApp.password="" --ServerApp.allow_origin="*" --ServerApp.base_url="/" --ServerApp.authenticate_prometheus=False
environment:
NB_USER: jovyan
NB_UID: 1000
NB_PREFIX: /
HOME: /home/jovyan
LANG: en_US.UTF-8
LANGUAGE: en_US.UTF-8
LC_ALL: en_US.UTF-8
package-repositories:
- type: apt
components: [main]
suites: [jammy]
key-id: 9FD3B784BC1C6FC31A8A0A1C1655A0AB68576280
url: https://deb.nodesource.com/node_14.x
parts:
base-pkgs:
plugin: nil
# These were taken from the upstream base image. They *may not* all be required.
stage-packages:
- apt-transport-https
- bash
- bzip2
- ca-certificates
- curl
- git
- gnupg
- gnupg2
- locales
- lsb-release
- nano
- software-properties-common
- tzdata
- unzip
- vim
- wget
- zip
kubectl:
plugin: nil
stage-snaps:
- kubectl/1.21/stable
organize:
kubectl: bin/kubectl
stage:
- bin/kubectl
nodejs:
plugin: nil
stage-packages: [nodejs]
generate-locale:
plugin: nil
build-packages:
- locales
override-build: |
echo "en_US.UTF-8 UTF-8" > /etc/locale.gen
locale-gen
mkdir -p $CRAFT_PART_INSTALL/usr/lib/locale $CRAFT_PART_INSTALL/usr/share/i18n/locales
cp /usr/lib/locale/locale-archive $CRAFT_PART_INSTALL/usr/lib/locale/locale-archive
cp -r /usr/share/i18n/locales $CRAFT_PART_INSTALL/usr/share/i18n/locales
conda-jupyter:
plugin: nil
build-packages:
- lsb-release
- wget
build-environment:
# The URL and tag to fetch Kubeflow requirements files from
# Use this to adjust the Kubeflow version
- KF_BASE_URL: "https://raw.githubusercontent.com/kubeflow/kubeflow/v1.7.0/components/example-notebook-servers"
- MINIFORGE_ARCH: "x86_64"
- MINIFORGE_VERSION: "4.10.1-4"
- PIP_VERSION: "21.1.2"
- PYTHON_VERSION: "3.8.10"
- HOME: "/home/jovyan"
- CONDA_DIR: "/opt/conda"
- CONDA_BIN: "/opt/conda/bin"
override-build: |
mkdir -p "$CONDA_DIR" "$HOME"
# Download the miniforge installer
wget -qO miniforge.sh \
"https://github.com/conda-forge/miniforge/releases/download/${MINIFORGE_VERSION}/Miniforge3-${MINIFORGE_VERSION}-Linux-${MINIFORGE_ARCH}.sh"
# Download the miniforge install shasums
wget -qO miniforge.sh.sha256 \
"https://github.com/conda-forge/miniforge/releases/download/${MINIFORGE_VERSION}/Miniforge3-${MINIFORGE_VERSION}-Linux-${MINIFORGE_ARCH}.sh.sha256"
# Verify that the downloaded installer is correct
echo "$(cat miniforge.sh.sha256 | awk '{ print $1; }') miniforge.sh" | sha256sum --check
# Run the miniforge installer
/bin/sh miniforge.sh -b -f -p "${CONDA_DIR}"
# Configure conda
"${CONDA_BIN}/conda" config --system --set auto_update_conda false
"${CONDA_BIN}/conda" config --system --set show_channel_urls true
echo "conda ${MINIFORGE_VERSION:0:-2}" >> "${CONDA_DIR}/conda-meta/pinned"
echo "python ${PYTHON_VERSION}" >> "${CONDA_DIR}/conda-meta/pinned"
# Install the correct versions of python, conda, pip
"${CONDA_BIN}/conda" install -y -q \
python="${PYTHON_VERSION}" \
conda="${MINIFORGE_VERSION:0:-2}" \
pip="${PIP_VERSION}"
# Clean up
"${CONDA_BIN}/conda" update -y -q --all
"${CONDA_BIN}/conda" clean -a -f -y
# Install the jupyter python requirements
wget -qO jupyter-requirements.txt "${KF_BASE_URL}/jupyter/requirements.txt"
"${CONDA_BIN}/pip" install --no-cache-dir -r jupyter-requirements.txt
# Generate a jupyter lab config
"${CONDA_BIN}/jupyter" lab --generate-config --allow-root
# Install the jupyter-pytorch cpu requirements
wget -qO requirements.txt "${KF_BASE_URL}/jupyter-pytorch/cpu-requirements.txt"
"${CONDA_BIN}/pip" install --no-cache-dir -r requirements.txt
# Install the jupyter-pytorch-full cpu requirements
wget -qO requirements.txt "${KF_BASE_URL}/jupyter-pytorch-full/requirements.txt"
"${CONDA_BIN}/pip" install --no-cache-dir -r requirements.txt
# Create some directories for staging files
mkdir -p "${CRAFT_PART_INSTALL}/opt" "${CRAFT_PART_INSTALL}/etc" "${CRAFT_PART_INSTALL}/home"
# Write some config files for activating conda in user sessions
echo ". /opt/conda/etc/profile.d/conda.sh" >> "${HOME}/.bashrc"
echo ". /opt/conda/etc/profile.d/conda.sh" >> "${CRAFT_PART_INSTALL}/etc/profile"
echo "conda activate base" >> "${HOME}/.bashrc"
echo "conda activate base" >> "${CRAFT_PART_INSTALL}/etc/profile"
# Do some cleanup
rm -rf "${HOME}/.wget-hsts" "${HOME}/.cache"
# Stage the conda directories
cp -r "${CONDA_DIR}" "${CRAFT_PART_INSTALL}/opt/conda"
cp -r "${HOME}" "${CRAFT_PART_INSTALL}/${HOME}"
non-root-user:
plugin: nil
after: [conda-jupyter]
overlay-script: |
# Create a user in the $CRAFT_OVERLAY chroot
useradd -R $CRAFT_OVERLAY -M -s /bin/bash -N -u 1000 jovyan
override-prime: |
craftctl default
chown -R 1000:users home/jovyan
chown -R 1000:users bin
chown -R 1000:users opt/conda