From f609fe0fb5c1f92bbc60f4c9097ce530b1ed63bb Mon Sep 17 00:00:00 2001 From: Ryan Kuba Date: Tue, 6 Feb 2024 20:34:25 +0000 Subject: [PATCH] Resolve KASM-5423 "Feature/ named schedules" --- ci-scripts/build.sh | 5 ----- ci-scripts/gitlab-ci.template | 6 ++++++ ci-scripts/manifest.sh | 24 ++++++++++++++++-------- ci-scripts/template-gitlab.py | 7 +++++++ 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/ci-scripts/build.sh b/ci-scripts/build.sh index b33976d..73224ca 100755 --- a/ci-scripts/build.sh +++ b/ci-scripts/build.sh @@ -10,11 +10,6 @@ if [ ${USE_PRIVATE_IMAGES} -eq 1 ]; then BASE=${BASE}-private fi -# Determine if this is a rolling build -if [ "${CI_PIPELINE_SOURCE}" == "schedule" ]; then - BASE_TAG=${BASE_TAG}-rolling -fi - ## Build/Push image to cache endpoint by pipeline ID ## docker build \ -t ${ORG_NAME}/image-cache-private:$(arch)-${NAME}-${SANITIZED_BRANCH}-${CI_PIPELINE_ID} \ diff --git a/ci-scripts/gitlab-ci.template b/ci-scripts/gitlab-ci.template index 1e75051..a8db237 100644 --- a/ci-scripts/gitlab-ci.template +++ b/ci-scripts/gitlab-ci.template @@ -136,6 +136,9 @@ test_{{ IMAGE.name }}: manifest_{{ IMAGE.name }}: stage: manifest when: always + variables: + SCHEDULED: "{{ SCHEDULED }}" + SCHEDULE_NAME: "{{ SCHEDULE_NAME }}" script: - apk add bash tar - bash ci-scripts/manifest.sh "{{ IMAGE.name }}" "multi"{% if IMAGE.singleapp %} @@ -162,6 +165,9 @@ manifest_{{ IMAGE.name }}: manifest_{{ IMAGE.name }}: stage: manifest when: always + variables: + SCHEDULED: "{{ SCHEDULED }}" + SCHEDULE_NAME: "{{ SCHEDULE_NAME }}" script: - apk add bash tar - bash ci-scripts/manifest.sh "{{ IMAGE.name }}" "single"{% if IMAGE.singleapp %} diff --git a/ci-scripts/manifest.sh b/ci-scripts/manifest.sh index 1728cec..b690cf6 100755 --- a/ci-scripts/manifest.sh +++ b/ci-scripts/manifest.sh @@ -19,23 +19,31 @@ else fi # Determine if this is a rolling build -if [ "${CI_PIPELINE_SOURCE}" == "schedule" ]; then - SANITIZED_BRANCH=${SANITIZED_BRANCH}-rolling +if [[ "${SCHEDULED}" != "NO" ]]; then + if [[ "${SCHEDULE_NAME}" == "NO" ]]; then + SANITIZED_BRANCH=${SANITIZED_BRANCH}-rolling + else + SANITIZED_BRANCH=${SANITIZED_BRANCH}-rolling-${SCHEDULE_NAME} + fi fi # Determine if we are doing a reversion if [ ! -z "${REVERT_PIPELINE_ID}" ]; then # If we are reverting modify the pipeline ID to the one passed CI_PIPELINE_ID=${REVERT_PIPELINE_ID} - if [ "${IS_ROLLING}" == "true" ]; then - SANITIZED_BRANCH=${SANITIZED_BRANCH}-rolling + if [[ "${IS_ROLLING}" == "true" ]]; then + if [[ "${SCHEDULE_NAME}" == "NO" ]]; then + SANITIZED_BRANCH=${SANITIZED_BRANCH}-rolling + else + SANITIZED_BRANCH=${SANITIZED_BRANCH}-rolling-${SCHEDULE_NAME} + fi fi fi # Check test output -if [ -z "${REVERT_PIPELINE_ID}" ]; then +if [[ -z "${REVERT_PIPELINE_ID}" ]]; then apk add curl - if [ "${TYPE}" == "multi" ]; then + if [[ "${TYPE}" == "multi" ]]; then ARCHES=("x86_64" "aarch64") else ARCHES=("x86_64") @@ -58,12 +66,12 @@ if [ -z "${REVERT_PIPELINE_ID}" ]; then fi # Fail job and go no further if tests did not pass -if [ "${FAILED}" == "true" ]; then +if [[ "${FAILED}" == "true" ]]; then exit 1 fi # Manifest for multi pull and push for single arch -if [ "${TYPE}" == "multi" ]; then +if [[ "${TYPE}" == "multi" ]]; then # Pull images from cache repo docker pull ${ORG_NAME}/image-cache-private:x86_64-${NAME}-${PULL_BRANCH}-${CI_PIPELINE_ID} diff --git a/ci-scripts/template-gitlab.py b/ci-scripts/template-gitlab.py index e3a8269..d1fb3b6 100644 --- a/ci-scripts/template-gitlab.py +++ b/ci-scripts/template-gitlab.py @@ -6,10 +6,15 @@ import os # Determine if this is a feature branch fileLimits = True +scheduled = 'NO' +scheduleName = 'NO' if os.getenv('SANITIZED_BRANCH').startswith('release') or os.getenv('SANITIZED_BRANCH') == 'develop': fileLimits = False if os.getenv('CI_PIPELINE_SOURCE') == 'schedule': fileLimits = False + scheduled = 'YES' +if 'SCHEDULE_NAME' in os.environ: + scheduleName = os.getenv('SCHEDULE_NAME') if os.getenv('USE_PRIVATE_IMAGES') == 1: fileLimits = False @@ -21,6 +26,8 @@ with open("template-vars.yaml", 'r') as stream: templateVars['USE_PRIVATE_IMAGES'] = os.getenv('USE_PRIVATE_IMAGES') templateVars['BASE_TAG'] = os.getenv('BASE_TAG') templateVars['FILE_LIMITS'] = fileLimits + templateVars['SCHEDULED'] = scheduled + templateVars['SCHEDULE_NAME'] = scheduleName # Read template file with open("gitlab-ci.template", 'r') as stream: