diff --git a/.github/charts-values-update-config.yaml b/.github/charts-values-update-config.yaml new file mode 100644 index 00000000..acc974cc --- /dev/null +++ b/.github/charts-values-update-config.yaml @@ -0,0 +1,29 @@ +--- + +# Charts release configuration file example +# This file is used to update the version of the helm charts and images in the values.yaml file +# It is used in the helm-charts-release action +# ${release} is replaced with the release version provided in the workflow + +charts: + - name: patroni-core + chart_file: charts/patroni-core/Chart.yaml + values_file: charts/patroni-core/values.yaml + image: + - ghcr.io/netcracker/qubership-credential-manager:#latest + - ghcr.io/netcracker/pgskipper-operator:${release} + - ghcr.io/netcracker/pgskipper-patroni-16:#latest + - ghcr.io/netcracker/pgskipper-upgrade:#^release-.+ + - ghcr.io/netcracker/pgskipper-operator-tests:${release} + - name: patroni-services + chart_file: charts/patroni-services/Chart.yaml + values_file: charts/patroni-services/values.yaml + image: + - ghcr.io/netcracker/qubership-credential-manager:#latest + - ghcr.io/netcracker/pgskipper-operator:${release} + - ghcr.io/netcracker/pgskipper-monitoring-agent:#^release-.+ + - ghcr.io/netcracker/pgskipper-backup-daemon:#^release-.+ + - ghcr.io/netcracker/pgskipper-dbaas-adapter:#^release-.+ + - ghcr.io/netcracker/qubership-query-exporter:#^release-.+ + - ghcr.io/netcracker/pgskipper-replication-controller:#^release-.+ + - ghcr.io/netcracker/pgskipper-operator-tests:${release} diff --git a/.github/docker-build-config.json b/.github/docker-build-config.json new file mode 100644 index 00000000..b2dccf18 --- /dev/null +++ b/.github/docker-build-config.json @@ -0,0 +1,20 @@ +{ + "components": [ + { + "name": "pgskipper-operator", + "file": "build/Dockerfile", + "context": "." + }, + { + "name": "pgskipper-operator-tests", + "file": "tests/Dockerfile", + "context": "tests" + }, + { + "name": "pgskipper-operator-transfer", + "file": "./docker-transfer/Dockerfile", + "context": "." + } + ], + "platforms": "linux/amd64,linux/arm64" +} \ No newline at end of file diff --git a/.github/workflows/helm-charts-release.yaml b/.github/workflows/helm-charts-release.yaml new file mode 100644 index 00000000..f2bfa6f1 --- /dev/null +++ b/.github/workflows/helm-charts-release.yaml @@ -0,0 +1,183 @@ +--- + +name: Helm Charts Release +on: + workflow_dispatch: + inputs: + release: + description: 'Release version' + required: true + type: string +permissions: + contents: write + packages: write +run-name: ${{ github.repository }} Release ${{ github.event.inputs.release }} +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true +jobs: + check-tag: + runs-on: ubuntu-latest + steps: + - name: Check if tag exists + id: check_tag + uses: netcracker/qubership-workflow-hub/actions/tag-action@v1.0.4 + with: + tag-name: '${{ inputs.release }}' + ref: ${{ github.ref }} + create-tag: false + check-tag: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + load-docker-build-components: + runs-on: ubuntu-latest + outputs: + component: ${{ steps.load_component.outputs.components }} + platforms: ${{ steps.load_component.outputs.platforms }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Load Docker Configuration + id: load_component + run: | + verify=$(cat "$GITHUB_WORKSPACE/.github/docker-build-config.json" | jq ' + def verify_structure: + .components as $components + | .platforms as $platforms + | ($components | type == "array") + and (all($components[]; has("name") and has("file") and has("context"))) + and ($platforms | type == "string"); + verify_structure + | if . then true else false end + ') + if [ ${verify} == 'true' ]; then + echo "✅ $GITHUB_WORKSPACE/.github/docker-build-config.json file is valid" + components=$(jq -c ".components" "$GITHUB_WORKSPACE/.github/docker-build-config.json") + platforms=$(jq -c ".platforms" "$GITHUB_WORKSPACE/.github/docker-build-config.json") + else + echo "❗ $GITHUB_WORKSPACE/.github/docker-build-config.json file is invalid" + echo "❗ $GITHUB_WORKSPACE/.github/docker-build-config.json file is invalid" >> $GITHUB_STEP_SUMMARY + exit 1 + fi + echo "components=${components}" >> $GITHUB_OUTPUT + echo "platforms=${platforms}" >> $GITHUB_OUTPUT + + docker-check-build: + needs: [load-docker-build-components, check-tag] + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + component: ${{ fromJson(needs.load-docker-build-components.outputs.component) }} + steps: + - name: Get version for current component + id: get-version + run: | + echo "IMAGE=${{ matrix.component.name }}" >> $GITHUB_ENV + - name: Docker build + uses: netcracker/qubership-workflow-hub/actions/docker-action@v1.0.4 + with: + ref: ${{ github.ref }} + download-artifact: false + dry-run: true + component: ${{ toJson(matrix.component) }} + platforms: ${{ needs.load-docker-build-components.outputs.platforms }} + tags: "${{ env.IMAGE_VERSION }}" + env: + GITHUB_TOKEN: ${{ github.token }} + chart-release-prepare: + needs: [check-tag, load-docker-build-components, docker-check-build] + runs-on: ubuntu-latest + outputs: + images-versions: ${{ steps.update-versions.outputs.images-versions }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: "Update versions in values" + id: update-versions + uses: netcracker/qubership-workflow-hub/actions/charts-values-update-action@main + with: + release-version: ${{ inputs.release }} + config-file: .github/charts-values-update-config.yaml + env: + ${{ insert }}: ${{ vars }} + - name: "Debug" + run: | + echo "Images versions: ${{ steps.update-versions.outputs.images-versions }}" + + docker-build: + needs: [chart-release-prepare, load-docker-build-components] + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + component: ${{ fromJson(needs.load-docker-build-components.outputs.component) }} + steps: + - name: Get version for current component + id: get-version + run: | + echo "IMAGE_VERSION=${{ fromJson(needs.chart-release-prepare.outputs.images-versions)[matrix.component.name] || inputs.release }}" >> $GITHUB_ENV + + - name: Docker build + uses: netcracker/qubership-workflow-hub/actions/docker-action@v1.0.4 + with: + ref: release-${{ inputs.release }} + download-artifact: false + dry-run: false + component: ${{ toJson(matrix.component) }} + platforms: ${{ needs.load-docker-build-components.outputs.platforms }} + tags: "${{ env.IMAGE_VERSION }},latest" + env: + GITHUB_TOKEN: ${{ github.token }} + charts-release: + needs: [docker-build] + continue-on-error: false + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: release-${{ inputs.release }} + + - name: Configure Git + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + + - name: Run chart-releaser + id: chart-releaser + uses: netcracker/chart-releaser-action@main + with: + charts_dir: charts + release_name_template: "{{ .Version }}" + skip_existing: true + skip_upload: true + env: + CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + + - name: Show chart-releaser output + run: | + echo "::debug::Changed Charts: ${{ steps.chart-releaser.outputs.changed_charts}}" + echo "::debug::Charts versions: ${{ steps.chart-releaser.outputs.chart_version}}" + + - name: "Release-drafter" + uses: netcracker/release-drafter@master + with: + config-name: release-drafter-config.yml + publish: true + name: ${{ inputs.release }} + tag: ${{ inputs.release }} + version: ${{ inputs.release }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Upload Assets + uses: netcracker/qubership-workflow-hub/actions/assets-action@v1.0.4 + with: + tag: ${{ inputs.release }} + item-path: .cr-release-packages/*.tgz + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}