Skip to content

Commit

Permalink
Refactor ACR variable names for consistency and clarity.
Browse files Browse the repository at this point in the history
  • Loading branch information
backwind1233 authored and edburns committed Sep 24, 2024
1 parent b7701e4 commit 32251aa
Show file tree
Hide file tree
Showing 10 changed files with 245 additions and 6 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/package-helm-chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: package-helm-chart

on:
push:
branches:
- main
paths:
- 'charts/**'

workflow_dispatch:

jobs:
package-helm-chart:
permissions:
contents: read
packages: write

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set environment variables
id: set-variables
run: |
echo "REPOSITORY=ghcr.io/$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
echo "VERSION=$(yq -r .version ./charts/cargotracker-liberty-aks/Chart.yaml)" >> "$GITHUB_OUTPUT"
- name: Env variable output
id: test-variables
run: |
echo ${{ steps.set-variables.outputs.REPOSITORY }}
echo ${{ steps.set-variables.outputs.VERSION }}
- name: Login to GitHub Container Registry
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- name: Package and push helm chart
run: |
helm package ./charts/cargotracker-liberty-aks --version ${{ steps.set-variables.outputs.VERSION }}
helm push ./cargotracker-liberty-aks-chart-${{ steps.set-variables.outputs.VERSION }}.tgz oci://${{ steps.set-variables.outputs.REPOSITORY }}/charts
publish-helm-chart:
permissions:
id-token: write
packages: write
contents: write
actions: read
deployments: read
pull-requests: read

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Publish Helm chart to GitHub Pages
uses: stefanprodan/helm-gh-pages@0ad2bb377311d61ac04ad9eb6f252fb68e207260 # v1.7.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
linting: off
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@
hs_err_pid*

