From 006c92114997122d2bbd475ff6dad0fdedb770ba Mon Sep 17 00:00:00 2001 From: Yihau Chen Date: Tue, 26 Nov 2024 02:32:15 +0800 Subject: [PATCH] ci: introduce ci/docker/env.sh (#3774) Co-authored-by: sakridge (cherry picked from commit f3201756b76880857630ef47933aa675e1343c6e) --- ci/docker-run-default-image.sh | 4 ++-- ci/docker/Dockerfile | 3 ++- ci/docker/build.sh | 17 +++++++++++------ ci/docker/env.sh | 34 ++++++++++++++++++++++++++++++++++ ci/rust-version.sh | 2 -- net/net.sh | 6 +++--- 6 files changed, 52 insertions(+), 14 deletions(-) create mode 100755 ci/docker/env.sh diff --git a/ci/docker-run-default-image.sh b/ci/docker-run-default-image.sh index 927167cc8ef1ac..d6c536ddb6b992 100755 --- a/ci/docker-run-default-image.sh +++ b/ci/docker-run-default-image.sh @@ -5,6 +5,6 @@ set -e here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # shellcheck disable=SC1091 -source "$here/rust-version.sh" +source "$here/docker/env.sh" -"$here/docker-run.sh" "${ci_docker_image:?}" "$@" +"$here/docker-run.sh" "${CI_DOCKER_IMAGE:?}" "$@" diff --git a/ci/docker/Dockerfile b/ci/docker/Dockerfile index 7f7b69c30ce68f..b99b8ee5ff25b2 100644 --- a/ci/docker/Dockerfile +++ b/ci/docker/Dockerfile @@ -1,4 +1,5 @@ -FROM ubuntu:20.04 +ARG BASE_IMAGE= +FROM ${BASE_IMAGE} ARG \ RUST_VERSION= \ diff --git a/ci/docker/build.sh b/ci/docker/build.sh index 0c20c5e928d94d..c37a821673577c 100755 --- a/ci/docker/build.sh +++ b/ci/docker/build.sh @@ -5,7 +5,7 @@ set -e here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # shellcheck disable=SC1091 -source "$here/../rust-version.sh" +source "$here/env.sh" platform=() if [[ $(uname -m) = arm64 ]]; then @@ -13,11 +13,16 @@ if [[ $(uname -m) = arm64 ]]; then platform+=(--platform linux/amd64) fi -echo "build image: ${ci_docker_image:?}" +echo "build image: ${CI_DOCKER_IMAGE:?}" docker build "${platform[@]}" \ -f "$here/Dockerfile" \ - --build-arg "RUST_VERSION=${rust_stable:?}" \ - --build-arg "RUST_NIGHTLY_VERSION=${rust_nightly:?}" \ - -t "$ci_docker_image" . + --build-arg "BASE_IMAGE=${BASE_IMAGE}" \ + --build-arg "RUST_VERSION=${RUST_VERSION}" \ + --build-arg "RUST_NIGHTLY_VERSION=${RUST_NIGHTLY_VERSION}" \ + --build-arg "GOLANG_VERSION=${GOLANG_VERSION}" \ + --build-arg "NODE_MAJOR=${NODE_MAJOR}" \ + --build-arg "SCCACHE_VERSION=${SCCACHE_VERSION}" \ + --build-arg "GRCOV_VERSION=${GRCOV_VERSION}" \ + -t "$CI_DOCKER_IMAGE" . -docker push "$ci_docker_image" +docker push "$CI_DOCKER_IMAGE" diff --git a/ci/docker/env.sh b/ci/docker/env.sh new file mode 100755 index 00000000000000..d59183278d9bb4 --- /dev/null +++ b/ci/docker/env.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +ci_docker_env_sh_here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +# shellcheck disable=SC1091 +source "${ci_docker_env_sh_here}/../rust-version.sh" + +if [[ -z "${rust_stable}" || -z "${rust_nightly}" ]]; then + echo "Error: rust_stable or rust_nightly is empty. Please check rust-version.sh." >&2 + exit 1 +fi + +export BASE_IMAGE=ubuntu:22.04 +export RUST_VERSION="${rust_stable}" +export RUST_NIGHTLY_VERSION="${rust_nightly}" +export GOLANG_VERSION=1.21.3 +export NODE_MAJOR=18 +export SCCACHE_VERSION=v0.8.1 +export GRCOV_VERSION=v0.8.18 + +hash_vars=( + "${BASE_IMAGE}" + "${RUST_VERSION}" + "${RUST_NIGHTLY_VERSION}" + "${GOLANG_VERSION}" + "${NODE_MAJOR}" + "${SCCACHE_VERSION}" + "${GRCOV_VERSION}" +) +hash_input=$(IFS="_"; echo "${hash_vars[*]}") +ci_docker_hash=$(echo -n "${hash_input}" | sha256sum | head -c 8) + +SANITIZED_BASE_IMAGE="${BASE_IMAGE//:/-}" +export CI_DOCKER_IMAGE="anzaxyz/ci:${SANITIZED_BASE_IMAGE}_rust-${RUST_VERSION}_${RUST_NIGHTLY_VERSION}_${ci_docker_hash}" diff --git a/ci/rust-version.sh b/ci/rust-version.sh index c55d5ba4462998..bc88c84d2d34fb 100644 --- a/ci/rust-version.sh +++ b/ci/rust-version.sh @@ -37,8 +37,6 @@ export rust_stable="$stable_version" export rust_nightly=nightly-"$nightly_version" -export ci_docker_image="anzaxyz/ci:rust_${rust_stable}_${rust_nightly}" - [[ -z $1 ]] || ( rustup_install() { diff --git a/net/net.sh b/net/net.sh index 3ef7430ebd54d6..2be711be089402 100755 --- a/net/net.sh +++ b/net/net.sh @@ -192,9 +192,9 @@ build() { supported=("20.04") declare MAYBE_DOCKER= if [[ $(uname) != Linux || ! " ${supported[*]} " =~ $(lsb_release -sr) ]]; then - # shellcheck source=ci/rust-version.sh - source "$SOLANA_ROOT"/ci/rust-version.sh - MAYBE_DOCKER="ci/docker-run.sh ${ci_docker_image:?}" + # shellcheck source=ci/docker/env.sh + source "$SOLANA_ROOT"/ci/docker/env.sh + MAYBE_DOCKER="ci/docker-run.sh ${CI_DOCKER_IMAGE:?}" fi SECONDS=0 (