Skip to content

Commit

Permalink
Merge branch 'main' into gpt_shortest_path
Browse files Browse the repository at this point in the history
  • Loading branch information
backwind1233 committed Sep 29, 2024
2 parents 78cb73d + 4c960e9 commit 68bd17e
Show file tree
Hide file tree
Showing 29 changed files with 225 additions and 2,000 deletions.
1 change: 1 addition & 0 deletions .github/workflows/setupOpenLibertyAks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ jobs:
uses: actions/download-artifact@v4
with:
name: ${{steps.artifact_file.outputs.artifactName}}
path: ${{steps.artifact_file.outputs.artifactName}}
- uses: azure/login@v1
id: azure-login
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ hs_err_pid*
target/*
/custom-values.yaml
/.idea/
/tmp-build/
/infra/azure.liberty.aks/
2 changes: 1 addition & 1 deletion .scripts/setup-env-variables-template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export DB_PASSWORD="Secret123456" # PostgreSQL database password
export DB_PORT_NUMBER=5432
export DB_SERVER_NAME="${DB_RESOURCE_NAME}.postgres.database.azure.com" # PostgreSQL host name
export DB_USER=liberty${DB_RESOURCE_NAME}
export LIBERTY_AKS_REPO_REF="048e776e9efe2ffed8368812e198c1007ba94b2c" # WASdev/azure.liberty.aks
export LIBERTY_AKS_REPO_REF="5886de1248e1cdcc891c1135d6ad3ae6660f0adf" # WASdev/azure.liberty.aks
export NAMESPACE=default
export WORKSPACE_NAME="${RESOURCE_GROUP_NAME}ws"
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Cargo Tracker is a Domain-Driven Design Jakarta EE application. The application
* [Clone Cargo Tracker](#clone-cargo-tracker)
* [Prepare your variables for deployments](#prepare-your-variables-for-deployments)
* [Clone Liberty on AKS Bicep templates](#clone-liberty-on-aks-bicep-templates)
* [Build Liberty on AKS Bicep templates](#build-liberty-on-aks-bicep-templates)
* [Sign in to Azure](#sign-in-to-azure)
* [Create a resource group](#create-a-resource-group)
* [Prepare deployment parameters](#prepare-deployment-parameters)
Expand Down Expand Up @@ -45,6 +46,7 @@ In this sample, you will:
* Verify your application
* Monitor application
* Automate deployments using GitHub Actions
* Automate deployments using AZD

## Prerequisites

Expand All @@ -64,6 +66,9 @@ In this sample, you will:

## Unit-1 - Deploy and monitor Cargo Tracker

> [!NOTE]
> You can jump to [Unit-3 - Automate deployments using AZD](#unit-3---automate-deployments-using-azd) if you want to automate deployments using AZD instead of manually deploying Cargo Tracker.
### Clone Cargo Tracker

Clone the sample app repository to your development environment.
Expand All @@ -74,7 +79,7 @@ export DIR="$PWD/cargotracker-liberty-aks"

git clone https://github.com/Azure-Samples/cargotracker-liberty-aks.git ${DIR}/cargotracker
cd ${DIR}/cargotracker
git checkout 20240808
git checkout 20240924
```

If you see a message about `detached HEAD state`, it is safe to ignore. It just means you have checked out a tag.
Expand Down Expand Up @@ -128,7 +133,6 @@ mvn install:install-file -Dfile=${DIR}/azure-javaee-iaas-parent-${VERSION}.pom \

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

```

### Sign in to Azure
Expand Down Expand Up @@ -726,14 +730,13 @@ Use following steps to automate deployments using the Azure Developer CLI (azd).
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).
### How to Run
1. Change into the directory that has cargo tracker checked out, and ensure the tag is checked out.
1. Clone the Cargo Tracker repository to your development environment.
```bash
cd ${DIR}/cargotracker
git checkout 20240919
git clone https://github.com/Azure-Samples/cargotracker-liberty-aks.git
cd cargotracker-liberty-aks
```

1. Run the following command to authenticate with Azure using the Azure CLI.
Expand All @@ -754,6 +757,9 @@ Use following steps to automate deployments using the Azure Developer CLI (azd).
1. Run the following command to provision the required Azure resources. Input the required parameters when prompted.
* Be sure to select the correct Azure subscription when prompted.
* We observe that `westus` region has a higher likelihood of success than `eastus`.
```bash
azd provision
```
Expand Down
24 changes: 16 additions & 8 deletions azd-hooks/postprovision.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
HELM_REPO_URL="https://azure-javaee.github.io/cargotracker-liberty-aks"
HELM_REPO_NAME="cargotracker-liberty-aks"
AZURE_OPENAI_MODEL_NAME="gpt-4o"
AZURE_OPENAI_MODEL_VERSION="2024-08-06"
# if folder tmp-build exists, delete the folder
if [ -d "tmp-build" ];
then rm -rf tmp-build;
fi

export HELM_REPO_URL="https://azure-javaee.github.io/cargotracker-liberty-aks"
export HELM_REPO_NAME="cargotracker-liberty-aks"
export AZURE_OPENAI_MODEL_NAME="gpt-4o"
export AZURE_OPENAI_MODEL_VERSION="2024-08-06"
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)
export AKS_NAME=$(az aks list -g ${RESOURCE_GROUP_NAME} --query \[0\].name -o tsv)

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

echo "Create Helm repository"
# Check if the repo exists before removing
if helm repo list | grep -q "${HELM_REPO_NAME}"; then
echo "Removing Repo '${HELM_REPO_NAME}'"
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 \
Expand Down Expand Up @@ -106,7 +114,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}
azureOpenAIKey: ${AZURE_OPENAI_KEY}
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
34 changes: 34 additions & 0 deletions azd-hooks/preprovision.sh
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
az extension add --upgrade -n application-insights
source .scripts/setup-env-variables-template.sh

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
git checkout ${LIBERTY_AKS_REPO_REF}
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

rm -rf ${DIR}
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
Loading

0 comments on commit 68bd17e

Please sign in to comment.