diff --git a/.gitignore b/.gitignore index 0fb1c0ab0..548ad2340 100644 --- a/.gitignore +++ b/.gitignore @@ -189,7 +189,6 @@ ClientBin/ *~ *.dbmdl *.dbproj.schemaview -*.pfx *.publishsettings node_modules/ orleans.codegen.cs diff --git a/azure-docs/builds/images/android-build-step1.png b/azure-docs/builds/images/android-build-step1.png new file mode 100644 index 000000000..b43243b73 Binary files /dev/null and b/azure-docs/builds/images/android-build-step1.png differ diff --git a/azure-docs/builds/images/android-build-step2.png b/azure-docs/builds/images/android-build-step2.png new file mode 100644 index 000000000..67419b3ba Binary files /dev/null and b/azure-docs/builds/images/android-build-step2.png differ diff --git a/azure-docs/builds/images/android-build-step3.png b/azure-docs/builds/images/android-build-step3.png new file mode 100644 index 000000000..ae703c16d Binary files /dev/null and b/azure-docs/builds/images/android-build-step3.png differ diff --git a/azure-docs/builds/images/android-build-step4.png b/azure-docs/builds/images/android-build-step4.png new file mode 100644 index 000000000..8311e5647 Binary files /dev/null and b/azure-docs/builds/images/android-build-step4.png differ diff --git a/azure-docs/builds/images/android-build-step5.png b/azure-docs/builds/images/android-build-step5.png new file mode 100644 index 000000000..b6789e97f Binary files /dev/null and b/azure-docs/builds/images/android-build-step5.png differ diff --git a/azure-docs/builds/images/android-build.png b/azure-docs/builds/images/android-build.png new file mode 100644 index 000000000..d21233571 Binary files /dev/null and b/azure-docs/builds/images/android-build.png differ diff --git a/azure-docs/builds/images/ios-build-step1.png b/azure-docs/builds/images/ios-build-step1.png new file mode 100644 index 000000000..e19a7e803 Binary files /dev/null and b/azure-docs/builds/images/ios-build-step1.png differ diff --git a/azure-docs/builds/images/ios-build-step2.png b/azure-docs/builds/images/ios-build-step2.png new file mode 100644 index 000000000..04b747911 Binary files /dev/null and b/azure-docs/builds/images/ios-build-step2.png differ diff --git a/azure-docs/builds/images/ios-build-step3.png b/azure-docs/builds/images/ios-build-step3.png new file mode 100644 index 000000000..0744be5e7 Binary files /dev/null and b/azure-docs/builds/images/ios-build-step3.png differ diff --git a/azure-docs/builds/images/ios-build.png b/azure-docs/builds/images/ios-build.png new file mode 100644 index 000000000..35f25c29f Binary files /dev/null and b/azure-docs/builds/images/ios-build.png differ diff --git a/azure-docs/builds/xamarin-android.md b/azure-docs/builds/xamarin-android.md new file mode 100644 index 000000000..1459f151e --- /dev/null +++ b/azure-docs/builds/xamarin-android.md @@ -0,0 +1,95 @@ +# Xamarin Android Build + +Follow these steps to create a VSTS build for your eShopOnContainers app (android). + +**Note**: This document assumes basic knowledge about creating builds and configuring external VSTS connections + +## Creating the build + +Despite the _"Get Sources"_ task there are five tasks more in the build: + +1. Restore NuGet Packages +2. Build Xamarin Android Project +3. Download the certstore to sign the APK +4. Sign the APK +5. Publish the build artifact. + +![Android Build Steps](images/android-build.png) + +Let's discuss each of them. + +### Restore NuGet Packages + +Add a "NuGet restore" task and enter the following configuration: + +1. Enter `eShopOnContainers-Android.sln` in "Path to solution, packages.config, or project.json". This sln is created ex professo for the build and contains only the Xamarin Android project plus the Xamarin Forms one. + +![Android Build Step 1](images/android-build-step1.png) + +### Build the project + +Add a "Xamarin Android" task with following configuration: + +1. `**/*Droid*.csproj` in "Project" +2. `$(build.binariesdirectory)/$(BuildConfiguration)` in "Output Directory" +3. `$(BuildConfiguration)` in "Configuration" +4. Ensure that the "Create App Package" checkbox is enabled +5. In "JDK Options" be sure to select "JDK 8" in the "JDK Version" dropdown. + +![Android Build Step 2](images/android-build-step2.png) + +### Download the keystore to sign the build + +** Note** This require you have a valid keystore. Refer to [this Xamarin article](https://developer.xamarin.com/guides/android/deployment,_testing,_and_metrics/publishing_an_application/part_2_-_signing_the_android_application_package/) for instructions on how create one, using Visual Studio and Xamarin. Or if you prefer, you can read [how use the Android SDK tools to create a keystore](https://developer.android.com/studio/publish/app-signing.html). + +This build assumes the keystore is stored somewhere in internet. Beware on where you store your keystores! Keem them safe and privately. Always consider other possible alternatives on where store the keycert: + +1. Store in the source control repository, **assuming it's private**. For public repositories this option is discarded +2. Store in the build agent. If you use a custom VSTS build agent, store the keycert files locally in the agent. This is simple and secure. +3. Store in internet. If this is the case, **protect the resource**. You can be forced to use this option if your repository is public *and* you use the VSTS hosted agent. + +Add a task "Download file" (**Note:** this task is installed [through a VSTS extension](https://marketplace.visualstudio.com/items?itemName=automagically.DownloadFile)) with following configuration: + +1. `$(keystore.url)$(keystore.name)` in "File URL" +2. `$(Build.SourcesDirectory)` in "Destination Folder" + +Fill the "Credentials" section accordly. + +![Android Build Step 3](images/android-build-step3.png) + +**Note:** You can, of course, use any other way to download the file (like a Powershell task). + +### Signing the APK + +Add a "Android Signing" task with following configuation: + +1. `$(build.binariesdirectory)/$(BuildConfiguration)/*.apk` in "APK Files" +2. Ensure the checkbox "Sign the APK" is checked +3. `$(Build.SourcesDirectory)\$(keystore.name)` in "Keystore file". This location has to be where the keystore is. If you downloaded it using a previous task (as our example), use the same value. If keystore is physically in the VSTS agent you can use the filepath. +4. `$(keystore.pwd)` in "Keystore Password" +5. `$(keystore.alias)` in "Keystore Alias" +6. `$(key.pwd)` in "Key password". +7. `-verbose` in "Jarsigner Arguments" +7. Ensure the checkbox "Zipalign" is checked. + +![Android Build Step 4](images/android-build-step4.png) + +### Publishing build artifact + +Add a "Publish Build Artifacts" task, with following configuration: + +1. `$(build.binariesdirectory)/$(BuildConfiguration)` in "Path to publish" +2. `drop` in "Artifact Name" +3. `Server` in "Artifact Type" + +![Android Build Step 5](images/android-build-step5.png) + +## Variables + +You need to setup the following variables: + +1. `keystore.pwd` -> Password of the keystore +2. `keystore.alias` -> Alias of the keystore +3. `keystore.url` -> Full URL of the keystore +4. `key.pwd` -> Password of the key + diff --git a/azure-docs/builds/xamarin-iOS.md b/azure-docs/builds/xamarin-iOS.md new file mode 100644 index 000000000..a47a880f3 --- /dev/null +++ b/azure-docs/builds/xamarin-iOS.md @@ -0,0 +1,63 @@ +# Xamarin iOS Build + +Follow these steps to create a VSTS build for your eShopOnContainers app (iOS) + +**Note**: This document assumes basic knowledge about creating builds and configuring external VSTS connections + +## Creating the build + +Despite the _"Get Sources"_ task there are three tasks more in the build: + +1. Build Xamarin iOS Project +2. Copy generated packages +3. Publish the build artifact. + +![iOS Build Steps](images/ios-build.png) + +Let's discuss each of them. + +### Build the project + +Add a "Xamarin iOS" task with following configuration: + +1. `eShopOnContainers-iOS.sln` in "Solution". This solution has been created ex professo for the build. +2. Ensure that the "Create App Package" checkbox is enabled + +**About signing & Provisioning section** + +In order to deploy your app to a physical device you must sign it using a certificate with a provisioning profile. Refer to [this blog +post of the Xamarin team](https://blog.xamarin.com/continuous-integration-for-ios-apps-with-visual-studio-team-services/) for more info. + +Basically you have three options for setting the certificate (p12 file) and the provisioning profile: + +1. Use MacInCloud VSTS agent and setup the p12 file and provisioning profile in the setup [https://blogs.msdn.microsoft.com/visualstudioalm/2015/11/18/macincloud-visual-studio-team-services-build-and-improvements-to-ios-build-support/](https://blogs.msdn.microsoft.com/visualstudioalm/2015/11/18/macincloud-visual-studio-team-services-build-and-improvements-to-ios-build-support/) +2. Use a custom mac machine with the certificate and provisioning profile installed. In this case you don't have to do anything else. +3. Have the p12 file and the provisioning profile reachable on somewhere + +If you choose option 3, you need to download the certificate and the provisioning profile into the build agent (using a previous build task). +Once downloaded two files, you have to specify the location of both in the "Signing & Provisioning Section". + +![iOS Build Step 1](images/ios-build-step1.png) + +### Copy generated files to output folder + +Add a "Copy files" task with following configuration: + +1. `src/Mobile/eShopOnContainers/eShopOnContainers.iOS/bin/iPhone/$(BuildConfiguration)` in "Source Folder" +2. `**/*.ipa` in "Contents" +3. `$(Build.ArtifactStagingDirectory)` in "Target Folder" +4. Ensure that "Clean Target folder" (under "Advanced" section) is checked + +This way we copy the generated IPA in the _Build.ArtifactStagingDirectory_ folder (and remove any previous IPA generated by a previous build). + +![iOS Build Step 2](images/ios-build-step2.png) + +### Publishing build artifact + +Add a "Publish Build Artifacts" task, with following configuration: + +1. `$(Build.ArtifactStagingDirectory)` in "Path to publish" +2. `drop` in "Artifact Name" +3. `Server` in "Artifact Type" + +![Android Build Step 3](images/ios-build-step3.png) diff --git a/azure-docs/readme.md b/azure-docs/readme.md new file mode 100644 index 000000000..f7a60b5b3 --- /dev/null +++ b/azure-docs/readme.md @@ -0,0 +1,6 @@ +# Azure Related Documentation + +## Builds and releases + +1. [VSTS build for Xamarin App (Android)](builds/xamarin-android.md) +2. [VSTS build for Xamarin App (iOS)](builds/xamarin-iOS.md) diff --git a/cli-linux/run.sh b/cli-linux/run.sh new file mode 100644 index 000000000..aaeb164fa --- /dev/null +++ b/cli-linux/run.sh @@ -0,0 +1,7 @@ +#!/bin/bash +docker stop $(docker ps -a -q) +docker rm $(docker ps -a -q) +docker images |grep -v REPOSITORY|awk '{print $1}'|xargs -L1 docker pull +export ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP=$(curl ipinfo.io/ip) +docker-compose -f docker-compose.images.yml -f docker-compose.prod.yml up -d --force-recreate + diff --git a/deploy/az/cosmos/deploycosmos.json b/deploy/az/cosmos/deploycosmos.json new file mode 100644 index 000000000..8c03983a2 --- /dev/null +++ b/deploy/az/cosmos/deploycosmos.json @@ -0,0 +1,32 @@ +{ + "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "name": { + "type": "String" + } + }, + "variables": { + "name": "[concat(parameters('name'), uniqueString(resourceGroup().id))]", + "location":"[resourceGroup().location]" + }, + "resources": [ + { + "type": "Microsoft.DocumentDb/databaseAccounts", + "kind": "MongoDB", + "name": "[variables('name')]", + "apiVersion": "2015-04-08", + "location": "[variables('location')]", + "properties": { + "databaseAccountOfferType": "Standard", + "locations": [ + { + "id": "[concat(variables('name'), '-', variables('location'))]", + "failoverPriority": 0, + "locationName": "[variables('location')]" + } + ] + } + } + ] +} \ No newline at end of file diff --git a/deploy/az/cosmos/deploycosmos.parameters.json b/deploy/az/cosmos/deploycosmos.parameters.json new file mode 100644 index 000000000..725bb7cf9 --- /dev/null +++ b/deploy/az/cosmos/deploycosmos.parameters.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "name": { + "value": "eshop-nosql" + } + } +} \ No newline at end of file diff --git a/deploy/az/create-resources.cmd b/deploy/az/create-resources.cmd new file mode 100644 index 000000000..bd27efe3e --- /dev/null +++ b/deploy/az/create-resources.cmd @@ -0,0 +1,23 @@ +@echo off +if %1.==. GOTO error +if %2.==. GOTO error +if NOT %3.==-c. GOTO deployresources +if %4.==. GOTO error +echo Creating resource group %2 in '%4' +call az group create --name %2 --location %4 +:deployresources +echo Deploying ARM template '%1.json' in resource group %2 +call az group deployment create --resource-group %2 --parameters @%1.parameters.json --template-file %1.json +GOTO end +:error +echo. +echo Usage: +echo create-resources arm-file resource-group-name [-c location] +echo arm-file: Path to ARM template WITHOUT .json extension. An parameter file with same name plus '.parameters' MUST exist in same folde +echo resource-grop-name: Name of the resource group to use or create +echo -c: If appears means that resource group must be created. If -c is specified, must use enter location +echo. +echo Examples: +echo create-resources path_and_filename testgroup (Deploys path_and_filename.json with parameters specified in path_and_filename.parameters.json file). +echo create-resources path_and_filename newgroup -c westus (Deploys path_and_filename.json (with parameters specified in path_and_filename.parameters.json file) in a NEW resource group named newgroup in the westus location) +:end diff --git a/deploy/az/readme.md b/deploy/az/readme.md new file mode 100644 index 000000000..cee4581cb --- /dev/null +++ b/deploy/az/readme.md @@ -0,0 +1,20 @@ +# Deploying resources using create-resources script + +The `create-resources` script is a basic script to allow easy deployment of one ARM template in one resource group. You can deploy to an existing resource group or to create one. + +## Deploying to a existing resource group + +Just type `create-resources path-to-arm-template resourcegroup`. Called this way the script will: + +1. Search for `path-to-arm-template.json` and `path-to-arm-template.parameters.json` files +2. If they exist, will deploy them in the `resourcegroup` specified (that has to exist). + +## Deploying to a new resource group + +Just type `create-resources path-to-arm-template resourcegroup -c location`. Called this way the script will: + +1. Search for `path-to-arm-template.json` and `path-to-arm-template.parameters.json` files +2. If they exist, will create the `resourcegroup` specified in the `location` specified. +3. Finally will deploy `path-to-arm-template.json` and `path-to-arm-template.parameters.json` files in the `resourcegroup` + + diff --git a/deploy/az/redis/readme.md b/deploy/az/redis/readme.md new file mode 100644 index 000000000..093a9af14 --- /dev/null +++ b/deploy/az/redis/readme.md @@ -0,0 +1,31 @@ +# Deploying Redis Cache + +The ARM template `redisdeploy.json` and its parameter file (`redisdeploy.parameters.json`) are used to deploy following resources: + +1. One Redis Cache + +## Editing sbusdeploy.parameters.json file + +You can edit the `redisdeploy.parameters.parameters.json` file to set your values, but is not needed. The only parameter than can +be set is: + +1. `namespaceprefix` is a string that is used to create the Redis namespace. ARM script creates unique values by appending a unique string to this parameter value, so you can leave the default value. + +## Deploy the template + +Once parameter file is edited you can deploy it using [create-resources script](../readme.md). + +i. e. if you are in windows, to deploy sql databases in a new resourcegroup located in westus, go to `deploy\az` folder and type: + +``` +create-resources.cmd redis\redisdeploy newResourceGroup -c westus +``` + + + + + + + + + diff --git a/deploy/az/redis/redisdeploy.json b/deploy/az/redis/redisdeploy.json new file mode 100644 index 000000000..04b53a3b6 --- /dev/null +++ b/deploy/az/redis/redisdeploy.json @@ -0,0 +1,42 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "namespaceprefix": { + "type": "string", + "metadata": { + "description": "Name of the Redis namespace" + } + } + }, + "variables": { + "location": "[resourceGroup().location]", + "namespaceprefix": "[concat(parameters('namespaceprefix'), uniqueString(resourceGroup().id))]", + "sbVersion": "2016-04-01" + }, + "resources": [ + { + "type": "Microsoft.Cache/Redis", + "name": "[variables('namespaceprefix')]", + "apiVersion": "[variables('sbVersion')]", + "location": "[variables('location')]", + "scale": null, + "properties": { + "redisVersion": "3.2.7", + "sku": { + "name": "Standard", + "family": "C", + "capacity": 1 + }, + "enableNonSslPort": true, + "redisConfiguration": { + "maxclients": "1000", + "maxmemory-reserved": "50", + "maxfragmentationmemory-reserved": "50", + "maxmemory-policy": "volatile-lru", + "maxmemory-delta": "50" + } + } + } + ] +} \ No newline at end of file diff --git a/deploy/az/redis/redisdeploy.parameters.json b/deploy/az/redis/redisdeploy.parameters.json new file mode 100644 index 000000000..42d2e470e --- /dev/null +++ b/deploy/az/redis/redisdeploy.parameters.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "namespaceprefix": { + "value": "eshopredis" + } + } +} \ No newline at end of file diff --git a/deploy/az/servicebus/readme.md b/deploy/az/servicebus/readme.md new file mode 100644 index 000000000..3ed8e8a0e --- /dev/null +++ b/deploy/az/servicebus/readme.md @@ -0,0 +1,33 @@ +# Deploying Azure Service Bus + +The ARM template `sbusdeploy.json` and its parameter file (`sbusdeploy.parameters.json`) are used to deploy following resources: + +1. One Service Bus namespace +2. One Service Bus +3. Subscriptions used by application + +## Editing sbusdeploy.parameters.json file + +You can edit the `sbusdeploy.parameters.parameters.json` file to set your values, but is not needed. The only parameter than can +be set is: + +1. `namespaceprefix` is a string that is used to create the namespace. ARM script creates unique values by appending a unique string to this parameter value, so you can leave the default value. + +## Deploy the template + +Once parameter file is edited you can deploy it using [create-resources script](../readme.md). + +i. e. if you are in windows, to deploy sql databases in a new resourcegroup located in westus, go to `deploy\az` folder and type: + +``` +create-resources.cmd servicebus\sbusdeploy newResourceGroup -c westus +``` + + + + + + + + + diff --git a/deploy/az/servicebus/sbusdeploy.json b/deploy/az/servicebus/sbusdeploy.json new file mode 100644 index 000000000..5f6ce3c90 --- /dev/null +++ b/deploy/az/servicebus/sbusdeploy.json @@ -0,0 +1,145 @@ +{ + "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "namespaceprefix": { + "type": "string", + "metadata": { + "description": "Name of the Service Bus namespace" + } + } + }, + "variables": { + "serviceBusTopicName": "eshop_event_bus", + "BasketSubscriptionName": "Basket", + "CatalogSubscriptionName": "Catalog", + "OrderingSubscriptionName": "Ordering", + "location": "[resourceGroup().location]", + "sbVersion": "2015-08-01", + "defaultSASKeyName": "Root", + "namespace":"[concat(parameters('namespaceprefix'), uniqueString(resourceGroup().id))]", + "authRuleResourceId": "[resourceId('Microsoft.ServiceBus/namespaces/topics/authorizationRules', variables('namespace'), variables('serviceBusTopicName'), variables('defaultSASKeyName'))]" + }, + "resources": [ + { + "apiVersion": "[variables('sbVersion')]", + "name": "[variables('namespace')]", + "type": "Microsoft.ServiceBus/Namespaces", + "location": "[variables('location')]", + "sku": { + "name": "Standard", + "tier": "Standard" + }, + "resources": [ + { + "apiVersion": "[variables('sbVersion')]", + "name": "[variables('serviceBusTopicName')]", + "type": "Topics", + "dependsOn": [ + "[concat('Microsoft.ServiceBus/namespaces/', variables('namespace'))]" + ], + "properties": { + "path": "[variables('serviceBusTopicName')]", + "defaultMessageTimeToLive": "14.00:00:00", + "maxSizeInMegabytes": 1024, + "requiresDuplicateDetection": false, + "enableBatchedOperations": true, + "sizeInBytes": 0, + "filteringMessagesBeforePublishing": false, + "isAnonymousAccessible": false, + "status": "Active", + "supportOrdering": false, + "autoDeleteOnIdle": "10675199.02:48:05.4775807", + "enablePartitioning": true, + "isExpress": false, + "enableSubscriptionPartitioning": false, + "enableExpress": false + }, + "resources": [ + { + "type": "AuthorizationRules", + "name": "[variables('defaultSASKeyName')]", + "apiVersion": "[variables('sbVersion')]", + "properties": { + "rights": [ + "Manage", + "Send", + "Listen" + ] + }, + "dependsOn": [ + "[variables('serviceBusTopicName')]" + ] + }, + { + "apiVersion": "[variables('sbVersion')]", + "name": "[variables('BasketSubscriptionName')]", + "type": "Subscriptions", + "dependsOn": [ + "[variables('serviceBusTopicName')]" + ], + "properties": { + "lockDuration": "00:00:30", + "requiresSession": false, + "defaultMessageTimeToLive": "14.00:00:00", + "deadLetteringOnMessageExpiration": true, + "deadLetteringOnFilterEvaluationExceptions": true, + "maxDeliveryCount": 10, + "enableBatchedOperations": false, + "status": "Active", + "autoDeleteOnIdle": "10675199.02:48:05.4775807", + "entityAvailabilityStatus": "Available" + } + }, + { + "apiVersion": "[variables('sbVersion')]", + "name": "[variables('OrderingSubscriptionName')]", + "type": "Subscriptions", + "dependsOn": [ + "[variables('serviceBusTopicName')]" + ], + "properties": { + "lockDuration": "00:00:30", + "requiresSession": false, + "defaultMessageTimeToLive": "14.00:00:00", + "deadLetteringOnMessageExpiration": true, + "deadLetteringOnFilterEvaluationExceptions": true, + "maxDeliveryCount": 10, + "enableBatchedOperations": false, + "status": "Active", + "autoDeleteOnIdle": "10675199.02:48:05.4775807", + "entityAvailabilityStatus": "Available" + } + }, + { + "apiVersion": "[variables('sbVersion')]", + "name": "[variables('CatalogSubscriptionName')]", + "type": "Subscriptions", + "dependsOn": [ + "[variables('serviceBusTopicName')]" + ], + "properties": { + "lockDuration": "00:00:30", + "requiresSession": false, + "defaultMessageTimeToLive": "14.00:00:00", + "deadLetteringOnMessageExpiration": true, + "deadLetteringOnFilterEvaluationExceptions": true, + "maxDeliveryCount": 10, + "enableBatchedOperations": false, + "status": "Active", + "autoDeleteOnIdle": "10675199.02:48:05.4775807", + "entityAvailabilityStatus": "Available" + } + } + ] + } + ] + } + ], + "outputs": { + "NamespaceConnectionString": { + "type": "string", + "value": "[listkeys(variables('authRuleResourceId'), variables('sbVersion')).primaryConnectionString]" + } + } +} \ No newline at end of file diff --git a/deploy/az/servicebus/sbusdeploy.parameters.json b/deploy/az/servicebus/sbusdeploy.parameters.json new file mode 100644 index 000000000..f14b5329d --- /dev/null +++ b/deploy/az/servicebus/sbusdeploy.parameters.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "namespaceprefix": { + "value": "eshopsb" + } + } +} diff --git a/deploy/az/sql/readme.md b/deploy/az/sql/readme.md new file mode 100644 index 000000000..0359fb727 --- /dev/null +++ b/deploy/az/sql/readme.md @@ -0,0 +1,36 @@ +# Deploying SQL Server & SQL Databases + +The ARM template `sqldeploy.json` and its parameter file (`sqldeploy.parameters.json`) are used to deploy following resources: + +1. One SQL Server +2. Three SQL databases (for ordering, catalog and identity) services. +3. Firewall rules to **allow access from any IP to SQL Server**. This allows easy management, but is not desired in production environments. + +## Editing sqldeploy.parameters.json file + +You **must** edit the `sqldeploy.parameters.json` file to set login and password of the admin user. + +1. `sql_server` is a object parameter that contains the sql server name and the database names. You can leave default values if you want. +2. `admin` is a string with the admin logon. You MUST provide a valid value +3. `adminpwd` is a string with the admin password. You MUST provide a valid value + +ARM script ensures uniqueness of the SQL server created by appending one unique string in its name (defined in the `sql_server.name` parameter). + +## Deploy the template + +Once parameter file is edited you can deploy it using [create-resources script](../readme.md). +i. e. if you are in windows, to deploy sql databases in a new resourcegroup located in westus, go to `deploy\az` folder and type: + +``` +create-resources.cmd sql\sqldeploy newResourceGroup -c westus +``` + + + + + + + + + + diff --git a/deploy/az/sql/sqldeploy.json b/deploy/az/sql/sqldeploy.json new file mode 100644 index 000000000..397c94ad6 --- /dev/null +++ b/deploy/az/sql/sqldeploy.json @@ -0,0 +1,123 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "sql_server": { + "type": "object" + }, + "admin": { + "type": "string" + }, + "adminpwd": { + "type": "string" + } + }, + "variables": { + "sql_server_name": "[concat(parameters('sql_server').name, '-', uniqueString(resourceGroup().id))]", + "admin": "[parameters('admin')]", + "adminpwd": "[parameters('adminpwd')]" + }, + "resources": [ + { + "type": "Microsoft.Sql/servers", + "name": "[variables('sql_server_name')]", + "apiVersion": "2014-04-01-preview", + "location": "[resourceGroup().location]", + "properties": { + "administratorLogin": "[variables('admin')]", + "administratorLoginPassword": "[variables('adminpwd')]", + "version": "12.0" + }, + "resources": [ + { + "type": "databases", + "name": "[parameters('sql_server').dbs.ordering]", + "apiVersion": "2014-04-01-preview", + "location": "[resourceGroup().location]", + "properties": { + "edition": "Standard", + "collation": "SQL_Latin1_General_CP1_CI_AS", + "maxSizeBytes": "1073741824", + "requestedServiceObjectiveName": "S1" + }, + "dependsOn": [ + "[concat('Microsoft.Sql/servers/', variables('sql_server_name'))]" + ] + }, + { + "type": "databases", + "name": "[parameters('sql_server').dbs.identity]", + "apiVersion": "2014-04-01-preview", + "location": "[resourceGroup().location]", + "properties": { + "edition": "Standard", + "collation": "SQL_Latin1_General_CP1_CI_AS", + "maxSizeBytes": "1073741824", + "requestedServiceObjectiveName": "S1" + }, + "dependsOn": [ + "[concat('Microsoft.Sql/servers/', variables('sql_server_name'))]" + ] + }, + { + "type": "databases", + "name": "[parameters('sql_server').dbs.catalog]", + "apiVersion": "2014-04-01-preview", + "location": "[resourceGroup().location]", + "properties": { + "edition": "Standard", + "collation": "SQL_Latin1_General_CP1_CI_AS", + "maxSizeBytes": "1073741824", + "requestedServiceObjectiveName": "S1" + }, + "dependsOn": [ + "[concat('Microsoft.Sql/servers/', variables('sql_server_name'))]" + ] + }, + { + "type": "databases", + "name": "[parameters('sql_server').dbs.marketing]", + "apiVersion": "2014-04-01-preview", + "location": "[resourceGroup().location]", + "properties": { + "edition": "Standard", + "collation": "SQL_Latin1_General_CP1_CI_AS", + "maxSizeBytes": "1073741824", + "requestedServiceObjectiveName": "S1" + }, + "dependsOn": [ + "[concat('Microsoft.Sql/servers/', variables('sql_server_name'))]" + ] + }, + { + "type": "firewallrules", + "name": "AllowAllWindowsAzureIps", + "apiVersion": "2014-04-01-preview", + "location": "[resourceGroup().location]", + "properties": { + "startIpAddress": "0.0.0.0", + "endIpAddress": "0.0.0.0" + }, + "dependsOn": [ + "[concat('Microsoft.Sql/servers/', variables('sql_server_name'))]" + ] + }, + { + "type": "firewallrules", + "name": "AllConnectionsAllowed", + "apiVersion": "2014-04-01-preview", + "location": "[resourceGroup().location]", + "properties": { + "startIpAddress": "0.0.0.0", + "endIpAddress": "255.255.255.255" + }, + "dependsOn": [ + "[concat('Microsoft.Sql/servers/', variables('sql_server_name'))]" + ] + } + ] + } + ], + "outputs": { + } +} diff --git a/deploy/az/sql/sqldeploy.parameters.json b/deploy/az/sql/sqldeploy.parameters.json new file mode 100644 index 000000000..982e78f4c --- /dev/null +++ b/deploy/az/sql/sqldeploy.parameters.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "sql_server": { + "value": { + "name": "eshopsql", + "dbs": { + "ordering": "orderingdb", + "identity": "identitydb", + "catalog": "catalogdb", + "marketing": "marketingdb" + } + } + }, + "admin": { + "value": null + }, + "adminpwd": { + "value": null + } + } +} \ No newline at end of file diff --git a/deploy/az/storage/deploystorage.json b/deploy/az/storage/deploystorage.json new file mode 100644 index 000000000..e3fced6b2 --- /dev/null +++ b/deploy/az/storage/deploystorage.json @@ -0,0 +1,91 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "catalogstorage": { + "type": "string" + }, + "profileName" : { + "type": "string" + } + }, + "variables": { + "catalogstorage": "[concat(parameters('catalogstorage'), uniqueString(resourceGroup().id))]", + "endpointName": "[concat('endpoint-', uniqueString(resourceGroup().id))]", + "profileName": "[parameters('profileName')]" + }, + "resources": [ + { + "type": "Microsoft.Storage/storageAccounts", + "name": "[variables('catalogstorage')]", + "apiVersion": "2016-01-01", + "location": "[resourceGroup().location]", + "tags": { + "displayName": "[variables('catalogstorage')]" + }, + "sku": { + "name": "Standard_LRS" + }, + "kind": "Storage" + }, + { + "name": "[variables('profileName')]", + "type": "Microsoft.Cdn/profiles", + "location": "[resourceGroup().location]", + "apiVersion": "2016-04-02", + "tags": { + "displayName": "[variables('profileName')]" + }, + "sku": { + "name": "Standard_Verizon" + }, + "resources": [ + { + "apiVersion": "2016-04-02", + "name": "[variables('endpointName')]", + "type": "endpoints", + "dependsOn": [ + "[variables('profileName')]", + "[variables('catalogstorage')]" + ], + "location": "[resourceGroup().location]", + "tags": { + "displayName": "[variables('endpointName')]" + }, + "properties": { + "originHostHeader": "[replace(replace(reference(resourceId('Microsoft.Storage/storageAccounts', variables('catalogstorage')),'2015-06-15' ).primaryEndpoints.blob,'https://',''),'/','')]", + "isHttpAllowed": true, + "isHttpsAllowed": true, + "queryStringCachingBehavior": "IgnoreQueryString", + "contentTypesToCompress": [ + "text/plain", + "text/html", + "text/css", + "application/x-javascript", + "text/javascript" + ], + "isCompressionEnabled": "True", + "origins": [ + { + "name": "origin1", + "properties": { + "hostName": "[replace(replace(reference(resourceId('Microsoft.Storage/storageAccounts', variables('catalogstorage')),'2015-06-15' ).primaryEndpoints.blob,'https://',''),'/','')]" + } + } + ] + } + } + ] + } + ], + "outputs": { + "hostName": { + "type": "string", + "value": "[reference(resourceId('Microsoft.cdn/profiles/endpoints', variables('profileName'), variables('endpointName'))).hostName]" + }, + "originHostHeader": { + "type": "string", + "value": "[reference(resourceId('Microsoft.cdn/profiles/endpoints', variables('profileName'), variables('endpointName'))).originHostHeader]" + } + } +} \ No newline at end of file diff --git a/deploy/az/storage/deploystorage.parameters.json b/deploy/az/storage/deploystorage.parameters.json new file mode 100644 index 000000000..2c5256a09 --- /dev/null +++ b/deploy/az/storage/deploystorage.parameters.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "catalogstorage": { + "value": "catalog" + }, + "profileName":{ + "value": "eshopcatalog" + } + } +} \ No newline at end of file diff --git a/deploy/az/vms/docker-machine.md b/deploy/az/vms/docker-machine.md new file mode 100644 index 000000000..71cbbd4a7 --- /dev/null +++ b/deploy/az/vms/docker-machine.md @@ -0,0 +1,48 @@ +# Create a VM using docker-machine + +Ensure you are logged in the desired subscription Refer to [this article](https://docs.microsoft.com/en-us/cli/azure/authenticate-azure-cli) for more details. + +1. Use `az account show` to find your subscription id. +2. Use `docker-machine create --driver azure --azure-subscription-id --azure-resource-group --azure-ssh-user ` + +After use `docker-machine create` you'll need to authenticate in Azure (even thought if you are logged using `az`, because this is not an Azure CLI 2.0 command). This command will fully create the VM with all the needed settings to run Docker. + +**Note** Refer to this article with all the [parameters that docker-machine accepts when creating Azure VMs](https://docs.docker.com/machine/drivers/azure/#options) for finding more parameters. + +## Connecting your local environment with docker host running on the VM + +Using docker-machine you control the remote VM from your local development environment (you don't need to use ssh to login to remote VM). + +Connecting your local environment to a remote host is using by setting some environment variables, but the easiest way is to use again the docker-machine command. Just type `docker-machine env machine_name` (where machine_name is the name you gave when you created the VM). That command **do not change anything**, so do'nt do really nothing, but **outputs the environment variables you have to set**. This is the output of the command (running on a windows workstation): + +``` +SET DOCKER_TLS_VERIFY=1 +SET DOCKER_HOST=tcp://104.42.236.237:2376 +SET DOCKER_CERT_PATH=C:\Users\etoma\.docker\machine\machines\ufohost +SET DOCKER_MACHINE_NAME=ufohost +SET COMPOSE_CONVERT_WINDOWS_PATHS=true +REM Run this command to configure your shell: +REM @FOR /f "tokens=*" %i IN ('docker-machine env ufohost') DO @%i +``` + +You have to set all these environment variables, or (as the command suggest) just copy and paste the last line in your terminal. + +Once you did this, your local development machine is connected to VM running Docker on Azure: all docker and docker-compose commands will run in the VM instead of your local Docker machine! + + + + + + + + + + + + + + + + + + diff --git a/deploy/az/vms/linux-vm/linuxvm.json b/deploy/az/vms/linux-vm/linuxvm.json new file mode 100644 index 000000000..5b4778ebe --- /dev/null +++ b/deploy/az/vms/linux-vm/linuxvm.json @@ -0,0 +1,199 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "newStorageAccountName": { + "type": "string", + "metadata": { + "description": "Unique DNS Name for the Storage Account where the Virtual Machine's disks will be placed." + } + }, + "adminUsername": { + "type": "string", + "metadata": { + "description": "Username for the Virtual Machine." + } + }, + "adminPassword": { + "type": "securestring", + "metadata": { + "description": "Password for the Virtual Machine." + } + }, + "dnsNameForPublicIP": { + "type": "string", + "metadata": { + "description": "Unique DNS Name for the Public IP used to access the Virtual Machine." + } + }, + "ubuntuOSVersion": { + "type": "string", + "defaultValue": "14.04.4-LTS", + "metadata": { + "description": "The Ubuntu version for deploying the Docker containers. This will pick a fully patched image of this given Ubuntu version. Allowed values: 14.04.4-LTS, 15.10, 16.04.0-LTS" + }, + "allowedValues": [ + "14.04.4-LTS", + "15.10", + "16.04.0-LTS" + ] + }, + "VMName": { + "type": "string", + "metadata": { + "description": "Name of VM in Azure" + } + } + }, + "variables": { + "newStorageAccountName": "[take(concat(parameters('newStorageAccountName'), uniqueString(resourceGroup().id)), 23)]", + "dnsNameForPublicIP": "[concat(parameters('dnsNameForPublicIP'), uniqueString(resourceGroup().id))]", + "imagePublisher": "Canonical", + "imageOffer": "UbuntuServer", + "OSDiskName": "osdiskfordockersimple", + "nicName": "myVMNicD", + "extensionName": "DockerExtension", + "addressPrefix": "10.0.0.0/16", + "subnetName": "Subnet", + "subnetPrefix": "10.0.0.0/24", + "storageAccountType": "Standard_LRS", + "publicIPAddressName": "myPublicIPD", + "publicIPAddressType": "Dynamic", + "vmStorageAccountContainerName": "vhds", + "vmName": "[parameters('VMName')]", + "vmSize": "Standard_F1", + "virtualNetworkName": "MyVNETD", + "vnetID": "[resourceId('Microsoft.Network/virtualNetworks',variables('virtualNetworkName'))]", + "subnetRef": "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]" + }, + "resources": [ + { + "type": "Microsoft.Storage/storageAccounts", + "name": "[variables('newStorageAccountName')]", + "apiVersion": "2015-05-01-preview", + "location": "[resourceGroup().location]", + "properties": { + "accountType": "[variables('storageAccountType')]" + } + }, + { + "apiVersion": "2015-05-01-preview", + "type": "Microsoft.Network/publicIPAddresses", + "name": "[variables('publicIPAddressName')]", + "location": "[resourceGroup().location]", + "properties": { + "publicIPAllocationMethod": "[variables('publicIPAddressType')]", + "dnsSettings": { + "domainNameLabel": "[variables('dnsNameForPublicIP')]" + } + } + }, + { + "apiVersion": "2015-05-01-preview", + "type": "Microsoft.Network/virtualNetworks", + "name": "[variables('virtualNetworkName')]", + "location": "[resourceGroup().location]", + "properties": { + "addressSpace": { + "addressPrefixes": [ + "[variables('addressPrefix')]" + ] + }, + "subnets": [ + { + "name": "[variables('subnetName')]", + "properties": { + "addressPrefix": "[variables('subnetPrefix')]" + } + } + ] + } + }, + { + "apiVersion": "2015-05-01-preview", + "type": "Microsoft.Network/networkInterfaces", + "name": "[variables('nicName')]", + "location": "[resourceGroup().location]", + "dependsOn": [ + "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]", + "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]" + ], + "properties": { + "ipConfigurations": [ + { + "name": "ipconfig1", + "properties": { + "privateIPAllocationMethod": "Dynamic", + "publicIPAddress": { + "id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]" + }, + "subnet": { + "id": "[variables('subnetRef')]" + } + } + } + ] + } + }, + { + "apiVersion": "2015-05-01-preview", + "type": "Microsoft.Compute/virtualMachines", + "name": "[variables('vmName')]", + "location": "[resourceGroup().location]", + "dependsOn": [ + "[concat('Microsoft.Storage/storageAccounts/', variables('newStorageAccountName'))]", + "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]" + ], + "properties": { + "hardwareProfile": { + "vmSize": "[variables('vmSize')]" + }, + "osProfile": { + "computerName": "[variables('vmName')]", + "adminUsername": "[parameters('adminUsername')]", + "adminPassword": "[parameters('adminPassword')]" + }, + "storageProfile": { + "imageReference": { + "publisher": "[variables('imagePublisher')]", + "offer": "[variables('imageOffer')]", + "sku": "[parameters('ubuntuOSVersion')]", + "version": "latest" + }, + "osDisk": { + "name": "osdisk1", + "vhd": { + "uri": "[concat('http://',variables('newStorageAccountName'),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/',variables('OSDiskName'),'.vhd')]" + }, + "caching": "ReadWrite", + "createOption": "FromImage" + } + }, + "networkProfile": { + "networkInterfaces": [ + { + "id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]" + } + ] + } + } + }, + { + "type": "Microsoft.Compute/virtualMachines/extensions", + "name": "[concat(variables('vmName'),'/', variables('extensionName'))]", + "apiVersion": "2015-05-01-preview", + "location": "[resourceGroup().location]", + "dependsOn": [ + "[concat('Microsoft.Compute/virtualMachines/', variables('vmName'))]" + ], + "properties": { + "publisher": "Microsoft.Azure.Extensions", + "type": "DockerExtension", + "typeHandlerVersion": "1.0", + "autoUpgradeMinorVersion": true, + "settings": { } + } + } + ] +} + diff --git a/deploy/az/vms/linux-vm/linuxvm.parameters.json b/deploy/az/vms/linux-vm/linuxvm.parameters.json new file mode 100644 index 000000000..d34dfd1d9 --- /dev/null +++ b/deploy/az/vms/linux-vm/linuxvm.parameters.json @@ -0,0 +1,7 @@ +{ + "newStorageAccountName": { "value": "eshopsrvmvstorage" }, + "adminUsername": { "value": "eshop" }, + "adminPassword": { "value": "Pass@word" }, + "dnsNameForPublicIP": { "value": "eshop-srv" }, + "VMName": {"value": "MyDockerVM2"} +} diff --git a/deploy/az/vms/plain-vm.md b/deploy/az/vms/plain-vm.md new file mode 100644 index 000000000..4e06ed0d3 --- /dev/null +++ b/deploy/az/vms/plain-vm.md @@ -0,0 +1,77 @@ +# Deploy a VM to run the services + +Follow these instructions to deploy a Linux-based VM with the Docker Host installed, or a VM with Windows Server 2016 plus +windows containers and Docker Daemon. + +**Note**: Use this option, only if you want to provide an environment using images pulled from DockerHub (for example, to create a test environment). If you want to +be able to deploy images built by yourself (but not pushed to DockerHub) follow the [instructions about using docker-machine](./docker-machine.md). + +You can use this machine to install the microservices and having a "development" environment (useful to develop and test the client apps). + +Please note that this deployment is not a production deployment. In a production-based scenario, you should deploy all containers in ACS. + +## Create the VM + +Ensure you are logged in the desired subscription (use `az login` and `az account set` if needed. Refer to [this article](https://docs.microsoft.com/en-us/cli/azure/authenticate-azure-cli) for more details. + +Go to `linux-vm` or `win-vm` folder (based on if you want a Linux or Windows VM). Then: + +1. Edit the file `linuxvm.parameters.json` or `windowsvm.parameters.json` (based on what VM do you want to create) with your desired values +2. Run the [create-resources script](../readme.md) to deploy the desired template (`linux-vm/linuxvm.json` or `win-vm/windowsvm.json`). + +I. e. if you are in Windows and want to deploy a linux based VM, in a new resourcegroup located in westus, go to `deploy\az` folder and type: + +``` +create-resources.cmd vms\linux-vm\linuxvm newResourceGroup -c westus +``` + +**Note:** To avoid errors, ARM template used generates unique names for: + +1. VM used storage +2. Public DNS + +Those public names are based on the parameters set in the parameters file. + +### The parameters file (linuxvm.parameters.json or winsowsvm.parameters.json) + +Both files are identical and contains the minimum set of parameters needed by the ARM template to deploy the VM. ARM template accepts some other parameters (set with default values). Look the template for more info. + +The parameters defined are: + +1. `newStorageAccountName`: Name of the storage created for the VM. To ensure uniqueness a unique suffix will be added to this value. +2. `adminUsername`: Admin login +3. `adminPassword`: Admin password +4. `dnsNameForPublicIP`: DNS of the VM. To ensure uniqueness a unique suffix will be added to this value. +5. `VMName`: Name of the VM inside Azure + +## Finding the IP and DNS of the VM + +To find the IP and FQDN of the VM you can type `az vm list --resource-group --output table --show-details` (where resourcegroup is the +name of the resourcegroup where you created the VM). This command will generate output like: + +``` +Name ResourceGroup PowerState PublicIps Fqdns Location +---------- --------------- ------------ ------------- ------------------------------------------------ ---------- +MyDockerVM MyResourceGroup VM running xx.xx.xxx.xxx eshop-srvxxxxxxxxxxxxx.westus.cloudapp.azure.com westus +``` + +You can use this information to connect your new VM. + +## Deploy services in the VM + +We are providing public images of the services in DockerHub (https://hub.docker.com/u/eshop/). To use these images, just create a folder in the VM and copy +following files to it (those files are in the root of the repo): + +1. `docker-compose.nobuild.yml` +2. `docker-compose.prod.yml` + +**Note:** The `docker-compose.nobuild.yml` is just a version of the `docker-compose.yml` without the `build` section. Is neede due [docker-compose bug](https://github.com/docker/compose/issues/2945). + +Then log into the VM and run the command `docker-compose -f docker-compose.nobuild.yml -f docker-compose.prod.yml up --no-build -d` to start all the microservices. + + + + + + + diff --git a/deploy/az/vms/readme.md b/deploy/az/vms/readme.md new file mode 100644 index 000000000..25085f75c --- /dev/null +++ b/deploy/az/vms/readme.md @@ -0,0 +1,10 @@ +## Create VM with Docker installed + +There are two options for creating VM machines with Docker installed: + +1. [Deploying a Linux VM to run single-server development environment using docker-machine (**Recommended for development environments**)](./docker-machine.md) +2. [Deploying a Linux VM or Windows Server 2016 to run a single-server development environment using ARM template (**Recommended for creating testing environments**)](./plain-vm.md) + +If you want to create a VM for deploying images you build locally, then use the first option. + +If you want to create a VM to run images deployed to DockerHub (to provide some test environment) then use the second option. \ No newline at end of file diff --git a/deploy/az/vms/win-vm/windowsvm.json b/deploy/az/vms/win-vm/windowsvm.json new file mode 100644 index 000000000..78bebdfef --- /dev/null +++ b/deploy/az/vms/win-vm/windowsvm.json @@ -0,0 +1,290 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + + "VMName": { + "type": "string", + "metadata": { + "description": "This name will also be used to prefix the network security group, storage, virtual network, network card, subnet and public IP address name." + } + }, + + "adminUsername": { + "type": "string", + "metadata": { + "description": "Username for the Virtual Machine." + } + }, + + "adminPassword": { + "type": "securestring", + "metadata": { + "description": "Password for the Virtual Machine." + } + }, + + "dnsNameForPublicIP": { + "type": "string", + "metadata": { + "description": "Unique DNS Name for the Public IP used to access the Virtual Machine." + } + }, + + "newStorageAccountName": { + "type": "string", + "metadata": { + "description": "Storage name for the Virtual Machine." + } + }, + "vmSize": { + "type": "string", + "defaultValue": "Standard_D1", + "metadata": { + "description": "VM Size" + } + } + }, + + "variables": { + "newStorageAccountName": "[take(concat(parameters('newStorageAccountName'), uniqueString(resourceGroup().id)), 23)]", + "dnsNameForPublicIP": "[concat(parameters('dnsNameForPublicIP'), uniqueString(resourceGroup().id))]", + "windowsOSVersion": "2016-Datacenter", + "imagePublisher": "MicrosoftWindowsServer", + "imageOffer": "WindowsServer", + "OSDiskName": "[concat(parameters('VMName'),'_osdisk')]", + "nicName": "[concat(parameters('VMName'),'_nic')]", + "addressPrefix": "10.0.0.0/16", + "subnetName": "[concat(parameters('VMName'),'_subnet')]", + "subnetPrefix": "10.0.0.0/24", + "networkSecurityGroupName": "[concat(parameters('VMName'),'_nsg')]", + "storageAccountType": "Standard_LRS", + "publicIPAddressName": "[concat(parameters('VMName'),'_pubip')]", + "publicIPAddressType": "Dynamic", + "vmStorageAccountContainerName": "vhds", + "apiVersion": "2015-05-01-preview", + "virtualNetworkName": "[concat(parameters('VMName'),'_vnet')]", + "vnetID": "[resourceId('Microsoft.Network/virtualNetworks',variables('virtualNetworkName'))]", + "subnetRef": "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]" + }, + "resources": [ + { + "type": "Microsoft.Network/networkSecurityGroups", + "name": "[variables('networkSecurityGroupName')]", + "apiVersion": "[variables('apiVersion')]", + "location": "[resourceGroup().location]", + "properties": { + "securityRules": [ + { + "name": "HTTP", + "properties": { + "description": "HTTP", + "protocol": "Tcp", + "sourcePortRange": "*", + "destinationPortRange": "80", + "sourceAddressPrefix": "*", + "destinationAddressPrefix": "*", + "access": "Allow", + "priority": 100, + "direction": "Inbound" + } + }, + + { + "name": "RDP", + "properties": { + "description": "RDP", + "protocol": "Tcp", + "sourcePortRange": "*", + "destinationPortRange": "3389", + "sourceAddressPrefix": "*", + "destinationAddressPrefix": "*", + "access": "Allow", + "priority": 200, + "direction": "Inbound" + } + }, + + { + "name": "Docker", + "properties": { + "description": "Docker", + "protocol": "Tcp", + "sourcePortRange": "*", + "destinationPortRange": "2375", + "sourceAddressPrefix": "*", + "destinationAddressPrefix": "*", + "access": "Allow", + "priority": 300, + "direction": "Inbound" + } + } + + ] + } + }, + + { + "type": "Microsoft.Storage/storageAccounts", + "name": "[variables('newStorageAccountName')]", + "apiVersion": "[variables('apiVersion')]", + "location": "[resourceGroup().location]", + "tags": { + "displayName": "StorageAccount" + }, + "properties": { + "accountType": "[variables('storageAccountType')]" + } + }, + + { + "apiVersion": "[variables('apiVersion')]", + "type": "Microsoft.Network/publicIPAddresses", + "name": "[variables('publicIPAddressName')]", + "location": "[resourceGroup().location]", + "tags": { + "displayName": "PublicIPAddress" + }, + "properties": { + "publicIPAllocationMethod": "[variables('publicIPAddressType')]", + "dnsSettings": { + "domainNameLabel": "[tolower(variables('dnsNameForPublicIP'))]" + } + } + }, + + { + "apiVersion": "[variables('apiVersion')]", + "type": "Microsoft.Network/virtualNetworks", + "name": "[variables('virtualNetworkName')]", + "location": "[resourceGroup().location]", + "dependsOn": [ + "[concat('Microsoft.Network/networkSecurityGroups/', variables('networkSecurityGroupName'))]" + ], + "tags": { + "displayName": "VirtualNetwork" + }, + "properties": { + "addressSpace": { + "addressPrefixes": [ + "[variables('addressPrefix')]" + ] + }, + "subnets": [ + { + "name": "[variables('subnetName')]", + "properties": { + "addressPrefix": "[variables('subnetPrefix')]", + "networkSecurityGroup": { + "id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]" + } + } + } + ] + } + }, + + { + "apiVersion": "[variables('apiVersion')]", + "type": "Microsoft.Network/networkInterfaces", + "name": "[variables('nicName')]", + "location": "[resourceGroup().location]", + "tags": { + "displayName": "NetworkInterface" + }, + "dependsOn": [ + "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]", + "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]" + ], + "properties": { + "ipConfigurations": [ + { + "name": "ipconfig1", + "properties": { + "privateIPAllocationMethod": "Dynamic", + "publicIPAddress": { + "id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]" + }, + "subnet": { + "id": "[variables('subnetRef')]" + } + } + } + ] + } + }, + + { + "apiVersion": "[variables('apiVersion')]", + "type": "Microsoft.Compute/virtualMachines", + "name": "[parameters('VMName')]", + "location": "[resourceGroup().location]", + "tags": { + "displayName": "VirtualMachine" + }, + "dependsOn": [ + "[concat('Microsoft.Storage/storageAccounts/', variables('newStorageAccountName'))]", + "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]" + ], + "properties": { + "hardwareProfile": { + "vmSize": "[parameters('vmSize')]" + }, + "osProfile": { + "computername": "[parameters('VMName')]", + "adminUsername": "[parameters('adminUsername')]", + "adminPassword": "[parameters('adminPassword')]" + }, + "storageProfile": { + "imageReference": { + "publisher": "[variables('imagePublisher')]", + "offer": "[variables('imageOffer')]", + "sku": "[variables('windowsOSVersion')]", + "version": "latest" + }, + "osDisk": { + "name": "osdisk", + "vhd": { + "uri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/', variables('newStorageAccountName')), variables('apiVersion')).primaryEndpoints.blob, variables('vmStorageAccountContainerName'),'/',variables('OSDiskName'),'.vhd')]" + }, + "caching": "ReadWrite", + "createOption": "FromImage" + } + }, + "networkProfile": { + "networkInterfaces": [ + { + "id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]" + } + ] + } + }, + "resources": [ + { + "name": "containerConfiguration", + "type": "extensions", + "location": "[resourceGroup().location]", + "apiVersion": "2015-06-15", + "dependsOn": [ + "[concat('Microsoft.Compute/virtualMachines/', parameters('VMName'))]" + ], + "tags": { + "displayName": "containerConfiguration" + }, + "properties": { + "publisher": "Microsoft.Compute", + "type": "CustomScriptExtension", + "typeHandlerVersion": "1.2", + "autoUpgradeMinorVersion": true, + "settings": { + "fileUris": [ + "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/windows-server-containers-preview/azure-containers.ps1" + ], + "commandToExecute": "[concat('powershell.exe -ExecutionPolicy Unrestricted -File azure-containers.ps1 -adminuser ',parameters('adminUsername'))]" + } + } + } + ] + } + ] +} \ No newline at end of file diff --git a/deploy/az/vms/win-vm/windowsvm.parameters.json b/deploy/az/vms/win-vm/windowsvm.parameters.json new file mode 100644 index 000000000..7a2773a54 --- /dev/null +++ b/deploy/az/vms/win-vm/windowsvm.parameters.json @@ -0,0 +1,7 @@ +{ + "newStorageAccountName": { "value": "eshopsrvmvstoragewin" }, + "adminUsername": { "value": "eshop" }, + "adminPassword": { "value": "Pass@word" }, + "dnsNameForPublicIP": { "value": "eshop-srv-win" }, + "VMName": {"value": "eshop-srv-win"} +} diff --git a/deploy/readme.md b/deploy/readme.md new file mode 100644 index 000000000..7d760c6bd --- /dev/null +++ b/deploy/readme.md @@ -0,0 +1,27 @@ +# Deploying Resources On Azure + +## Pre-requisites +1. [Azure CLI 2.0 Installed](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli) +2. Azure subscription created + +Login into your azure subscription by typing `az login` (note that you maybe need to use `az account set` to set the subscription to use). Refer to [this article](https://docs.microsoft.com/en-us/cli/azure/authenticate-azure-cli) for more details + +## Deploying using CLI + +## Deploying Virtual machines to host the services + +1. [Deploying a Linux VM to run single-server development environment using docker-machine (**Recommended for development environments**)](az/vms/docker-machine.md) +2. [Deploying a Linux VM or Windows Server 2016 to run a single-server development environment using ARM template (**Recommended for creating testing environments**)](az/vms/plain-vm.md) + +Using `docker-machine` is the recommended way to create a VM with docker installed. But it is limited to Linux based VMs. + +## Deploying Azure resources used by the services + +1. [Deploying SQL Server and databases](az/sql/readme.md) +2. [Deploying Azure Service Bus](az/servicebus/readme.md) +3. [Deploying Redis Cache](az/redis/readme.md) + + + + + diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 14528ccff..f5ad0c9f3 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -16,9 +16,9 @@ services: environment: - ASPNETCORE_ENVIRONMENT=Development - ASPNETCORE_URLS=http://0.0.0.0:80 - - ConnectionString=basket.data + - ConnectionString=${ESHOP_AZURE_REDIS:-basket.data} - identityUrl=http://identity.api #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105. - - EventBusConnection=rabbitmq + - EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq} ports: - "5103:80" @@ -27,8 +27,8 @@ services: - ASPNETCORE_ENVIRONMENT=Development - ASPNETCORE_URLS=http://0.0.0.0:80 - ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word - - ExternalCatalogBaseUrl=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5101 #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105. - - EventBusConnection=rabbitmq + - PicBaseUrl=${ESHOP_AZURE_STORAGE_ACCOUNT:-http://localhost:5101/api/v1/pic/} #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105. + - EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq} - UseCustomizationData=True ports: - "5101:80" @@ -51,7 +51,7 @@ services: - ASPNETCORE_URLS=http://0.0.0.0:80 - ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word - identityUrl=http://identity.api #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105. - - EventBusConnection=rabbitmq + - EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq} - UseCustomizationData=True ports: - "5102:80" diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 8b9762cf5..c7c6fc3a8 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -17,9 +17,9 @@ services: environment: - ASPNETCORE_ENVIRONMENT=Production - ASPNETCORE_URLS=http://0.0.0.0:80 - - ConnectionString=basket.data + - ConnectionString=${ESHOP_AZURE_REDIS:-basket.data} - identityUrl=http://identity.api #Local: You need to open your host's firewall at range 5100-5105. at range 5100-5105. - - EventBusConnection=rabbitmq + - EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq} ports: - "5103:80" @@ -29,7 +29,7 @@ services: - ASPNETCORE_URLS=http://0.0.0.0:80 - ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word - ExternalCatalogBaseUrl=http://${ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP}:5101 #Local: You need to open your host's firewall at range 5100-5105. at range 5100-5105. - - EventBusConnection=rabbitmq + - EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq} ports: - "5101:80" @@ -50,7 +50,7 @@ services: - ASPNETCORE_URLS=http://0.0.0.0:80 - ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word - identityUrl=http://identity.api #Local: You need to open your host's firewall at range 5100-5105. at range 5100-5105. - - EventBusConnection=rabbitmq + - EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq} ports: - "5102:80" diff --git a/eShopOnContainers-ServicesAndWebApps.sln b/eShopOnContainers-ServicesAndWebApps.sln index 9a8fefaac..c2de71c31 100644 --- a/eShopOnContainers-ServicesAndWebApps.sln +++ b/eShopOnContainers-ServicesAndWebApps.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26430.12 +VisualStudioVersion = 15.0.26430.13 MinimumVisualStudioVersion = 10.0.40219.1 Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{FEA0C318-FFED-4D39-8781-265718CA43DD}" EndProject @@ -96,6 +96,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Marketing", "Marketing", "{ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Marketing.API", "src\Services\Marketing\Marketing.API\Marketing.API.csproj", "{DF395F85-B010-465D-857A-7EBCC512C0C2}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventBusServiceBus", "src\BuildingBlocks\EventBus\EventBusServiceBus\EventBusServiceBus.csproj", "{69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Ad-Hoc|Any CPU = Ad-Hoc|Any CPU @@ -1262,6 +1264,54 @@ Global {DF395F85-B010-465D-857A-7EBCC512C0C2}.Release|x64.Build.0 = Release|Any CPU {DF395F85-B010-465D-857A-7EBCC512C0C2}.Release|x86.ActiveCfg = Release|Any CPU {DF395F85-B010-465D-857A-7EBCC512C0C2}.Release|x86.Build.0 = Release|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Ad-Hoc|ARM.ActiveCfg = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Ad-Hoc|ARM.Build.0 = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Ad-Hoc|x64.ActiveCfg = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Ad-Hoc|x64.Build.0 = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Ad-Hoc|x86.ActiveCfg = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Ad-Hoc|x86.Build.0 = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.AppStore|Any CPU.Build.0 = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.AppStore|ARM.ActiveCfg = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.AppStore|ARM.Build.0 = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.AppStore|iPhone.ActiveCfg = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.AppStore|iPhone.Build.0 = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.AppStore|x64.ActiveCfg = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.AppStore|x64.Build.0 = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.AppStore|x86.ActiveCfg = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.AppStore|x86.Build.0 = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Debug|ARM.ActiveCfg = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Debug|ARM.Build.0 = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Debug|iPhone.Build.0 = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Debug|x64.ActiveCfg = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Debug|x64.Build.0 = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Debug|x86.ActiveCfg = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Debug|x86.Build.0 = Debug|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Release|Any CPU.Build.0 = Release|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Release|ARM.ActiveCfg = Release|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Release|ARM.Build.0 = Release|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Release|iPhone.ActiveCfg = Release|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Release|iPhone.Build.0 = Release|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Release|x64.ActiveCfg = Release|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Release|x64.Build.0 = Release|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Release|x86.ActiveCfg = Release|Any CPU + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1308,5 +1358,6 @@ Global {23A33F9B-7672-426D-ACF9-FF8436ADC81A} = {88B22DBB-AA8F-4290-A454-2C109352C345} {A5260DE0-1FDD-467E-9CC1-A028AB081CEE} = {91CF7717-08AB-4E65-B10E-0B426F01E2E8} {DF395F85-B010-465D-857A-7EBCC512C0C2} = {A5260DE0-1FDD-467E-9CC1-A028AB081CEE} + {69AF10D3-AA76-4FF7-B187-EC7E8CC5F5B8} = {807BB76E-B2BB-47A2-A57B-3D1B20FF5E7F} EndGlobalSection EndGlobal diff --git a/src/BuildingBlocks/EventBus/EventBus/EventBus.csproj b/src/BuildingBlocks/EventBus/EventBus/EventBus.csproj index 37aeb8d1f..fe7e35d98 100644 --- a/src/BuildingBlocks/EventBus/EventBus/EventBus.csproj +++ b/src/BuildingBlocks/EventBus/EventBus/EventBus.csproj @@ -10,6 +10,7 @@ + diff --git a/src/BuildingBlocks/EventBus/EventBusServiceBus/DefaultServiceBusPersisterConnection.cs b/src/BuildingBlocks/EventBus/EventBusServiceBus/DefaultServiceBusPersisterConnection.cs new file mode 100644 index 000000000..db1b6b390 --- /dev/null +++ b/src/BuildingBlocks/EventBus/EventBusServiceBus/DefaultServiceBusPersisterConnection.cs @@ -0,0 +1,45 @@ +using Microsoft.Azure.ServiceBus; +using Microsoft.Extensions.Logging; +using System; +using System.IO; + +namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus +{ + public class DefaultServiceBusPersisterConnection :IServiceBusPersisterConnection + { + private readonly ILogger _logger; + private readonly ServiceBusConnectionStringBuilder _serviceBusConnectionStringBuilder; + private ITopicClient _topicClient; + + bool _disposed; + + public DefaultServiceBusPersisterConnection(ServiceBusConnectionStringBuilder serviceBusConnectionStringBuilder, + ILogger logger) + { + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + + _serviceBusConnectionStringBuilder = serviceBusConnectionStringBuilder ?? + throw new ArgumentNullException(nameof(serviceBusConnectionStringBuilder)); + _topicClient = new TopicClient(_serviceBusConnectionStringBuilder, RetryPolicy.Default); + } + + public ServiceBusConnectionStringBuilder ServiceBusConnectionStringBuilder => _serviceBusConnectionStringBuilder; + + public ITopicClient CreateModel() + { + if(_topicClient.IsClosedOrClosing) + { + _topicClient = new TopicClient(_serviceBusConnectionStringBuilder, RetryPolicy.Default); + } + + return _topicClient; + } + + public void Dispose() + { + if (_disposed) return; + + _disposed = true; + } + } +} diff --git a/src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.cs b/src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.cs new file mode 100644 index 000000000..24c5fba39 --- /dev/null +++ b/src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.cs @@ -0,0 +1,180 @@ +namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus +{ + using System; + using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; + using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; + using Microsoft.Extensions.Logging; + using Microsoft.Azure.ServiceBus; + using Newtonsoft.Json; + using System.Text; + using System.Threading.Tasks; + using Microsoft.eShopOnContainers.BuildingBlocks.EventBus; + using System.Reflection; + using Microsoft.Azure.ServiceBus.Filters; + using Autofac; + using Newtonsoft.Json.Linq; + + public class EventBusServiceBus : IEventBus + { + private readonly IServiceBusPersisterConnection _serviceBusPersisterConnection; + private readonly ILogger _logger; + private readonly IEventBusSubscriptionsManager _subsManager; + private readonly SubscriptionClient _subscriptionClient; + private readonly ILifetimeScope _autofac; + private readonly string AUTOFAC_SCOPE_NAME = "eshop_event_bus"; + + public EventBusServiceBus(IServiceBusPersisterConnection serviceBusPersisterConnection, + ILogger logger, IEventBusSubscriptionsManager subsManager, string subscriptionClientName, + ILifetimeScope autofac) + { + _serviceBusPersisterConnection = serviceBusPersisterConnection; + _logger = logger; + _subsManager = subsManager ?? new InMemoryEventBusSubscriptionsManager(); + + _subscriptionClient = new SubscriptionClient(serviceBusPersisterConnection.ServiceBusConnectionStringBuilder, + subscriptionClientName); + _autofac = autofac; + + RemoveDefaultRule(); + RegisterSubscriptionClientMessageHandler(); + } + + public void Publish(IntegrationEvent @event) + { + var eventName = @event.GetType().Name; + var jsonMessage = JsonConvert.SerializeObject(@event); + var body = Encoding.UTF8.GetBytes(jsonMessage); + + var message = new Message + { + MessageId = new Guid().ToString(), + Body = Encoding.UTF8.GetBytes(jsonMessage), + Label = eventName, + }; + + var topicClient = _serviceBusPersisterConnection.CreateModel(); + + topicClient.SendAsync(message) + .GetAwaiter() + .GetResult(); + } + + public void SubscribeDynamic(string eventName) + where TH : IDynamicIntegrationEventHandler + { + _subsManager.AddDynamicSubscription(eventName); + } + + public void Subscribe() + where T : IntegrationEvent + where TH : IIntegrationEventHandler + { + var eventName = typeof(T).Name; + var containsKey = _subsManager.HasSubscriptionsForEvent(); + if (!containsKey) + { + try + { + _subscriptionClient.AddRuleAsync(new RuleDescription + { + Filter = new CorrelationFilter { Label = eventName }, + Name = eventName + }).GetAwaiter().GetResult(); + } + catch(ServiceBusException) + { + _logger.LogInformation($"The messaging entity {eventName} already exists."); + } + } + + _subsManager.AddSubscription(); + } + + public void Unsubscribe() + where T : IntegrationEvent + where TH : IIntegrationEventHandler + { + var eventName = typeof(T).Name; + + try + { + _subscriptionClient + .RemoveRuleAsync(eventName) + .GetAwaiter() + .GetResult(); + } + catch (MessagingEntityNotFoundException) + { + _logger.LogInformation($"The messaging entity {eventName} Could not be found."); + } + + _subsManager.RemoveSubscription(); + } + + public void UnsubscribeDynamic(string eventName) + where TH : IDynamicIntegrationEventHandler + { + _subsManager.RemoveDynamicSubscription(eventName); + } + + public void Dispose() + { + _subsManager.Clear(); + } + + private void RegisterSubscriptionClientMessageHandler() + { + _subscriptionClient.RegisterMessageHandler( + async (message, token) => + { + var eventName = message.Label; + var messageData = Encoding.UTF8.GetString(message.Body); + await ProcessEvent(eventName, messageData); + }, + new MessageHandlerOptions() { MaxConcurrentCalls = 10, AutoComplete = true }); + } + + private async Task ProcessEvent(string eventName, string message) + { + if (_subsManager.HasSubscriptionsForEvent(eventName)) + { + using (var scope = _autofac.BeginLifetimeScope(AUTOFAC_SCOPE_NAME)) + { + var subscriptions = _subsManager.GetHandlersForEvent(eventName); + foreach (var subscription in subscriptions) + { + if (subscription.IsDynamic) + { + var handler = scope.ResolveOptional(subscription.HandlerType) as IDynamicIntegrationEventHandler; + dynamic eventData = JObject.Parse(message); + await handler.Handle(eventData); + } + else + { + var eventType = _subsManager.GetEventTypeByName(eventName); + var integrationEvent = JsonConvert.DeserializeObject(message, eventType); + var handler = scope.ResolveOptional(subscription.HandlerType); + var concreteType = typeof(IIntegrationEventHandler<>).MakeGenericType(eventType); + await (Task)concreteType.GetMethod("Handle").Invoke(handler, new object[] { integrationEvent }); + } + } + } + } + } + + private void RemoveDefaultRule() + { + try + { + _subscriptionClient + .RemoveRuleAsync(SubscriptionClient.DefaultRule) + .GetAwaiter() + .GetResult(); + } + catch (MessagingEntityNotFoundException) + { + _logger.LogInformation($"The messaging entity {SubscriptionClient.DefaultRule} Could not be found."); + } + } + } +} diff --git a/src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.csproj b/src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.csproj new file mode 100644 index 000000000..5be30800e --- /dev/null +++ b/src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.csproj @@ -0,0 +1,17 @@ + + + + netcoreapp1.1 + Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus + + + + + + + + + + + + \ No newline at end of file diff --git a/src/BuildingBlocks/EventBus/EventBusServiceBus/IServiceBusPersisterConnection.cs b/src/BuildingBlocks/EventBus/EventBusServiceBus/IServiceBusPersisterConnection.cs new file mode 100644 index 000000000..283031247 --- /dev/null +++ b/src/BuildingBlocks/EventBus/EventBusServiceBus/IServiceBusPersisterConnection.cs @@ -0,0 +1,12 @@ +namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus +{ + using System; + using Microsoft.Azure.ServiceBus; + + public interface IServiceBusPersisterConnection : IDisposable + { + ServiceBusConnectionStringBuilder ServiceBusConnectionStringBuilder { get; } + + ITopicClient CreateModel(); + } +} \ No newline at end of file diff --git a/src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/Base/ViewModelLocator.cs b/src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/Base/ViewModelLocator.cs old mode 100755 new mode 100644 diff --git a/src/Mobile/eShopOnContainers/eShopOnContainers.Windows/project.json b/src/Mobile/eShopOnContainers/eShopOnContainers.Windows/project.json old mode 100755 new mode 100644 diff --git a/src/Services/Basket/Basket.API/Basket.API.csproj b/src/Services/Basket/Basket.API/Basket.API.csproj index 5287dcc96..26dcd6529 100644 --- a/src/Services/Basket/Basket.API/Basket.API.csproj +++ b/src/Services/Basket/Basket.API/Basket.API.csproj @@ -20,6 +20,7 @@ + @@ -38,6 +39,7 @@ + diff --git a/src/Services/Basket/Basket.API/Model/RedisBasketRepository.cs b/src/Services/Basket/Basket.API/Model/RedisBasketRepository.cs index 4ca90f383..e896c0773 100644 --- a/src/Services/Basket/Basket.API/Model/RedisBasketRepository.cs +++ b/src/Services/Basket/Basket.API/Model/RedisBasketRepository.cs @@ -4,7 +4,6 @@ using Newtonsoft.Json; using StackExchange.Redis; using System.Collections.Generic; using System.Linq; -using System.Net; using System.Threading.Tasks; namespace Microsoft.eShopOnContainers.Services.Basket.API.Model @@ -16,12 +15,10 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model private ConnectionMultiplexer _redis; - public RedisBasketRepository(IOptionsSnapshot options, ILoggerFactory loggerFactory) { _settings = options.Value; _logger = loggerFactory.CreateLogger(); - } public async Task DeleteBasketAsync(string id) @@ -93,21 +90,12 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model } private async Task ConnectToRedisAsync() - { - // TODO: Need to make this more robust. ConnectionMultiplexer.ConnectAsync doesn't like domain names or IPv6 addresses. - if (IPAddress.TryParse(_settings.ConnectionString, out var ip)) - { - _redis = await ConnectionMultiplexer.ConnectAsync(ip.ToString()); - _logger.LogInformation($"Connecting to database at {_settings.ConnectionString}"); - } - else - { - // workaround for https://github.com/StackExchange/StackExchange.Redis/issues/410 - var ips = await Dns.GetHostAddressesAsync(_settings.ConnectionString); - _logger.LogInformation($"Connecting to database {_settings.ConnectionString} at IP {ips.First().ToString()}"); - _redis = await ConnectionMultiplexer.ConnectAsync(ips.First().ToString()); - } + { + var configuration = ConfigurationOptions.Parse(_settings.ConnectionString, true); + configuration.ResolveDns = true; + + _logger.LogInformation($"Connecting to database {configuration.SslHost}."); + _redis = await ConnectionMultiplexer.ConnectAsync(configuration); } - } } diff --git a/src/Services/Basket/Basket.API/Startup.cs b/src/Services/Basket/Basket.API/Startup.cs index 83b259d5b..9ac2f9bd4 100644 --- a/src/Services/Basket/Basket.API/Startup.cs +++ b/src/Services/Basket/Basket.API/Startup.cs @@ -26,6 +26,9 @@ using System.Linq; using System.Net; using System.Threading.Tasks; +using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus; +using Microsoft.Azure.ServiceBus; + namespace Microsoft.eShopOnContainers.Services.Basket.API { public class Startup @@ -68,23 +71,40 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API services.AddSingleton(sp => { var settings = sp.GetRequiredService>().Value; - var ips = Dns.GetHostAddressesAsync(settings.ConnectionString).Result; + ConfigurationOptions configuration = ConfigurationOptions.Parse(settings.ConnectionString, true); + configuration.ResolveDns = true; - return ConnectionMultiplexer.Connect(ips.First().ToString()); + return ConnectionMultiplexer.Connect(configuration); }); - services.AddSingleton(sp => + if (Configuration.GetValue("AzureServiceBusEnabled")) { - var settings = sp.GetRequiredService>().Value; - var logger = sp.GetRequiredService>(); - var factory = new ConnectionFactory() + services.AddSingleton(sp => { - HostName = settings.EventBusConnection - }; + var settings = sp.GetRequiredService>().Value; + var logger = sp.GetRequiredService>(); + + var serviceBusConnection = new ServiceBusConnectionStringBuilder(settings.EventBusConnection); + + return new DefaultServiceBusPersisterConnection(serviceBusConnection, logger); + }); + } + else + { + services.AddSingleton(sp => + { + var settings = sp.GetRequiredService>().Value; + var logger = sp.GetRequiredService>(); + var factory = new ConnectionFactory() + { + HostName = settings.EventBusConnection + }; + + return new DefaultRabbitMQPersistentConnection(factory, logger); + }); + } - return new DefaultRabbitMQPersistentConnection(factory, logger); - }); services.AddSwaggerGen(options => { @@ -109,7 +129,8 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API services.AddSingleton(); services.AddTransient(); services.AddTransient(); - RegisterServiceBus(services); + + RegisterEventBus(services); services.AddOptions(); var container = new ContainerBuilder(); @@ -117,9 +138,27 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API return new AutofacServiceProvider(container.Build()); } - private void RegisterServiceBus(IServiceCollection services) + private void RegisterEventBus(IServiceCollection services) { - services.AddSingleton(); + if (Configuration.GetValue("AzureServiceBusEnabled")) + { + services.AddSingleton(sp => + { + var serviceBusPersisterConnection = sp.GetRequiredService(); + var iLifetimeScope = sp.GetRequiredService(); + var logger = sp.GetRequiredService>(); + var eventBusSubcriptionsManager = sp.GetRequiredService(); + var subscriptionClientName = Configuration["SubscriptionClientName"]; + + return new EventBusServiceBus(serviceBusPersisterConnection, logger, + eventBusSubcriptionsManager, subscriptionClientName, iLifetimeScope); + }); + } + else + { + services.AddSingleton(); + } + services.AddSingleton(); services.AddTransient(); diff --git a/src/Services/Basket/Basket.API/appsettings.json b/src/Services/Basket/Basket.API/appsettings.json index 31f76d0d0..f062f76d7 100644 --- a/src/Services/Basket/Basket.API/appsettings.json +++ b/src/Services/Basket/Basket.API/appsettings.json @@ -8,5 +8,7 @@ } }, "IdentityUrl": "http://localhost:5105", - "ConnectionString": "127.0.0.1" -} + "ConnectionString": "127.0.0.1", + "AzureServiceBusEnabled": false, + "SubscriptionClientName": "Basket" +} \ No newline at end of file diff --git a/src/Services/Catalog/Catalog.API/Catalog.API.csproj b/src/Services/Catalog/Catalog.API/Catalog.API.csproj index 2bb53692a..8521583f8 100644 --- a/src/Services/Catalog/Catalog.API/Catalog.API.csproj +++ b/src/Services/Catalog/Catalog.API/Catalog.API.csproj @@ -64,6 +64,7 @@ + diff --git a/src/Services/Catalog/Catalog.API/CatalogSettings.cs b/src/Services/Catalog/Catalog.API/CatalogSettings.cs index 55d65ae9c..a8c47991e 100644 --- a/src/Services/Catalog/Catalog.API/CatalogSettings.cs +++ b/src/Services/Catalog/Catalog.API/CatalogSettings.cs @@ -2,10 +2,11 @@ { public class CatalogSettings { - public string ExternalCatalogBaseUrl {get;set;} + public string PicBaseUrl { get;set;} public string EventBusConnection { get; set; } public bool UseCustomizationData { get; set; } + public bool AzureStorageEnabled { get; set; } } } diff --git a/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs b/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs index bb411f4d9..ca1ef9e3b 100644 --- a/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs +++ b/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs @@ -200,7 +200,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers CatalogTypeId = product.CatalogTypeId, Description = product.Description, Name = product.Name, - PictureUri = product.PictureUri, + PictureFileName = product.PictureFileName, Price = product.Price }; _catalogContext.CatalogItems.Add(item); @@ -231,14 +231,14 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers private List ChangeUriPlaceholder(List items) { - var baseUri = _settings.ExternalCatalogBaseUrl; - - items.ForEach(x => + var baseUri = _settings.PicBaseUrl; + + items.ForEach(catalogItem => { - if (!x.PictureUri.Contains('/')) - { - x.PictureUri = $"{baseUri}/api/v1/pic/{x.PictureUri}"; - } + catalogItem.PictureUri = _settings.AzureStorageEnabled + ? baseUri + catalogItem.PictureFileName + : baseUri + catalogItem.Id; + }); return items; diff --git a/src/Services/Catalog/Catalog.API/Controllers/PicController.cs b/src/Services/Catalog/Catalog.API/Controllers/PicController.cs index 47bc33a02..2114f21e4 100644 --- a/src/Services/Catalog/Catalog.API/Controllers/PicController.cs +++ b/src/Services/Catalog/Catalog.API/Controllers/PicController.cs @@ -1,6 +1,9 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure; using System.IO; +using System.Threading.Tasks; // For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860 @@ -10,9 +13,13 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers public class PicController : Controller { private readonly IHostingEnvironment _env; - public PicController(IHostingEnvironment env) + private readonly CatalogContext _catalogContext; + + public PicController(IHostingEnvironment env, + CatalogContext catalogContext) { _env = env; + _catalogContext = catalogContext; } [HttpGet("{filename}")] diff --git a/src/Services/Catalog/Catalog.API/Infrastructure/CatalogContext.cs b/src/Services/Catalog/Catalog.API/Infrastructure/CatalogContext.cs index cd26632e0..f58541b62 100644 --- a/src/Services/Catalog/Catalog.API/Infrastructure/CatalogContext.cs +++ b/src/Services/Catalog/Catalog.API/Infrastructure/CatalogContext.cs @@ -36,9 +36,11 @@ builder.Property(ci => ci.Price) .IsRequired(true); - builder.Property(ci => ci.PictureUri) + builder.Property(ci => ci.PictureFileName) .IsRequired(false); + builder.Ignore(ci => ci.PictureUri); + builder.HasOne(ci => ci.CatalogBrand) .WithMany() .HasForeignKey(ci => ci.CatalogBrandId); diff --git a/src/Services/Catalog/Catalog.API/Infrastructure/CatalogMigrations/20170530133114_AddPictureFileName.Designer.cs b/src/Services/Catalog/Catalog.API/Infrastructure/CatalogMigrations/20170530133114_AddPictureFileName.Designer.cs new file mode 100644 index 000000000..23c0e5344 --- /dev/null +++ b/src/Services/Catalog/Catalog.API/Infrastructure/CatalogMigrations/20170530133114_AddPictureFileName.Designer.cs @@ -0,0 +1,99 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure; + +namespace Catalog.API.Infrastructure.Migrations +{ + [DbContext(typeof(CatalogContext))] + [Migration("20170530133114_AddPictureFile")] + partial class AddPictureFile + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "1.1.1") + .HasAnnotation("SqlServer:Sequence:.catalog_brand_hilo", "'catalog_brand_hilo', '', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("SqlServer:Sequence:.catalog_hilo", "'catalog_hilo', '', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("SqlServer:Sequence:.catalog_type_hilo", "'catalog_type_hilo', '', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Model.CatalogBrand", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_brand_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("Brand") + .IsRequired() + .HasMaxLength(100); + + b.HasKey("Id"); + + b.ToTable("CatalogBrand"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Model.CatalogItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("CatalogBrandId"); + + b.Property("CatalogTypeId"); + + b.Property("Description"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50); + + b.Property("PictureFileName"); + + b.Property("Price"); + + b.HasKey("Id"); + + b.HasIndex("CatalogBrandId"); + + b.HasIndex("CatalogTypeId"); + + b.ToTable("Catalog"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Model.CatalogType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_type_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("Type") + .IsRequired() + .HasMaxLength(100); + + b.HasKey("Id"); + + b.ToTable("CatalogType"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Model.CatalogItem", b => + { + b.HasOne("Microsoft.eShopOnContainers.Services.Catalog.API.Model.CatalogBrand", "CatalogBrand") + .WithMany() + .HasForeignKey("CatalogBrandId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Microsoft.eShopOnContainers.Services.Catalog.API.Model.CatalogType", "CatalogType") + .WithMany() + .HasForeignKey("CatalogTypeId") + .OnDelete(DeleteBehavior.Cascade); + }); + } + } +} diff --git a/src/Services/Catalog/Catalog.API/Infrastructure/CatalogMigrations/20170530133114_AddPictureFileName.cs b/src/Services/Catalog/Catalog.API/Infrastructure/CatalogMigrations/20170530133114_AddPictureFileName.cs new file mode 100644 index 000000000..fc7f4dc8d --- /dev/null +++ b/src/Services/Catalog/Catalog.API/Infrastructure/CatalogMigrations/20170530133114_AddPictureFileName.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Catalog.API.Infrastructure.Migrations +{ + public partial class AddPictureFile : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameColumn( + name: "PictureUri", + table: "Catalog", + newName: "PictureFileName"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameColumn( + name: "PictureFileName", + table: "Catalog", + newName: "PictureUri"); + } + } +} diff --git a/src/Services/Catalog/Catalog.API/Model/CatalogItem.cs b/src/Services/Catalog/Catalog.API/Model/CatalogItem.cs index f3c04f595..459c60098 100644 --- a/src/Services/Catalog/Catalog.API/Model/CatalogItem.cs +++ b/src/Services/Catalog/Catalog.API/Model/CatalogItem.cs @@ -13,6 +13,8 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Model public decimal Price { get; set; } + public string PictureFileName { get; set; } + public string PictureUri { get; set; } public int CatalogTypeId { get; set; } diff --git a/src/Services/Catalog/Catalog.API/Startup.cs b/src/Services/Catalog/Catalog.API/Startup.cs index 8f2102f8b..a0a9c48b6 100644 --- a/src/Services/Catalog/Catalog.API/Startup.cs +++ b/src/Services/Catalog/Catalog.API/Startup.cs @@ -6,11 +6,13 @@ using global::Catalog.API.IntegrationEvents; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; + using Microsoft.Azure.ServiceBus; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ; + using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus; using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF; using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Services; using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure; @@ -114,23 +116,39 @@ services.AddTransient(); - services.AddSingleton(sp => + if (Configuration.GetValue("AzureServiceBusEnabled")) { - var settings = sp.GetRequiredService>().Value; - var logger = sp.GetRequiredService>(); - var factory = new ConnectionFactory() + services.AddSingleton(sp => { - HostName = settings.EventBusConnection - }; + var settings = sp.GetRequiredService>().Value; + var logger = sp.GetRequiredService>(); - return new DefaultRabbitMQPersistentConnection(factory, logger); - }); + var serviceBusConnection = new ServiceBusConnectionStringBuilder(settings.EventBusConnection); + + return new DefaultServiceBusPersisterConnection(serviceBusConnection, logger); + }); + } + else + { + services.AddSingleton(sp => + { + var settings = sp.GetRequiredService>().Value; + var logger = sp.GetRequiredService>(); + var factory = new ConnectionFactory() + { + HostName = settings.EventBusConnection + }; + + return new DefaultRabbitMQPersistentConnection(factory, logger); + }); + } - RegisterServiceBus(services); + RegisterEventBus(services); var container = new ContainerBuilder(); container.Populate(services); return new AutofacServiceProvider(container.Build()); + } public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) @@ -189,25 +207,37 @@ ); } - private void RegisterServiceBus(IServiceCollection services) + private void RegisterEventBus(IServiceCollection services) { - services.AddSingleton(); - services.AddSingleton(); + if (Configuration.GetValue("AzureServiceBusEnabled")) + { + services.AddSingleton(sp => + { + var serviceBusPersisterConnection = sp.GetRequiredService(); + var iLifetimeScope = sp.GetRequiredService(); + var logger = sp.GetRequiredService>(); + var eventBusSubcriptionsManager = sp.GetRequiredService(); + var subscriptionClientName = Configuration["SubscriptionClientName"]; + + return new EventBusServiceBus(serviceBusPersisterConnection, logger, + eventBusSubcriptionsManager, subscriptionClientName, iLifetimeScope); + }); + + } + else + { + services.AddSingleton(); + } + services.AddSingleton(); services.AddTransient, OrderStatusChangedToAwaitingValidationIntegrationEventHandler>(); services.AddTransient, OrderStatusChangedToPaidIntegrationEventHandler>(); } - - private void ConfigureEventBus(IApplicationBuilder app) + protected virtual void ConfigureEventBus(IApplicationBuilder app) { var eventBus = app.ApplicationServices.GetRequiredService(); - - eventBus.Subscribe>(); - eventBus.Subscribe>(); } } } diff --git a/src/Services/Catalog/Catalog.API/settings.json b/src/Services/Catalog/Catalog.API/settings.json index c60969ab7..8ad31e765 100644 --- a/src/Services/Catalog/Catalog.API/settings.json +++ b/src/Services/Catalog/Catalog.API/settings.json @@ -1,6 +1,6 @@ { "ConnectionString": "Server=tcp:127.0.0.1,5433;Initial Catalog=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word", - "ExternalCatalogBaseUrl": "http://localhost:5101", + "PicBaseUrl": "http://localhost:5101", "UseCustomizationData": true, "Logging": { "IncludeScopes": false, @@ -9,5 +9,8 @@ "System": "Information", "Microsoft": "Information" } - } + }, + "AzureServiceBusEnabled": false, + "AzureStorageEnabled": true, + "SubscriptionClientName": "Catalog" } diff --git a/src/Services/Ordering/Ordering.API/Ordering.API.csproj b/src/Services/Ordering/Ordering.API/Ordering.API.csproj index b59dcbd1a..29d50f326 100644 --- a/src/Services/Ordering/Ordering.API/Ordering.API.csproj +++ b/src/Services/Ordering/Ordering.API/Ordering.API.csproj @@ -23,6 +23,7 @@ + diff --git a/src/Services/Ordering/Ordering.API/Startup.cs b/src/Services/Ordering/Ordering.API/Startup.cs index d9989f07f..cb33d9991 100644 --- a/src/Services/Ordering/Ordering.API/Startup.cs +++ b/src/Services/Ordering/Ordering.API/Startup.cs @@ -14,10 +14,12 @@ using Infrastructure.Services; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; + using Microsoft.Azure.ServiceBus; using Microsoft.EntityFrameworkCore; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ; + using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus; using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF; using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Services; using Microsoft.Extensions.Configuration; @@ -118,19 +120,35 @@ services.AddTransient(); - services.AddSingleton(sp => + if (Configuration.GetValue("AzureServiceBusEnabled")) { - var logger = sp.GetRequiredService>(); + services.AddSingleton(sp => + { + var logger = sp.GetRequiredService>(); + + var serviceBusConnectionString = Configuration["EventBusConnection"]; + var serviceBusConnection = new ServiceBusConnectionStringBuilder(serviceBusConnectionString); - var factory = new ConnectionFactory() + return new DefaultServiceBusPersisterConnection(serviceBusConnection, logger); + }); + } + else + { + services.AddSingleton(sp => { - HostName = Configuration["EventBusConnection"] - }; + var logger = sp.GetRequiredService>(); - return new DefaultRabbitMQPersistentConnection(factory, logger); - }); + var factory = new ConnectionFactory() + { + HostName = Configuration["EventBusConnection"] + }; + + return new DefaultRabbitMQPersistentConnection(factory, logger); + }); + } + + RegisterEventBus(services); - RegisterServiceBus(services); services.AddOptions(); //configure autofac @@ -162,7 +180,6 @@ }); WaitForSqlAvailabilityAsync(loggerFactory, app, env).Wait(); - ConfigureEventBus(app); var integrationEventLogContext = new IntegrationEventLogContext( new DbContextOptionsBuilder() @@ -170,12 +187,7 @@ .Options); integrationEventLogContext.Database.Migrate(); - } - - private void RegisterServiceBus(IServiceCollection services) - { - services.AddSingleton(); - services.AddSingleton(); + ConfigureEventBus(app); } private void ConfigureEventBus(IApplicationBuilder app) @@ -201,6 +213,29 @@ }); } + private void RegisterEventBus(IServiceCollection services) + { + if (Configuration.GetValue("AzureServiceBusEnabled")) + { + services.AddSingleton(sp => + { + var serviceBusPersisterConnection = sp.GetRequiredService(); + var iLifetimeScope = sp.GetRequiredService(); + var logger = sp.GetRequiredService>(); + var eventBusSubcriptionsManager = sp.GetRequiredService(); + var subscriptionClientName = Configuration["SubscriptionClientName"]; + + return new EventBusServiceBus(serviceBusPersisterConnection, logger, + eventBusSubcriptionsManager, subscriptionClientName, iLifetimeScope); + }); + } + else + { + services.AddSingleton(); + } + + services.AddSingleton(); + } private async Task WaitForSqlAvailabilityAsync(ILoggerFactory loggerFactory, IApplicationBuilder app, IHostingEnvironment env, int retries = 0) { diff --git a/src/Services/Ordering/Ordering.API/settings.json b/src/Services/Ordering/Ordering.API/settings.json index d6736bfc2..152a95d54 100644 --- a/src/Services/Ordering/Ordering.API/settings.json +++ b/src/Services/Ordering/Ordering.API/settings.json @@ -9,5 +9,7 @@ "System": "Information", "Microsoft": "Information" } - } + }, + "AzureServiceBusEnabled": false, + "SubscriptionClientName": "Ordering" }