Skip to content

Commit

Permalink
chore(bors): merge pull request #555
Browse files Browse the repository at this point in the history
555: ci: add script to run pytests r=niladrih a=niladrih



Co-authored-by: Niladri Halder <[email protected]>
  • Loading branch information
mayastor-bors and niladrih committed Oct 23, 2024
2 parents b24823e + c142995 commit 599683a
Show file tree
Hide file tree
Showing 17 changed files with 360 additions and 76 deletions.
18 changes: 15 additions & 3 deletions .github/workflows/k8s-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: DeterminateSystems/nix-installer-action@v11
with:
kvm: true
Expand All @@ -17,12 +19,22 @@ jobs:
export NIX_PATH=nixpkgs=$(jq '.nixpkgs.url' nix/sources.json -r)
echo "NIX_PATH=$NIX_PATH" >> $GITHUB_ENV
nix-shell ./scripts/k8s/shell.nix --run "echo"
- name: Build binaries and images
id: build
run: |
TAG=$(nix-shell ./shell.nix --run './scripts/python/generate-test-tag.sh')
BIN=$(mktemp -p . -d -t test-bin-XXXXXX)
nix-shell ./shell.nix --run "./scripts/python/tag-chart.sh $TAG"
RUSTFLAGS="-C debuginfo=0 -C strip=debuginfo" ./scripts/release.sh --tag $TAG --build-bins --build-binary-out $BIN --no-static-linking --skip-publish --debug
echo "tag=$TAG" >> $GITHUB_OUTPUT
echo "bin=$BIN" >> $GITHUB_OUTPUT
- name: BootStrap k8s cluster
run: |
nix-shell ./scripts/k8s/shell.nix --run "./scripts/k8s/deployer.sh start --label"
- name: Install Helm Chart
run: |
nix-shell ./scripts/k8s/shell.nix --run "./scripts/helm/install.sh --dep-update --wait"
- name: Load images to Kind cluster
run: nix-shell ./scripts/k8s/shell.nix --run "./scripts/k8s/load-images-to-kind.sh --tag ${{ steps.build.outputs.tag }} --trim-debug-suffix"
- name: Run Pytests
run: nix-shell ./shell.nix --run './scripts/python/test.sh'
- name: The job has failed
if: ${{ failure() }}
run: |
Expand Down
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,5 @@ __pycache__
/kubectl-plugin

# Pytest assets
/test-bin-*
tests/bdd/venv

# Minikube assets
tests/bdd/minikube/.cleanup_config.yaml
tests/bdd/minikube/.cleanup_config.yaml.lock
tests/bdd/minikube/bin
13 changes: 11 additions & 2 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
{ system ? null, allInOne ? true, incremental ? false, static ? false, img_tag ? "", tag ? "", img_org ? "", product_prefix ? "" }:
{ system ? null
, allInOne ? true
, incremental ? false
, static ? false
, img_tag ? ""
, tag ? ""
, img_org ? ""
, product_prefix ? ""
, rustFlags ? ""
}:
let
sources = import ./nix/sources.nix;
hostSystem = (import sources.nixpkgs { }).hostPlatform.system;
pkgs = import sources.nixpkgs {
overlays = [ (_: _: { inherit sources; }) (import ./nix/overlay.nix { inherit allInOne incremental static img_tag tag img_org product_prefix; }) (import sources.rust-overlay) ];
overlays = [ (_: _: { inherit sources; }) (import ./nix/overlay.nix { inherit allInOne incremental static img_tag tag img_org product_prefix rustFlags; }) (import sources.rust-overlay) ];
system = if system != null then system else hostSystem;
};
in
Expand Down
12 changes: 10 additions & 2 deletions nix/overlay.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
{ allInOne ? true, incremental ? false, static ? false, img_tag ? "", tag ? "", img_org ? "", product_prefix ? "" }:
{ allInOne ? true
, incremental ? false
, static ? false
, img_tag ? ""
, tag ? ""
, img_org ? ""
, product_prefix ? ""
, rustFlags ? ""
}:
let
config = import ./config.nix;
img_prefix = if product_prefix == "" then config.product_prefix else product_prefix;
in
self: super: {
sourcer = super.callPackage ./lib/sourcer.nix { };
images = super.callPackage ./pkgs/images { inherit img_tag img_org img_prefix; };
extensions = super.callPackage ./pkgs/extensions { inherit allInOne incremental static tag; };
extensions = super.callPackage ./pkgs/extensions { inherit allInOne incremental static tag rustFlags; };
openapi-generator = super.callPackage ./../dependencies/control-plane/nix/pkgs/openapi-generator { };
utils = super.callPackage ./pkgs/utils { inherit incremental; };
channel = import ./lib/rust.nix { pkgs = super.pkgs; };
Expand Down
11 changes: 9 additions & 2 deletions nix/pkgs/extensions/cargo-project.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
# for development and not for CI
, incremental ? false
, static ? false
, rustFlags
}:
let
stable_channel = {
Expand Down Expand Up @@ -105,6 +106,12 @@ let
doCheck = false;
};
release_build = { "release" = true; "debug" = false; };
flags =
if builtins.stringLength rustFlags > 0
then builtins.split " " rustFlags
else if static
then [ "-C" "target-feature=+crt-static" ]
else [ ];
in
let
build_with_naersk = { buildType, cargoBuildFlags }:
Expand Down Expand Up @@ -133,7 +140,7 @@ let
export OPENSSL_LIB_DIR=${static_ssl.out}/lib
export OPENSSL_INCLUDE_DIR=${static_ssl.dev}/include
'';
${if static then "RUSTFLAGS" else null} = [ "-C" "target-feature=+crt-static" ];
${if flags == [ ] then null else "RUSTFLAGS"} = flags;
cargoLock = {
lockFile = ../../../Cargo.lock;
};
Expand All @@ -151,7 +158,7 @@ in

