From 1880043a8003278b3f5c85aa26657d8947cc3cb0 Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Fri, 14 Mar 2025 02:03:00 -0500 Subject: [PATCH] chore: add building catalog GA (#181) * chore: add building catalog GA Signed-off-by: Jack Yu * feat: should include prerelease Signed-off-by: Jack Yu --------- Signed-off-by: Jack Yu --- .../build-and-publish-catalog-on-release.yaml | 36 +++++++++ .github/workflows/build-extension-catalog.yml | 81 +++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 .github/workflows/build-and-publish-catalog-on-release.yaml create mode 100644 .github/workflows/build-extension-catalog.yml diff --git a/.github/workflows/build-and-publish-catalog-on-release.yaml b/.github/workflows/build-and-publish-catalog-on-release.yaml new file mode 100644 index 00000000..3e41a295 --- /dev/null +++ b/.github/workflows/build-and-publish-catalog-on-release.yaml @@ -0,0 +1,36 @@ +name: Build Harvester Catalog Image and Publish on Release + +on: + workflow_dispatch: + release: + types: [published] + +defaults: + run: + shell: bash + working-directory: ./ + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 1 + + - name: Run tests + uses: ./.github/actions/lint + + build-and-push-extension-catalog: + needs: lint + uses: ./.github/workflows/build-extension-catalog.yml + permissions: + actions: write + contents: read + packages: write + id-token: write + with: + registry_target: docker.io + registry_user: rancher + repository_name: harvester-ui-catalog + secrets: inherit diff --git a/.github/workflows/build-extension-catalog.yml b/.github/workflows/build-extension-catalog.yml new file mode 100644 index 00000000..c81f8a27 --- /dev/null +++ b/.github/workflows/build-extension-catalog.yml @@ -0,0 +1,81 @@ +name: Build and release Extension Catalog Image to registry + +on: + workflow_call: + inputs: + registry_target: + required: true + type: string + repository_name: + required: true + type: string + registry_user: + required: true + type: string + outputs: + build-extension-catalog-job-status: + value: ${{ jobs.build-extension-catalog.outputs.build-status }} + +jobs: + build-and-push-extension-catalog: + name: Build container image + if: github.ref_type == 'tag' || (github.ref == 'refs/heads/main' && github.event_name != 'pull_request') + runs-on: ubuntu-latest + permissions: + actions: write + contents: read + packages: write + id-token: write + outputs: + build-status: ${{ job.status }} + steps: + - name: Read Secrets + uses: rancher-eio/read-vault-secrets@main + with: + secrets: | + secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials username | DOCKER_USERNAME ; + secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials password | DOCKER_PASSWORD ; + + - name: Checkout repository (normal flow) + uses: actions/checkout@v4 + + - name: Enable Corepack + run: corepack enable + + - name: Configure Git + run: | + git config user.name 'github-actions[bot]' + git config user.email 'github-actions[bot]@users.noreply.github.com' + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ env.DOCKER_USERNAME }} + password: ${{ env.DOCKER_PASSWORD }} + + - name: Setup Helm + uses: azure/setup-helm@v3 + with: + version: v3.8.0 + + - name: Setup Nodejs with yarn caching + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: yarn + + - name: Install dependencies + run: yarn + + - name: Build and push UI image + run: | + publish="yarn publish-pkgs -c -r ${{ inputs.registry_target }} -o ${{ inputs.registry_user }}" + $publish + + REPO_NAME=$(echo "${{ github.repository }}" | cut -d'/' -f2) + IMAGE_VERSION=$(cat package.json | jq .version | sed 's/"//g') + FULL_IMAGE_NAME=$(echo ${{ inputs.registry_target }}/${{ inputs.registry_user }}/ui-extension-$REPO_NAME:$IMAGE_VERSION) + IMAGE_ID=$(docker inspect --format='{{.Id}}' $FULL_IMAGE_NAME) + + docker tag $IMAGE_ID ${{ inputs.registry_target }}/${{ inputs.registry_user }}/${{ inputs.repository_name }}:$IMAGE_VERSION + docker push ${{ inputs.registry_target }}/${{ inputs.registry_user }}/${{ inputs.repository_name }}:$IMAGE_VERSION \ No newline at end of file