Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add k8s all-in-one ci #160

Merged
merged 13 commits into from
Oct 22, 2024
File renamed without changes.
39 changes: 39 additions & 0 deletions .github/all-in-one/k8s/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

chartsFolder=${1:-./../../../charts}

ls $chartsFolder

UNIVERSER_VERSION=$(docker run --rm -v $chartsFolder/universer/:/tmp/ mikefarah/yq:4 e '.image.tag' /tmp/values.yaml)
UNIVERSER_SQL_VERSION=$(docker run --rm -v $chartsFolder/universer/:/tmp/ mikefarah/yq:4 e '.job.image.tag' /tmp/values.yaml)
UNIVER_COLLABORATION_VERSION=$(docker run --rm -v $chartsFolder/collaboration-server/:/tmp/ mikefarah/yq:4 e '.image.tag' /tmp/values.yaml)
UNIVER_COLLABORATION_LITE_VERSION=$(docker run --rm -v $chartsFolder/collaboration-demo/:/tmp/ mikefarah/yq:4 e '.image.tag' /tmp/values.yaml)
UNIVER_WORKER_EXCHANGE_VERSION=$(docker run --rm -v $chartsFolder/univer-stack/:/tmp/ mikefarah/yq:4 e '.worker.image.tag' /tmp/values.yaml)

echo "UNIVERSER_VERSION: $UNIVERSER_VERSION"

sed -i -e 's/${UNIVERSER_VERSION}/'${UNIVERSER_VERSION}'/g' image-list.sh
sed -i 's/${UNIVERSER_SQL_VERSION}/'${UNIVERSER_SQL_VERSION}'/g' image-list.sh
sed -i 's/${UNIVER_COLLABORATION_VERSION}/'${UNIVER_COLLABORATION_VERSION}'/g' image-list.sh
sed -i 's/${UNIVER_COLLABORATION_LITE_VERSION}/'${UNIVER_COLLABORATION_LITE_VERSION}'/g' image-list.sh
sed -i 's/${UNIVER_WORKER_EXCHANGE_VERSION}/'${UNIVER_WORKER_EXCHANGE_VERSION}'/g' image-list.sh

cat image-list.sh

. ./image-list.sh

for image in "${images[@]}"; do
docker pull $image
done

docker save "${images[@]}" | gzip > univer-image.tar.gz

helm pull oci://univer-acr-registry.cn-shenzhen.cr.aliyuncs.com/helm-charts/univer-stack --destination .

chart=$(ls univer-stack-*.tgz | head -n 1)
version=$(echo "$chart" | sed -n 's/univer-stack-\(.*\).tgz/\1/p')

tar -cvf k8s-all-in-one.${version}.tar univer-image.tar.gz $chart image-list.sh install.sh load-image.sh uninstall.sh

echo "ALLINONE_PATH=$(echo $PWD/k8s-all-in-one.${version}.tar)" >> $GITHUB_ENV
echo "ALLINONE_TAR=$(echo k8s-all-in-one.${version}.tar)" >> $GITHUB_ENV
22 changes: 22 additions & 0 deletions .github/all-in-one/k8s/image-list.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

