Skip to content

Commit 9f8fcf2

Browse files
committed
test: docker image for self-testing codeflare in a pod
1 parent d471078 commit 9f8fcf2

File tree

14 files changed

+607
-14
lines changed

14 files changed

+607
-14
lines changed

deploy/self-test/Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM node:lts-bullseye-slim
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
5+
ENV GITHUB=github.com
6+
ENV ORG=project-codeflare
7+
ENV REPO=codeflare-cli
8+
ENV BRANCH=main
9+
10+
RUN apt update && apt -y install git python3 python3-pip build-essential curl sudo \
11+
&& pip3 install --no-cache-dir -U pip && pip3 install --no-cache-dir -U setuptools \
12+
&& apt -y autoclean && apt -y clean && rm -rf /var/lib/apt/lists/* \
13+
&& usermod -aG sudo node \
14+
&& echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
15+
16+
USER node
17+
WORKDIR /home/node
18+
19+
ADD self-test.sh /home/node/self-test.sh
20+
21+
ENTRYPOINT ["bash"]
22+
CMD ["./self-test.sh"]

deploy/self-test/run.sh

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env bash
2+
3+
SCRIPTDIR=$(cd $(dirname "$0") && pwd)
4+
5+
# name of the configmap
6+
CM=codeflare-self-test-config
7+
8+
# we will test the latest **remote** version of the current local
9+
# org+branch e.g. if your local branch is from org `starpit` and
10+
# branch `fixing-bug`, then make sure to commit and push your changes
11+
# to the remote, otherwise any changes you hoped to test will not be
12+
# picked up
13+
ORG=${GITHUB_REPOSITORY_OWNER-$(git config remote.$(git config branch.main.remote).url | cut -f2 -d: | cut -f1 -d/)}
14+
BRANCH=$(git branch --show-current)
15+
echo "github org=$ORG branch=$BRANCH"
16+
17+
# if you hit ctrl+c, we will tear everything down
18+
trap cleanup INT
19+
20+
# configure kind if needed
21+
function kind() {
22+
if [ -n "$NEEDS_KIND" ]; then
23+
export KUBECONFIG=$("$SCRIPTDIR"/../../tests/kind/setup.sh)
24+
fi
25+
}
26+
27+
# delete the job and configmap (etc.)
28+
function cleanup() {
29+
tput setaf 5
30+
kubectl delete cm $CM
31+
kubectl delete -f "$SCRIPTDIR"/self-test.yaml
32+
tput sgr0
33+
}
34+
35+
# create the job and configmap (etc.)
36+
function start() {
37+
# necessary to support cloning when run as a github action; the
38+
# cloning happens in self-test.sh, inside the running pod (spawned
39+
# by this apply)
40+
if [ -n "$GITHUB_ACTOR" ] && [ -n "$GITHUB_TOKEN" ]; then
41+
GITHUB_ACTOR_PREFIX="$GITHUB_ACTOR:$GITHUB_TOKEN@"
42+
fi
43+
44+
tput setaf 5
45+
kubectl create cm $CM \
46+
--from-literal=ORG=$ORG \
47+
--from-literal=BRANCH=$BRANCH \
48+
--from-literal=VARIANTS=$VARIANTS \
49+
--from-literal=GITHUB_ACTOR_PREFIX=$GITHUB_ACTOR_PREFIX \
50+
--from-literal=GITHUB_SHA=$GITHUB_SHA \
51+
--from-literal=GITHUB_REF=$GITHUB_REF
52+
53+
kubectl apply -f "$SCRIPTDIR"/self-test.yaml
54+
tput sgr0
55+
}
56+
57+
# wait for a pod (of the job) to be ready
58+
function waitForReady() {
59+
tput setaf 3
60+
echo "Waiting for job to start"
61+
tput sgr0
62+
kubectl wait pod -l job-name=codeflare-self-test --for=condition=Ready
63+
}
64+
65+
# stream out the logs of our job's pod(s)
66+
function logs() {
67+
tput setaf 3
68+
echo "Streaming out job logs"
69+
tput sgr0
70+
kubectl logs -l job-name=codeflare-self-test -f
71+
}
72+
73+
function waitForComplete() {
74+
tput setaf 3
75+
echo "Waiting for job completion"
76+
tput sgr0
77+
kubectl wait pod -l job-name=codeflare-self-test --for=condition=Complete --timeout=-1s
78+
}
79+
80+
kind
81+
cleanup
82+
start
83+
waitForReady
84+
logs
85+
waitForComplete

deploy/self-test/self-test.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
set -o pipefail
5+
6+
SCRIPTDIR=$(cd $(dirname "$0") && pwd)
7+
8+
if [ -n "$GITHUB_REF" ]; then
9+
echo "Cloning org=$ORG ref=$GITHUB_REF"
10+
mkdir test
11+
git init
12+
git remote add origin https://github.com/${ORG}/${REPO}
13+
git clone -c 'remote.origin.fetch=+refs/changes/*:${GITHUB_REF%/merge}/changes/*' https://${GITHUB_ACTOR_PREFIX}${GITHUB}/${ORG}/${REPO}.git test
14+
git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin +${GITHUB_SHA}:${GITHUB_REF}
15+
else
16+
echo "Cloning org=$ORG branch=$BRANCH"
17+
git clone https://${GITHUB_ACTOR_PREFIX}${GITHUB}/${ORG}/${REPO}.git -b ${BRANCH} test
18+
fi
19+
cd test
20+
npm ci
21+
npm run build:headless
22+
23+
export KUI_HEADLESS=true
24+
export KUI_HEADLESS_WEBPACK=true
25+
export CODEFLARE_HEADLESS_HOME=$PWD/dist/headless
26+
27+
./bin/codeflare openshift/oc
28+
./bin/codeflare kubernetes/kubectl
29+
30+
export KUBE_NS_FOR_REAL=$(kubectl get job codeflare-self-test -o custom-columns=NS:.metadata.namespace --no-headers)
31+
echo "Kubernetes namespace: $KUBE_NS_FOR_REAL"
32+
33+
if [ -n "$VARIANTS" ]; then
34+
variants=$VARIANTS
35+
else
36+
variants="gpu1 non-gpu"
37+
fi
38+
echo "Using these variants: $variants"
39+
40+
for variant in $variants; do
41+
# for profile in ./tests/kind/profiles/*; do
42+
for profile in $variant/keep-it-simple; do
43+
echo "================== $profile =================="
44+
./tests/kind/run.sh -i $profile
45+
done
46+
done

deploy/self-test/self-test.yaml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: codeflare-self-test-serviceaccount
5+
---
6+
kind: Role
7+
apiVersion: rbac.authorization.k8s.io/v1
8+
metadata:
9+
name: codeflare-self-test-role
10+
rules:
11+
- apiGroups: [""]
12+
resources: ["pods", "pods/exec", "services"]
13+
verbs: ["create", "events", "get", "watch", "list"]
14+
- apiGroups: ["batch"]
15+
resources: ["jobs"]
16+
verbs: ["create", "get", "watch", "list"]
17+
- apiGroups: [""]
18+
resources: ["pods/exec"]
19+
verbs: ["create", "delete"]
20+
#- apiGroups: ["apps"]
21+
# resources: [deployments]
22+
# verbs: [get, list]
23+
---
24+
apiVersion: rbac.authorization.k8s.io/v1
25+
kind: RoleBinding
26+
metadata:
27+
name: codeflare-self-test-rolebinding
28+
subjects:
29+
- kind: ServiceAccount
30+
name: codeflare-self-test-serviceaccount
31+
roleRef:
32+
kind: Role
33+
name: codeflare-self-test-role
34+
apiGroup: rbac.authorization.k8s.io
35+
36+
---
37+
apiVersion: batch/v1
38+
kind: Job
39+
metadata:
40+
name: codeflare-self-test
41+
spec:
42+
template:
43+
spec:
44+
serviceAccountName: codeflare-self-test-serviceaccount
45+
containers:
46+
- name: self-test
47+
image: ghcr.io/project-codeflare/codeflare-self-test:latest
48+
imagePullPolicy: Always
49+
resources:
50+
limits:
51+
cpu: 2
52+
memory: 5Gi
53+
requests:
54+
cpu: 300m
55+
memory: 5Gi
56+
env:
57+
- name: GUIDEBOOK_RUN_ARGS
58+
value: "-V"
59+
- name: MODE
60+
value: development # otherwise building codeflare-cli takes a huge amount of memory
61+
- name: KUBE_CONTEXT_FOR_TEST
62+
value: kind-codeflare-test # must match with tests/kind/profiles/...
63+
- name: KUBE_NS_FOR_TEST
64+
value: default # must match with tests/kind/profiles/...
65+
- name: CODEFLARE_NAMESPACE_RESTRICTED # restrict use of cluster-scoped resources
66+
value: "true"
67+
- name: GITHUB_SHA
68+
valueFrom:
69+
configMapKeyRef:
70+
name: codeflare-self-test-config
71+
key: GITHUB_SHA
72+
- name: GITHUB_REF
73+
valueFrom:
74+
configMapKeyRef:
75+
name: codeflare-self-test-config
76+
key: GITHUB_REF
77+
- name: GITHUB_ACTOR_PREFIX
78+
valueFrom:
79+
configMapKeyRef:
80+
name: codeflare-self-test-config
81+
key: GITHUB_ACTOR_PREFIX
82+
- name: VARIANTS
83+
valueFrom:
84+
configMapKeyRef:
85+
name: codeflare-self-test-config
86+
key: VARIANTS
87+
- name: ORG
88+
valueFrom:
89+
configMapKeyRef:
90+
name: codeflare-self-test-config
91+
key: ORG
92+
- name: BRANCH
93+
valueFrom:
94+
configMapKeyRef:
95+
name: codeflare-self-test-config
96+
key: BRANCH
97+
restartPolicy: Never
98+
backoffLimit: 1

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"prepare": "cross-env husky install",
2121
"build:docker:cli": "npm run build:headless-maybe && docker build -f deploy/cli/Dockerfile -t ghcr.io/project-codeflare/codeflare-cli .",
2222
"build:docker:logs": "npm run build:headless-maybe && docker build -f deploy/log-aggregator/Dockerfile -t ghcr.io/project-codeflare/codeflare-log-aggregator .",
23+
"build:docker:self-test": "cd deploy/self-test && docker build -t ghcr.io/project-codeflare/codeflare-self-test .",
2324
"build:headless-maybe": "if [ ! -n \"$FAST\" ]; then npm run build:headless; fi",
2425
"build:headless": "CLIENT_HOME=$PWD webpack-cli --mode=${MODE-production} --config node_modules/@kui-shell/webpack/headless-webpack.config.js",
2526
"docker:debug": "ENTRYPOINT=bash ./bin/codeflare -d",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Hyperparameter Tuning With Ray Tune
2+
3+
Citation: https://torchtutorialstaging.z5.web.core.windows.net/beginner/hyperparameter_tuning_tutorial.html
4+
On: 20221019
5+
By: @starpit

0 commit comments

Comments
 (0)