From 4c7d6a93eaa0ee268d64a7a3e5d846f520d3244f Mon Sep 17 00:00:00 2001 From: yy <56745951+lingdie@users.noreply.github.com> Date: Thu, 17 Oct 2024 16:42:56 +0800 Subject: [PATCH] Devbox offline deploy. (#5159) * add devbox offline install scripts * devbox-offline * fix kubefile --- deploy/devbox/Kubefile | 11 +++++++ deploy/devbox/init.sh | 33 +++++++++++++++++++ deploy/devbox/scripts/init.sh | 6 ++++ deploy/objectstorage/init.sh | 2 +- frontend/providers/devbox/deploy/Kubefile | 8 +---- .../devbox/deploy/manifests/deploy.yaml.tmpl | 8 ++--- .../devbox/deploy/manifests/rbac.yaml | 30 ----------------- .../deploy/scripts/update-backup-label.sh | 30 ----------------- 8 files changed, 56 insertions(+), 72 deletions(-) create mode 100644 deploy/devbox/Kubefile create mode 100644 deploy/devbox/init.sh create mode 100644 deploy/devbox/scripts/init.sh delete mode 100644 frontend/providers/devbox/deploy/manifests/rbac.yaml delete mode 100644 frontend/providers/devbox/deploy/scripts/update-backup-label.sh diff --git a/deploy/devbox/Kubefile b/deploy/devbox/Kubefile new file mode 100644 index 00000000000..b3edf5f36b7 --- /dev/null +++ b/deploy/devbox/Kubefile @@ -0,0 +1,11 @@ +FROM scratch +COPY tars tars +COPY scripts scripts + +ENV cloudDomain=${cloudDomain:-"127.0.0.1.nip.io"} +ENV cloudPort="" +ENV registryAddr=${registryAddr:-"sealos.hub:5000"} +ENV registryUser=${registryUser:-"admin"} +ENV registryPassword=${registryPassword:-"passw0rd"} + +CMD ["bash scripts/init.sh"] diff --git a/deploy/devbox/init.sh b/deploy/devbox/init.sh new file mode 100644 index 00000000000..875547bca3d --- /dev/null +++ b/deploy/devbox/init.sh @@ -0,0 +1,33 @@ +#!/bin/bash +readonly ARCH=${1:-amd64} +set -e + +mkdir -p tars + +RetryPullImageInterval=3 +RetrySleepSeconds=3 + + +retryPullImage() { + local image=$1 + local retry=0 + local retryMax=3 + set +e + while [ $retry -lt $RetryPullImageInterval ]; do + sealos pull --policy=always --platform=linux/"${ARCH}" $image >/dev/null && break + retry=$(($retry + 1)) + echo "retry pull image $image, retry times: $retry" + sleep $RetrySleepSeconds + done + set -e + if [ $retry -eq $retryMax ]; then + echo "pull image $image failed" + exit 1 + fi +} + +retryPullImage ghcr.io/labring/sealos-cloud-devbox-controller:latest +retryPullImage ghcr.io/labring/sealos-cloud-devbox-frontend:latest + +sealos save -o tars/devbox-controller.tar ghcr.io/labring/sealos-cloud-devbox-controller:latest +sealos save -o tars/devbox-frontend.tar ghcr.io/labring/sealos-cloud-devbox-frontend:latest diff --git a/deploy/devbox/scripts/init.sh b/deploy/devbox/scripts/init.sh new file mode 100644 index 00000000000..54e779f940c --- /dev/null +++ b/deploy/devbox/scripts/init.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +set -e + +sealos run tars/devbox-controller.tar -e cloudDomain=${cloudDomain} -e cloudPort=${cloudPort} -e registryAddr=${registryAddr} -e registryUser=${registryUser} -e registryPassword=${registryPassword} +sealos run tars/devbox-frontend.tar -e cloudDomain=${cloudDomain} -e cloudPort=${cloudPort} diff --git a/deploy/objectstorage/init.sh b/deploy/objectstorage/init.sh index 5fbe719077d..9e1b22eba1c 100644 --- a/deploy/objectstorage/init.sh +++ b/deploy/objectstorage/init.sh @@ -1,6 +1,6 @@ #!/bin/bash set -e -export readonly ARCH=${1:-amd64} +readonly ARCH=${1:-amd64} mkdir -p tars RetryPullImageInterval=3 diff --git a/frontend/providers/devbox/deploy/Kubefile b/frontend/providers/devbox/deploy/Kubefile index ffb761baf08..b5729882e69 100644 --- a/frontend/providers/devbox/deploy/Kubefile +++ b/frontend/providers/devbox/deploy/Kubefile @@ -8,12 +8,6 @@ COPY manifests manifests ENV cloudDomain="127.0.0.1.nip.io" ENV cloudPort="" ENV certSecretName="wildcard-cert" -ENV monitorUrl="http://database-monitor.sealos.svc.cluster.local:9090" -ENV minioUrl="" -ENV minioAccessKey="" -ENV minioSecretKey="" -ENV minioPort="" -ENV migrateFileImage="" -ENV minioBucketName="" +ENV registryAddr="sealos.hub:5000" CMD ["kubectl apply -f manifests"] diff --git a/frontend/providers/devbox/deploy/manifests/deploy.yaml.tmpl b/frontend/providers/devbox/deploy/manifests/deploy.yaml.tmpl index 6514f1538f2..4790c8b5b86 100644 --- a/frontend/providers/devbox/deploy/manifests/deploy.yaml.tmpl +++ b/frontend/providers/devbox/deploy/manifests/deploy.yaml.tmpl @@ -38,17 +38,17 @@ spec: - name: devbox-frontend env: - name: SEALOS_DOMAIN - value: { { .cloudDomain } } + value: {{ .cloudDomain }} - name: INGRESS_SECRET value: wildcard-cert - name: REGISTRY_ADDR - value: hub.{{ .cloudDomain }}{{ if .cloudPort }}:{{ .cloudPort }}{{ end }} + value: {{ .registryAddr }} - name: DEVBOX_AFFINITY_ENABLE value: 'true' - name: MONITOR_URL value: http://launchpad-monitor.sealos.svc.cluster.local:8428 - name: SQUASH_ENABLE - value: 'true' + value: 'false' - name: ACCOUNT_URL value: http://account-service.account-system.svc.cluster.local:2333 securityContext: @@ -63,7 +63,7 @@ spec: cpu: 2000m memory: 2048Mi requests: - cpu: 10m + cpu: 100m memory: 128Mi # do not modify this image, it is used for CI/CD image: ghcr.io/labring/sealos-devbox-frontend:latest diff --git a/frontend/providers/devbox/deploy/manifests/rbac.yaml b/frontend/providers/devbox/deploy/manifests/rbac.yaml deleted file mode 100644 index ff8e7b80519..00000000000 --- a/frontend/providers/devbox/deploy/manifests/rbac.yaml +++ /dev/null @@ -1,30 +0,0 @@ -apiVersion: v1 -kind: ServiceAccount -metadata: - name: cluster-version-reader - namespace: devbox-frontend ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - name: cluster-version-reader -rules: - - apiGroups: ['apps.kubeblocks.io'] - resources: ['clusterversions'] - verbs: ['get', 'watch', 'list'] - - apiGroups: ['dataprotection.kubeblocks.io'] - resources: ['backuprepos'] - verbs: ['get', 'watch', 'list'] ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - name: cluster-version-reader-rolebinding -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: cluster-version-reader -subjects: - - kind: ServiceAccount - name: cluster-version-reader - namespace: devbox-frontend diff --git a/frontend/providers/devbox/deploy/scripts/update-backup-label.sh b/frontend/providers/devbox/deploy/scripts/update-backup-label.sh deleted file mode 100644 index 016a6fa8c98..00000000000 --- a/frontend/providers/devbox/deploy/scripts/update-backup-label.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -encodeToHex() { - local input="$1" - input=$(echo "$input" | cut -c -30) - echo -n "$input" | xxd -p | tr -d '\n' -} - -decodeFromHex() { - local input="$1" - echo -n "$input" | xxd -r -p -} - -backups=$(kubectl get Backup -A -o json | jq -c '.items[]') - -echo "$backups" | while IFS= read -r backup; do - namespace=$(echo "$backup" | jq -r '.metadata.namespace') - name=$(echo "$backup" | jq -r '.metadata.name') - - current_value=$(echo "$backup" | jq -r '.metadata.labels["backup-remark"] // empty') - if [ -n "$current_value" ]; then - encoded_value=$(encodeToHex "$current_value") - - kubectl patch Backup "$name" -n "$namespace" --type='json' -p="[{\"op\": \"replace\", \"path\": \"/metadata/labels/backup-remark\", \"value\": \"$encoded_value\"}]" - - echo "Updated $namespace/$name: backup-remark before: $current_value, after: $encoded_value" - else - echo "No non-empty backup-remark label found for $namespace/$name" - fi -done \ No newline at end of file