diff --git a/setup/docker/opsfile.yml b/setup/docker/opsfile.yml index 1fb27a4..e43b194 100644 --- a/setup/docker/opsfile.yml +++ b/setup/docker/opsfile.yml @@ -66,8 +66,7 @@ tasks: - envsubst -i kind.yaml -o _kind.yaml - > kind create cluster - --kubeconfig="$OPS_TMP/kubeconfig" - --wait=1m --name=nuvolaris + --wait=2m --name=nuvolaris --config=_kind.yaml - | docker exec nuvolaris-control-plane mkdir -p /etc/containerd/certs.d/127.0.0.1:32000 @@ -79,12 +78,16 @@ tasks: skip_verify = true EOF' docker exec nuvolaris-control-plane systemctl restart containerd + kind export kubeconfig -n nuvolaris --kubeconfig "$OPS_TMP/kubeconfig" + echo "waiting for kind ready..." + retry -t 100 -m 600 test -e $OPS_TMP/kubeconfig + retry kubectl --kubeconfig $OPS_TMP/kubeconfig cluster-info ingress: silent: true cmds: - > - kubectl --kubeconfig="$OPS_TMP/kubeconfig" + retry kubectl --kubeconfig="$OPS_TMP/kubeconfig" apply -f ingress-deploy.yaml check-space: @@ -93,38 +96,6 @@ tasks: cmds: - uv run space.py - preload: - silent: true - desc: preload the Apache OpenServerless images in docker to speed up the cluster creation - ignore_errors: true - status: - - config SKIP_PRELOAD_IMAGES - cmds: - - | - for image in "$IMAGES_STREAMER" "$IMAGES_OPERATOR" "$IMAGES_CONTROLLER" - do - docker pull "$image" --platform "linux/{{ARCH}}" - if ! kind load docker-image "$image" --name {{.CLUSTER}} - then - echo "*** Cannot preload images. You can disable preload with ops -config SKIP_PRELOAD_IMAGES=1" - echo "*** Workaround on Docker Desktop: disable 'Use containerd for pulling and storing images' on General" - echo "*** WARNING! If you skip preload, it can take a lot of time before the system starts. Be patient." - exit 1 - fi - docker rmi "$image" - done - - | - jq -r '.runtimes[][] - | select(.default == true) - | .image - | "\(.prefix)/\(.name):\(.tag)"' <$OPS_ROOT/runtimes.json \ - | rg apache/openserverless-runtime \ - | while read -r image; do - docker pull "$image" --platform "linux/{{ARCH}}" - kind load docker-image "$image" --name "{{.CLUSTER}}" - docker rmi "$image" - done - clean-all: silent: true desc: remove all images and containers from docker @@ -141,13 +112,16 @@ tasks: silent: true desc: create the Apache OpenServerless cluster in Docker cmds: - - ops util freeze docker-load - - task: cluster - - ops util freeze kind-load - - task: ingress - - cp "$OPS_TMP/kubeconfig" "$OPS_TMP/kind-{{.CLUSTER}}.kubeconfig" - status: - - kind get clusters | rg {{.CLUSTER}} + - | + if kind get clusters | rg {{.CLUSTER}} + then kind export kubeconfig --name {{.CLUSTER}} --kubeconfig "$OPS_TMP/kubeconfig" + else + ops util freeze docker-load + ops setup docker cluster + ops util freeze kind-load + ops setup docker ingress + fi + - cp "$OPS_TMP/kubeconfig" "$OPS_TMP/kind-{{.CLUSTER}}.kubeconfig" delete: silent: true diff --git a/setup/opsfile.yml b/setup/opsfile.yml index eac7fa9..f4bd7f2 100644 --- a/setup/opsfile.yml +++ b/setup/opsfile.yml @@ -144,10 +144,6 @@ tasks: task check-ports PORTS="{{ .PORTS }}" fi {{.RUN}} ops setup docker create - if test -z {{.__skip_preload_images}} - then - {{.RUN}} ops setup docker preload - fi {{.RUN}} ops setup kubernetes create {{.RUN}} ops setup nuvolaris login config STATUS_LAST=devcluster diff --git a/util/docopts.md b/util/docopts.md index f2bff4c..1ab1629 100644 --- a/util/docopts.md +++ b/util/docopts.md @@ -44,7 +44,6 @@ Usage: util ingress-type util edit [] util link-plugin - util docker-proxy [] [] [--remove] ``` ## Commands @@ -70,7 +69,6 @@ Usage: - ingress-type return the ingress type - edit edit (with vscode) the current tasks or a plugin - link-plugin link the in current directory to the global list -- docker-proxy launch (or remove) in docker a proxy listening in public (default 8080) to the (default devel.miniops.me) ``` ## Options diff --git a/util/freeze/opsfile.yml b/util/freeze/opsfile.yml index 4ab7731..5ebb6b4 100644 --- a/util/freeze/opsfile.yml +++ b/util/freeze/opsfile.yml @@ -12,7 +12,6 @@ vars: sh: > awk '/image:/{print $2}' $OPS_ROOT/setup/docker/kind.yaml | tee _docker.lst - tasks: docker-list: @@ -46,7 +45,7 @@ tasks: if test -e "$file" then echo "already saved $img.{{ARCH}} " else echo ">>> Saving: $img" - if docker pull "$img" + if docker pull --platform linux/{{ARCH}} "$img" then echo "OK: save $file" else echo "*** FAIL: pull $img" fi @@ -58,7 +57,7 @@ tasks: done kind-save: - silent: false + silent: true desc: list images in kindes env: CLU: "{{.KIND_CLUSTER}}" @@ -75,8 +74,8 @@ tasks: file={{.IMAGES}}/kind/"$(base64 -e "$img")" if test -e "$file" then echo "already saved $img" - else echo ">>> Saving: $img" - if ! docker pull "$img" + else echo ">>> Saving: {{ARCH}} $img" + if ! docker pull --platform linux/{{ARCH}} "$img" then echo "*** FAIL pull $img" ; continue fi if ! docker save "$img" -o "$file" @@ -140,16 +139,15 @@ tasks: desc: load disk images in kind cmds: - | - N=0 for file in {{.IMAGES}}/kind/* do - N=$(($N+1)) - printf "\rKind: loading images: [$(seq 1 $N | awk '{printf "#"}')]" - #echo $file b64="$(basename "$file")" img="$(base64 -d "${b64#*-}")" - kind load image-archive "$file" -n {{.CLUSTER}} --nodes {{.CLUSTER}}-control-plane + echo "Kind: loading $img" + docker exec -i {{.CLUSTER}}-control-plane ctr --namespace=k8s.io images import --snapshotter=overlayfs - < "$file" done + echo 'Images loaded:' + - task: kind-list status: - test -z "$(ls {{.IMAGES}}/kind/* 2>/dev/null)" diff --git a/util/kube/opsfile.yml b/util/kube/opsfile.yml index 129f03c..5d16367 100644 --- a/util/kube/opsfile.yml +++ b/util/kube/opsfile.yml @@ -33,7 +33,7 @@ env: tasks: waitfor: - desc: wait for an object matching a condition + desc: wait for an object matching a condition silent: true cmds: - test -n "{{.OBJ}}" || die "use OBJ=" @@ -42,14 +42,14 @@ tasks: N=0 RES=false while [[ $N -lt {{.RETRY}} ]] - do + do if kubectl -n nuvolaris wait --for="{{.FOR}}" "{{.OBJ}}" --timeout="{{.TIMEOUT}}s" - then RES=true; break + then RES=true; break else echo "$((N++)) Waiting {{.OBJ}} for {{.FOR}}" sleep "{{.SLEEP}}s" fi done - $RES + $RES wait: desc: wait for a value matching the given jsonpath on the specific resources under the namespace nuvolaris @@ -61,17 +61,17 @@ tasks: N=0 RES=false while [[ $N -lt {{.RETRY}} ]] - do + do MATCHING_VALUE="$(kubectl -n nuvolaris get {{.OBJECT}} -o jsonpath='{{.JSONPATH}}')" if [[ -z "$MATCHING_VALUE" ]] - then + then echo "$((N++)) Waiting for {{.JSONPATH}} to be non empty value" sleep 5 - else + else RES=true; break fi done - $RES + $RES export: desc: exporting NAMEd kubeconfig to specified FILE @@ -80,7 +80,7 @@ tasks: - test -e "$OPS_TMP/{{.NAME}}.kubeconfig" || die "no {{.NAME}} kubeconfig" - | FILE="$(realpath {{.FILE}})" - cp "$OPS_TMP/kubeconfig" "$FILE" + cp "$OPS_TMP/kubeconfig" "$FILE" import: desc: importing FILE to the NAMEd kubeconfig diff --git a/util/opsfile.yml b/util/opsfile.yml index e938cd5..3d7e00e 100644 --- a/util/opsfile.yml +++ b/util/opsfile.yml @@ -279,33 +279,6 @@ tasks: exit 1 fi - docker-proxy: - desc: create in docker a proxy to expose miniops.me (or others) - silent: true - vars: - PORT: '{{or ._port_ "8080"}}' - HOST: '{{or ._host_ "devel.miniops.me"}}' - NGINX_CONF: > - server { - listen 80; - location / { - proxy_pass http://nuvolaris-control-plane:80; - proxy_set_header Host {{.HOST}}; - } - } - cmds: - - | - if {{.__remove}} - then docker rm docker-proxy-{{.PORT}} -f - else - if docker run -d --name docker-proxy-{{.PORT}} -p {{.PORT}}:80 --network kind nginx:alpine sh -c \ - "echo '{{.NGINX_CONF}}' > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'" - then echo "docker-proxy started on port {{.PORT}} to http://{{.HOST}}" - else echo "Cannot start docker-proxy-{{.PORT}} - either the port is busy or another instance is running, remove it" - fi - fi - - freeze: desc: freeze util