build = { buildType, cargoBuildFlags ? [ ] }:
if buildAllInOne then
builder { inherit buildType; cargoBuildFlags = [ "-p rpc" "-p metrics-exporter" "-p call-home" "-p upgrade" ]; }
builder { inherit buildType; cargoBuildFlags = [ "-p rpc" "-p metrics-exporter" "-p call-home" "-p upgrade" "-p kubectl-plugin" ]; }
else
builder { inherit buildType cargoBuildFlags; };
}
22 changes: 15 additions & 7 deletions nix/pkgs/extensions/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, git, lib, pkgs, allInOne, incremental, static, sourcer, tag ? "" }:
{ stdenv, git, lib, pkgs, allInOne, incremental, static, sourcer, tag ? "", rustFlags }:
let
versionDrv = import ../../lib/version.nix { inherit sourcer lib stdenv git tag; };
version = builtins.readFile "${versionDrv}";
Expand All @@ -8,7 +8,9 @@ let
"tag_or_long" = builtins.readFile "${versionDrv.tag_or_long}";
};
project-builder =
pkgs.callPackage ../extensions/cargo-project.nix { inherit sourcer gitVersions allInOne incremental static; };
pkgs.callPackage ../extensions/cargo-project.nix {
inherit sourcer gitVersions allInOne incremental static rustFlags;
};
installer = { pname, src, suffix ? "" }:
stdenv.mkDerivation rec {
inherit pname src;
Expand Down Expand Up @@ -70,12 +72,18 @@ let
pname = "obs-callhome-stats";
};
};
kubectl-plugin = installer {
src = builder.build {
inherit buildType;
cargoBuildFlags = [ "--bin kubectl-mayastor" ];
kubectl-plugin = rec {
recurseForDerivations = true;
plugin_builder = { buildType, builder, cargoBuildFlags ? [ "-p kubectl-plugin" ] }: builder.build { inherit buildType cargoBuildFlags; };
plugin_installer = { pname, src }: installer { inherit pname src; };
plugin = plugin_installer {
src =
if allInOne then
plugin_builder { inherit buildType builder; cargoBuildFlags = [ "-p kubectl-plugin" ]; }
else
plugin_builder { inherit buildType builder; cargoBuildFlags = [ "--bin kubectl-mayastor" ]; };
pname = "kubectl-mayastor";
};
pname = "kubectl-mayastor";
};
};
in
Expand Down
60 changes: 7 additions & 53 deletions scripts/helm/publish-chart-yaml.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/usr/bin/env bash

SCRIPTDIR="$(dirname "$(realpath "${BASH_SOURCE[0]:-"$0"}")")"
ROOTDIR="$SCRIPTDIR/../.."

source "$ROOTDIR/scripts/utils/yaml.sh"
source "$ROOTDIR/scripts/utils/repo.sh"

# On a new appTag, update the Chart.yaml which is used to publish the chart to the appropriate
# version and appVersion.
# For this first iteration version and appVersion in the Chart.yaml *MUST* point to the stable
Expand All @@ -24,46 +30,12 @@ die()

set -euo pipefail

# This uses the existing remote refs for the openebs/mayastor-extensions repo to find the latest 'release/x.y' branch.
# Requires a 'git fetch origin' (origin being the remote entry for openebs/mayastor-extensions) or equivalent, if not
# done already.
latest_release_branch() {
if [ -n "$LATEST_RELEASE_BRANCH" ]; then
echo "$LATEST_RELEASE_BRANCH"
return 0
fi

cd "$ROOTDIR"

# The latest release branch name is required for generating the helm chart version/appVersion
# for the 'main' branch only.
# The 'git branch' command in the below lines checks remote refs for release/x.y branch entries.
# Because the 'main' branch is not a significant branch for a user/contributor, this approach towards
# finding the latest release branch assumes that this script is used when the 'openebs/mayastor-extensions'
# repo is present amongst git remote refs. This happens automatically when the 'openebs/mayastor-extensions'
# repo is cloned, and not a user/contributor's fork.
local latest_release_branch=$(git branch \
--all \
--list "origin/release/*.*" \
--format '%(refname:short)' \
--sort 'refname' \
| tail -n 1)

if [ "$latest_release_branch" == "" ]; then
latest_release_branch="origin/release/0.0"
fi

cd - >/dev/null

echo "${latest_release_branch#*origin/}"
}

helm_testing_branch_version() {
local release_branch=$1
local helm_kind=""

if [[ "$check_branch" == "helm-testing/develop" ]]; then
release_branch=$(latest_release_branch)
release_branch=$(latest_release_branch "origin")
helm_kind="main"
elif [[ "$check_branch" =~ ^helm-testing\/release\/[0-9.]+$ ]]; then
release_branch="${check_branch#helm-testing/}"
Expand Down Expand Up @@ -203,22 +175,6 @@ index_yaml()
fi
}

# yq-go eats up blank lines
# this function gets around that using diff with --ignore-blank-lines
yq_ibl()
{
set +e
diff_out=$(diff -B <(yq '.' "$2") <(yq "$1" "$2"))
error=$?
if [ "$error" != "0" ] && [ "$error" != "1" ]; then
exit "$error"
fi
if [ -n "$diff_out" ]; then
echo "$diff_out" | patch --quiet --no-backup-if-mismatch "$2" -
fi
set -euo pipefail
}

output_yaml()
{
newChartVersion=$1
Expand Down Expand Up @@ -272,8 +228,6 @@ Examples:
EOF
}

SCRIPTDIR="$(dirname "$(realpath "${BASH_SOURCE[0]:-"$0"}")")"
ROOTDIR="$SCRIPTDIR/../.."
CHART_FILE=${CHART_FILE:-"$ROOTDIR/chart/Chart.yaml"}
CHART_VALUES=${CHART_VALUES:-"$ROOTDIR/chart/values.yaml"}
CHART_DOC=${CHART_DOC:-"$ROOTDIR/chart/doc.yaml"}
Expand Down
69 changes: 69 additions & 0 deletions scripts/k8s/load-images-to-kind.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env bash

# Print usage options for this script.
print_help() {
cat <<EOF
Usage: $(basename "${0}") --tag <TAG>
Options:
-h, --help Display this text.
--tag <TAG> Input the container image tag.
--trim-debug-suffix Remove the '-debug' suffix from image names.
Examples:
$(basename "${0}") --tag "ribbit"
EOF
}

SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]:-"$0"}")")"
ROOT_DIR="$SCRIPT_DIR/../.."
# Imports
source "$ROOT_DIR/scripts/utils/log.sh"

