diff --git a/.github/workflows/common.yml b/.github/workflows/common.yml index e73de21d..25f5d004 100644 --- a/.github/workflows/common.yml +++ b/.github/workflows/common.yml @@ -95,70 +95,70 @@ jobs: matrix: ${{ env.matrix }} jdk_build: ${{ env.JDK_BUILD }} jre_version: ${{ env.JRE_DEFAULT }} -# scale-runners-up: -# runs-on: ubuntu-latest -# needs: -# - parameters -# concurrency: -# group: stream-apps-gh-runners -# cancel-in-progress: false -# steps: -# - name: 'Configure: checkout stream-applications' -# uses: actions/checkout@v3 -# with: -# ref: 'main' -# - name: 'Configure: checkout stream-applications' -# uses: actions/checkout@v3 -# with: -# ref: 'main' -# - name: Ensure scripts are executable -# shell: bash -# run: find . -type f -name "*.sh" -exec chmod a+x '{}' \; -# - name: 'Configure: Configure provider for stream-apps-gh-runners' -# id: 'configure-runner-type' -# shell: bash -# run: | -# RUNNER_TYPE=$(./scripts/determine-provider.sh stream-apps-gh-runners) -# echo "RUNNER_TYPE=$RUNNER_TYPE" -# echo "RUNNER_TYPE=$RUNNER_TYPE" >> $GITHUB_ENV -# outputs: -# runner-type: '${{ env.RUNNER_TYPE }}' -# - name: 'Install: gcloud cli' -# if: ${{ env.RUNNER_TYPE == 'gke' }} -# uses: ./.github/actions/install-gcloud -# - name: 'Action: gcloud auth' -# if: ${{ env.RUNNER_TYPE == 'gke' }} -# id: auth_gcloud -# uses: 'google-github-actions/auth@v0' -# with: -# create_credentials_file: true -# credentials_json: ${{ secrets.GCP_CRED_JSON }} -# - name: 'Configure: Install TMC' -# if: ${{ env.RUNNER_TYPE == 'tmc' }} -# uses: ./.github/actions/install-tmc -# - name: 'Action: Login to TMC' -# if: ${{ env.RUNNER_TYPE == 'tmc' }} -# uses: ./.github/actions/auth-tmc -# with: -# tmc_api_token: ${{ secrets.TMC_API_TOKEN }} -# fail_on_error: false -# - name: 'Install: Groovy' -# uses: ./.github/actions/install-groovy -# with: -# version: 4.0.4 -# - name: 'Action: Scale Runners Up by ${{ needs.parameters.outputs.max_parallel }}' -# uses: ./.github/actions/scale-runners-up -# timeout-minutes: 45 -# with: -# verbose: ${{ inputs.verbose }} -# max_parallel: ${{ toJson(needs.parameters.outputs.max_parallel) }} -# GH_ARC_APP_ID: ${{ secrets.GH_ARC_APP_ID }} -# GH_ARC_INSTALLATION_ID: ${{ secrets.GH_ARC_INSTALLATION_ID }} -# GH_ARC_PRIVATE_KEY: ${{ secrets.GH_ARC_PRIVATE_KEY }} -# GH_ARC_PAT: ${{ secrets.GH_ARC_PAT }} - core: + scale-runners-up: runs-on: ubuntu-latest -# runs-on: 'stream-ci-large' + needs: + - parameters + concurrency: + group: stream-apps-gh-runners + cancel-in-progress: false + steps: + - name: 'Configure: checkout stream-applications' + uses: actions/checkout@v3 + with: + ref: 'main' + - name: 'Configure: checkout stream-applications' + uses: actions/checkout@v3 + with: + ref: 'main' + - name: Ensure scripts are executable + shell: bash + run: find . -type f -name "*.sh" -exec chmod a+x '{}' \; + - name: 'Configure: Configure provider for stream-apps-gh-runners' + id: 'configure-runner-type' + shell: bash + run: | + RUNNER_TYPE=$(./scripts/determine-provider.sh stream-apps-gh-runners) + echo "RUNNER_TYPE=$RUNNER_TYPE" + echo "RUNNER_TYPE=$RUNNER_TYPE" >> $GITHUB_ENV + outputs: + runner-type: '${{ env.RUNNER_TYPE }}' + - name: 'Install: gcloud cli' + if: ${{ env.RUNNER_TYPE == 'gke' }} + uses: ./.github/actions/install-gcloud + - name: 'Action: gcloud auth' + if: ${{ env.RUNNER_TYPE == 'gke' }} + id: auth_gcloud + uses: 'google-github-actions/auth@v0' + with: + create_credentials_file: true + credentials_json: ${{ secrets.GCP_CRED_JSON }} + - name: 'Configure: Install TMC' + if: ${{ env.RUNNER_TYPE == 'tmc' }} + uses: ./.github/actions/install-tmc + - name: 'Action: Login to TMC' + if: ${{ env.RUNNER_TYPE == 'tmc' }} + uses: ./.github/actions/auth-tmc + with: + tmc_api_token: ${{ secrets.TMC_API_TOKEN }} + fail_on_error: false + - name: 'Install: Groovy' + uses: ./.github/actions/install-groovy + with: + version: 4.0.4 + - name: 'Action: Scale Runners Up by ${{ needs.parameters.outputs.max_parallel }}' + uses: ./.github/actions/scale-runners-up + timeout-minutes: 45 + with: + verbose: ${{ inputs.verbose }} + max_parallel: ${{ toJson(needs.parameters.outputs.max_parallel) }} + GH_ARC_APP_ID: ${{ secrets.GH_ARC_APP_ID }} + GH_ARC_INSTALLATION_ID: ${{ secrets.GH_ARC_INSTALLATION_ID }} + GH_ARC_PRIVATE_KEY: ${{ secrets.GH_ARC_PRIVATE_KEY }} + GH_ARC_PAT: ${{ secrets.GH_ARC_PAT }} + core: +# runs-on: ubuntu-latest + runs-on: 'stream-ci-large' needs: - parameters steps: @@ -218,14 +218,14 @@ jobs: needs: - core - parameters -# - scale-runners-up + - scale-runners-up strategy: fail-fast: false max-parallel: 4 matrix: app: ${{ fromJson(needs.parameters.outputs.processors) }} - runs-on: 'ubuntu-latest' -# runs-on: 'stream-ci' +# runs-on: 'ubuntu-latest' + runs-on: 'stream-ci' steps: - name: 'Configure: checkout stream-applications' uses: actions/checkout@v3 @@ -280,14 +280,14 @@ jobs: needs: - core - parameters -# - scale-runners-up + - scale-runners-up strategy: max-parallel: 4 fail-fast: false matrix: app: ${{ fromJson(needs.parameters.outputs.sinks) }} - runs-on: 'ubuntu-latest' -# runs-on: 'stream-ci' +# runs-on: 'ubuntu-latest' + runs-on: 'stream-ci' steps: - name: 'Configure: checkout stream-applications' uses: actions/checkout@v3 @@ -342,15 +342,15 @@ jobs: needs: - core - parameters -# - scale-runners-up + - scale-runners-up strategy: max-parallel: 4 fail-fast: false # will be removed when private runners are used. matrix: app: ${{ fromJson(needs.parameters.outputs.sources) }} - runs-on: 'ubuntu-latest' -# runs-on: 'stream-ci' +# runs-on: 'ubuntu-latest' + runs-on: 'stream-ci' steps: - name: 'Configure: checkout stream-applications' uses: actions/checkout@v3 @@ -400,52 +400,52 @@ jobs: DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} DEFAULT_JDK: ${{ needs.parameters.outputs.jre_version }} run: ./publish-app.sh "stream-applications" "applications/source/${{ matrix.app }}" -# scale-runners-down: -# if: ${{ success() }} -# runs-on: ubuntu-latest -# needs: -# - parameters -# - processors -# - sinks -# - sources -# concurrency: -# group: stream-apps-gh-runners -# cancel-in-progress: false -# steps: -# - name: 'Configure: checkout stream-applications' -# uses: actions/checkout@v3 -# with: -# ref: 'main' -# - name: 'Action: Ensure scripts are executable' -# shell: bash -# run: find . -type f -name "*.sh" -exec chmod a+x '{}' \; -# - name: 'Configure: Runners Cluster provider' -# shell: bash -# run: | -# RUNNER_TYPE=$(./scripts/determine-provider.sh stream-apps-gh-runners) -# if [ "$RUNNER_TYPE" != "gke" ]; then -# RUNNER_TYPE=tmc -# fi -# echo "RUNNER_TYPE=$RUNNER_TYPE" >> $GITHUB_ENV -# - name: 'Install: gcloud cli' -# if: ${{ env.RUNNER_TYPE == 'gke' }} -# uses: ./.github/actions/install-gcloud -# - name: 'Action: gcloud auth' -# if: ${{ env.RUNNER_TYPE == 'gke' }} -# id: auth_gcloud -# uses: 'google-github-actions/auth@v0' -# with: -# create_credentials_file: true -# credentials_json: ${{ secrets.GCP_CRED_JSON }} -# - name: 'Configure: Install TMC' -# if: ${{ env.RUNNER_TYPE == 'tmc' }} -# uses: ./.github/actions/install-tmc -# - name: 'Action: Login to TMC' -# if: ${{ env.RUNNER_TYPE == 'tmc' }} -# uses: ./.github/actions/auth-tmc -# with: -# tmc_api_token: ${{ secrets.TMC_API_TOKEN }} -# - name: 'Action: Decrease runners with ${{ needs.parameters.outputs.max_parallel }}' -# uses: ./.github/actions/decrease-runners -# with: -# dec: ${{ needs.parameters.outputs.max_parallel }} + scale-runners-down: + if: ${{ success() }} + runs-on: ubuntu-latest + needs: + - parameters + - processors + - sinks + - sources + concurrency: + group: stream-apps-gh-runners + cancel-in-progress: false + steps: + - name: 'Configure: checkout stream-applications' + uses: actions/checkout@v3 + with: + ref: 'main' + - name: 'Action: Ensure scripts are executable' + shell: bash + run: find . -type f -name "*.sh" -exec chmod a+x '{}' \; + - name: 'Configure: Runners Cluster provider' + shell: bash + run: | + RUNNER_TYPE=$(./scripts/determine-provider.sh stream-apps-gh-runners) + if [ "$RUNNER_TYPE" != "gke" ]; then + RUNNER_TYPE=tmc + fi + echo "RUNNER_TYPE=$RUNNER_TYPE" >> $GITHUB_ENV + - name: 'Install: gcloud cli' + if: ${{ env.RUNNER_TYPE == 'gke' }} + uses: ./.github/actions/install-gcloud + - name: 'Action: gcloud auth' + if: ${{ env.RUNNER_TYPE == 'gke' }} + id: auth_gcloud + uses: 'google-github-actions/auth@v0' + with: + create_credentials_file: true + credentials_json: ${{ secrets.GCP_CRED_JSON }} + - name: 'Configure: Install TMC' + if: ${{ env.RUNNER_TYPE == 'tmc' }} + uses: ./.github/actions/install-tmc + - name: 'Action: Login to TMC' + if: ${{ env.RUNNER_TYPE == 'tmc' }} + uses: ./.github/actions/auth-tmc + with: + tmc_api_token: ${{ secrets.TMC_API_TOKEN }} + - name: 'Action: Decrease runners with ${{ needs.parameters.outputs.max_parallel }}' + uses: ./.github/actions/decrease-runners + with: + dec: ${{ needs.parameters.outputs.max_parallel }} diff --git a/scripts/decrease-runners.sh b/scripts/decrease-runners.sh index 21f0f504..f58c9b03 100755 --- a/scripts/decrease-runners.sh +++ b/scripts/decrease-runners.sh @@ -20,12 +20,15 @@ if [ "$1" = "" ]; then echo "Expected number to decrease" exit 1 fi +CLUSTER_NAME=stream-apps-gh-runners echo "Checking stream-apps-gh-runners" DEC=$1 MIN_RUNNERS=$2 -SCALING=$(jq '.stream-apps-gh-runners.runner_scaling' $PARENT/config/defaults.json | sed 's/\"//g') -cp $SCDIR/k8s/runners-stream-ci-${SCALING}-template.yaml runners-stream-ci-change.yaml + +SCALE_MIN=$($SCDIR/determine-default.sh $CLUSTER_NAME "scale_down") +SCALING=$($SCDIR/determine-default.sh $CLUSTER_NAME "runner_scaling") + if [ "$SCALING" == "auto" ]; then MAX_RUNNERS=$(max_replicas) MAX_RUNNERS=$((MAX_RUNNERS - DEC)) @@ -33,11 +36,11 @@ if [ "$SCALING" == "auto" ]; then if [ "$MIN_RUNNERS" == "" ]; then MIN_RUNNERS=$((CURRENT - DEC)) fi - if ((MAX_RUNNERS < 1)); then - MAX_RUNNERS=1 + if ((MAX_RUNNERS < SCALE_MIN)); then + MAX_RUNNERS=SCALE_MIN fi - if ((MIN_RUNNERS < 1)); then - MIN_RUNNERS=1 + if ((MIN_RUNNERS < SCALE_MIN)); then + MIN_RUNNERS=SCALE_MIN fi else CURRENT=$(count_runners) @@ -50,20 +53,31 @@ if [ "$MIN_RUNNERS" != "" ]; then TARGET=$MIN_RUNNERS fi fi -if ((TARGET < 1)); then - TARGET=1 +if ((TARGET < SCALE_MIN)); then + TARGET=SCALE_MIN fi -OS=$(uname) -OS="${OS//./L&}" -ARCH=$(uname -i) +if [ "$OS" = "" ]; then + OS=$(uname) +fi +OS="${OS//./L&}" #lowercase +if [ "$ARCH" = "" ]; then + ARCH=$(uname -i) +fi +ARCH="${ARCH//./L&}" #lowercase case $ARCH in "x86_64") ARCH=amd64 ;; +"arm" | "arm64" | "armv8" | "aarch64") + ARCH=arm64 + ;; *) echo "Architecture:$ARCH may not be supported by summerwind/actions-runner" ;; esac +# the specific template +cp $SCDIR/k8s/runners-stream-ci-${SCALING}-template.yaml runners-stream-ci-change.yaml + IMAGE_SHA=$(wget -q -O- https://hub.docker.com/v2/repositories/summerwind/actions-runner/tags | jq --arg os $OS --arg arch $ARCH '.results | map(select(.name="latest")) | .[0].images | map(select(.os==$os and .architecture==$arch)) | .[0].digest' | sed 's/\"//g') if [ "$IMAGE_SHA" == "" ]; then IMAGE_SHA="latest"