Skip to content

Commit 7a1e8ef

Browse files
SONAR-25177 Define a wrapper Azure chart
1 parent c5a890a commit 7a1e8ef

File tree

11 files changed

+848
-79
lines changed

11 files changed

+848
-79
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/bash
2+
set -e # Exit immediately if a command exits with a non-zero status.
3+
4+
# --- Configuration Variables ---
5+
# IMPORTANT: Replace these placeholder values with your actual details.
6+
# You might want to set these as environment variables or use a secure method
7+
# for production environments.
8+
9+
# Version of the original SonarQube chart (e.g., 2025.3.0)
10+
# This should match the version in charts/sonarqube/Chart.yaml
11+
SONARQUBE_CHART_VERSION="2025.3.0"
12+
13+
# Azure Container Registry (ACR) details
14+
# This should match the 'registryServer' in your manifest.yaml
15+
ACR_REGISTRY="testdavi.azurecr.io"
16+
ACR_USERNAME="${AZURE_ACR_USERNAME:-}" # Use environment variable or provide directly
17+
ACR_PASSWORD="${AZURE_ACR_PASSWORD:-}" # Use environment variable or provide directly
18+
19+
# Application name from manifest.yaml (used for the CNAB bundle name)
20+
APPLICATION_NAME="sonarqube"
21+
22+
# --- Script Start ---
23+
24+
echo "--- Starting Azure Marketplace K8s App Packaging Process ---"
25+
26+
cd ..
27+
cd azure-marketplace-k8s-app
28+
29+
# 1. Clean up previous build artifacts
30+
echo "1. Cleaning up old build artifacts..."
31+
# Removes:
32+
# - .cnab/ directory (where the bundle is built)
33+
# - The packaged wrapper chart (if it was created previously)
34+
# - The charts/ directory within the wrapper chart (containing the .tgz)
35+
# - The Chart.lock file within the wrapper chart
36+
rm -rf .cnab/ "${APPLICATION_NAME}-azure-${SONARQUBE_CHART_VERSION}" sonarqube-azure/charts/ sonarqube-azure/Chart.lock
37+
38+
# Ensure the wrapper chart's charts/ directory exists for unpacking
39+
# mkdir -p sonarqube-azure/charts/
40+
41+
# 2. Navigate into the wrapper chart directory and update Helm dependencies
42+
echo "2. Updating Helm dependencies for the wrapper chart (sonarqube-azure)..."
43+
# This command will read sonarqube-azure/Chart.yaml and package the 'sonarqube'
44+
# dependency (from ../charts/sonarqube) into sonarqube-azure/charts/sonarqube-${SONARQUBE_CHART_VERSION}.tgz
45+
cd sonarqube-azure
46+
helm dependency update
47+
echo "Helm dependencies updated. Packaged subchart is now in sonarqube-azure/charts/."
48+
49+
# 3. Decompress the subchart for CPA validation
50+
echo "3. Decompressing the SonarQube subchart for CPA validation..."
51+
cd charts
52+
tar -xzf "sonarqube-${SONARQUBE_CHART_VERSION}.tgz"
53+
rm "sonarqube-${SONARQUBE_CHART_VERSION}.tgz"
54+
echo "SonarQube subchart decompressed and .tgz removed."
55+
56+
# 4. Navigate back to the main offer directory
57+
cd ../.. # Back to azure-marketplace-k8s-app/
58+
59+
# 5. Perform Docker login to your Azure Container Registry
60+
echo "5. Logging into Azure Container Registry: ${ACR_REGISTRY}..."
61+
if [ -z "${ACR_USERNAME}" ] || [ -z "${ACR_PASSWORD}" ]; then
62+
echo "WARNING: ACR_USERNAME or ACR_PASSWORD not set. Docker login might fail or prompt for credentials."
63+
docker login "${ACR_REGISTRY}"
64+
else
65+
echo "${ACR_PASSWORD}" | docker login "${ACR_REGISTRY}" --username "${ACR_USERNAME}" --password-stdin
66+
fi
67+
echo "Docker login complete."
68+
69+
# 6. Run CPA verify within the container
70+
echo "6. Running CPA verification (cpa verify)..."
71+
# The -v ./:/data mounts the current directory (azure-marketplace-k8s-app) to /data inside the container.
72+
# CPA commands will operate on files relative to /data.
73+
docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock -v "$(pwd)":/data mcr.microsoft.com/container-package-app:latest cpa verify --directory /data
74+
echo "CPA verification complete."
75+
76+
# 7. Run CPA buildbundle within the container
77+
echo "7. Building the CPA bundle (cpa buildbundle)..."
78+
# This creates the .cnab directory and the bundle file (e.g., sonarqube.cnab)
79+
# in the current directory (mounted as /data in container).
80+
DOCKER_BUILDKIT=1 docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock -v "$(pwd)":/data mcr.microsoft.com/container-package-app:latest cpa buildbundle --force --directory /data
81+
echo "CPA bundle built successfully."
82+
echo "CPA bundle pushed to ACR successfully!"
83+
84+
echo "--- Azure Marketplace K8s App Packaging Process Complete ---"

