Skip to content

Commit

Permalink
ci: introduce ci/docker/env.sh (solana-labs#3774)
Browse files Browse the repository at this point in the history
Co-authored-by: sakridge <[email protected]>
  • Loading branch information
yihau and sakridge authored Nov 25, 2024
1 parent 52f132c commit f320175
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 14 deletions.
4 changes: 2 additions & 2 deletions ci/docker-run-default-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}" "$@"
3 changes: 2 additions & 1 deletion ci/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM ubuntu:20.04
ARG BASE_IMAGE=
FROM ${BASE_IMAGE}

ARG \
RUST_VERSION= \
Expand Down
17 changes: 11 additions & 6 deletions ci/docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@ 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
# Ref: https://blog.jaimyn.dev/how-to-build-multi-architecture-docker-images-on-an-m1-mac/#tldr
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"
34 changes: 34 additions & 0 deletions ci/docker/env.sh
Original file line number Diff line number Diff line change
@@ -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}"
2 changes: 0 additions & 2 deletions ci/rust-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions net/net.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
(
Expand Down

0 comments on commit f320175

Please sign in to comment.