set -e

TAG=
TRIM_DEBUG_SUFFIX=0

while test $# -gt 0; do
arg="$1"
case "$arg" in
--tag)
test $# -lt 2 && log_fatal "missing value for the argument '$arg'"
TAG=$2
shift
;;
--tag=*)
TAG=${arg#*=}
;;
--trim-debug-suffix)
TRIM_DEBUG_SUFFIX=1
;;
-h* | --help*)
print_help
exit 0
;;
*)
print_help
log_fatal "unexpected argument '$arg'" 1
;;
esac
shift
done

if [ -z "$TAG" ]; then
log_fatal "requires an image tag"
fi

IMAGE_TAG="v${TAG#v}"
# This list is static and is bound to fall out of date.
# TODO: generate the list of container images at run time from build assets.
images=("upgrade-job" "obs-callhome" "obs-callhome-stats" "metrics-exporter-io-engine")
load_cmd="kind load docker-image"
for image in "${images[@]}"; do
if [ "$TRIM_DEBUG_SUFFIX" = 1 ]; then
docker tag "openebs/mayastor-"$image"-debug":$IMAGE_TAG "openebs/mayastor-"$image:$IMAGE_TAG
fi
load_cmd+=" openebs/mayastor-"$image:$IMAGE_TAG
done
eval $load_cmd
2 changes: 1 addition & 1 deletion scripts/k8s/setup-io-prereq.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ install_kernel_modules() {
DISTRO="$(distro)"
case "$DISTRO" in
Ubuntu)
$SUDO apt-get install linux-modules-extra-$(uname -r)
$SUDO apt-get update && $SUDO apt-get install -y linux-modules-extra-$(uname -r)
;;
NixOS | *)
install_kernel_modules_nsup "$DISTRO"
Expand Down
Loading

0 comments on commit 599683a

Please sign in to comment.