From 6c0847b6225e43dd9082d679b3089123eec23577 Mon Sep 17 00:00:00 2001
From: Zygmunt Krynicki <zygmunt.krynicki@huawei.com>
Date: Tue, 19 Oct 2021 18:27:59 +0200
Subject: [PATCH] .oniro-ci: route jobs to specific instance sizes

Zephyr and FreeRTOS jobs do not require 16GB of RAM to build and
constitute the bulk of our CI (by number) quota usage. By moving them to
smaller instances, with 4GB of RAM, we can use the remaining quota
better.

On the infrastructure side we now have a new auto-scaling pool, with
s3.large.2 instances. Those join the existing s3.xlarge.4 (formerly
known as "heavy") and s3.large.8 (formerly known as "light").

The .workspace job uses the s2.large.8 by default, making a safe (but
expensive) default. Specific jobs deviate as follows:

 - zephyr and freertos jobs use s3.large.2
 - two blueprint jobs with more recipes use s3.xlarge.4

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@huawei.com>
---
 .oniro-ci/build-generic.yaml         |  5 ++++-
 .oniro-ci/machines-and-flavours.yaml |  6 ++++--
 docs/ci/hidden-jobs/workspace.rst    | 10 ++++++++++
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/.oniro-ci/build-generic.yaml b/.oniro-ci/build-generic.yaml
index 98364abc..75f80019 100644
--- a/.oniro-ci/build-generic.yaml
+++ b/.oniro-ci/build-generic.yaml
@@ -6,7 +6,7 @@
   interruptible: true
   image:
     name: registry.ostc-eu.org/ostc/containers/ostc-builder:latest
-  tags: [large-disk, $CI_ONIRO_RUNNER_TAG]
+  tags: [large-disk, $CI_ONIRO_RUNNER_TAG, $CI_ONIRO_INSTANCE_SIZE]
   variables:
     CI_ONIRO_RUNNER_TAG : ""
     CI_ONIRO_MANIFEST_URL: https://git.ostc-eu.org/distro/oniro
@@ -14,6 +14,7 @@
     CI_ONIRO_MANIFEST_NAME: default.xml
     CI_ONIRO_MANIFEST_MIRROR: ostc-develop
     CI_ONIRO_GIT_REPO_PATH: ""
+    CI_ONIRO_INSTANCE_SIZE: s3.large.8
   before_script:
     - test ! -e "$CI_PROJECT_DIR"/.scratch-dir-name || (
         echo "precondition failed - concurrent modification of $CI_PROJECT_DIR"
@@ -218,6 +219,7 @@
   variables:
     CI_ONIRO_BUILD_FLAVOUR: zephyr
     CI_ONIRO_BITBAKE_TARGETS: "zephyr-philosophers"
+    CI_ONIRO_INSTANCE_SIZE: s3.large.2
   script:
     - test -n "$CI_ONIRO_BITBAKE_TARGETS" || (
         echo "nothing to build - CI_ONIRO_BITBAKE_TARGETS is empty"
@@ -233,6 +235,7 @@
   extends: .bitbake-workspace
   variables:
     CI_ONIRO_BUILD_FLAVOUR: freertos
+    CI_ONIRO_INSTANCE_SIZE: s3.large.2
   script:
     - !reference [.bitbake-workspace, script]
     - time bitbake freertos-demo
diff --git a/.oniro-ci/machines-and-flavours.yaml b/.oniro-ci/machines-and-flavours.yaml
index 24364744..ca217f3f 100644
--- a/.oniro-ci/machines-and-flavours.yaml
+++ b/.oniro-ci/machines-and-flavours.yaml
@@ -86,6 +86,7 @@ zephyr-96b-nitrogen:
     MACHINE: 96b-nitrogen
     CI_ONIRO_RECIPE_NAME: zephyr-philosophers
     CI_ONIRO_BUILD_FLAVOUR: zephyr
+    CI_ONIRO_INSTANCE_SIZE: s3.large.2
 
 zephyr-96b-nitrogen-tests:
   extends: .build-image
@@ -93,6 +94,7 @@ zephyr-96b-nitrogen-tests:
     MACHINE: 96b-nitrogen
     CI_ONIRO_RECIPE_NAME: zephyr-kernel-test-all
     CI_ONIRO_BUILD_FLAVOUR: zephyr
+    CI_ONIRO_INSTANCE_SIZE: s3.large.2
 
 zephyr-96b-avenger:
   extends: .build-zephyr
@@ -126,16 +128,16 @@ blueprint-smartpanel-zephyr:
 
 blueprint-smartpanel-linux:
   extends: .build-linux
-  tags: [large-disk, bitbake-friendly, heavy, $CI_ONIRO_RUNNER_TAG]
   variables:
     MACHINE: stm32mp1-av96
     DISTRO: oniro-linux-blueprint-dashboard
     CI_ONIRO_BITBAKE_TARGETS: "blueprint-dashboard-gateway-image"
+    CI_ONIRO_INSTANCE_SIZE: s3.xlarge.4
 
 blueprint-gateway-linux:
   extends: .build-linux
-  tags: [large-disk, bitbake-friendly, heavy, $CI_ONIRO_RUNNER_TAG]
   variables:
     MACHINE: raspberrypi4-64
     DISTRO: oniro-linux-blueprint-gateway
     CI_ONIRO_BITBAKE_TARGETS: "blueprint-gateway-image"
+    CI_ONIRO_INSTANCE_SIZE: s3.xlarge.4
diff --git a/docs/ci/hidden-jobs/workspace.rst b/docs/ci/hidden-jobs/workspace.rst
index 68555244..71f00314 100644
--- a/docs/ci/hidden-jobs/workspace.rst
+++ b/docs/ci/hidden-jobs/workspace.rst
@@ -30,6 +30,16 @@ process of constructing the workspace from scratch.
 Variables
 =========
 
+CI_ONIRO_INSTANCE_SIZE
+----------------------
+
+An arbitrary GitLab Runner tag selecting the size of a system instance which
+processes the .workspace job, or its derivative. This defaults to s3.large.8
+which translates to two cores and 16GB of memory.
+
+This can be used to route specific jobs to specific instance sizes using
+easy-to-use variable map, rather than more painful to use tag list.
+
 CI_ONIRO_RUNNER_TAG
 -------------------
 
-- 
GitLab