-
Notifications
You must be signed in to change notification settings - Fork 3
/
justfile
262 lines (224 loc) · 8.27 KB
/
justfile
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
export JUST_DIR := justfile_directory()
export NXC_BRANCH := `basename $PWD`
# nxc command from local source version
nxc_local := "nix develop --override-input nxc path:" + justfile_directory() + " -c nxc"
nix_flags := "--nix-flags \"--override-input nxc path:" + justfile_directory() + "\""
#examples:= `cd examples && ls -I "*.*"`
DEFAULT_BASIC_EXAMPLES := "basic basic-nur execo scripts setup webserver"
DEFAULT_COMMON_EXAMPLES := "basic basic-nur execo multi-compositions nbp-mpi nixos-cluster scripts setup shared-directories-users webserver"
DEFAULT_DOCKER_EXAMPLES := DEFAULT_BASIC_EXAMPLES
#DEFAULT_VM_EXAMPLES := DEFAULT_COMMON_EXAMPLES + " kernel"
DEFAULT_VM_EXAMPLES := DEFAULT_BASIC_EXAMPLES
DEFAULT_G5K_EXAMPLES := DEFAULT_COMMON_EXAMPLES + " kernel"
DEFAULT_G5K_SITE := "grenoble"
export TEST_TMP_DIR := `echo $HOME` + "/nxc-test-tmp"
DEFAULT_NBNODES := "1"
DEFAULT_WALLTIME := "1:0"
DEFAULT_EXAMPLE := "basic"
alias b := build
alias d := develop_with_poetry
alias p := poetry
default:
@just --list
_copy_prepare_example TMPDIR EXAMPLE:
#!/usr/bin/env bash
set -euxo pipefail
cp -a examples/{{ EXAMPLE }}/* {{ TMPDIR }}
cd {{ TMPDIR }}
git init && git add *
build_and_test FLAVOUR EXAMPLE:
#!/usr/bin/env bash
set -euxo pipefail
mkdir -p $TEST_TMP_DIR/{{ FLAVOUR }}
tmpdir=$(mktemp -d $TEST_TMP_DIR/{{ FLAVOUR }}/{{ EXAMPLE }}.XXXXXX)
#prepare directory
just _copy_prepare_example $tmpdir {{ EXAMPLE }}
cd $tmpdir
if [[ $(hostname -d) == *"grid5000"* ]] ; then
shopt -s expand_aliases && alias nxc_local="nxc"
else
shopt -s expand_aliases && alias nxc_local="{{ nxc_local }}"
fi
nxc_local build {{ nix_flags }} -f {{ FLAVOUR }}
if [[ {{ FLAVOUR }} == "vm" ]]; then
# nxc_local start -t # TOFIX
nxc_local start &
sleep 20
nxc_local driver -t
pkill qemu-system
else
nxc_local start
nxc_local driver -t
nxc_local stop
fi
build FLAVOUR EXAMPLE:
#!/usr/bin/env bash
set -euxo pipefail
mkdir -p $HOME/nxc-test-tmp/{{ FLAVOUR }}
tmpdir=$(mktemp -d $TEST_TMP_DIR/{{ FLAVOUR }}/{{ EXAMPLE }}.XXXXXX)
#prepare directory
just _copy_prepare_example $tmpdir {{ EXAMPLE }}
cd $tmpdir
if [[ $(hostname -d) == *"grid5000"* ]] ; then
shopt -s expand_aliases && alias nxc_local="nxc"
else
shopt -s expand_aliases && alias nxc_local="{{ nxc_local }}"
fi
nxc_local build {{ nix_flags }} -f {{ FLAVOUR }}
docker EXAMPLE="basic":
just build_and_test docker {{ EXAMPLE }}
vm EXAMPLE="basic":
just build_and_test vm {{ EXAMPLE }}
list_examples:
#!/usr/bin/env bash
cd $JUST_DIR/examples
for example in `ls -I "*.*"`; do echo "$example"; echo poy; done
_examples_test FLAVOUR +EXAMPLES:
#!/usr/bin/env bash
for example in {{ EXAMPLES }} ; do
printf "###\n### Example: $example\n###\n"
just {{ FLAVOUR }} $example
done
# Build/test selected example with Docker flavour
docker_tests +DOCKER_EXAMPLES=DEFAULT_DOCKER_EXAMPLES:
just _examples_test docker {{ DOCKER_EXAMPLES }}
vm_tests +VM_EXAMPLES=DEFAULT_VM_EXAMPLES:
just _examples_test vm {{ VM_EXAMPLES }}
# build test examples w/ docker (TODO add filter examples or use docker_tests)
docker_examples:
#!/usr/bin/env bash
cd $JUST_DIR/examples
for example in `ls -I "*.*"`; do
echo "$example"
just docker $example
done
clean_nxc_test:
@echo clean
rm -f $TEST_TMP_DIR
# Rsynch current worktree to G5K
rsync_g5k SITE=DEFAULT_G5K_SITE:
#!/usr/bin/env bash
set -euxo pipefail
rsync -avz $JUST_DIR/.. --delete --exclude '\#*' {{ SITE }}.g5k:nxc-test-src
# change gitdir ref from absolute to relative path
ssh grenoble.g5k "find nxc-test-src -name .git -exec sed -i 's/ .*bare/ \.\.\/\.bare/' {} \;"
oarsub_g5k_script NBNODES=DEFAULT_NBNODES WALLTIME=DEFAULT_WALLTIME:
#!/usr/bin/env bash
# TODO test if there is already active job
set -euxo pipefail
cd $JUST_DIR
shopt -s expand_aliases && alias nxc_local="{{ nxc_local }}"
g5k_script=$(nxc helper g5k_script)
export $(oarsub -l nodes={{ NBNODES }},walltime={{ WALLTIME }}:0:0 \
-O $TEST_TMP_DIR/OAR.%jobid%.stdout -E $TEST_TMP_DIR/OAR.%jobid%.stderr \
"$g5k_script {{ WALLTIME }}h" | grep OAR_JOB_ID)
echo $OAR_JOB_ID > $TEST_TMP_DIR/OAR_JOB_ID
start_test_g5k_nfs_store EXAMPLE:
#!/usr/bin/env bash
# take the repo of the last built composition
set -euxo pipefail
if [[ $(hostname -d) == *"grid5000"* ]] ; then
shopt -s expand_aliases && alias nxc_local="nxc"
else
shopt -s expand_aliases && alias nxc_local="{{ nxc_local }}"
fi
compo_dir=$(ls -rtd $TEST_TMP_DIR/g5k-nfs-store/{{ EXAMPLE }}* | tail -n 1)
OAR_JOB_ID=$(cat $TEST_TMP_DIR/OAR_JOB_ID)
if [ -z $OAR_JOB_ID ]; then
echo "no OAR_JOB_ID, need to submit OAR job before (oarsub_g5k_script)"
fi
# test if job exist ant it's in approtiate state
oarjob_status=$(oarstat -j $OAR_JOB_ID -s)
if [[ ! "${oarjob_status##* }" =~ ^(Waiting|Launching|Running|toLaunch|Hold|toAckReservation)$ ]]; then
echo "Job's status issue: $oarjob_status"
exit 1
fi
cd $compo_dir
machine_file=$TEST_TMP_DIR/OAR.$OAR_JOB_ID.stdout
nxc start -m $machine_file -W
nxc driver -t
# build and test g5k-nfs-store flavoured test (launchable remotly or on site)
g5k_nfs_store_test SITE=DEFAULT_G5K_SITE EXAMPLE=DEFAULT_EXAMPLE NBNODES=DEFAULT_NBNODES:
#!/usr/bin/env bash
set -euxo pipefail
hostname_fqdn=$(hostname --fqdn)
if [[ $hostname_fqdn =~ "grid5000.fr" ]]; then
if [[ $hostname_fqdn =~ "{{ SITE }}.grid5000.fr" ]]; then
just build g5k-nfs-store {{ EXAMPLE }}
just start_test_g5k_nfs_store {{ EXAMPLE }}
exit
else
remote={{ SITE }}
fi
else
remote={{ SITE }}.g5k
fi
echo $hostname_fqdn $remote {{ SITE }}
ssh $remote "cd nxc-test-src/$NXC_BRANCH && just g5k_nfs_store_test"
print_examples_nixpkgs_version:
git --no-pager grep NixOS/nixpkgs examples
# Set flakes nixpkgs (arg example: 23.11)
set_flake_nixpkgs_version version: && print_examples_nixpkgs_version
@find . -type f -name 'flake.nix' -exec sed -i 's/github:NixOS\/nixpkgs\/.*/github:NixOS\/nixpkgs\/{{ version }}";/g' {} +
# Prune containers
docker_container_prune:
docker container prune
# Launch poetry shell (from nixpkgs)
develop_with_poetry:
nix run nixpkgs#poetry shell
# Launch poetry (from nixpkgs)
poetry +commands:
nix run nixpkgs#poetry {{ commands }}
# Create new worktree
wkt-create DIR:
git worktree add ../{{ DIR }}
# Create new worktree to prepare the next xx.xx-dev
wkt-create-nixos-unstable DIR:
cd ../nixos-unstable && git worktree add ../{{ DIR }}
g5k-install-nxc-nix:
#!/usr/bin/env bash
pip install nixos-compose
nxc helper install-nix
g5k-uninstall-nxc-nix:
#!/usr/bin/env bash
pip uninstall nixos-compose
chmod 777 -R ~/.local/share/nix
rm -rf ~/.local/share/nix
g5k-install-just SITE:
ssh {{ SITE }}.g5k "mkdir -p ~/.local/bin &&curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to ~/.local/bin"
build_and_test_from_installed FLAVOUR EXAMPLE="basic":
#!/usr/bin/env bash
set -euxo pipefail
mkdir -p $TEST_TMP_DIR/{{ FLAVOUR }}
tmpdir=$(mktemp -d $TEST_TMP_DIR/{{ FLAVOUR }}/{{ EXAMPLE }}.XXXXXX)
#prepare directory
echo $tmpdir
cd $tmpdir
nxc init -f {{ FLAVOUR }} -t {{ EXAMPLE }}
nxc build -f {{ FLAVOUR }}
if [[ {{ FLAVOUR }} == "vm" ]]; then
# nxc_local start -t # TOFIX
nxc start &
sleep 20
nxc driver -t
pkill qemu-system
else
nxc start
nxc driver -t
nxc stop
fi
publish-on-pypi:
#!/usr/bin/env bash
if [[ {{ NXC_BRANCH }} == "master" ]]; then
echo "Publish must be done from an XX.XX branch" && exit 1
else
just poetry "-- publish --build -u __token__ -p $(cat ~/tokens/nxc)"
fi
build-tgz:
just poetry build
g5k-install-tgz SITE="grenoble":
#!/usr/bin/env bash
rsync -avz dist/ --delete --exclude '*.whl' {{ SITE }}.g5k:nxc-dist
lastest_tgz=$(ls -t dist -I '*.whl'| head -n 1)
echo "Install $lastest_tgz on {{ SITE }} site"
ssh {{ SITE }}.g5k "pip uninstall -y nixos-compose ; pip install nxc-dist/$lastest_tgz ; nxc --version"