Skip to content

Build and Push Container #45

Build and Push Container

Build and Push Container #45

Workflow file for this run

name: Build and Push Container
on:
workflow_dispatch:
inputs:
postgres-major-version:
description: "Postgres major version to release."
type: string
required: true
charts:
description: "Json list with helm charts to upgrade."
type: string
required: true
workflow_call:
inputs:
postgres-major-version:
description: "Postgres major version to release."
type: string
required: true
charts:
description: "Json list with helm charts to upgrade."
type: string
required: true
secrets:
COSIGN_KEY_OPENSIGHT:
required: true
COSIGN_KEY_PASSWORD_OPENSIGHT:
required: true
GREENBONE_BOT_TOKEN:
required: true
permissions:
contents: read
packages: write
id-token: write
pull-requests: write
jobs:
push-postgres:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Push
id: build
uses: greenbone/actions/container-build-push-generic@v3
with:
build-args: "POSTGRES_VERSION=${{ inputs.postgres-major-version }}"
cosign-key: ${{ secrets.COSIGN_KEY_OPENSIGHT }}
cosign-key-password: ${{ secrets.COSIGN_KEY_PASSWORD_OPENSIGHT }}
cosign-tlog-upload: "false"
image-url: ${{ github.repository }}
image-labels: |
org.opencontainers.image.vendor=Greenbone
org.opencontainers.image.base.name=postgres:${{ inputs.postgres-major-version }}
image-tags: |
type=raw,value=${{ inputs.postgres-major-version }}
registry: ${{ vars.IMAGE_REGISTRY }}
registry-username: ${{ github.actor }}
registry-password: ${{ secrets.GITHUB_TOKEN }}
- name: Helm upgrade matrix
id: upgrade
run: |
echo "matrix=$(echo '${{ inputs.charts }}' | jq -r '{include:[.[] | {chart: ., digest: "${{ steps.build.outputs.digest }}" }]} | @json')" >> $GITHUB_OUTPUT
outputs:
matrix: ${{ steps.upgrade.outputs.matrix }}
push-helm:
needs: push-postgres
if: ${{ needs.push-postgres.outputs.matrix }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
# We have to run one workflow after the other here
# because our product Helm Chart Construction Process cannot handle multiple processes.
max-parallel: 1
matrix: ${{ fromJSON(needs.push-postgres.outputs.matrix) }}
steps:
- name: Get helm chart tags
id: tags
uses: greenbone/actions/oci-info@v3
with:
repository: "helm-charts/${{ matrix.chart }}"
namespace: greenbone
user: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Increment helm version
id: version
shell: bash
run: |
# Get the latest tag filtered by postgres major version.
t="$(echo -e '${{ steps.tags.outputs.output }}' | grep -E '${{ inputs.postgres-major-version }}.[0-9]+.[0-9]+' | sort -nr | sed q)"
IFS='.' read -r -a v <<< "$t"
# Increment patch level
v[2]=$((v[2] + 1))
echo "output=v$(IFS="."; echo "${v[*]// /}")" >> $GITHUB_OUTPUT
- name: Trigger service helm chart upgrade
if: ${{ steps.version.outputs.output }}
uses: greenbone/actions/trigger-workflow@v3
with:
token: ${{ secrets.GREENBONE_BOT_TOKEN }}
repository: "greenbone/product-helm-chart"
workflow: "service-chart-upgrade.yml"
inputs: '{"chart": "${{ matrix.chart }}", "chart-version": "${{ steps.version.outputs.output }}", "container-digest": "${{ matrix.digest }}"}'
- name: Trigger product helm chart upgrade
if: ${{ steps.version.outputs.output }}
uses: greenbone/actions/trigger-workflow@v3
with:
token: ${{ secrets.GREENBONE_BOT_TOKEN }}
repository: "greenbone/product-helm-chart"
workflow: "product-chart-upgrade.yml"
inputs: '{"chart": "${{ matrix.chart }}", "tag": "${{ steps.version.outputs.output }}"}'
notify:
needs:
- push-postgres
- push-helm
if: ${{ !cancelled() }}
uses: greenbone/workflows/.github/workflows/notify-mattermost-3rd-gen.yml@main
with:
status: ${{ contains(needs.*.result, 'failure') && 'failure' || 'success' }}
secrets: inherit