From 9a45c8d21e4d2c993e6b07bf7e8edc6b017d9d34 Mon Sep 17 00:00:00 2001 From: tuntoja <58987095+tuntoja@users.noreply.github.com> Date: Tue, 6 Dec 2022 11:51:27 +0100 Subject: [PATCH] fix(delivery): add delivery to old yum repo (#456) --- .github/actions/delivery/action.yml | 80 +++++++++++++++++++++++--- .github/workflows/centreon-collect.yml | 8 ++- 2 files changed, 78 insertions(+), 10 deletions(-) diff --git a/.github/actions/delivery/action.yml b/.github/actions/delivery/action.yml index 7b3ded223ee..b58b34f2d89 100644 --- a/.github/actions/delivery/action.yml +++ b/.github/actions/delivery/action.yml @@ -1,6 +1,9 @@ name: "delivery" description: "RPM and DEB packages delivery Centreon" inputs: + module_name: + description: "The name of the module" + required: true distrib: description: "The distribution used for packaging" required: true @@ -16,6 +19,21 @@ inputs: cache_key: description: "The cached package key" required: true + update_repo_path: + description: "The update repo script path" + required: true + cloudfront_id: + description: "The cloudfront ID for repo url" + required: true + yum_repo_address: + description: "The yum legacy repo address" + required: true + yum_repo_key: + description: "The yum repo key" + required: true + yum_repo_url: + description: "The legacy yum repo url" + required: true runs: using: "composite" @@ -41,6 +59,13 @@ runs: key: ${{ inputs.cache_key }}-${{ env.build }}-${{ inputs.distrib }} restore-keys: ${{ inputs.cache_key }}-${{ env.build }}-${{ inputs.distrib }} + - name: Setup awscli + run: | + curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" + sudo unzip -q awscliv2.zip + sudo ./aws/install + shell: bash + - name: Publish packages run: | if [[ -z "$GITHUB_HEAD_REF" ]]; @@ -52,35 +77,72 @@ runs: echo "[DEBUG] - Branch name: $BRANCHNAME" case "$BRANCHNAME" in develop | dev-[2-9][0-9].[0-9][0-9].x) - REPO="unstable" + SUBREPO="unstable" ;; release* | hotfix*) - REPO="testing" + SUBREPO="testing" ;; master | [2-9][0-9].[0-9][0-9].x) - REPO="stable" + SUBREPO="stable" ;; *) echo -n "[INFO] NO DELIVERY FOR THIS BRANCH" exit 0 ;; esac + FILES="*.${{ env.extfile }}"; - DISTRIB="${{ inputs.distrib }}"; - echo "[DEBUG] - Repo: $REPO" - echo "[DEBUG] - FILES: $FILES" - echo "[DEBUG] - DISTRIB: $DISTRIB" + for FILE in $FILES do echo "[DEBUG] - File: $FILE" VERSION=${{ inputs.version }} + MAJOR="$VERSION" + DISTRIB="${{ inputs.distrib }}"; + REPOTYPE="$SUBREPO" + ARCH=$(echo $FILE | grep -oP '(x86_64|noarch)') + PROJECT=${{ inputs.module_name }} + FOLDER=$(basename $FILE .rpm) + PROJECT_PATH="standard" + + echo "[DEBUG] - Arch: $ARCH" + echo "[DEBUG] - Suprepo: $SUBREPO" + echo "[DEBUG] - FILES: $FILES" + echo "[DEBUG] - DISTRIB: $DISTRIB" echo "[DEBUG] - Version: $VERSION" + if [[ "${{ env.extfile }}" == "deb" ]] ; then echo "[DEBUG] - https://artifactory.apps.centreon.com/artifactory/debian-$VERSION-$REPO/pool/$FILE;deb.distribution=bullseye;deb.component=main;deb.architecture=amd64" curl -v -u "${{ inputs.repos_username }}":"${{ inputs.repos_password }}" -X PUT "https://artifactory.apps.centreon.com/artifactory/debian-$VERSION-$REPO/pool/$FILE;deb.distribution=bullseye;deb.component=main;deb.architecture=amd64" -T "./$FILE" else - echo "[DEBUG] - https://artifactory.apps.centreon.com/artifactory/rpm-$VERSION-$REPO/$DISTRIB/$REPO/x86_64/centreon-collect" - curl -v -u "${{ inputs.repos_username }}":"${{ inputs.repos_password }}" -X PUT "https://artifactory.apps.centreon.com/artifactory/rpm-$VERSION-$REPO/$DISTRIB/$REPO/x86_64/centreon-collect/$FILE" -T "./$FILE" + #echo "[DEBUG] - https://artifactory.apps.centreon.com/artifactory/rpm-$VERSION-$REPO/$DISTRIB/$REPO/x86_64/centreon-collect" + #curl -v -u "${{ inputs.repos_username }}":"${{ inputs.repos_password }}" -X PUT "https://artifactory.apps.centreon.com/artifactory/rpm-$VERSION-$REPO/$DISTRIB/$REPO/x86_64/centreon-collect/$FILE" -T "./$FILE" + + eval `ssh-agent` + ssh-add - <<< "${{ inputs.yum_repo_key }}" + TARGET="/srv/centreon-yum/yum.centreon.com/$PROJECT_PATH/$MAJOR/$DISTRIB/$REPOTYPE/$ARCH/$PROJECT/$FOLDER" + PROJECT_LOCATION="/srv/centreon-yum/yum.centreon.com/$PROJECT_PATH/$MAJOR/$DISTRIB/$REPOTYPE/$ARCH/$PROJECT" + METADATAS="/srv/centreon-yum/yum.centreon.com/$PROJECT_PATH/$MAJOR/$DISTRIB/$REPOTYPE/$ARCH" + echo "[DEBUG] - Folder: $FOLDER" + echo "[DEBUG] - Project : $PROJECT" + echo "[DEBUG] - Target : $TARGET" + echo "[DEBUG] - PROJECT_LOCATION : $PROJECT_LOCATION" + ssh -o StrictHostKeyChecking=no "${{ inputs.yum_repo_address }}" mkdir -p "$TARGET" 2>&- + scp -o StrictHostKeyChecking=no "$FILE" "${{ inputs.yum_repo_address }}:$TARGET" 2>&- + #ssh -o StrictHostKeyChecking=no "${{ inputs.yum_repo_address }}" "ls -drc $PROJECT_LOCATION/* 2>&- | head -n -6 | xargs rm -rf" + ssh -o StrictHostKeyChecking=no "${{ inputs.yum_repo_address }}" "sh "${{ inputs.update_repo_path }}" $METADATAS" 2>&- + fi + done + + ID="${{ inputs.cloudfront_id }}" + PATHS="/$PROJECT_PATH/$MAJOR/$DISTRIB/$REPOTYPE/$ARCH/*" + ITERATIONS=1 + until aws cloudfront create-invalidation --distribution-id "$ID" --paths "$PATHS"; do + if [ ${ITERATIONS} -eq 10 ]; then + return 0 fi + echo "couldn't invalidate cache, AWS quota might have been reached, retrying in 30 seconds..." + sleep 30s + ITERATIONS=$((ITERATIONS+1)) done shell: bash diff --git a/.github/workflows/centreon-collect.yml b/.github/workflows/centreon-collect.yml index a3c1705441f..e3adc0f9015 100644 --- a/.github/workflows/centreon-collect.yml +++ b/.github/workflows/centreon-collect.yml @@ -42,7 +42,7 @@ jobs: echo "release=$GITHUB_RUN_ATTEMPT" >> $GITHUB_OUTPUT ;; *) - echo "release=${{ github.sha }}" >> $GITHUB_OUTPUT + echo "release=`date +%s`.`echo ${{ github.sha }} | cut -c -7`" >> $GITHUB_OUTPUT ;; esac shell: bash @@ -211,6 +211,12 @@ jobs: with: distrib: ${{ matrix.distrib }} version: ${{ env.version }} + module_name: centreon-collect repos_username: ${{ secrets.REPOS_USERNAME }} repos_password: ${{ secrets.REPOS_PASSWORD }} cache_key: cache-${{ github.sha }}-${{ github.run_id }} + update_repo_path: ${{ secrets.UPDATE_REPO_PATH }} + cloudfront_id: ${{ secrets.CLOUDFRONT_ID }} + yum_repo_address: ${{ secrets.YUM_REPO_ADDRESS }} + yum_repo_key: ${{ secrets.YUM_REPO_KEY }} + yum_repo_url: ${{ secrets.YUM_REPO_URL }} \ No newline at end of file