forked from Azure-Samples/cargotracker-liberty-aks
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Azure-Samples#16 from azure-javaee/240814_azd_enab…
…le_gzh Enable azd support for cargotracker-liberty-aks
- Loading branch information
Showing
19 changed files
with
802 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,5 @@ | |
hs_err_pid* | ||
|
||
target/* | ||
/custom-values.yaml | ||
/.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export GATEWAY_PUBLICIP_ID=$(az network application-gateway list \ | ||
--resource-group ${RESOURCE_GROUP_NAME} \ | ||
--query '[0].frontendIPConfigurations[0].publicIPAddress.id' -o tsv) | ||
export GATEWAY_HOSTNAME=$(az network public-ip show --ids ${GATEWAY_PUBLICIP_ID} --query 'dnsSettings.fqdn' -o tsv) | ||
export CARGO_TRACKER_URL="http://${GATEWAY_HOSTNAME}/cargo-tracker/" | ||
echo "Cargo Tracker URL: ${CARGO_TRACKER_URL}" | ||
|
||
kubectl rollout restart deployment/cargo-tracker-cluster |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# enable Helm support | ||
azd config set alpha.aks.helm on | ||
|
||
echo "Create Helm repository" | ||
HELM_REPO_URL="https://azure-javaee.github.io/cargotracker-liberty-aks" | ||
HELM_REPO_NAME="cargotracker-liberty-aks" | ||
|
||
# Check if the repo exists before removing | ||
if helm repo list | grep -q "${HELM_REPO_NAME}"; then | ||
helm repo remove ${HELM_REPO_NAME} | ||
echo "Repo '${HELM_REPO_NAME}' removed." | ||
else | ||
echo "Repo '${HELM_REPO_NAME}' not found in the list." | ||
fi | ||
|
||
helm repo add ${HELM_REPO_NAME} ${HELM_REPO_URL} | ||
|
||
|
||
export AKS_NAME=$(az aks list -g ${RESOURCE_GROUP_NAME} --query \[0\].name -o tsv) | ||
|
||
az aks enable-addons \ | ||
--addons monitoring \ | ||
--name ${AKS_NAME} \ | ||
--resource-group ${RESOURCE_GROUP_NAME} \ | ||
--workspace-resource-id ${WORKSPACE_ID} | ||
|
||
echo "Provision postgresql server" | ||
az postgres flexible-server create \ | ||
--resource-group ${RESOURCE_GROUP_NAME} \ | ||
--name ${DB_RESOURCE_NAME} \ | ||
--location ${LOCATION} \ | ||
--admin-user ${DB_USER_NAME} \ | ||
--admin-password ${DB_USER_PASSWORD} \ | ||
--version 15 --public-access 0.0.0.0 \ | ||
--tier Burstable \ | ||
--sku-name Standard_B1ms \ | ||
--yes | ||
|
||
echo "Provision postgresql database" | ||
az postgres flexible-server db create \ | ||
--resource-group ${RESOURCE_GROUP_NAME} \ | ||
--server-name ${DB_RESOURCE_NAME} \ | ||
--database-name ${DB_NAME} | ||
|
||
echo "Allow Access to Azure Services" | ||
az postgres flexible-server firewall-rule create \ | ||
-g ${RESOURCE_GROUP_NAME} \ | ||
-n ${DB_RESOURCE_NAME} \ | ||
-r "AllowAllWindowsAzureIps" \ | ||
--start-ip-address "0.0.0.0" \ | ||
--end-ip-address "0.0.0.0" | ||
|
||
az postgres flexible-server parameter set --name max_prepared_transactions --value 10 -g ${RESOURCE_GROUP_NAME} --server-name ${DB_RESOURCE_NAME} | ||
az postgres flexible-server restart -g ${RESOURCE_GROUP_NAME} --name ${DB_RESOURCE_NAME} | ||
|
||
run_maven_command() { | ||
mvn -q -Dexec.executable=echo -Dexec.args="$1" --non-recursive exec:exec 2>/dev/null | sed -e 's/\x1b\[[0-9;]*m//g' | tr -d '\r\n' | ||
} | ||
|
||
IMAGE_NAME=$(run_maven_command '${project.artifactId}') | ||
IMAGE_VERSION=$(run_maven_command '${project.version}') | ||
|
||
########################################################## | ||
# Create the custom-values.yaml file | ||
########################################################## | ||
cat << EOF > custom-values.yaml | ||
appInsightConnectionString: ${APP_INSIGHTS_CONNECTION_STRING} | ||
loginServer: ${AZURE_REGISTRY_NAME} | ||
imageName: ${IMAGE_NAME} | ||
imageTag: ${IMAGE_VERSION} | ||
EOF | ||
|
||
########################################################## | ||
# DB | ||
########################################################## | ||
cat << EOF >> custom-values.yaml | ||
namespace: ${AZURE_AKS_NAMESPACE} | ||
db: | ||
ServerName: ${DB_RESOURCE_NAME}.postgres.database.azure.com | ||
PortNumber: 5432 | ||
Name: ${DB_NAME} | ||
User: ${DB_USER_NAME} | ||
Password: ${DB_USER_PASSWORD} | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
|
||
# Build and push docker image to ACR | ||
echo "Get image name and version......" | ||
|
||
run_maven_command() { | ||
mvn -q -Dexec.executable=echo -Dexec.args="$1" --non-recursive exec:exec 2>/dev/null | sed -e 's/\x1b\[[0-9;]*m//g' | tr -d '\r\n' | ||
} | ||
|
||
IMAGE_NAME=$(run_maven_command '${project.artifactId}') | ||
IMAGE_VERSION=$(run_maven_command '${project.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 ${ACR_PASSWORD} -p ${ACR_PASSWORD} ${ACR_SERVER} | ||
|
||
export DOCKER_BUILDKIT=1 | ||
docker buildx create --use | ||
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
az extension add --upgrade -n application-insights |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# yaml-language-server: $schema=https://raw.githubusercontent.com/Azure/azure-dev/main/schemas/v1.0/azure.yaml.json | ||
|
||
name: cargotracker-liberty-aks-demo | ||
metadata: | ||
template: [email protected] | ||
hooks: | ||
postprovision: | ||
posix: | ||
shell: sh | ||
continueOnError: false | ||
interactive: true | ||
run: azd-hooks/postprovision.sh | ||
predeploy: # This hook is executed before the deployment of the application to create the custom-values.yaml file | ||
posix: | ||
shell: sh | ||
continueOnError: false | ||
interactive: true | ||
run: azd-hooks/predeploy.sh | ||
postdeploy: # This hook is executed after the deployment of the application to create the custom-values.yaml file | ||
posix: | ||
shell: sh | ||
continueOnError: false | ||
interactive: true | ||
run: azd-hooks/postdeploy.sh | ||
|
||
services: | ||
demo: | ||
host: aks | ||
k8s: | ||
namespace: default | ||
helm: | ||
releases: | ||
- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Patterns to ignore when building packages. | ||
# This supports shell glob matching, relative path matching, and | ||
# negation (prefixed with !). Only one pattern per line. | ||
.DS_Store | ||
# Common VCS dirs | ||
.git/ | ||
.gitignore | ||
.bzr/ | ||
.bzrignore | ||
.hg/ | ||
.hgignore | ||
.svn/ | ||
# Common backup files | ||
*.swp | ||
*.bak | ||
*.tmp | ||
*.orig | ||
*~ | ||
# Various IDEs | ||
.project | ||
.idea/ | ||
*.tmproj | ||
.vscode/ |
Oops, something went wrong.