Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the initial version of ai shopping cart #4

Merged
merged 13 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "AI Shopping Cart Dev Container",
"image": "mcr.microsoft.com/devcontainers/java:1-17-bullseye",
"features": {
// See https://containers.dev/features for list of features
"ghcr.io/devcontainers/features/docker-in-docker:2": {
},
"ghcr.io/azure/azure-dev/azd:latest": {},
"ghcr.io/devcontainers/features/java:1": {
"version": "none",
"installMaven": true,
"mavenVersion": "3.8.8"
},
"ghcr.io/devcontainers/features/node:1": {
"version": "19.4.0"
},
"ghcr.io/devcontainers-contrib/features/typescript:2": {}
},
"customizations": {
"vscode": {
"extensions": [
"GitHub.vscode-github-actions",
"ms-azuretools.azure-dev",
"ms-azuretools.vscode-azurefunctions",
"ms-azuretools.vscode-bicep",
"ms-azuretools.vscode-docker",
"vscjava.vscode-java-pack",
"amodio.tsl-problem-matcher"
]
}
},
"forwardPorts": [
// Forward ports if needed for local development
],
"postCreateCommand": "",
"remoteUser": "vscode",
"hostRequirements": {
"memory": "8gb"
}
}
17 changes: 16 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,28 @@ What kind of change does this Pull Request introduce?
```

## How to Test
* Get the code
* Get the code

```
git clone [repo-address]
cd [repo-name]
git checkout [branch-name]
```

* Run the front-end

```
cd src/frontend
npm install
npm start
```

* Run the AI Shopping Cart Service
<!-- Add the version of the backend -->
```
cd ../ai-shopping-cart-service
./mvnw clean package
java -jar target/ai-shopping-cart-service-<add-the-version-here>.jar
```

* Test the code
Expand Down
8 changes: 4 additions & 4 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ documentation:
- 'assets/*'
- 'assets/**/*'

# Add 'scr: ai-shopping-cart-service' for any change in /src/ai-shopping-cart-service
'scr: ai-shopping-cart-service':
# Add 'src: ai-shopping-cart-service' for any change in /src/ai-shopping-cart-service
'src: ai-shopping-cart-service':
- 'src/ai-shopping-cart-service/*'
- 'src/ai-shopping-cart-service/**/*'

# Add 'scr: frontend' for any change in /src/frontend
'scr: frontend':
# Add 'src: frontend' for any change in /src/frontend
'src: frontend':
- 'src/frontend/*'
- 'src/frontend/**/*'

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.azure
.vscode
14 changes: 14 additions & 0 deletions azure.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/Azure/azure-dev/main/schemas/alpha/azure.yaml.json

name: shopping-cart
metadata:
template: [email protected]
services:
frontend:
language: js
project: ./src/frontend
host: containerapp
ai-shopping-cart-service:
language: java
project: ./src/ai-shopping-cart-service
host: springapp
37 changes: 37 additions & 0 deletions infra/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Infrastructure for AI Shopping Cart Sample Apps

This folder contains the infrastructure for the AI Shopping Cart sample apps. The infrastructure is supposed to be deployed using [Azure Developer CLI](https://learn.microsoft.com/en-us/azure/developer/azure-developer-cli/overview) (azd). You can check the [AI Shopping Cart README](../README.md) for more information about the sample apps and to deploy it using `azd`.

## Deploy with Azure Developer CLI

To deploy only the infrastructure, you can use the following command in the root folder of this repository:

```bash
azd provision
```

Be sure to set all the parameters as described in the [AI Shopping Cart README](../README.md).

## Deploy with Azure CLI

It can also be deployed manually using [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest) (az). The following instructions assume you have already installed Azure CLI. Follow these steps to deploy the infrastructure:

1. Login to Azure CLI using the following command:

```bash
az login
```

1. Set the subscription you want to use:

```bash
az account set --subscription <subscription-id>
```

1. Set the required parameters in `main.parameters.json` file

1. Deploy the template:

```bash
az deployment sub --template-file main.bicep --location <location> --name <deployment-name> --parameters ./main.parameters.json
```
136 changes: 136 additions & 0 deletions infra/abbreviations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
{
"analysisServicesServers": "as",
"apiManagementService": "apim-",
"appConfigurationConfigurationStores": "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",
"springApps": "spring-",
"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-"
}
94 changes: 94 additions & 0 deletions infra/app/ai-shopping-cart-service.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
targetScope = 'resourceGroup'

/* -------------------------------------------------------------------------- */
/* PARAMETERS */
/* -------------------------------------------------------------------------- */

@description('Name of the Spring Apps instance to deploy.')
param name string

@description('Location in which the resources will be deployed. Default value is the resource group location.')
param location string = resourceGroup().location

@description('Tags that will be added to all the resources. For Azure Developer CLI, "azd-env-name" should be added to the tags.')
param tags object = {}

// param applicationInsightsName string

@description('Name of the existing Container Apps Environment in which the Spring Apps instance is deployed.')
param containerAppsEnvironmentName string

@description('Name of the Spring App. This name is used to add "azd-service-name" to the tags for the Spring Apps Instance. This is required for Azure Developer CLI to know which service to deploy. Default value is "ai-shopping-cart-service". If you change this value, make sure to change the name of the service in "azure.yaml" file as well.')
param appName string = 'ai-shopping-cart-service'

@description('Relative path to the AI shopping cart service JAR.')
param relativePath string

/* ------------------------------- PostgreSQL ------------------------------- */

@description('Name of the existing Postgres Flexible Server. This is the relational database used by the Spring App to save the state of the shopping cart.')
param postgresFlexibleServerName string

@description('Name of the Postgres database. Several databases can be created in the same Postgres Flexible Server. We need to know the one that is created for this microservice.')
param postgresDatabaseName string

@secure()
@description('Password of the Postgres Flexible Server administrator. This is the password that was set when the Postgres Flexible Server was created.')
param postgresAdminPassword string

/* --------------------------------- OpenAI --------------------------------- */

@description('Azure Open AI API key.')
param azureOpenAiApiKey string

@description('Azure Open AI endpoint.')
param azureOpenAiEndpoint string

@description('Azure Open AI deployment ID.')
param azureOpenAiDeploymentId string

/* -------------------------------------------------------------------------- */
/* VARIABLES */
/* -------------------------------------------------------------------------- */

@description('Spring Data Source URL. It is composed of the Postgres Flexible Server FQDN and the database name.')
var springDatasourceUrl = 'jdbc:postgresql://${postgresFlexibleServer.properties.fullyQualifiedDomainName}:5432/${postgresDatabaseName}?sslmode=require'

/* -------------------------------------------------------------------------- */
/* RESOURCES */
/* -------------------------------------------------------------------------- */

resource postgresFlexibleServer 'Microsoft.DBforPostgreSQL/flexibleServers@2023-03-01-preview' existing = {
name: postgresFlexibleServerName
}

module springApps '../core/host/spring-apps-consumption.bicep' = {
name: name
params: {
name: name
location: location
tags: union(tags, { 'azd-service-name': appName })
// applicationInsightsName: applicationInsightsName
containerAppsEnvironmentName: containerAppsEnvironmentName
appName: appName
relativePath: relativePath
environmentVariables: {
SPRING_DATASOURCE_URL: springDatasourceUrl
SPRING_DATASOURCE_USERNAME: postgresFlexibleServer.properties.administratorLogin
SPRING_DATASOURCE_PASSWORD: postgresAdminPassword
AZURE_OPENAI_API_KEY: azureOpenAiApiKey
AZURE_OPENAI_ENDPOINT: azureOpenAiEndpoint
AZURE_OPENAI_DEPLOYMENT_ID: azureOpenAiDeploymentId
}
}
}

/* -------------------------------------------------------------------------- */
/* OUTPUTS */
/* -------------------------------------------------------------------------- */

@description('Name of AI Shopping Cart Service Spring App.')
output SERVICE_AI_SHOPPING_CART_NAME string = springApps.outputs.springAppName

@description('URI of AI Shopping Cart Service Spring App.')
output SERVICE_AI_SHOPPING_CART_URI string = springApps.outputs.uri
Loading