|
| 1 | +name: GCP build template |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + gcp_registry: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + description: "GCP registry URL (e.g., gcr.io/sonarsource-public)" |
| 10 | + gcp_product_name: |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + description: "GCP product name" |
| 14 | + build_type: |
| 15 | + required: true |
| 16 | + type: string |
| 17 | + description: "Type of build: 'staging' or 'production'" |
| 18 | + platforms: |
| 19 | + required: false |
| 20 | + type: string |
| 21 | + description: "Platforms to build for" |
| 22 | + default: "linux/amd64,linux/arm64" |
| 23 | + extra_docker_build_args: |
| 24 | + required: false |
| 25 | + type: string |
| 26 | + description: "Extra docker build arguments" |
| 27 | + default: "" |
| 28 | + current_version: |
| 29 | + required: true |
| 30 | + type: string |
| 31 | + description: "Current version to build/promote" |
| 32 | + public_image_name: |
| 33 | + required: false |
| 34 | + type: string |
| 35 | + description: "Public image name for production builds" |
| 36 | + default: "sonarqube" |
| 37 | + component_type: |
| 38 | + required: true |
| 39 | + type: string |
| 40 | + description: "Component type: 'app' or 'search'" |
| 41 | + |
| 42 | +jobs: |
| 43 | + gcp-build: |
| 44 | + name: GCP build ${{ inputs.build_type }} (${{ inputs.component_type }}) |
| 45 | + runs-on: ubuntu-24.04-large |
| 46 | + |
| 47 | + steps: |
| 48 | + - name: Checkout repository |
| 49 | + uses: actions/checkout@v4 |
| 50 | + |
| 51 | + - name: Set up variables |
| 52 | + id: vars |
| 53 | + run: | |
| 54 | + # Construct version path |
| 55 | + VERSION_PATH="commercial-editions/datacenter/${{ inputs.component_type }}" |
| 56 | + |
| 57 | + # Construct image name based on component type |
| 58 | + if [ "${{ inputs.component_type }}" == "search" ]; then |
| 59 | + IMAGE_NAME="${{ inputs.gcp_registry }}/${{ inputs.gcp_product_name }}/sonarqube-dce-search" |
| 60 | + else |
| 61 | + IMAGE_NAME="${{ inputs.gcp_registry }}/${{ inputs.gcp_product_name }}" |
| 62 | + fi |
| 63 | + |
| 64 | + # Calculate minor version |
| 65 | + MINOR_VERSION=$(echo "${{ inputs.current_version }}" | cut -d '.' -f 1,2) |
| 66 | + |
| 67 | + echo "version_path=${VERSION_PATH}" >> $GITHUB_OUTPUT |
| 68 | + echo "image_name=${IMAGE_NAME}" >> $GITHUB_OUTPUT |
| 69 | + echo "minor_version=${MINOR_VERSION}" >> $GITHUB_OUTPUT |
| 70 | +
|
| 71 | + - id: secrets |
| 72 | + name: Retrieve secrets from Vault |
| 73 | + uses: SonarSource/vault-action-wrapper@v3 |
| 74 | + with: |
| 75 | + secrets: | |
| 76 | + development/team/sonarqube/kv/data/gcp-marketplace-registry-staging key | gcp_sa_key; |
| 77 | +
|
| 78 | + - name: Pull public datacenter images (production only) |
| 79 | + if: ${{ inputs.build_type == 'production' }} |
| 80 | + env: |
| 81 | + PUBLIC_IMAGE_NAME: ${{ inputs.public_image_name }} |
| 82 | + CURRENT_VERSION: ${{ inputs.current_version }} |
| 83 | + COMPONENT_TYPE: ${{ inputs.component_type }} |
| 84 | + run: | |
| 85 | + echo "Pull the ${PUBLIC_IMAGE_NAME} datacenter public images" |
| 86 | + docker pull "${PUBLIC_IMAGE_NAME}:${CURRENT_VERSION}-datacenter-${COMPONENT_TYPE}" |
| 87 | +
|
| 88 | + - name: Login to GCP registry |
| 89 | + run: | |
| 90 | + export DOCKER_GCLOUD_PASSWORD=$(echo '${{ fromJSON(steps.secrets.outputs.vault).gcp_sa_key }}' | base64 -d) |
| 91 | + echo "${DOCKER_GCLOUD_PASSWORD}" | docker login -u _json_key --password-stdin https://${{ inputs.gcp_registry }} |
| 92 | +
|
| 93 | + - name: Set up Docker Buildx |
| 94 | + uses: docker/setup-buildx-action@v3 |
| 95 | + with: |
| 96 | + name: multibuilder |
| 97 | + driver: docker-container |
| 98 | + install: true |
| 99 | + |
| 100 | + - name: Set up QEMU for multi-arch builds (staging only) |
| 101 | + if: ${{ inputs.build_type == 'staging' }} |
| 102 | + uses: docker/setup-qemu-action@v3 |
| 103 | + with: |
| 104 | + platforms: all |
| 105 | + |
| 106 | + - name: Build and push to GCP staging |
| 107 | + if: ${{ inputs.build_type == 'staging' }} |
| 108 | + env: |
| 109 | + STAGING_IMAGE_NAME: ${{ steps.vars.outputs.image_name }} |
| 110 | + TAG: ${{ inputs.current_version }} |
| 111 | + MINOR_TAG: ${{ steps.vars.outputs.minor_version }} |
| 112 | + VERSION: ${{ steps.vars.outputs.version_path }} |
| 113 | + EXTRA_DOCKER_BUILD_ARGS: ${{ inputs.extra_docker_build_args }} |
| 114 | + run: | |
| 115 | + echo "Build and promote the ${STAGING_IMAGE_NAME}:${TAG} and ${STAGING_IMAGE_NAME}:${MINOR_TAG} image supporting two architectures, linux/amd64 and linux/arm64" |
| 116 | + .cirrus/multi-arch-build.sh "${STAGING_IMAGE_NAME}" "${TAG}" "${VERSION}" |
| 117 | + .cirrus/multi-arch-build.sh "${STAGING_IMAGE_NAME}" "${MINOR_TAG}" "${VERSION}" |
| 118 | +
|
| 119 | + - name: Promote datacenter image to GCP production |
| 120 | + if: ${{ inputs.build_type == 'production' }} |
| 121 | + env: |
| 122 | + PUBLIC_IMAGE_NAME: ${{ inputs.public_image_name }} |
| 123 | + CURRENT_VERSION: ${{ inputs.current_version }} |
| 124 | + CURRENT_MINOR_VERSION: ${{ steps.vars.outputs.minor_version }} |
| 125 | + GCP_REGISTRY: ${{ inputs.gcp_registry }} |
| 126 | + GCP_PRODUCT_NAME: ${{ inputs.gcp_product_name }} |
| 127 | + COMPONENT_TYPE: ${{ inputs.component_type }} |
| 128 | + TARGET_IMAGE_NAME: ${{ steps.vars.outputs.image_name }} |
| 129 | + run: | |
| 130 | + echo "Promote the ${PUBLIC_IMAGE_NAME}:${CURRENT_VERSION}-datacenter-${COMPONENT_TYPE} images supporting one architecture (linux/amd64) to the GCP registry ${GCP_REGISTRY}" |
| 131 | + echo -e "FROM ${PUBLIC_IMAGE_NAME}:${CURRENT_VERSION}-datacenter-${COMPONENT_TYPE}" | docker buildx build \ |
| 132 | + --platform linux/amd64 \ |
| 133 | + --provenance=false \ |
| 134 | + --annotation "manifest,manifest-descriptor:com.googleapis.cloudmarketplace.product.service.name=services/official-sonarqube-data-center-edition.endpoints.sonarsource-public.cloud.goog" \ |
| 135 | + --tag "${TARGET_IMAGE_NAME}:${CURRENT_VERSION}" \ |
| 136 | + --tag "${TARGET_IMAGE_NAME}:${CURRENT_MINOR_VERSION}" \ |
| 137 | + --push - |
0 commit comments