From 3e4c54e29ab89885ebfbb9b3ee11fd711ceb66a9 Mon Sep 17 00:00:00 2001 From: QXYang686 Date: Mon, 16 Feb 2026 11:22:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9E=84=E5=BB=BA=E8=84=9A=E6=9C=AC=E5=87=86?= =?UTF-8?q?=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.sh | 29 +++++++++++++++++++++++++++++ build/build-image.sh | 37 +++++++++++++++++++++++++++++++++++++ build/builder-setup.sh | 12 ++++++++++++ build/host-setup.sh | 19 +++++++++++++++++++ build/registry-setup.sh | 13 +++++++++++++ system-setup.sh | 23 +++++++++++++++++++++++ 6 files changed, 133 insertions(+) create mode 100644 build.sh create mode 100644 build/build-image.sh create mode 100644 build/builder-setup.sh create mode 100644 build/host-setup.sh create mode 100644 build/registry-setup.sh create mode 100644 system-setup.sh diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..9ff609e --- /dev/null +++ b/build.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +set -e + +export REGISTRY=registry.yqxpro.com + +pushd common-base +npx devcontainer build \ + --platform linux/amd64,linux/arm64 \ + --image-name ${REGISTRY}/devcontainers/common-base --push \ + --cache-to type=registry,ref=${REGISTRY}/devcontainers/common-base:buildcache,mode=max \ + --cache-from type=registry,ref=${REGISTRY}/devcontainers/common-base:buildcache +popd + +pushd develop-base +npx devcontainer build \ + --platform linux/amd64,linux/arm64 \ + --image-name ${REGISTRY}/devcontainers/develop-base --push \ + --cache-to type=registry,ref=${REGISTRY}/devcontainers/develop-base:buildcache,mode=max \ + --cache-from type=registry,ref=${REGISTRY}/devcontainers/develop-base:buildcache +popd + +pushd universal-base +npx devcontainer build \ + --platform linux/amd64,linux/arm64 \ + --image-name ${REGISTRY}/devcontainers/universal-base --push \ + --cache-to type=registry,ref=${REGISTRY}/devcontainers/universal-base:buildcache,mode=max \ + --cache-from type=registry,ref=${REGISTRY}/devcontainers/universal-base:buildcache +popd diff --git a/build/build-image.sh b/build/build-image.sh new file mode 100644 index 0000000..174967c --- /dev/null +++ b/build/build-image.sh @@ -0,0 +1,37 @@ +#!/bin/bash +set -eux + +export BUILDX_BUILDER=hk-builder + +export REGISTRY="registry.yqxpro.com" + +export S3_ENDPOINT_URL=https://oss-cn-hongkong-internal.aliyuncs.com +export S3_REGION=cn-hongkong +export S3_BUCKET=hk-builder-cache-yqxpro +export S3_ACCESSKEY=LTAI5t8AtjWfsqQWYnyBeCjH +export S3_SECRETKEY=UPKF20AmcW2zB5BwAMIQeQgZeTkMEs +export S3_CONFIG=endpoint_url=${S3_ENDPOINT_URL},region=${S3_REGION},bucket=${S3_BUCKET},access_key_id=${S3_ACCESSKEY},secret_access_key=${S3_SECRETKEY} + +build() { + local target="$1" + + echo "Build $target started" + + pushd $target + npx devcontainer build \ + --platform linux/amd64,linux/arm64 \ + --image-name ${REGISTRY}/devcontainers/$target --push \ + --cache-to type=s3,${S3_CONFIG},prefix=$target/,mode=max \ + --cache-from type=s3,${S3_CONFIG},prefix=$target/ + popd + + echo "Build $target completed" +} + +main() { + for target in "$@"; do + build "$target" + done +} + +main "$@" diff --git a/build/builder-setup.sh b/build/builder-setup.sh new file mode 100644 index 0000000..589a37d --- /dev/null +++ b/build/builder-setup.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -eux + +export TARGET_USER=ecs-user +export REGISTRY_IP=172.22.178.82 + +sudo apt update +sudo apt install -y npm git +curl -fsSL https://raw.githubusercontent.com/docker/docker-install/master/install.sh | sh +sudo usermod -aG docker $TARGET_USER + +echo "$REGISTRY_IP registry.yqxpro.com" | sudo tee -a /etc/hosts diff --git a/build/host-setup.sh b/build/host-setup.sh new file mode 100644 index 0000000..bcf1e6d --- /dev/null +++ b/build/host-setup.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -eux + +# SSH 配置中先准备好 hk-builder-linux-arm64 和 hk-builder-linux-amd64 +docker buildx create \ + --name hk-builder \ + --driver docker-container \ + --driver-opt network=host \ + --platform linux/amd64 \ + --node hk-builder-linux-amd64 \ + ssh://hk-builder-linux-amd64 +docker buildx create \ + --name hk-builder \ + --driver docker-container \ + --driver-opt network=host \ + --platform linux/arm64 \ + --append \ + --node hk-builder-linux-arm64 \ + ssh://hk-builder-linux-arm64 diff --git a/build/registry-setup.sh b/build/registry-setup.sh new file mode 100644 index 0000000..a08ed03 --- /dev/null +++ b/build/registry-setup.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -eux + +tar xvzf certs.tgz +docker run -d \ + --restart=always \ + --name registry \ + -v "$(pwd)"/certs:/certs \ + -e REGISTRY_HTTP_ADDR=0.0.0.0:443 \ + -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/registry.yqxpro.com.crt \ + -e REGISTRY_HTTP_TLS_KEY=/certs/registry.yqxpro.com.key \ + -p 443:443 \ + registry:3 diff --git a/system-setup.sh b/system-setup.sh new file mode 100644 index 0000000..fba4cf3 --- /dev/null +++ b/system-setup.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +sudo apt update +sudo apt install -y npm git +curl -fsSL https://raw.githubusercontent.com/docker/docker-install/master/install.sh | sh +sudo usermod -aG docker $USER +docker buildx create --use --bootstrap --name multiarch-builder --driver-opt network=host +echo "127.0.0.1 registry.yqxpro.com" | sudo tee -a /etc/hosts + +tar xvzf certs.tgz +docker run -d \ + --restart=always \ + --name registry \ + -v "$(pwd)"/certs:/certs \ + -e REGISTRY_HTTP_ADDR=0.0.0.0:443 \ + -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/registry.yqxpro.com.crt \ + -e REGISTRY_HTTP_TLS_KEY=/certs/registry.yqxpro.com.key \ + -p 443:443 \ + registry:3 + +git clone https://gitea.yqxpro.com/QXYang686/devcontainers.git +cd devcontainers +npm install