Skip to content

Commit

Permalink
Add ACR variable exports and update login logic in deployment scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
backwind1233 committed Sep 25, 2024
1 parent e75268c commit ea0ce60
Show file tree
Hide file tree
Showing 9 changed files with 210 additions and 34 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
hs_err_pid*

target/*
<<<<<<< HEAD
=======
/custom-values.yaml
/.idea/
>>>>>>> 80fda3d (Refactor ACR variable names for consistency and clarity.)
/tmp-build/
/infra/azure.liberty.aks/
25 changes: 0 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -725,31 +725,6 @@ Use following steps to automate deployments using the Azure Developer CLI (azd).
1. [Azure Developer CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/install-azd) (azd) installed.
2. Docker installed. You can install Docker by following the instructions [here](https://docs.docker.com/get-docker/).
3. Azure CLI installed. You can install the Azure CLI by following the instructions [here](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli).
4. You have executed the following steps from the preceding units:
1. [Clone Cargo Tracker](#clone-cargo-tracker)
1. [Prepare your variables for deployments](#prepare-your-variables-for-deployments)
1. [Clone Liberty on AKS Bicep templates](#clone-liberty-on-aks-bicep-templates)
1. [Build Liberty on AKS Bicep templates](#build-liberty-on-aks-bicep-templates)
5. Populate the `infra/azure.liberty.aks` directory with the built Liberty on AKS Bicep templates.
```bash
cd $DIR/cargotracker/infra/azure.liberty.aks
envsubst < parameters_json.template > parameters.json
```

Verify the environment variables have been successfully replaced:

```bash
grep azure.liberty.aks parameters.json
```

You should see no `$` characters in this output. If you see a `$` in the output, ensure you have followed the steps in **Prepare your variables for deployments**.

6. Copy the built Liberty on AKS Bicep templates so azd can invoke them.

```bash
cp -r ${DIR}/azure.liberty.aks/target/bicep/* .
```
### How to Run
Expand Down
17 changes: 16 additions & 1 deletion azd-hooks/postprovision.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# if folder tmp-build exists, delete the folder
if [ -d "tmp-build" ];
then rm -rf tmp-build;
fi

export ACR_NAME=$(az acr list -g ${RESOURCE_GROUP_NAME} --query [0].name -o tsv)
export ACR_SERVER=$(az acr show -n $ACR_NAME -g ${RESOURCE_GROUP_NAME} --query 'loginServer' -o tsv)
export ACR_USER_NAME=$(az acr credential show -n $ACR_NAME -g ${RESOURCE_GROUP_NAME} --query 'username' -o tsv)
export ACR_PASSWORD=$(az acr credential show -n $ACR_NAME -g ${RESOURCE_GROUP_NAME} --query 'passwords[0].value' -o tsv)

echo ACR_NAME=$ACR_NAME
echo ACR_SERVER=$ACR_SERVER
echo ACR_USER_NAME=$ACR_USER_NAME
echo ACR_PASSWORD=$ACR_PASSWORD

# enable Helm support
azd config set alpha.aks.helm on

Expand Down Expand Up @@ -65,7 +80,7 @@ IMAGE_VERSION=$(run_maven_command '${project.version}')
##########################################################
cat << EOF > custom-values.yaml
appInsightConnectionString: ${APP_INSIGHTS_CONNECTION_STRING}
loginServer: ${AZURE_REGISTRY_NAME}
loginServer: ${ACR_SERVER}
imageName: ${IMAGE_NAME}
imageTag: ${IMAGE_VERSION}
EOF
Expand Down
7 changes: 6 additions & 1 deletion azd-hooks/predeploy.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/bin/bash

export ACR_NAME=$(az acr list -g ${RESOURCE_GROUP_NAME} --query [0].name -o tsv)
export ACR_SERVER=$(az acr show -n $ACR_NAME -g ${RESOURCE_GROUP_NAME} --query 'loginServer' -o tsv)
export ACR_USER_NAME=$(az acr credential show -n $ACR_NAME -g ${RESOURCE_GROUP_NAME} --query 'username' -o tsv)
export ACR_PASSWORD=$(az acr credential show -n $ACR_NAME -g ${RESOURCE_GROUP_NAME} --query 'passwords[0].value' -o tsv)

# Build and push docker image to ACR
echo "Get image name and version......"

Expand All @@ -15,7 +20,7 @@ echo "Docker build and push to ACR Server ${ACR_SERVER} with image name ${IMAGE_
mvn clean package -DskipTests
cd target

docker login -u ${ACR_PASSWORD} -p ${ACR_PASSWORD} ${ACR_SERVER}
docker login -u ${ACR_USER_NAME} -p ${ACR_PASSWORD} ${ACR_SERVER}

export DOCKER_BUILDKIT=1
docker buildx create --use
Expand Down
30 changes: 30 additions & 0 deletions azd-hooks/preprovision.sh
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
az extension add --upgrade -n application-insights

mkdir tmp-build
DIR=$(pwd)/tmp-build
echo "Current directory: $DIR"

cd ${DIR}
git clone https://github.com/WASdev/azure.liberty.aks ${DIR}/azure.liberty.aks

cd ${DIR}/azure.liberty.aks
export VERSION=$(mvn help:evaluate -Dexpression=project.parent.version -q -DforceStdout | grep -v '^\[' | tr -d '\r')

cd ${DIR}
curl -L -o ${DIR}/azure-javaee-iaas-parent-${VERSION}.pom \
https://github.com/azure-javaee/azure-javaee-iaas/releases/download/azure-javaee-iaas-parent-${VERSION}/azure-javaee-iaas-parent-${VERSION}.pom


mvn install:install-file -Dfile=${DIR}/azure-javaee-iaas-parent-${VERSION}.pom \
-DgroupId=com.microsoft.azure.iaas \
-DartifactId=azure-javaee-iaas-parent \
-Dversion=${VERSION} \
-Dpackaging=pom

cd ${DIR}/azure.liberty.aks
mvn clean package -DskipTests

mkdir -p ${DIR}/../infra/azure.liberty.aks
cp -r ${DIR}/azure.liberty.aks/target/bicep/* ${DIR}/../infra/azure.liberty.aks

# shell sleep 5 seconds
sleep 5
6 changes: 6 additions & 0 deletions azure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ name: cargotracker-liberty-aks-demo
metadata:
template: [email protected]
hooks:
preprovision:
posix:
shell: sh
continueOnError: false
interactive: true
run: azd-hooks/preprovision.sh
postprovision:
posix:
shell: sh
Expand Down
135 changes: 135 additions & 0 deletions infra/abbreviations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
{
"analysisServicesServers": "as",
"apiManagementService": "apim-",
"appConfigurationStores": "appcs-",
"appManagedEnvironments": "cae-",
"appContainerApps": "ca-",
"authorizationPolicyDefinitions": "policy-",
"automationAutomationAccounts": "aa-",
"blueprintBlueprints": "bp-",
"blueprintBlueprintsArtifacts": "bpa-",
"cacheRedis": "redis-",
"cdnProfiles": "cdnp-",
"cdnProfilesEndpoints": "cdne-",
"cognitiveServicesAccounts": "cog-",
"cognitiveServicesFormRecognizer": "cog-fr-",
"cognitiveServicesTextAnalytics": "cog-ta-",
"computeAvailabilitySets": "avail-",
"computeCloudServices": "cld-",
"computeDiskEncryptionSets": "des",
"computeDisks": "disk",
"computeDisksOs": "osdisk",
"computeGalleries": "gal",
"computeSnapshots": "snap-",
"computeVirtualMachines": "vm",
"computeVirtualMachineScaleSets": "vmss-",
"containerInstanceContainerGroups": "ci",
"containerRegistryRegistries": "cr",
"containerServiceManagedClusters": "aks-",
"databricksWorkspaces": "dbw-",
"dataFactoryFactories": "adf-",
"dataLakeAnalyticsAccounts": "dla",
"dataLakeStoreAccounts": "dls",
"dataMigrationServices": "dms-",
"dBforMySQLServers": "mysql-",
"dBforPostgreSQLServers": "psql-",
"devicesIotHubs": "iot-",
"devicesProvisioningServices": "provs-",
"devicesProvisioningServicesCertificates": "pcert-",
"documentDBDatabaseAccounts": "cosmos-",
"eventGridDomains": "evgd-",
"eventGridDomainsTopics": "evgt-",
"eventGridEventSubscriptions": "evgs-",
"eventHubNamespaces": "evhns-",
"eventHubNamespacesEventHubs": "evh-",
"hdInsightClustersHadoop": "hadoop-",
"hdInsightClustersHbase": "hbase-",
"hdInsightClustersKafka": "kafka-",
"hdInsightClustersMl": "mls-",
"hdInsightClustersSpark": "spark-",
"hdInsightClustersStorm": "storm-",
"hybridComputeMachines": "arcs-",
"insightsActionGroups": "ag-",
"insightsComponents": "appi-",
"keyVaultVaults": "kv-",
"kubernetesConnectedClusters": "arck",
"kustoClusters": "dec",
"kustoClustersDatabases": "dedb",
"logicIntegrationAccounts": "ia-",
"logicWorkflows": "logic-",
"machineLearningServicesWorkspaces": "mlw-",
"managedIdentityUserAssignedIdentities": "id-",
"managementManagementGroups": "mg-",
"migrateAssessmentProjects": "migr-",
"networkApplicationGateways": "agw-",
"networkApplicationSecurityGroups": "asg-",
"networkAzureFirewalls": "afw-",
"networkBastionHosts": "bas-",
"networkConnections": "con-",
"networkDnsZones": "dnsz-",
"networkExpressRouteCircuits": "erc-",
"networkFirewallPolicies": "afwp-",
"networkFirewallPoliciesWebApplication": "waf",
"networkFirewallPoliciesRuleGroups": "wafrg",
"networkFrontDoors": "fd-",
"networkFrontdoorWebApplicationFirewallPolicies": "fdfp-",
"networkLoadBalancersExternal": "lbe-",
"networkLoadBalancersInternal": "lbi-",
"networkLoadBalancersInboundNatRules": "rule-",
"networkLocalNetworkGateways": "lgw-",
"networkNatGateways": "ng-",
"networkNetworkInterfaces": "nic-",
"networkNetworkSecurityGroups": "nsg-",
"networkNetworkSecurityGroupsSecurityRules": "nsgsr-",
"networkNetworkWatchers": "nw-",
"networkPrivateDnsZones": "pdnsz-",
"networkPrivateLinkServices": "pl-",
"networkPublicIPAddresses": "pip-",
"networkPublicIPPrefixes": "ippre-",
"networkRouteFilters": "rf-",
"networkRouteTables": "rt-",
"networkRouteTablesRoutes": "udr-",
"networkTrafficManagerProfiles": "traf-",
"networkVirtualNetworkGateways": "vgw-",
"networkVirtualNetworks": "vnet-",
"networkVirtualNetworksSubnets": "snet-",
"networkVirtualNetworksVirtualNetworkPeerings": "peer-",
"networkVirtualWans": "vwan-",
"networkVpnGateways": "vpng-",
"networkVpnGatewaysVpnConnections": "vcn-",
"networkVpnGatewaysVpnSites": "vst-",
"notificationHubsNamespaces": "ntfns-",
"notificationHubsNamespacesNotificationHubs": "ntf-",
"operationalInsightsWorkspaces": "log-",
"portalDashboards": "dash-",
"powerBIDedicatedCapacities": "pbi-",
"purviewAccounts": "pview-",
"recoveryServicesVaults": "rsv-",
"resourcesResourceGroups": "rg-",
"searchSearchServices": "srch-",
"serviceBusNamespaces": "sb-",
"serviceBusNamespacesQueues": "sbq-",
"serviceBusNamespacesTopics": "sbt-",
"serviceEndPointPolicies": "se-",
"serviceFabricClusters": "sf-",
"signalRServiceSignalR": "sigr",
"sqlManagedInstances": "sqlmi-",
"sqlServers": "sql-",
"sqlServersDataWarehouse": "sqldw-",
"sqlServersDatabases": "sqldb-",
"sqlServersDatabasesStretch": "sqlstrdb-",
"storageStorageAccounts": "st",
"storageStorageAccountsVm": "stvm",
"storSimpleManagers": "ssimp",
"streamAnalyticsCluster": "asa-",
"synapseWorkspaces": "syn",
"synapseWorkspacesAnalyticsWorkspaces": "synw",
"synapseWorkspacesSqlPoolsDedicated": "syndp",
"synapseWorkspacesSqlPoolsSpark": "synsp",
"timeSeriesInsightsEnvironments": "tsi-",
"webServerFarms": "plan-",
"webSitesAppService": "app-",
"webSitesAppServiceEnvironment": "ase-",
"webSitesFunctions": "func-",
"webStaticSites": "stapp-"
}
4 changes: 0 additions & 4 deletions infra/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,7 @@ module monitoring './shared/monitoring.bicep' = {
scope: rg
}

output ACR_PASSWORD string = openLibertyOnAks.outputs.acrPassword
output ACR_SERVER string = openLibertyOnAks.outputs.acrServerName
output ACR_USER_NAME string = openLibertyOnAks.outputs.acrUsername
output AZURE_AKS_CLUSTER_NAME string = openLibertyOnAks.outputs.clusterName
output AZURE_REGISTRY_NAME string = openLibertyOnAks.outputs.acrServerName
output AZURE_RESOURCE_GROUP string = rg.name
output DB_NAME string = 'liberty-db-${suffix}'
output DB_RESOURCE_NAME string = 'liberty-server-${suffix}'
Expand Down
15 changes: 15 additions & 0 deletions infra/main.parameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"environmentName": {
"value": "${AZURE_ENV_NAME}"
},
"location": {
"value": "${AZURE_LOCATION}"
},
"principalId": {
"value": "${AZURE_PRINCIPAL_ID}"
}
}
}

0 comments on commit ea0ce60

Please sign in to comment.