azure-marketplace-k8s-app/Chart.yaml

Lines changed: 0 additions & 29 deletions
This file was deleted.

azure-marketplace-k8s-app/helpers.sh

Lines changed: 0 additions & 14 deletions
This file was deleted.

azure-marketplace-k8s-app/mainTemplate.json

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,11 @@
175175
},
176176
"resources": [
177177
{
178-
"type": "Microsoft.ContainerService/managedClusters",
179178
"condition": "[parameters('createNewCluster')]",
179+
"type": "Microsoft.ContainerService/managedClusters",
180180
"apiVersion": "2024-05-01",
181181
"name": "[parameters('clusterResourceName')]",
182182
"location": "[parameters('location')]",
183-
"dependsOn": [],
184-
"tags": {},
185183
"sku": {
186184
"name": "Basic",
187185
"tier": "Free"
@@ -209,9 +207,7 @@
209207
"type": "VirtualMachineScaleSets",
210208
"mode": "System",
211209
"maxPods": 110,
212-
"availabilityZones": [],
213-
"enableNodePublicIP": false,
214-
"tags": {}
210+
"enableNodePublicIP": false
215211
}
216212
],
217213
"networkProfile": {
@@ -235,9 +231,18 @@
235231
}
236232
},
237233
{
234+
"scope": "[concat('Microsoft.ContainerService/managedClusters/', parameters('clusterResourceName'))]",
238235
"type": "Microsoft.KubernetesConfiguration/extensions",
239236
"apiVersion": "2023-05-01",
240237
"name": "[parameters('extensionResourceName')]",
238+
"plan": {
239+
"name": "[variables('plan-name')]",
240+
"publisher": "[variables('plan-publisher')]",
241+
"product": "[variables('plan-offerID')]"
242+
},
243+
"dependsOn": [
244+
"[resourceId('Microsoft.ContainerService/managedClusters/', parameters('clusterResourceName'))]"
245+
],
241246
"properties": {
242247
"extensionType": "[variables('clusterExtensionTypeName')]",
243248
"autoUpgradeMinorVersion": true,
@@ -248,20 +253,8 @@
248253
"jdbcOverwrite.jdbcUrl": "[parameters('jdbcOverwriteJdbcUrl')]",
249254
"jdbcOverwrite.jdbcUsername": "[parameters('jdbcOverwriteJdbcUsername')]",
250255
"jdbcOverwrite.jdbcPassword": "[parameters('jdbcOverwriteJdbcPassword')]"
251-
},
252-
"configurationProtectedSettings": {
253-
254256
}
255-
},
256-
"plan": {
257-
"name": "[variables('plan-name')]",
258-
"publisher": "[variables('plan-publisher')]",
259-
"product": "[variables('plan-offerID')]"
260-
},
261-
"scope": "[concat('Microsoft.ContainerService/managedClusters/', parameters('clusterResourceName'))]",
262-
"dependsOn": [
263-
"[resourceId('Microsoft.ContainerService/managedClusters/', parameters('clusterResourceName'))]"
264-
]
257+
}
265258
}
266259
],
267260
"outputs": {

azure-marketplace-k8s-app/manifest.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ applicationName: sonarqube
22
publisher: "SonarSource"
33
description: "SonarQube Server is a self-managed, automatic code review tool that systematically helps you deliver clean code. As a core element of our Sonar solution, SonarQube integrates into your existing workflow and detects issues in your code to help you perform continuous code inspections of your projects. The tool analyses 30+ different programming languages and integrates into your CI pipeline and DevOps platform to ensure that your code meets high-quality standards."
44
version: 2025.2.0
5-
helmChart: "../charts/sonarqube"
5+
helmChart: "./sonarqube-azure"
66
clusterArmTemplate: "./mainTemplate.json"
77
uiDefinition: "./createUIDefinition.json"
88
registryServer: "testdavi.azurecr.io" # Verify this!
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v2 # Or v1 depending on your Helm version
2+
name: my-sonarqube-offer
3+
version: 1.0.0 # This is the version of your wrapper chart
4+
appVersion: "2025.2.0" # This could match the SonarQube app version
5+
description: "SonarQube Offer for Azure Marketplace with custom configurations"
6+
type: application
7+
dependencies:
8+
- name: sonarqube # The name of the chart you're wrapping
9+
version: "2025.3.0" # IMPORTANT: Match the version from charts/sonarqube/Chart.yaml
10+
repository: "file://../../charts/sonarqube" # Reference your local SonarQube chart
11+
# OR if you've already packaged sonarqube as a .tgz in my-sonarqube-offer/charts/:
12+
# repository: "file://./charts/sonarqube-YOUR_SONARQUBE_CHART_VERSION.tgz"
13+
# condition: sonarqube.enabled # Example: Allow enabling/disabling the subchart
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Default values for azure-marketplace-k8s-app.
2+
# This is a YAML-formatted file.
3+
sonarqube:
4+
edition: enterprise
5+
monitoringPasscode: helloguys
6+
7+
postgresql:
8+
# Enable to deploy the bitnami PostgreSQL chart
9+
enabled: false
10+
11+
global:
12+
azure:
13+
identity:
14+
# Application's Managed Service Identity (MSI) Client ID. ClientID can be used to generate authentication token to communicate to external services like Microsoft Marketplace Metering API
15+
clientId: "DONOTMODIFY" # Azure populates this value at deployment time
16+
marketplace:
17+
# id of the plan purchased for the Azure Marketplace Kubernetes application,to be used in usage event payload to metering api, for more information please refer: https://learn.microsoft.com/en-us/partner-center/marketplace/marketplace-metering-service-apis
18+
planId: "DONOTMODIFY" # Azure populates this value at deployment time
19+
extension:
20+
# resource id of the Azure Marketplace Kubernetes application,to be used in usage event payload to metering api, for more information please refer: https://learn.microsoft.com/en-us/partner-center/marketplace/marketplace-metering-service-apis
21+
resourceId: "DONOTMODIFY" # application's Azure Resource ID, Azure populates this value at deployment time
22+
images:
23+
sonarqube:
24+
registry: testdavi.azurecr.io
25+
image: sonarqube
26+
tag: 2025.2.0-enterprise
27+
postgres:
28+
registry: testdavi.azurecr.io
29+
image: sonarqube
30+
tag: 2025.2.0-enterprise
31+
nginx:
32+
registry: testdavi.azurecr.io
33+
image: sonarqube
34+
tag: 2025.2.0-enterprise

azure-marketplace-k8s-app/values.yaml

Lines changed: 0 additions & 8 deletions
This file was deleted.

charts/sonarqube/templates/_helpers.tpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,12 @@ app.kubernetes.io/version: {{ (tpl (include "image.tag" .) . ) | trunc 63 | trim
5353
Expand the Application Image name.
5454
*/}}
5555
{{- define "sonarqube.image" -}}
56+
{{- if and .Values.global .Values.global.azure .Values.global.azure.images .Values.global.azure.images.sonarqube }}
57+
{{- printf "%s/%s:%s" .Values.global.azure.images.sonarqube.registry .Values.global.azure.images.sonarqube.image .Values.global.azure.images.sonarqube.tag }}
58+
{{- else }}
5659
{{- printf "%s:%s" .Values.image.repository (tpl (include "image.tag" .) .) }}
5760
{{- end -}}
61+
{{- end -}}
5862

5963
{{/*
6064
Define the image.tag value that computes the right tag to be used as `sonarqube.image`

charts/sonarqube/values.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,6 @@ community:
5656
enabled: false
5757
buildNumber: "25.1.0.102122"
5858

59-
global:
60-
azure:
61-
images:
62-
sonarqube:
63-
registry: testdavi.azurecr.io
64-
image: sonarqube
65-
tag: 2025.2.0-enterprise
66-
6759
image:
6860
repository: sonarqube
6961
# tag: ""

0 commit comments

Comments
 (0)