# Conflicts: # docker-compose.override.yml # src/Services/Catalog/Catalog.API/CatalogSettings.cs # src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs # src/Services/Catalog/Catalog.API/Controllers/PicController.cs # src/Services/Catalog/Catalog.API/Infrastructure/CatalogContextSeed.cs # src/Services/Catalog/Catalog.API/settings.json # src/Services/Ordering/Ordering.API/Startup.cspull/457/head
@ -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 | |||
@ -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) |
@ -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) |
@ -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 | |||
@ -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')]" | |||
} | |||
] | |||
} | |||
} | |||
] | |||
} |
@ -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" | |||
} | |||
} | |||
} |
@ -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 |
@ -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` | |||
@ -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 | |||
``` | |||
@ -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" | |||
} | |||
} | |||
} | |||
] | |||
} |
@ -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" | |||
} | |||
} | |||
} |
@ -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 | |||
``` | |||
@ -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]" | |||
} | |||
} | |||
} |
@ -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" | |||
} | |||
} | |||
} |
@ -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 | |||
``` | |||
@ -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": { | |||
} | |||
} |
@ -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 | |||
} | |||
} | |||
} |
@ -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]" | |||
} | |||
} | |||
} |
@ -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" | |||
} | |||
} | |||
} |
@ -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 <subs_id> --azure-resource-group <resource_group> --azure-ssh-user <login_name> <machine_name>` | |||
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! | |||
@ -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": { } | |||
} | |||
} | |||
] | |||
} | |||
@ -0,0 +1,7 @@ | |||
{ | |||
"newStorageAccountName": { "value": "eshopsrvmvstorage" }, | |||
"adminUsername": { "value": "eshop" }, | |||
"adminPassword": { "value": "Pass@word" }, | |||
"dnsNameForPublicIP": { "value": "eshop-srv" }, | |||
"VMName": {"value": "MyDockerVM2"} | |||
} |
@ -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 <resourcegroup> --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. | |||
@ -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. |
@ -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'))]" | |||
} | |||
} | |||
} | |||
] | |||
} | |||
] | |||
} |
@ -0,0 +1,7 @@ | |||
{ | |||
"newStorageAccountName": { "value": "eshopsrvmvstoragewin" }, | |||
"adminUsername": { "value": "eshop" }, | |||
"adminPassword": { "value": "Pass@word" }, | |||
"dnsNameForPublicIP": { "value": "eshop-srv-win" }, | |||
"VMName": {"value": "eshop-srv-win"} | |||
} |
@ -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) | |||
@ -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<DefaultServiceBusPersisterConnection> _logger; | |||
private readonly ServiceBusConnectionStringBuilder _serviceBusConnectionStringBuilder; | |||
private ITopicClient _topicClient; | |||
bool _disposed; | |||
public DefaultServiceBusPersisterConnection(ServiceBusConnectionStringBuilder serviceBusConnectionStringBuilder, | |||
ILogger<DefaultServiceBusPersisterConnection> 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; | |||
} | |||
} | |||
} |
@ -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<EventBusServiceBus> _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<EventBusServiceBus> 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<TH>(string eventName) | |||
where TH : IDynamicIntegrationEventHandler | |||
{ | |||
_subsManager.AddDynamicSubscription<TH>(eventName); | |||
} | |||
public void Subscribe<T, TH>() | |||
where T : IntegrationEvent | |||
where TH : IIntegrationEventHandler<T> | |||
{ | |||
var eventName = typeof(T).Name; | |||
var containsKey = _subsManager.HasSubscriptionsForEvent<T>(); | |||
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<T, TH>(); | |||
} | |||
public void Unsubscribe<T, TH>() | |||
where T : IntegrationEvent | |||
where TH : IIntegrationEventHandler<T> | |||
{ | |||
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<T, TH>(); | |||
} | |||
public void UnsubscribeDynamic<TH>(string eventName) | |||
where TH : IDynamicIntegrationEventHandler | |||
{ | |||
_subsManager.RemoveDynamicSubscription<TH>(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."); | |||
} | |||
} | |||
} | |||
} |
@ -0,0 +1,17 @@ | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>netcoreapp1.1</TargetFramework> | |||
<RootNamespace>Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus</RootNamespace> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="Microsoft.Azure.ServiceBus" Version="0.0.5-preview" /> | |||
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.1" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\EventBus\EventBus.csproj" /> | |||
</ItemGroup> | |||
</Project> |
@ -0,0 +1,12 @@ | |||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus | |||
{ | |||
using System; | |||
using Microsoft.Azure.ServiceBus; | |||
public interface IServiceBusPersisterConnection : IDisposable | |||
{ | |||
ServiceBusConnectionStringBuilder ServiceBusConnectionStringBuilder { get; } | |||
ITopicClient CreateModel(); | |||
} | |||
} |
@ -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<int>("Id") | |||
.ValueGeneratedOnAdd() | |||
.HasAnnotation("SqlServer:HiLoSequenceName", "catalog_brand_hilo") | |||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); | |||
b.Property<string>("Brand") | |||
.IsRequired() | |||
.HasMaxLength(100); | |||
b.HasKey("Id"); | |||
b.ToTable("CatalogBrand"); | |||
}); | |||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Model.CatalogItem", b => | |||
{ | |||
b.Property<int>("Id") | |||
.ValueGeneratedOnAdd() | |||
.HasAnnotation("SqlServer:HiLoSequenceName", "catalog_hilo") | |||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); | |||
b.Property<int>("CatalogBrandId"); | |||
b.Property<int>("CatalogTypeId"); | |||
b.Property<string>("Description"); | |||
b.Property<string>("Name") | |||
.IsRequired() | |||
.HasMaxLength(50); | |||
b.Property<string>("PictureFileName"); | |||
b.Property<decimal>("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<int>("Id") | |||
.ValueGeneratedOnAdd() | |||
.HasAnnotation("SqlServer:HiLoSequenceName", "catalog_type_hilo") | |||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); | |||
b.Property<string>("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); | |||
}); | |||
} | |||
} | |||
} |
@ -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"); | |||
} | |||
} | |||
} |