images=(
"univer-acr-registry.cn-shenzhen.cr.aliyuncs.com/release/univer-collaboration:${UNIVER_COLLABORATION_VERSION}"
"univer-acr-registry.cn-shenzhen.cr.aliyuncs.com/release/univer-collaboration-lite:${UNIVER_COLLABORATION_LITE_VERSION}"
"univer-acr-registry.cn-shenzhen.cr.aliyuncs.com/release/universer:${UNIVERSER_VERSION}"
"univer-acr-registry.cn-shenzhen.cr.aliyuncs.com/release/worker-exchange:${UNIVER_WORKER_EXCHANGE_VERSION}"
"univer-acr-registry.cn-shenzhen.cr.aliyuncs.com/release/universer-sql:${UNIVERSER_SQL_VERSION}"
"univer-acr-registry.cn-shenzhen.cr.aliyuncs.com/release/postgres:16.1"
"univer-acr-registry.cn-shenzhen.cr.aliyuncs.com/release/mysql:8.0.36-debian-11-r2"
"univer-acr-registry.cn-shenzhen.cr.aliyuncs.com/release/postgres-exporter:0.15.0-debian-11-r6"
"univer-acr-registry.cn-shenzhen.cr.aliyuncs.com/release/temporal-admin-tools:1.22.4"
"univer-acr-registry.cn-shenzhen.cr.aliyuncs.com/release/temporal:1.22.4"
"univer-acr-registry.cn-shenzhen.cr.aliyuncs.com/release/temporal-ui:2.16.2"
"univer-acr-registry.cn-shenzhen.cr.aliyuncs.com/release/redis:7.2.4-debian-11-r4"
"univer-acr-registry.cn-shenzhen.cr.aliyuncs.com/release/redis-exporter:1.56.0-debian-11-r1"
"univer-acr-registry.cn-shenzhen.cr.aliyuncs.com/release/rabbitmq:3.12.3-debian-11-r0"
"univer-acr-registry.cn-shenzhen.cr.aliyuncs.com/release/minio:2024.8.3-debian-12-r1"
"univer-acr-registry.cn-shenzhen.cr.aliyuncs.com/release/install-cni:1.20.1"
"univer-acr-registry.cn-shenzhen.cr.aliyuncs.com/release/pilot:1.20.1"
"univer-acr-registry.cn-shenzhen.cr.aliyuncs.com/release/proxyv2:1.20.1"
)
13 changes: 13 additions & 0 deletions .github/all-in-one/k8s/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

NAMESPACE="univer"

CHART=$(ls univer-stack-*.tgz | tail -n 1)

helm upgrade --install -n $NAMESPACE --create-namespace \
--set global.istioNamespace="$NAMESPACE" \
--values values.yaml \
univer-stack ./$CHART

kubectl rollout restart -n $NAMESPACE deployment/collaboration-server
kubectl rollout restart -n $NAMESPACE deployment/universer
53 changes: 53 additions & 0 deletions .github/all-in-one/k8s/load-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/sh

REGISTRY=""
IMAGE_NAMESPACE=""

# check docker command
if ! command -v docker &> /dev/null; then
echo "docker command not found"
exit 1
fi

while [ $# -gt 0 ]; do
case "$1" in
--registry)
REGISTRY="$2"
;;
--namespace)
IMAGE_NAMESPACE="$2"
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
shift 2
done

IMAGE_NAMESPACE=${IMAGE_NAMESPACE:-"release"}

echo "REGISTRY: $REGISTRY"
echo "IMAGE_NAMESPACE: $IMAGE_NAMESPACE"

if [ -z "$REGISTRY" ]; then
echo "Please specify the registry"
exit 1
fi

. ./image-list.sh

docker load -i univer-image.tar.gz

for image in "${images[@]}"; do
docker tag $image $REGISTRY/$IMAGE_NAMESPACE/$(basename $image)
docker push $REGISTRY/$IMAGE_NAMESPACE/$(basename $image)
done

SED="sed -i"
if [ "$(uname)" == "Darwin" ]; then
SED="sed -i \"\""
fi

$SED -e 's#${REGISTRY}#'${REGISTRY}'#' values.yaml
$SED -e 's#${IMAGE_NAMESPACE}#'${IMAGE_NAMESPACE}'#' values.yaml
5 changes: 5 additions & 0 deletions .github/all-in-one/k8s/uninstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

NAMESPACE="univer"

helm uninstall -n $NAMESPACE univer-stack
74 changes: 74 additions & 0 deletions .github/all-in-one/k8s/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
univerStack:
temporalJob:
image:
registry: ${REGISTRY}
repository: ${IMAGE_NAMESPACE}/temporal-admin-tools

global:
hub: ${REGISTRY}/${IMAGE_NAMESPACE}

universer:
image:
registry: ${REGISTRY}
repository: ${IMAGE_NAMESPACE}/universer
job:
image:
registry: ${REGISTRY}
repository: ${IMAGE_NAMESPACE}/universer-sql

collaboration-server:
image:
registry: ${REGISTRY}
repository: ${IMAGE_NAMESPACE}/univer-collaboration

collaboration-demo:
image:
registry: ${REGISTRY}
repository: ${IMAGE_NAMESPACE}/univer-collaboration-lite

worker:
image:
registry: ${REGISTRY}
repository: ${IMAGE_NAMESPACE}/worker-exchange

