From b5c3c7fb88b709107d7eb21b7159124ebc3761a2 Mon Sep 17 00:00:00 2001 From: dor-sendblocks Date: Thu, 14 Sep 2023 17:31:33 +0300 Subject: [PATCH 01/10] add script --- .github/workflows/pull_request.yaml | 103 ----------------- .github/workflows/push.yaml | 168 ---------------------------- .github/workflows/release.yaml | 36 ------ 3 files changed, 307 deletions(-) delete mode 100644 .github/workflows/pull_request.yaml delete mode 100644 .github/workflows/push.yaml delete mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml deleted file mode 100644 index 1188e9a6..00000000 --- a/.github/workflows/pull_request.yaml +++ /dev/null @@ -1,103 +0,0 @@ -name: Pull Request - -on: - pull_request_target: - branches: - - master - paths-ignore: - - 'README.md' - - 'LICENSE' - -env: - CHART_NAME: "application" - -jobs: - build: - name: Build - if: "! contains(toJSON(github.event.commits.*.message), '[skip-ci]')" - runs-on: om-sno6-lcaas - - steps: - - - name: Check out code - uses: actions/checkout@v3 - with: - fetch-depth: 0 - ref: ${{github.event.pull_request.head.sha}} - - # Set Up Helm - - name: Set up Helm - uses: azure/setup-helm@v3 - with: - version: v3.8.2 - - # Lint - - name: Helm Lint - run: | - helm lint ${CHART_NAME} - - - name: Install kubectl - uses: azure/setup-kubectl@v3 - with: - version: v1.26.0 - - - name: Install tilt - run: curl -fsSL https://raw.githubusercontent.com/tilt-dev/tilt/master/scripts/install.sh | bash - - - name: Install CLI tools from OpenShift Mirror - uses: redhat-actions/openshift-tools-installer@v1 - with: - oc: "4" - - # This is used to setup kubeconfig, required by Tilt - - name: Login to cluster - run: oc login --token=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token) --server=https://kubernetes.default.svc --insecure-skip-tls-verify=true - - # This is required for adding ghcr helm registry - - name: Login to Container Registry - uses: docker/login-action@v2 - with: - registry: ghcr.io/stakater - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Tilt up - run: tilt ci --timeout 5m0s - - # Dry run to ensure that manifests are generated successfully - - name: Dry Run Chart - run: | - helm install ${CHART_NAME} ${CHART_NAME} -f ${CHART_NAME}/values-test.yaml -n stakater-chart-pipeline-test --dry-run --debug - - - name: Tilt down - if: always() - run: tilt down --delete-namespaces --file ./Tiltfile-delete - - - name: Comment on PR - uses: mshick/add-pr-comment@v2 - env: - GITHUB_TOKEN: ${{ secrets.STAKATER_GITHUB_TOKEN }} - with: - message-success: '@${{ github.actor }} validation successful`' - message-failure: '@${{ github.actor }} Yikes! You better fix it before anyone else finds out! [Build](https://github.com/${{ github.repository }}/commit/${{ github.event.pull_request.head.sha }}/checks) has Failed!' - allow-repeats: false - - - name: Notify Slack - uses: 8398a7/action-slack@v3 - if: always() # Pick up events even if the job fails or is canceled. - with: - status: ${{ job.status }} - fields: repo,author,action,eventName,ref,workflow - env: - SLACK_WEBHOOK_URL: ${{ secrets.STAKATER_DELIVERY_SLACK_WEBHOOK }} - - unittest: - name: Unit Tests - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - ref: ${{github.event.pull_request.head.sha}} - - uses: d3adb5/helm-unittest-action@v2 - with: - charts: application diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml deleted file mode 100644 index 914abaad..00000000 --- a/.github/workflows/push.yaml +++ /dev/null @@ -1,168 +0,0 @@ -name: Push - -concurrency: - group: push_on_master - cancel-in-progress: false - -on: - push: - branches: - - master - paths-ignore: - - 'README.md' - - 'LICENSE' - -env: - CHART_NAME: "application" - -jobs: - helm-dry-run: - name: helm-dry-run - if: "! contains(toJSON(github.event.commits.*.message), '[skip-ci]')" - runs-on: om-sno6-lcaas - - steps: - - name: Check out code - uses: actions/checkout@v3 - with: - persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token - fetch-depth: 0 # otherwise, you will fail to push refs to dest repo - - # Set Up Helm - - name: Set up Helm - uses: azure/setup-helm@v3 - with: - version: v3.8.2 - - # Lint - - name: Helm Lint - run: | - helm lint ${CHART_NAME} - - - name: Install kubectl - uses: azure/setup-kubectl@v3 - with: - version: v1.26.0 - - - name: Install tilt - run: curl -fsSL https://raw.githubusercontent.com/tilt-dev/tilt/master/scripts/install.sh | bash - - - name: Install CLI tools from OpenShift Mirror - uses: redhat-actions/openshift-tools-installer@v1 - with: - oc: "4" - - # This is used to setup kubeconfig, required by Tilt - - name: Login to cluster - run: oc login --token=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token) --server=https://kubernetes.default.svc --insecure-skip-tls-verify=true - - # This is required for adding ghcr helm registry - - name: Login to Container Registry - uses: docker/login-action@v2 - with: - registry: ghcr.io/stakater - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Tilt up - run: tilt ci --timeout 5m0s - - # Dry run to ensure that manifests are generated successfully - - name: Dry Run Chart - run: | - helm install ${CHART_NAME} ${CHART_NAME} -f ${CHART_NAME}/values-test.yaml -n stakater-chart-pipeline-test --dry-run --debug - - - name: Tilt down - if: always() - run: tilt down --delete-namespaces --file ./Tiltfile-delete - - - name: Notify Slack - uses: 8398a7/action-slack@v3 - if: failure() # Pick up events only if the job fails - with: - status: ${{ job.status }} - fields: repo,author,action,eventName,ref,workflow - env: - SLACK_WEBHOOK_URL: ${{ secrets.STAKATER_DELIVERY_SLACK_WEBHOOK }} - - push-changes: - runs-on: ubuntu-latest - needs: - - helm-dry-run - - steps: - - name: Check out code - uses: actions/checkout@v3 - with: - persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token - fetch-depth: 0 # otherwise, you will fail to push refs to dest repo - - # Generate tag for chart without "v" prefix - - name: Generate Tag - id: generate_tag - uses: anothrNick/github-tag-action@1.61.0 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - WITH_V: false - DEFAULT_BUMP: patch - DRY_RUN: true - - # Update chart tag to the latest semver tag - - name: Update Chart Version - env: - VERSION: ${{ steps.generate_tag.outputs.new_tag }} - run: | - make bump-chart - - # Set Up Helm - - name: Set up Helm - uses: azure/setup-helm@v3 - with: - version: v3.8.2 - - # Publish helm chart - - name: Publish Helm chart - uses: stefanprodan/helm-gh-pages@master - with: - branch: master - repository: stakater-charts - target_dir: docs - token: ${{ secrets.STAKATER_GITHUB_TOKEN }} - charts_dir: . - charts_url: https://stakater.github.io/stakater-charts - owner: stakater - linting: off - commit_username: stakater-user - commit_email: stakater@gmail.com - - # Commit back changes - - name: Commit files - run: | - git config --local user.email "stakater@gmail.com" - git config --local user.name "stakater-user" - git status - git add application/Chart.yaml - git commit -m "[skip-ci] Update artifacts" - - # Push Chart.yaml with Updated Version - - name: Push changes - uses: ad-m/github-push-action@master - with: - github_token: ${{ secrets.STAKATER_GITHUB_TOKEN }} - branch: ${{ inputs.RELEASE_BRANCH }} - - - name: Push Latest Tag - uses: anothrNick/github-tag-action@1.61.0 - env: - GITHUB_TOKEN: ${{ secrets.STAKATER_GITHUB_TOKEN }} - WITH_V: true - DEFAULT_BUMP: patch - - - name: Notify Slack - uses: 8398a7/action-slack@v3 - if: always() # Pick up events even if the job fails or is canceled. - with: - status: ${{ job.status }} - fields: repo,author,action,eventName,ref,workflow - env: - SLACK_WEBHOOK_URL: ${{ secrets.STAKATER_DELIVERY_SLACK_WEBHOOK }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml deleted file mode 100644 index 8497c1ae..00000000 --- a/.github/workflows/release.yaml +++ /dev/null @@ -1,36 +0,0 @@ -name: Release -on: - push: - tags: - - "v*" - -jobs: - build: - name: Release - runs-on: ubuntu-latest - - steps: - - name: Check out code - uses: actions/checkout@v2 - with: - fetch-depth: 0 # See: https://goreleaser.com/ci/actions/ - - - name: Create Release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ github.ref }} - release_name: ${{ github.ref }} - draft: false - prerelease: false - - - name: Notify Slack - uses: 8398a7/action-slack@v3 - if: always() - with: - status: ${{ job.status }} - fields: repo,author,action,eventName,ref,workflow - env: - SLACK_WEBHOOK_URL: ${{ secrets.STAKATER_DELIVERY_SLACK_WEBHOOK }} From 4d87f3248ada2131d18944b2201d36c16874734c Mon Sep 17 00:00:00 2001 From: dor-sendblocks Date: Thu, 14 Sep 2023 17:31:57 +0300 Subject: [PATCH 02/10] add script --- .github/scripts/create_version.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/scripts/create_version.sh diff --git a/.github/scripts/create_version.sh b/.github/scripts/create_version.sh new file mode 100644 index 00000000..767c16ae --- /dev/null +++ b/.github/scripts/create_version.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Ensure script exits on first error +set -e + +cd application +name=$(cat Chart.yaml | yq '.name') +output=$(helm package .) +app_name=$(echo "$output" | awk '{print $NF}') + + +create_output=$(aws --profile shared ecr-public create-repository --repository-name ${name} --region us-east-1 2>&1) + +if [[ $create_output == *"RepositoryAlreadyExistsException"* ]]; then + # If the repository already exists, describe the registry and get the registryUri + registry_uri=$(aws --profile shared ecr-public describe-registries --region us-east-1 --query "registries[0].registryUri" --output text) +else + # If the repository was created successfully, extract the registryUri from the creation output + registry_uri=$(echo $create_output | jq -r '.repository.registryUri') +fi + +aws --profile shared ecr-public get-login-password --region us-east-1 | helm registry login --username AWS --password-stdin ${registry_uri} +helm push ${app_name} oci://${registry_uri} \ No newline at end of file From b229559198f643d2bafe582156c373d9af5449fd Mon Sep 17 00:00:00 2001 From: dor-sendblocks Date: Mon, 18 Sep 2023 20:36:35 +0300 Subject: [PATCH 03/10] added tpl for values --- application/templates/_helpers.tpl | 7 +++++++ application/templates/valuesTpl.yaml | 1 + 2 files changed, 8 insertions(+) create mode 100644 application/templates/valuesTpl.yaml diff --git a/application/templates/_helpers.tpl b/application/templates/_helpers.tpl index 48f8166d..64323eaf 100644 --- a/application/templates/_helpers.tpl +++ b/application/templates/_helpers.tpl @@ -1,3 +1,10 @@ +{{- define "renderedValues" -}} +{{- $originalValues := .Values | toYaml }} +{{- $newValuesYaml := tpl $originalValues . }} +{{- $newValues := $newValuesYaml | fromYaml }} +{{- $_ := set $ "Values" $newValues -}} +{{- end }} + {{/* vim: set filetype=mustache: */}} {{/* diff --git a/application/templates/valuesTpl.yaml b/application/templates/valuesTpl.yaml new file mode 100644 index 00000000..fd66d58e --- /dev/null +++ b/application/templates/valuesTpl.yaml @@ -0,0 +1 @@ +{{- include "renderedValues" . }} \ No newline at end of file From 5e173e3584ff7ee22d4dc7f55c37aedcd5dc1859 Mon Sep 17 00:00:00 2001 From: dor-sendblocks Date: Sun, 25 Feb 2024 16:21:52 +0200 Subject: [PATCH 04/10] update the create version script under the .github --- .github/scripts/create_version.sh | 56 +++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/.github/scripts/create_version.sh b/.github/scripts/create_version.sh index 767c16ae..9fc65cdf 100644 --- a/.github/scripts/create_version.sh +++ b/.github/scripts/create_version.sh @@ -5,19 +5,61 @@ set -e cd application name=$(cat Chart.yaml | yq '.name') +version=$(cat Chart.yaml | yq '.version') + +# Define the internal variable (set it to true if it's sendblocks changes and not official changes by the author) +internal=false + +# Backup the original Chart.yaml +cp Chart.yaml Chart.yaml.backup + +# Check if internal is true and append "_sb" to the version if it is +if $internal; then + new_version="${version}-sb" + yq eval -i ".version = \"$new_version\"" Chart.yaml +else + new_version=$version +fi + output=$(helm package .) app_name=$(echo "$output" | awk '{print $NF}') +# Restore the original Chart.yaml from the backup +mv Chart.yaml.backup Chart.yaml + +# Temporarily disable exit on error +set +e create_output=$(aws --profile shared ecr-public create-repository --repository-name ${name} --region us-east-1 2>&1) +create_status=$? + +# Re-enable exit on error +set -e -if [[ $create_output == *"RepositoryAlreadyExistsException"* ]]; then - # If the repository already exists, describe the registry and get the registryUri - registry_uri=$(aws --profile shared ecr-public describe-registries --region us-east-1 --query "registries[0].registryUri" --output text) +if [[ $create_status -ne 0 && $create_output == *"RepositoryAlreadyExistsException"* ]]; then + echo "Repository '${name}' already exists in AWS ECR. Proceeding with existing repository." +elif [[ $create_status -eq 0 ]]; then + echo "Repository '${name}' successfully created in AWS ECR." else - # If the repository was created successfully, extract the registryUri from the creation output - registry_uri=$(echo $create_output | jq -r '.repository.registryUri') + echo "Failed to create repository '${name}' due to an unexpected error: $create_output" + exit 1 +fi + +registry_uri=$(aws --profile shared ecr-public describe-registries --region us-east-1 --query "registries[0].registryUri" --output text) + +# Temporarily disable exit on error +set +e + +image_exists=$(aws --profile shared ecr-public describe-images --repository-name ${name} --image-ids imageTag=${new_version} --region us-east-1 2>&1) +image_exists_status=$? + +# Re-enable exit on error +set -e + +if [[ $image_exists_status -eq 0 ]]; then + echo "Error: The version ${new_version} already exists in the repository." + exit 1 fi -aws --profile shared ecr-public get-login-password --region us-east-1 | helm registry login --username AWS --password-stdin ${registry_uri} -helm push ${app_name} oci://${registry_uri} \ No newline at end of file +aws --profile shared ecr-public get-login-password --region us-east-1 | helm registry login --username AWS --password-stdin public.ecr.aws +helm push ${app_name} oci://public.ecr.aws/w8w5v2r8 From 7d19a503db2db0fc40867c4c6c407a74058def26 Mon Sep 17 00:00:00 2001 From: dor-sendblocks Date: Sun, 25 Feb 2024 18:31:28 +0200 Subject: [PATCH 05/10] add scaled object --- application/templates/scaledobject_sb.yaml | 32 +++++++++++++++ application/values-sb.yaml | 47 ++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 application/templates/scaledobject_sb.yaml create mode 100644 application/values-sb.yaml diff --git a/application/templates/scaledobject_sb.yaml b/application/templates/scaledobject_sb.yaml new file mode 100644 index 00000000..a3e64efe --- /dev/null +++ b/application/templates/scaledobject_sb.yaml @@ -0,0 +1,32 @@ +{{- if and .Values.deployment.enabled .Values.scaledObject.enabled }} +apiVersion: keda.sh/v1alpha1 +kind: ScaledObject +metadata: + name: {{ template "application.name" . }}-scaled-object + namespace: {{ include "application.namespace" . }} + labels: + {{- include "application.labels" . | nindent 4 }} +spec: + scaleTargetRef: + name: {{ template "application.name" . }} + pollingInterval: {{ .Values.scaledObject.pollingInterval }} + cooldownPeriod: {{ .Values.scaledObject.cooldownPeriod }} + minReplicaCount: {{ .Values.scaledObject.minReplicaCount }} + maxReplicaCount: {{ .Values.scaledObject.maxReplicaCount }} +{{- with .Values.scaledObject.fallback }} + fallback: + failureThreshold: {{ .failureThreshold }} + replicas: {{ .replicas }} +{{- end }} + {{- if .Values.scaledObject.advanced }} + advanced: + horizontalPodAutoscalerConfig: + behavior: + scaleDown: +{{ toYaml .Values.scaledObject.advanced.scaleDown | nindent 10 }} + scaleUp: +{{ toYaml .Values.scaledObject.advanced.scaleUp | nindent 10 }} + {{- end }} + triggers: +{{ tpl (toYaml .Values.scaledObject.triggers) $ | nindent 4 }} +{{- end }} diff --git a/application/values-sb.yaml b/application/values-sb.yaml new file mode 100644 index 00000000..149ba522 --- /dev/null +++ b/application/values-sb.yaml @@ -0,0 +1,47 @@ +# Deployment settings +deployment: + enabled: true + +# scaledObjectAdvancedSb settings +scaledObject: + enabled: true + pollingInterval: 30 + cooldownPeriod: 300 + minReplicaCount: 1 + maxReplicaCount: 5 + fallback: + failureThreshold: 3 + replicas: 2 + + # Optional - use advanced scaling + advanced: + # ScaleDown configuration + scaleDown: + stabilizationWindowSeconds: 300 + policies: + - type: Percent + value: 100 + periodSeconds: 15 + selectPolicy: Max + + # ScaleUp configuration + scaleUp: + stabilizationWindowSeconds: 300 + policies: + - type: Percent + value: 100 + periodSeconds: 15 + selectPolicy: Max + + # Triggers for scaling + triggers: + - type: rabbitmq + metadata: + protocol: amqp + queueName: sepolia-identifiers + mode: QueueLength + value: "20" + authenticationRef: + kind: ClusterTriggerAuthentication + name: rabbitmq-trigger-auth + # Define additional triggers as needed From 8fcdd0d8061c61f80f619940eab47d4ffe75f6cc Mon Sep 17 00:00:00 2001 From: dor-sendblocks Date: Mon, 26 Feb 2024 11:38:52 +0200 Subject: [PATCH 06/10] add checks into scaledobjects and default value of false --- application/templates/scaledobject-sb.yaml | 36 ++++++++++++++++++++++ application/templates/scaledobject_sb.yaml | 32 ------------------- 2 files changed, 36 insertions(+), 32 deletions(-) create mode 100644 application/templates/scaledobject-sb.yaml delete mode 100644 application/templates/scaledobject_sb.yaml diff --git a/application/templates/scaledobject-sb.yaml b/application/templates/scaledobject-sb.yaml new file mode 100644 index 00000000..5d6e5f9b --- /dev/null +++ b/application/templates/scaledobject-sb.yaml @@ -0,0 +1,36 @@ +{{- if and .Values.deployment.enabled (and .Values.scaledObject (default false .Values.scaledObject.enabled)) }} +apiVersion: keda.sh/v1alpha1 +kind: ScaledObject +metadata: + name: {{ template "application.name" . }}-scaled-object + namespace: {{ include "application.namespace" . }} + labels: + {{- include "application.labels" . | nindent 4 }} +spec: + scaleTargetRef: + name: {{ template "application.name" . }} + pollingInterval: {{ required "Undefined pollingInterval for ScaledObject" .Values.scaledObject.pollingInterval }} + cooldownPeriod: {{ required "Undefined cooldownPeriod for ScaledObject" .Values.scaledObject.cooldownPeriod }} + minReplicaCount: {{ required "Undefined minReplicaCount for ScaledObject" .Values.scaledObject.minReplicaCount }} + maxReplicaCount: {{ required "Undefined maxReplicaCount for ScaledObject" .Values.scaledObject.maxReplicaCount }} +{{- $minReplicaCount := .Values.scaledObject.minReplicaCount }} +{{- with .Values.scaledObject.fallback }} + fallback: + failureThreshold: {{ default 3 .failureThreshold }} + replicas: {{ default $minReplicaCount .replicas }} +{{- end }} + {{- if .Values.scaledObject.advanced }} + {{- $scaleDown := required "Undefined scaleDown configuration in advanced settings" .Values.scaledObject.advanced.scaleDown }} + {{- $scaleUp := required "Undefined scaleUp configuration in advanced settings" .Values.scaledObject.advanced.scaleUp }} + advanced: + horizontalPodAutoscalerConfig: + behavior: + scaleDown: +{{- toYaml $scaleDown | nindent 10 }} + scaleUp: +{{- toYaml $scaleUp | nindent 10 }} + {{- end }} +{{- $triggers := required "Undefined triggers for ScaledObject" .Values.scaledObject.triggers }} + triggers: +{{- tpl (toYaml $triggers) $ | nindent 4 }} +{{- end }} diff --git a/application/templates/scaledobject_sb.yaml b/application/templates/scaledobject_sb.yaml deleted file mode 100644 index a3e64efe..00000000 --- a/application/templates/scaledobject_sb.yaml +++ /dev/null @@ -1,32 +0,0 @@ -{{- if and .Values.deployment.enabled .Values.scaledObject.enabled }} -apiVersion: keda.sh/v1alpha1 -kind: ScaledObject -metadata: - name: {{ template "application.name" . }}-scaled-object - namespace: {{ include "application.namespace" . }} - labels: - {{- include "application.labels" . | nindent 4 }} -spec: - scaleTargetRef: - name: {{ template "application.name" . }} - pollingInterval: {{ .Values.scaledObject.pollingInterval }} - cooldownPeriod: {{ .Values.scaledObject.cooldownPeriod }} - minReplicaCount: {{ .Values.scaledObject.minReplicaCount }} - maxReplicaCount: {{ .Values.scaledObject.maxReplicaCount }} -{{- with .Values.scaledObject.fallback }} - fallback: - failureThreshold: {{ .failureThreshold }} - replicas: {{ .replicas }} -{{- end }} - {{- if .Values.scaledObject.advanced }} - advanced: - horizontalPodAutoscalerConfig: - behavior: - scaleDown: -{{ toYaml .Values.scaledObject.advanced.scaleDown | nindent 10 }} - scaleUp: -{{ toYaml .Values.scaledObject.advanced.scaleUp | nindent 10 }} - {{- end }} - triggers: -{{ tpl (toYaml .Values.scaledObject.triggers) $ | nindent 4 }} -{{- end }} From 45dfbad1015111f03b42a686facf9f96c3fe9c63 Mon Sep 17 00:00:00 2001 From: dor-sendblocks Date: Mon, 26 Feb 2024 12:54:17 +0200 Subject: [PATCH 07/10] fix the create_version script --- .github/scripts/create_version.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) mode change 100644 => 100755 .github/scripts/create_version.sh diff --git a/.github/scripts/create_version.sh b/.github/scripts/create_version.sh old mode 100644 new mode 100755 index 9fc65cdf..8ce3079e --- a/.github/scripts/create_version.sh +++ b/.github/scripts/create_version.sh @@ -3,7 +3,9 @@ # Ensure script exits on first error set -e -cd application +SCRIPT_DIR=$(dirname "$0") +cd "${SCRIPT_DIR}/../../application" + name=$(cat Chart.yaml | yq '.name') version=$(cat Chart.yaml | yq '.version') From ec358c977ddf2acc73d75900a5fb07c783516c93 Mon Sep 17 00:00:00 2001 From: dor-sendblocks Date: Mon, 26 Feb 2024 13:00:37 +0200 Subject: [PATCH 08/10] fix the create_version script --- .github/scripts/create_version.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/create_version.sh b/.github/scripts/create_version.sh index 8ce3079e..565ed518 100755 --- a/.github/scripts/create_version.sh +++ b/.github/scripts/create_version.sh @@ -64,4 +64,4 @@ if [[ $image_exists_status -eq 0 ]]; then fi aws --profile shared ecr-public get-login-password --region us-east-1 | helm registry login --username AWS --password-stdin public.ecr.aws -helm push ${app_name} oci://public.ecr.aws/w8w5v2r8 +helm push ${app_name} oci://${registry_uri} From 6be5c34253b0fba26677a257cf3edb4e01b273d4 Mon Sep 17 00:00:00 2001 From: dor-sendblocks Date: Mon, 8 Apr 2024 11:47:29 +0300 Subject: [PATCH 09/10] added another features to script create_version.sh --- .github/scripts/create_version.sh | 59 +++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/.github/scripts/create_version.sh b/.github/scripts/create_version.sh index 565ed518..b69da091 100755 --- a/.github/scripts/create_version.sh +++ b/.github/scripts/create_version.sh @@ -9,30 +9,52 @@ cd "${SCRIPT_DIR}/../../application" name=$(cat Chart.yaml | yq '.name') version=$(cat Chart.yaml | yq '.version') -# Define the internal variable (set it to true if it's sendblocks changes and not official changes by the author) +# Prompt user to specify if the version is internal +echo "Is the version internal? (yes/no)" +read answer internal=false +if [ "${answer}" == "yes" ]; then + internal=true +fi # Backup the original Chart.yaml cp Chart.yaml Chart.yaml.backup -# Check if internal is true and append "_sb" to the version if it is +# The version in Chart.yaml remains unchanged +new_version=${version} + if $internal; then - new_version="${version}-sb" - yq eval -i ".version = \"$new_version\"" Chart.yaml + # Fetch all versions from ECR starting with the specified version prefix and ending with -sb.x + # Note: Adjust the following command to match your AWS CLI version and query capabilities + versions=$(aws --profile shared ecr-public describe-images --region us-east-1 --repository-name ${name} --query 'sort_by(imageDetails,& imagePushedAt)[*].imageTags' --output text | grep "^${version}-sb" | sort -V) + if [ -z "${versions}" ]; then + # If no versions found, start with -sb.1 + ecr_version="${version}-sb.1" + else + # If versions found, pick the last one and increment + last_version=$(echo "${versions}" | tail -n 1) + num=$(echo "$last_version" | grep -o -E '[0-9]+$') + new_num=$((num + 1)) + ecr_version="${version}-sb.${new_num}" + fi + # For internal use, we will use ecr_version to tag the ECR image + yq eval -i ".version = \"${ecr_version}\"" Chart.yaml else - new_version=$version + # For non-internal use, we keep the ECR tag same as the Chart version + ecr_version=$version fi +# Proceed with packaging using the original version in Chart.yaml output=$(helm package .) -app_name=$(echo "$output" | awk '{print $NF}') +chart_tgz_path=$(echo "$output" | awk '{print $NF}') # Restore the original Chart.yaml from the backup mv Chart.yaml.backup Chart.yaml -# Temporarily disable exit on error +# Temporarily disable exit on error for AWS CLI operations set +e -create_output=$(aws --profile shared ecr-public create-repository --repository-name ${name} --region us-east-1 2>&1) +create_output=$(aws --profile shared ecr-public create-repository --region us-east-1 --repository-name ${name} 2>&1) create_status=$? # Re-enable exit on error @@ -47,21 +69,30 @@ else exit 1 fi -registry_uri=$(aws --profile shared ecr-public describe-registries --region us-east-1 --query "registries[0].registryUri" --output text) - -# Temporarily disable exit on error +# Temporarily disable exit on error for AWS CLI operations set +e -image_exists=$(aws --profile shared ecr-public describe-images --repository-name ${name} --image-ids imageTag=${new_version} --region us-east-1 2>&1) +registry_uri=$(aws --profile shared ecr-public describe-registries --region us-east-1 --query "registries[0].registryUri" --output text) +# Check if the image version (for internal use, the ecr_version) already exists in the repository +image_exists=$(aws --profile shared ecr-public describe-images --region us-east-1 --repository-name ${name} --image-ids imageTag=${ecr_version} 2>&1) image_exists_status=$? # Re-enable exit on error set -e if [[ $image_exists_status -eq 0 ]]; then - echo "Error: The version ${new_version} already exists in the repository." + echo "Error: The version ${ecr_version} already exists in the repository." + rm ${chart_tgz_path} exit 1 fi +# Login to ECR and push the image aws --profile shared ecr-public get-login-password --region us-east-1 | helm registry login --username AWS --password-stdin public.ecr.aws -helm push ${app_name} oci://${registry_uri} +echo "chart tgz path: ${chart_tgz_path}" +echo "registry: oci://${registry_uri}" +echo "version: ${ecr_version}" +helm push ${chart_tgz_path} oci://${registry_uri} + +rm ${chart_tgz_path} + +echo "Completed successfully" \ No newline at end of file From e3749b3e0758f590525246ac7bccf84f39a5de67 Mon Sep 17 00:00:00 2001 From: dor-sendblocks Date: Tue, 20 Aug 2024 13:36:57 +0300 Subject: [PATCH 10/10] add idleReplicaCount for non trigger scaling --- application/templates/scaledobject-sb.yaml | 3 +++ application/values-sb.yaml | 1 + 2 files changed, 4 insertions(+) diff --git a/application/templates/scaledobject-sb.yaml b/application/templates/scaledobject-sb.yaml index 5d6e5f9b..f9afb781 100644 --- a/application/templates/scaledobject-sb.yaml +++ b/application/templates/scaledobject-sb.yaml @@ -13,6 +13,9 @@ spec: cooldownPeriod: {{ required "Undefined cooldownPeriod for ScaledObject" .Values.scaledObject.cooldownPeriod }} minReplicaCount: {{ required "Undefined minReplicaCount for ScaledObject" .Values.scaledObject.minReplicaCount }} maxReplicaCount: {{ required "Undefined maxReplicaCount for ScaledObject" .Values.scaledObject.maxReplicaCount }} + {{- if (not (eq .Values.scaledObject.idleReplicaCount nil)) }} + idleReplicaCount: {{ .Values.scaledObject.idleReplicaCount }} + {{- end }} {{- $minReplicaCount := .Values.scaledObject.minReplicaCount }} {{- with .Values.scaledObject.fallback }} fallback: diff --git a/application/values-sb.yaml b/application/values-sb.yaml index 149ba522..45900f98 100644 --- a/application/values-sb.yaml +++ b/application/values-sb.yaml @@ -9,6 +9,7 @@ scaledObject: cooldownPeriod: 300 minReplicaCount: 1 maxReplicaCount: 5 + idleReplicaCount: 0 fallback: failureThreshold: 3 replicas: 2