Skip to content

Commit dee828d

Browse files
committed
Add make-dev-pod script
- make-dev-pod.sh spawns a pod in which you can run these scripts. - Update `br.py` to get default values for --image and --gpu from `BATCHTOOLS_IMAGE` and `BATCHTOOLS_GPU`.
1 parent 9d60c68 commit dee828d

File tree

2 files changed

+126
-2
lines changed

2 files changed

+126
-2
lines changed

br.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,13 @@ class CreateJobCommandArgs(argparse.Namespace):
3636
default values.
3737
"""
3838

39-
gpu: Annotated[str, "v100"]
39+
gpu: Annotated[str, lambda: os.getenv("BATCHTOOLS_GPU", "v100")]
4040
image: Annotated[
4141
str,
42-
"image-registry.openshift-image-registry.svc:5000/redhat-ods-applications/csw-run-f25:latest",
42+
lambda: os.getenv(
43+
"BATCHTOOLS_IMAGE",
44+
"image-registry.openshift-image-registry.svc:5000/redhat-ods-applications/csw-run-f25:latest",
45+
),
4346
]
4447
context: Annotated[bool, True]
4548
name: Annotated[str, "job"]

make-dev-pod.sh

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/bin/bash
2+
3+
die() {
4+
echo "ERROR: $*" >&2
5+
exit 1
6+
}
7+
8+
if [[ $1 = "-d" ]]; then
9+
echo "Delete dev pod"
10+
oc delete pod dev-pod --wait=false
11+
oc wait --for delete pod/dev-pod
12+
fi
13+
14+
echo "Apply RBAC"
15+
oc apply -f- <<EOF || die "failed to apply RBAC"
16+
apiVersion: rbac.authorization.k8s.io/v1
17+
kind: Role
18+
metadata:
19+
name: dev-pod
20+
rules:
21+
- apiGroups:
22+
- ""
23+
resources:
24+
- pods
25+
- pods/exec
26+
verbs:
27+
- create
28+
- delete
29+
- get
30+
- list
31+
- patch
32+
- update
33+
- watch
34+
- apiGroups:
35+
- ""
36+
resources:
37+
- pods/log
38+
verbs:
39+
- get
40+
- apiGroups:
41+
- "batch"
42+
resources:
43+
- jobs
44+
verbs:
45+
- create
46+
- delete
47+
- get
48+
- list
49+
- patch
50+
- update
51+
- watch
52+
---
53+
apiVersion: rbac.authorization.k8s.io/v1
54+
kind: RoleBinding
55+
metadata:
56+
name: dev-pod
57+
roleRef:
58+
apiGroup: rbac.authorization.k8s.io
59+
kind: Role
60+
name: dev-pod
61+
subjects:
62+
- kind: ServiceAccount
63+
name: default
64+
EOF
65+
66+
if ! oc get pod dev-pod -o name >/dev/null 2>&1; then
67+
echo "Create dev pod"
68+
oc apply -f- <<EOF || die "failed to create dev pod"
69+
apiVersion: v1
70+
kind: Pod
71+
metadata:
72+
name: dev-pod
73+
labels:
74+
app: dev-pod
75+
spec:
76+
containers:
77+
- command:
78+
- pause
79+
env:
80+
- name: HOME
81+
value: /home/batchtools
82+
- name: BATCHTOOLS_IMAGE
83+
value: ghcr.io/larsks/batchtools-dev:latest
84+
- name: BATCHTOOLS_GPU
85+
value: none
86+
image: ghcr.io/larsks/batchtools-dev:latest
87+
imagePullPolicy: Always
88+
name: dev-pod
89+
volumeMounts:
90+
- mountPath: /home/batchtools
91+
name: workdir
92+
workingDir: /home/batchtools
93+
volumes:
94+
- name: workdir
95+
emptyDir: {}
96+
EOF
97+
fi
98+
99+
echo "Wait for dev pod to start"
100+
101+
timeout 60 bash <<EOF || die "timed out waiting for dev pod to start"
102+
# First we wait until the pod is ready
103+
oc wait --for condition=ready pod/dev-pod
104+
105+
# Then we wait until the container is responding
106+
while ! oc rsh dev-pod true >/dev/null 2>&1; do sleep 1; done
107+
EOF
108+
109+
echo "Copy local directory to dev pod"
110+
tmpfile=$(mktemp excludeXXXXXX)
111+
trap 'rm -f "$tmpfile"' EXIT
112+
{
113+
echo "$tmpfile"
114+
ls -d .* | grep -v '^\.git'
115+
ls -d _*
116+
} >>"$tmpfile"
117+
RSYNC_RSH="oc rsh -c dev-pod" rsync --recursive --exclude-from="$tmpfile" . dev-pod:/home/batchtools/ ||
118+
die "failed to sync local directory to dev pod"
119+
120+
echo "Install dependencies"
121+
oc rsh dev-pod uv sync || die "failed to install dependencies"

0 commit comments

Comments
 (0)