-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkflow.yaml
287 lines (271 loc) · 10.1 KB
/
workflow.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
permissions:
- '*'
sessions:
dashboard:
useTLS: false
redirect: true
jobs:
install_dask:
steps:
- name: Check Environment
if: ${{ inputs.install_python_environment}}
env:
sshcmd: ssh -o StrictHostKeyChecking=no ${{ inputs.resource.ip }}
conda_env: ${{ inputs.conda_env }}
run: |
set -x
conda_parent_dir=$(dirname ${{ inputs.conda_dir }})
# Check if marker files exist
${sshcmd} "[ -f ${conda_parent_dir}/.miniconda_installed ] && echo install_miniconda=false || echo install_miniconda=true" >> $OUTPUTS
${sshcmd} "[ -f ${conda_parent_dir}/.${conda_env}_installed ] && echo install_dask=false || echo install_dask=true" >> $OUTPUTS
- name: Install Miniconda
if: ${{ inputs.install_python_environment }}
env:
sshcmd: ssh -o StrictHostKeyChecking=no ${{ inputs.resource.ip }}
install_miniconda: ${{ needs.install_dask.outputs.install_miniconda }}
conda_dir: ${{ inputs.conda_dir }})
run: |
set -x
if ! ${install_miniconda}; then
exit 0
fi
ID=$(date +%s)-${RANDOM}
conda_parent_dir=$(dirname ${conda_dir})
${sshcmd} << EOF
wget --no-check-certificate https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /tmp/miniconda-${ID}.sh
mkdir -p ${conda_parent_dir}
bash /tmp/miniconda-${ID}.sh -b -p ${{ inputs.conda_dir }}
touch ${conda_parent_dir}/.miniconda_installed
EOF
- name: Install Dask
if: ${{ inputs.install_python_environment }}
env:
sshcmd: ssh -o StrictHostKeyChecking=no ${{ inputs.resource.ip }}
conda_env: ${{ inputs.conda_env }}
conda_dir: ${{ inputs.conda_dir }}
install_dask: ${{ needs.install_dask.outputs.install_dask }}
run: |
set -x
if ! ${install_dask}; then
exit 0
fi
conda_parent_dir=$(dirname ${conda_dir})
${sshcmd} << EOF
source ${conda_dir}/etc/profile.d/conda.sh
conda create --name ${conda_env} -y
conda activate ${conda_env}
conda install dask distributed dask-jobqueue -c conda-forge -y
touch ${conda_parent_dir}/.${conda_env}_installed
EOF
prepare_work_directory:
steps:
- name: Transfer Data
run: |
# Create remote job directory
ssh -o StrictHostKeyChecking=no ${{ inputs.resource.ip }} mkdir -p ~/${PWD/#$HOME/}
# Transfer dask script
scp dask_script.py ${{ inputs.resource.ip }}:~/${PWD/#$HOME/}
# Transfer inputs.json
scp inputs.json ${{ inputs.resource.ip }}:~/${PWD/#$HOME/}
create_session:
needs:
- install_dask
- prepare_work_directory
steps:
- name: Reserve dashboard ports
env:
sshcmd: ssh -o StrictHostKeyChecking=no ${{ inputs.resource.ip }}
run: |
local_port=$(pw agent open-port)
echo "export local_port=${local_port}" >> ports
echo "local_port=${local_port}" >> $OUTPUTS
dashboard_port=$(${sshcmd} pw agent open-port)
echo "export dashboard_port=${dashboard_port}" >> ports
echo "dashboard_port=${dashboard_port}" >> $OUTPUTS
nginx_proxy_port=$(${sshcmd} pw agent open-port)
echo "export nginx_proxy_port=${nginx_proxy_port}" >> ports
echo "nginx_proxy_port=${nginx_proxy_port}" >> $OUTPUTS
cat ports
- name: Get Controller Hostname
env:
sshcmd: ssh -o StrictHostKeyChecking=no ${{ inputs.resource.ip }}
run: |
target_hostname=$(${sshcmd} hostname)
echo "target_hostname=${target_hostname}" | tee -a $OUTPUTS
- name: Create session
uses: parallelworks/update-session
with:
remotePort: "${{ needs.create_session.outputs.nginx_proxy_port }}"
localPort: "${{ needs.create_session.outputs.local_port }}"
remoteHost: "${{ needs.create_session.outputs.target_hostname }}"
status: running
slug: "status"
target: ${{ inputs.resource.id }}
name: ${{ sessions.dashboard }}
run_dask:
needs:
- create_session
steps:
- name: Run Dask
env:
sshcmd: ssh -o StrictHostKeyChecking=no ${{ inputs.resource.ip }}
load_env: ${{ inputs.load_env }}
conda_env: ${{ inputs.conda_env }}
conda_dir: ${{ inputs.conda_dir }}
run: |
source ports
set -x
${sshcmd} << EOF
set -x
if [ -z "${load_env}" ]; then
source ${conda_dir}/etc/profile.d/conda.sh
conda activate ${conda_env}
else
eval ${load_env}
fi
export dashboard_port_worker=${dashboard_port}
export http_prefix=/me/session/${PW_USER}/${{ sessions.dashboard }}/
cd ~/${PWD/#$HOME/}
python -u dask_script.py &
dask_script_pid=\$!
echo \${dask_script_pid} > dask_script.pid
wait \${dask_script_pid}
rm dask_script.pid
EOF
cleanup: |
sshcmd="ssh -o StrictHostKeyChecking=no ${{ inputs.resource.ip }}"
container_name=$(echo ${PWD} | rev | cut -d'/' -f1-2 | rev | tr '/' '-')
${sshcmd} << EOF
cd ~/${PWD/#$HOME/}
sudo docker stop ${container_name}
# Check if the file dask_script.pid exists
if [ ! -f dask_script.pid ]; then
exit 0
fi
dask_script_pid=\$(cat dask_script.pid)
echo "Killing dask script PID \${dask_script_pid}"
kill \${dask_script_pid}
scancel \$(ls slurm-*.out | sed 's/slurm-\([0-9]\+\).out/\1/')
EOF
start_nginx_proxy:
needs:
- create_session
steps:
- name: Write Nginx config
run: |
source ports
# Write config file
cat >> config.conf <<HERE
server {
listen ${nginx_proxy_port};
server_name _;
index index.html index.htm index.php;
# Allow CORS
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type, Accept, Origin, User-Agent, DNT, Cache-Control, X-Mx-ReqToken, Keep-Alive, X-Requested-With, If-Modified-Since';
add_header X-Frame-Options "ALLOWALL";
client_max_body_size 1000M;
location / {
proxy_pass http://127.0.0.1:${dashboard_port}/me/session/${PW_USER}/${{ sessions.dashboard }}/; # Ensure this has a trailing slash
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header Host \$http_host;
proxy_set_header X-NginX-Proxy true;
# Optionally, handle WebSocket connections
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_set_header X-Forwarded-Host \$host;
proxy_set_header X-Forwarded-Port \$server_port;
}
}
HERE
scp config.conf ${{ inputs.resource.ip }}:~/${PWD/#$HOME/}
- name: Start Nginx Docker Container
env:
sshcmd: ssh -o StrictHostKeyChecking=no ${{ inputs.resource.ip }}
run: |
set -x
container_name=$(echo ${PWD} | rev | cut -d'/' -f1-2 | rev | tr '/' '-')
${sshcmd} << EOF
cd ~/${PWD/#$HOME/}
sudo service docker start
touch empty
touch nginx.logs
# change ownership to nginx user
sudo chown 101:101 nginx.logs
sudo docker run -d --rm --name ${container_name} -v $PWD/config.conf:/etc/nginx/conf.d/config.conf -v $PWD/empty:/etc/nginx/conf.d/default.conf -v $PWD/nginx.logs:/var/log/nginx/access.log -v $PWD/nginx.logs:/var/log/nginx/error.log --network=host nginxinc/nginx-unprivileged:1.25.3
EOF
'on':
execute:
inputs:
header:
type: header
text: Dask SLURM Demo
size: 20
resource:
type: compute-clusters
label: Select SLURM Cluster
include-workspace: false
provider:
- gclusterv2
- pclusterv2
- azclusterv2
- aws-slurm
- google-slurm
- azure-slurm
partition:
type: slurm-partitions
label: SLURM partition
resource: ${{ inputs.resource }}
cores_per_job:
label: Cores per job
type: number
min: 1
max: 10
default: 2
tooltip: cores parameter in SLURMCluster object
memory_per_job:
label: Memory per job
type: string
default: 8GB
tooltip: memory parameter in SLURMCluster object
minimum_jobs:
label: Minimum Jobs
type: number
min: 0
max: 10
default: 0
tooltip: minimum parameter of the SLURMCluster.adapt method
maximum_jobs:
label: Maximum Jobs
type: number
min: 0
max: 10
default: 10
tooltip: maximum parameter of the SLURMCluster.adapt method
install_python_environment:
label: Install Python Environment
type: boolean
default: true
conda_dir:
label: Path to install conda
type: string
default: ~/pw/software/miniconda3
hidden: ${{ inputs.install_python_environment == false }}
optional: ${{ .hidden }}
ignore: ${{ .hidden }}
conda_env:
label: Conda environment
type: string
default: dask-slurm
hidden: ${{ inputs.install_python_environment == false }}
optional: ${{ .hidden }}
ignore: ${{ .hidden }}
load_env:
label: Command to load the Python environment
type: string
hidden: ${{ inputs.install_python_environment == true }}
optional: ${{ .hidden }}
ignore: ${{ .hidden }}