target/*
<<<<<<< HEAD
=======
/custom-values.yaml
/.idea/
>>>>>>> 80fda3d (Refactor ACR variable names for consistency and clarity.)
2 changes: 1 addition & 1 deletion azd-hooks/postdeploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ export GATEWAY_HOSTNAME=$(az network public-ip show --ids ${GATEWAY_PUBLICIP_ID}
export CARGO_TRACKER_URL="http://${GATEWAY_HOSTNAME}/cargo-tracker/"
echo "Cargo Tracker URL: ${CARGO_TRACKER_URL}"

kubectl rollout restart deployment/cargo-tracker-cluster
kubectl rollout restart deployment/cargo-tracker-cluster
8 changes: 4 additions & 4 deletions azd-hooks/predeploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ run_maven_command() {
IMAGE_NAME=$(run_maven_command '${project.artifactId}')
IMAGE_VERSION=$(run_maven_command '${project.version}')

echo "Docker build and push to ACR Server ${ACRServer} with image name ${IMAGE_NAME} and version ${IMAGE_VERSION}"
echo "Docker build and push to ACR Server ${ACR_SERVER} with image name ${IMAGE_NAME} and version ${IMAGE_VERSION}"

mvn clean package -DskipTests
cd target

docker login -u ${ACRUserName} -p ${ACRPassword} ${ACRServer}
docker login -u ${ACR_PASSWORD} -p ${ACR_PASSWORD} ${ACR_SERVER}

export DOCKER_BUILDKIT=1
docker buildx create --use
docker buildx build --platform linux/amd64 -t ${ACRServer}/${IMAGE_NAME}:${IMAGE_VERSION} --pull --file=Dockerfile . --load
docker push ${ACRServer}/${IMAGE_NAME}:${IMAGE_VERSION}
docker buildx build --platform linux/amd64 -t ${ACR_SERVER}/${IMAGE_NAME}:${IMAGE_VERSION} --pull --file=Dockerfile . --load
docker push ${ACR_SERVER}/${IMAGE_NAME}:${IMAGE_VERSION}
1 change: 1 addition & 0 deletions azd-hooks/preprovision.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
az extension add --upgrade -n application-insights
2 changes: 1 addition & 1 deletion azure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ services:
- name: demo
chart: cargotracker-liberty-aks/cargotracker-liberty-aks-chart
version: 1.0.5
values: custom-values.yaml # This file is created by the predeploy hook
values: custom-values.yaml # This file is created by the predeploy hook
8 changes: 8 additions & 0 deletions charts/cargotracker-liberty-aks/templates/app-insight.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Secret
metadata:
name: app-insight-secret
namespace: "{{ .Values.namespace }}"
type: Opaque
stringData:
connection.string: "{{ .Values.appInsightConnectionString }}"
12 changes: 12 additions & 0 deletions charts/cargotracker-liberty-aks/templates/db-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Secret
metadata:
name: db-secret-sql
namespace: "{{ .Values.namespace }}"
type: Opaque
stringData:
db.server.name: "{{ .Values.db.ServerName }}"
db.port.number: "{{ .Values.db.PortNumber }}"
db.name: "{{ .Values.db.Name }}"
db.user: "{{ .Values.db.User }}"
db.password: "{{ .Values.db.Password }}"
111 changes: 111 additions & 0 deletions infra/main.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
targetScope = 'subscription'

@minLength(1)
@maxLength(64)
@description('Name of the environment that can be used as part of naming resource convention')
param environmentName string

@minLength(1)
@description('Primary location for all resources')
param location string

@description('The base URL for artifacts')
param _artifactsLocation string = 'https://raw.githubusercontent.com/WASdev/azure.liberty.aks/048e776e9efe2ffed8368812e198c1007ba94b2c/src/main/'

@description('Whether to create a new AKS cluster')
param createCluster bool = true

@description('The VM size for AKS nodes')
param vmSize string = 'Standard_DS2_v2'

@description('The minimum node count for AKS cluster')
param minCount int = 1

@description('The maximum node count for AKS cluster')
param maxCount int = 5

@description('Whether to create Azure Container Registry')
param createACR bool = true

@description('Whether to deploy the application')
param deployApplication bool = false

@description('Whether to enable Application Gateway Ingress')
param enableAppGWIngress bool = true

@description('The certificate option for Application Gateway')
param appGatewayCertificateOption string = 'generateCert'

@description('Whether to enable cookie-based affinity')
param enableCookieBasedAffinity bool = true

@description('Server administrator login name')
@secure()
param administratorLogin string = 'azureroot'

@description('Server administrator password')
@secure()
param administratorLoginPassword string

// Tags that should be applied to all resources.
//
// Note that 'azd-service-name' tags should be applied separately to service host resources.
// Example usage:
// tags: union(tags, { 'azd-service-name': <service name in azure.yaml> })
var tags = {
'azd-env-name': environmentName
}

var abbrs = loadJsonContent('./abbreviations.json')
var resourceToken = toLower(uniqueString(subscription().id, environmentName, location))
var suffix = take(resourceToken, 6)

resource rg 'Microsoft.Resources/resourceGroups@2022-09-01' = {
name: 'rg-${environmentName}-${take(resourceToken, 6)}'
location: location
tags: tags
}

module openLibertyOnAks './azure.liberty.aks/mainTemplate.bicep' = {
name: 'openliberty-on-aks'
params: {
_artifactsLocation: _artifactsLocation
location: location
createCluster: createCluster
vmSize: vmSize
minCount: minCount
maxCount: maxCount
createACR: createACR
deployApplication: deployApplication
enableAppGWIngress: enableAppGWIngress
appGatewayCertificateOption: appGatewayCertificateOption
enableCookieBasedAffinity: enableCookieBasedAffinity
}
scope: rg
}

module monitoring './shared/monitoring.bicep' = {
name: 'monitoring'
params: {
location: location
tags: tags
logAnalyticsName: '${abbrs.operationalInsightsWorkspaces}${resourceToken}'
applicationInsightsName: '${abbrs.insightsComponents}${resourceToken}'
}
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}'
output DB_USER_NAME string = administratorLogin
output DB_USER_PASSWORD string = administratorLoginPassword
output LOCATION string = location
output RESOURCE_GROUP_NAME string = rg.name
output WORKSPACE_ID string = monitoring.outputs.logAnalyticsWorkspaceId
output APP_INSIGHTS_CONNECTION_STRING string = monitoring.outputs.appInsightsConnectionString
35 changes: 35 additions & 0 deletions infra/shared/monitoring.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
param logAnalyticsName string
param applicationInsightsName string
param location string = resourceGroup().location
param tags object = {}

resource logAnalytics 'Microsoft.OperationalInsights/workspaces@2021-12-01-preview' = {
name: logAnalyticsName
location: location
tags: tags
properties: any({
retentionInDays: 30
features: {
searchVersion: 1
}
sku: {
name: 'PerGB2018'
}
})
}

resource applicationInsights 'Microsoft.Insights/components@2020-02-02' = {
name: applicationInsightsName
location: location
tags: tags
kind: 'web'
properties: {
Application_Type: 'web'
WorkspaceResourceId: logAnalytics.id
}
}

output applicationInsightsName string = applicationInsights.name
output logAnalyticsWorkspaceId string = logAnalytics.id
output logAnalyticsWorkspaceName string = logAnalytics.name
output appInsightsConnectionString string = applicationInsights.properties.ConnectionString

0 comments on commit 32251aa

Please sign in to comment.