From 4ea412249ae609ff8bc03af0d15248b90f35ff87 Mon Sep 17 00:00:00 2001 From: zyy17 Date: Wed, 28 Aug 2024 00:59:01 +0800 Subject: [PATCH] ci: add check-builder-rust-version job in release and change release-dev-builder-images trigger condition (#4615) --- .../workflows/release-dev-builder-images.yaml | 6 +++ .github/workflows/release.yml | 10 +++++ Makefile | 12 +++--- scripts/check-builder-rust-version.sh | 42 +++++++++++++++++++ 4 files changed, 64 insertions(+), 6 deletions(-) create mode 100755 scripts/check-builder-rust-version.sh diff --git a/.github/workflows/release-dev-builder-images.yaml b/.github/workflows/release-dev-builder-images.yaml index 9d63d9810a3d..33e6674d9bb1 100644 --- a/.github/workflows/release-dev-builder-images.yaml +++ b/.github/workflows/release-dev-builder-images.yaml @@ -1,6 +1,12 @@ name: Release dev-builder images on: + push: + branches: + - main + paths: + - rust-toolchain.toml + - 'docker/dev-builder/**' workflow_dispatch: # Allows you to run this workflow manually. inputs: release_dev_builder_ubuntu_image: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2d2b2184132e..f04d4e514acb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -98,6 +98,16 @@ permissions: contents: write # Allows the action to create a release. jobs: + check-builder-rust-version: + name: Check rust version in builder + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v4 + - name: Check Rust toolchain version + shell: bash + run: | + ./scripts/check-builder-rust-version.sh + allocate-runners: name: Allocate runners if: ${{ github.repository == 'GreptimeTeam/greptimedb' }} diff --git a/Makefile b/Makefile index c50e5ac19895..ec1e394c5a13 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ CARGO_BUILD_OPTS := --locked IMAGE_REGISTRY ?= docker.io IMAGE_NAMESPACE ?= greptime IMAGE_TAG ?= latest -DEV_IMAGE_TAG ?= 2024-06-06-b4b105ad-20240827021230 +DEV_BUILDER_IMAGE_TAG ?= 2024-06-06-b4b105ad-20240827021230 BUILDX_MULTI_PLATFORM_BUILD ?= false BUILDX_BUILDER_NAME ?= gtbuilder BASE_IMAGE ?= ubuntu @@ -78,7 +78,7 @@ build: ## Build debug version greptime. build-by-dev-builder: ## Build greptime by dev-builder. docker run --network=host \ -v ${PWD}:/greptimedb -v ${CARGO_REGISTRY_CACHE}:/root/.cargo/registry \ - -w /greptimedb ${IMAGE_REGISTRY}/${IMAGE_NAMESPACE}/dev-builder-${BASE_IMAGE}:${DEV_IMAGE_TAG} \ + -w /greptimedb ${IMAGE_REGISTRY}/${IMAGE_NAMESPACE}/dev-builder-${BASE_IMAGE}:${DEV_BUILDER_IMAGE_TAG} \ make build \ CARGO_EXTENSION="${CARGO_EXTENSION}" \ CARGO_PROFILE=${CARGO_PROFILE} \ @@ -92,7 +92,7 @@ build-by-dev-builder: ## Build greptime by dev-builder. build-android-bin: ## Build greptime binary for android. docker run --network=host \ -v ${PWD}:/greptimedb -v ${CARGO_REGISTRY_CACHE}:/root/.cargo/registry \ - -w /greptimedb ${IMAGE_REGISTRY}/${IMAGE_NAMESPACE}/dev-builder-android:${DEV_IMAGE_TAG} \ + -w /greptimedb ${IMAGE_REGISTRY}/${IMAGE_NAMESPACE}/dev-builder-android:${DEV_BUILDER_IMAGE_TAG} \ make build \ CARGO_EXTENSION="ndk --platform 23 -t aarch64-linux-android" \ CARGO_PROFILE=release \ @@ -106,7 +106,7 @@ build-android-bin: ## Build greptime binary for android. strip-android-bin: build-android-bin ## Strip greptime binary for android. docker run --network=host \ -v ${PWD}:/greptimedb \ - -w /greptimedb ${IMAGE_REGISTRY}/${IMAGE_NAMESPACE}/dev-builder-android:${DEV_IMAGE_TAG} \ + -w /greptimedb ${IMAGE_REGISTRY}/${IMAGE_NAMESPACE}/dev-builder-android:${DEV_BUILDER_IMAGE_TAG} \ bash -c '$${NDK_ROOT}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip --strip-debug /greptimedb/target/aarch64-linux-android/release/greptime' .PHONY: clean @@ -146,7 +146,7 @@ dev-builder: multi-platform-buildx ## Build dev-builder image. docker buildx build --builder ${BUILDX_BUILDER_NAME} \ --build-arg="RUST_TOOLCHAIN=${RUST_TOOLCHAIN}" \ -f docker/dev-builder/${BASE_IMAGE}/Dockerfile \ - -t ${IMAGE_REGISTRY}/${IMAGE_NAMESPACE}/dev-builder-${BASE_IMAGE}:${DEV_IMAGE_TAG} ${BUILDX_MULTI_PLATFORM_BUILD_OPTS} . + -t ${IMAGE_REGISTRY}/${IMAGE_NAMESPACE}/dev-builder-${BASE_IMAGE}:${DEV_BUILDER_IMAGE_TAG} ${BUILDX_MULTI_PLATFORM_BUILD_OPTS} . .PHONY: multi-platform-buildx multi-platform-buildx: ## Create buildx multi-platform builder. @@ -204,7 +204,7 @@ stop-etcd: ## Stop single node etcd for testing purpose. run-it-in-container: start-etcd ## Run integration tests in dev-builder. docker run --network=host \ -v ${PWD}:/greptimedb -v ${CARGO_REGISTRY_CACHE}:/root/.cargo/registry -v /tmp:/tmp \ - -w /greptimedb ${IMAGE_REGISTRY}/${IMAGE_NAMESPACE}/dev-builder-${BASE_IMAGE}:${DEV_IMAGE_TAG} \ + -w /greptimedb ${IMAGE_REGISTRY}/${IMAGE_NAMESPACE}/dev-builder-${BASE_IMAGE}:${DEV_BUILDER_IMAGE_TAG} \ make test sqlness-test BUILD_JOBS=${BUILD_JOBS} .PHONY: start-cluster diff --git a/scripts/check-builder-rust-version.sh b/scripts/check-builder-rust-version.sh new file mode 100755 index 000000000000..fcfbd7d189d3 --- /dev/null +++ b/scripts/check-builder-rust-version.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +set -e + +RUST_TOOLCHAIN_VERSION_FILE="rust-toolchain.toml" +DEV_BUILDER_UBUNTU_REGISTRY="docker.io" +DEV_BUILDER_UBUNTU_NAMESPACE="greptime" +DEV_BUILDER_UBUNTU_NAME="dev-builder-ubuntu" + +function check_rust_toolchain_version() { + DEV_BUILDER_IMAGE_TAG=$(grep "DEV_BUILDER_IMAGE_TAG ?= " Makefile | cut -d= -f2 | sed 's/^[ \t]*//') + if [ -z "$DEV_BUILDER_IMAGE_TAG" ]; then + echo "Error: No DEV_BUILDER_IMAGE_TAG found in Makefile" + exit 1 + fi + + DEV_BUILDER_UBUNTU_IMAGE="$DEV_BUILDER_UBUNTU_REGISTRY/$DEV_BUILDER_UBUNTU_NAMESPACE/$DEV_BUILDER_UBUNTU_NAME:$DEV_BUILDER_IMAGE_TAG" + + CURRENT_VERSION=$(grep -Eo '[0-9]{4}-[0-9]{2}-[0-9]{2}' "$RUST_TOOLCHAIN_VERSION_FILE") + if [ -z "$CURRENT_VERSION" ]; then + echo "Error: No rust toolchain version found in $RUST_TOOLCHAIN_VERSION_FILE" + exit 1 + fi + + RUST_TOOLCHAIN_VERSION_IN_BUILDER=$(docker run "$DEV_BUILDER_UBUNTU_IMAGE" rustc --version | grep -Eo '[0-9]{4}-[0-9]{2}-[0-9]{2}') + if [ -z "$RUST_TOOLCHAIN_VERSION_IN_BUILDER" ]; then + echo "Error: No rustc version found in $DEV_BUILDER_UBUNTU_IMAGE" + exit 1 + fi + + # Compare the version and the difference should be less than 1 day. + current_rust_toolchain_seconds=$(date -d "$CURRENT_VERSION" +%s) + rust_toolchain_in_dev_builder_ubuntu_seconds=$(date -d "$RUST_TOOLCHAIN_VERSION_IN_BUILDER" +%s) + date_diff=$(( (current_rust_toolchain_seconds - rust_toolchain_in_dev_builder_ubuntu_seconds) / 86400 )) + + if [ $date_diff -gt 1 ]; then + echo "Error: The rust toolchain '$RUST_TOOLCHAIN_VERSION_IN_BUILDER' in builder '$DEV_BUILDER_UBUNTU_IMAGE' maybe outdated, please update it to '$CURRENT_VERSION'" + exit 1 + fi +} + +check_rust_toolchain_version