chore: enable multi-architecture build and push in .cnb.yml and add backup/restore functions in bt.sh

This commit is contained in:
xiao 2025-01-07 16:13:36 +08:00
parent 85175046ad
commit e970fb98aa
2 changed files with 90 additions and 69 deletions

138
.cnb.yml
View File

@ -6,77 +6,77 @@ $:
build: build:
dockerfile: .ide/Dockerfile dockerfile: .ide/Dockerfile
push: push:
# - runner: - runner:
# tags: cnb:arch:amd64 tags: cnb:arch:amd64
# services: services:
# - docker - docker
# imports: https://cnb.cool/btpanel/secret/-/blob/main/docker.yml imports: https://cnb.cool/btpanel/secret/-/blob/main/docker.yml
# env: env:
# IMAGE_TAG: btpanel/baota:slim-linux-amd64 IMAGE_TAG: btpanel/baota:slim-linux-amd64
# stages: stages:
# - name: docker login - name: docker login
# script: docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWD" script: docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWD"
# - name: docker build - name: docker build
# script: docker build -t ${IMAGE_TAG} . script: docker build -t ${IMAGE_TAG} .
# - name: docker push - name: docker push
# script: docker push ${IMAGE_TAG} script: docker push ${IMAGE_TAG}
# - name: resolve - name: resolve
# type: cnb:resolve type: cnb:resolve
# options: options:
# key: build-amd64 key: build-amd64
# - runner: - runner:
# tags: cnb:arch:arm64:v8 tags: cnb:arch:arm64:v8
# services: services:
# - docker - docker
# imports: https://cnb.cool/btpanel/secret/-/blob/main/docker.yml imports: https://cnb.cool/btpanel/secret/-/blob/main/docker.yml
# env: env:
# IMAGE_TAG: btpanel/baota:slim-linux-arm64 IMAGE_TAG: btpanel/baota:slim-linux-arm64
# stages: stages:
# - name: docker login - name: docker login
# script: docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWD" script: docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWD"
# - name: docker build - name: docker build
# script: docker build -t ${IMAGE_TAG} . script: docker build -t ${IMAGE_TAG} .
# - name: docker push - name: docker push
# script: docker push ${IMAGE_TAG} script: docker push ${IMAGE_TAG}
# - name: resolve - name: resolve
# type: cnb:resolve type: cnb:resolve
# options: options:
# key: build-arm64 key: build-arm64
# - services: - services:
# - docker - docker
# imports: https://cnb.cool/btpanel/secret/-/blob/main/docker.yml imports: https://cnb.cool/btpanel/secret/-/blob/main/docker.yml
# env: env:
# IMAGE_TAG: btpanel/baota:slim IMAGE_TAG: btpanel/baota:slim
# stages: stages:
# - name: await the amd64 - name: await the amd64
# type: cnb:await type: cnb:await
# options: options:
# key: build-amd64 key: build-amd64
# - name: await the arm64 - name: await the arm64
# type: cnb:await type: cnb:await
# options: options:
# key: build-arm64 key: build-arm64
# - name: manifest - name: manifest
# image: cnbcool/manifest image: cnbcool/manifest
# settings: settings:
# username: $DOCKER_USERNAME username: $DOCKER_USERNAME
# password: $DOCKER_PASSWD password: $DOCKER_PASSWD
# target: ${IMAGE_TAG} target: ${IMAGE_TAG}
# template: ${IMAGE_TAG}-OS-ARCH template: ${IMAGE_TAG}-OS-ARCH
# platforms: platforms:
# - linux/amd64 - linux/amd64
# - linux/arm64 - linux/arm64
# - name: clear - name: clear
# image: lumir/remove-dockerhub-tag image: lumir/remove-dockerhub-tag
# args: args:
# - --user - --user
# - $DOCKER_USERNAME - $DOCKER_USERNAME
# - --password - --password
# - $DOCKER_PASSWD - $DOCKER_PASSWD
# - ${IMAGE_TAG}-linux-amd64 - ${IMAGE_TAG}-linux-amd64
# - ${IMAGE_TAG}-linux-arm64 - ${IMAGE_TAG}-linux-arm64
- runner: - runner:
tags: cnb:arch:amd64 tags: cnb:arch:amd64

21
bt.sh
View File

@ -8,6 +8,24 @@ Setup_Path=$Root_Path/server/mysql
Data_Path=$Root_Path/server/data Data_Path=$Root_Path/server/data
O_pl=$(cat /www/server/panel/data/o.pl) O_pl=$(cat /www/server/panel/data/o.pl)
backup_database() {
if [ -d "${Data_Path}" ] && [ ! -z "$(ls -A ${Data_Path})" ]; then
if [ ! -d "${Setup_Path}" ] || [ -z "$(ls -A ${Setup_Path})" ]; then
timestamp=$(date +"%s")
tar czf /www/server/data_backup_$timestamp.tar.gz -C ${Data_Path} .
fi
fi
}
restore_panel_data() {
if [ -f /www.tar.gz ]; then
if [ ! -d /www ] || [ -z "$(ls -A /www)" ] || [ ! -d /www/server/panel ] || [ -z "$(ls -A /www/server/panel)" ] || [ ! -d /www/server/panel/pyenv ] || [ -z "$(ls -A /www/server/panel/pyenv)" ]; then
tar xzf /www.tar.gz -C / --skip-old-files
rm -rf /www.tar.gz
fi
fi
}
soft_start(){ soft_start(){
# 扫描并启动所有服务 # 扫描并启动所有服务
init_scripts=$(ls ${init_path}) init_scripts=$(ls ${init_path})
@ -68,6 +86,9 @@ start_mysql(){
fi fi
} }
restore_panel_data > /dev/null
backup_database > /dev/null
is_empty_Data > /dev/null is_empty_Data > /dev/null
init_mysql > /dev/null init_mysql > /dev/null
start_mysql > /dev/null start_mysql > /dev/null