postgresql:
image:
registry: ${REGISTRY}
repository: ${IMAGE_NAMESPACE}/postgres

metrics:
image:
registry: ${REGISTRY}
repository: ${IMAGE_NAMESPACE}/postgres-exporter

temporal:
server:
image:
repository: ${REGISTRY}/${IMAGE_NAMESPACE}/temporal
admintools:
image:
repository: ${REGISTRY}/${IMAGE_NAMESPACE}/temporal-admin-tools
web:
image:
repository: ${REGISTRY}/${IMAGE_NAMESPACE}/temporal-ui

redis:
image:
registry: ${REGISTRY}
repository: ${IMAGE_NAMESPACE}/redis

metrics:
image:
registry: ${REGISTRY}
repository: ${IMAGE_NAMESPACE}/redis-exporter

rabbitmq:
image:
registry: ${REGISTRY}
repository: ${IMAGE_NAMESPACE}/rabbitmq

minio:
image:
registry: ${REGISTRY}
repository: ${IMAGE_NAMESPACE}/minio

30 changes: 28 additions & 2 deletions .github/workflows/all-in-one.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v4

- run: |
cp -r .github/all-in-one/ . && cd all-in-one
cp -r .github/all-in-one/docker-compose/ all-in-one && cd all-in-one

bash build.sh amd64

Expand All @@ -39,7 +39,7 @@ jobs:
- uses: actions/checkout@v4

- run: |
cp -R .github/all-in-one . && cd all-in-one
cp -r .github/all-in-one/docker-compose/ all-in-one && cd all-in-one

bash build.sh arm64

Expand All @@ -55,3 +55,29 @@ jobs:
accessKeyId: ${{ secrets.S3_ACCESS_KEY_ID }}
accessKeySecret: ${{ secrets.S3_ACCESS_KEY_SECRET }}
timeout: 1200s

build-k8s:
name: build-k8s
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- run: |
chartsFolder=$(pwd)/charts

cp -r .github/all-in-one/k8s/ all-in-one && cd all-in-one

bash build.sh $chartsFolder

ls -l

- name: Sync k8s-all-in-one.tar to OSS
uses: hexf00/upload-to-oss@v1
with:
source: '${{ env.ALLINONE_PATH }}'
dest: release/${{ env.ALLINONE_TAR }}
bucket: ${{ secrets.OSS_BUCKET }}
region: "oss-cn-shenzhen"
accessKeyId: ${{ secrets.S3_ACCESS_KEY_ID }}
accessKeySecret: ${{ secrets.S3_ACCESS_KEY_SECRET }}
timeout: 1200s
21 changes: 21 additions & 0 deletions .github/workflows/sync-to-oss.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,24 @@ jobs:
accessKeyId: ${{secrets.S3_ACCESS_KEY_ID}}
accessKeySecret: ${{secrets.S3_ACCESS_KEY_SECRET}}
if: ${{ github.event.inputs.sync-install == 'true' }}

update-chart:
name: Sync helm chart to oci
runs-on: ubuntu-latest
steps:
- name: default Checkout
uses: actions/checkout@v4

- name: Login to Aliyun Container Registry (ACR)
uses: aliyun/acr-login@v1
with:
login-server: univer-acr-registry.cn-shenzhen.cr.aliyuncs.com
region-id: cn-shenzhen
username: "${{ secrets.REGISTRY_USERNAME }}"
password: "${{ secrets.REGISTRY_PASSWORD }}"

- name: Sync helm chart to oci
run: |
helm repo add istio https://istio-release.storage.googleapis.com/charts
helm repo update
make all
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ worker: prepare
.PHONY: univer-stack
univer-stack: prepare
# Build and push univer-stack chart
@helm dependency build charts/univer-stack --skip-refresh
@helm package charts/univer-stack -d $(BUILD_DIR)
@helm push $(BUILD_DIR)/univer-stack-*.tgz oci://$(REGISTRY)/$(NS)
2 changes: 1 addition & 1 deletion charts/collaboration-demo/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ replicaCount: 1

image:
registry: univer-acr-registry.cn-shenzhen.cr.aliyuncs.com
repository: release/univer-collaboration-demo
repository: release/univer-collaboration-lite
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: 0.4.1 # VERSION
Expand Down