Skip to content

Commit 618548f

Browse files
authored
Merge pull request #8 from Azure-Samples/scripts_pr
scripts and readme.md
2 parents b93faf4 + f338c12 commit 618548f

File tree

4 files changed

+269
-8
lines changed

4 files changed

+269
-8
lines changed

scripts/build.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/bash
2+
3+
echo "Checking for prerequisites..."
4+
if ! type npm > /dev/null; then
5+
echo "Prerequisite Check 1: Install Node.js and NPM"
6+
exit 1
7+
fi
8+
9+
if ! type dotnet > /dev/null; then
10+
echo "Prerequisite Check 2: Install .NET Core 2.1 SDK or Runtime"
11+
exit 1
12+
fi
13+
14+
if ! type zip > /dev/null; then
15+
echo "Prerequisite Check 3: Install zip"
16+
exit 1
17+
fi
18+
19+
echo "Prerequisites satisfied"
20+
echo "******* BUILDING ARTIFACTS *******"
21+
22+
shift $((OPTIND - 1))
23+
echo "Building Categories Microservice..."
24+
HOME=`pwd`
25+
cd $HOME/categories/src/ContentReactor.Categories
26+
dotnet build
27+
cd $HOME/categories/src/ContentReactor.Categories/ContentReactor.Categories.Services.Tests
28+
dotnet test
29+
cd $HOME/categories/src/ContentReactor.Categories
30+
dotnet publish -c Release
31+
cd $HOME/categories/src/ContentReactor.Categories/ContentReactor.Categories.Api/bin/Release/netstandard2.0
32+
zip -r ContentReactor.Categories.Api.zip .
33+
cd $HOME/categories/src/ContentReactor.Categories/ContentReactor.Categories.WorkerApi/bin/Release/netstandard2.0
34+
zip -r ContentReactor.Categories.WorkerApi.zip .
35+
36+
37+
echo "Building Images Microservice..."
38+
cd $HOME/images/src/ContentReactor.Images
39+
dotnet build
40+
cd $HOME/images/src/ContentReactor.Images/ContentReactor.Images.Services.Tests
41+
dotnet test
42+
cd $HOME/images/src/ContentReactor.Images
43+
dotnet publish -c Release
44+
cd $HOME/images/src/ContentReactor.Images/ContentReactor.Images.Api/bin/Release/netstandard2.0
45+
zip -r ContentReactor.Images.Api.zip .
46+
cd $HOME/images/src/ContentReactor.Images/ContentReactor.Images.WorkerApi/bin/Release/netstandard2.0
47+
zip -r ContentReactor.Images.WorkerApi.zip .
48+
49+
echo "Building Audio Microservice..."
50+
cd $HOME/audio/src/ContentReactor.Audio
51+
dotnet build
52+
cd $HOME/audio/src/ContentReactor.Audio/ContentReactor.Audio.Services.Tests
53+
dotnet test
54+
cd $HOME/audio/src/ContentReactor.Audio
55+
dotnet publish -c Release
56+
cd $HOME/audio/src/ContentReactor.Audio/ContentReactor.Audio.Api/bin/Release/netstandard2.0
57+
zip -r ContentReactor.Audio.Api.zip .
58+
cd $HOME/audio/src/ContentReactor.Audio/ContentReactor.Audio.WorkerApi/bin/Release/netstandard2.0
59+
zip -r ContentReactor.Audio.WorkerApi.zip .
60+
61+
echo "Building Text Microservice..."
62+
cd $HOME/text/src/ContentReactor.Text
63+
dotnet build
64+
cd $HOME/text/src/ContentReactor.Text/ContentReactor.Text.Services.Tests
65+
dotnet test
66+
cd $HOME/text/src/ContentReactor.Text
67+
dotnet publish -c Release
68+
cd $HOME/text/src/ContentReactor.Text/ContentReactor.Text.Api/bin/Release/netstandard2.0
69+
zip -r ContentReactor.Text.Api.zip .
70+
71+
echo "Building proxy artifact..."
72+
cd $HOME/proxy/proxies
73+
zip -r proxies.zip .
74+
75+
echo "Building Web..."
76+
mkdir $HOME/web/src/signalr-web/SignalRMiddleware/SignalRMiddleware/wwwroot
77+
cd $HOME/web/src/signalr-web/SignalRMiddleware/
78+
dotnet build
79+
cd $HOME/web/src/signalr-web/SignalRMiddleware/SignalRMiddlewareTests/
80+
dotnet test
81+
82+
echo "Build successfully completed!"

scripts/deploy.sh

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
#!/bin/bash
2+
3+
echo "Provide Service Principal App ID: "
4+
read servicePrincipalAppId
5+
6+
echo "Provide Service Principal Password: "
7+
read servicePrincipalPassword
8+
9+
echo "Provide Service Principal Tenant ID: "
10+
read servicePrincipalTenantId
11+
12+
echo "Provide subscription ID: "
13+
read subscriptionId
14+
15+
HOME=`pwd`
16+
echo "Provide any unique suffix string (max length 15 characters, recommended to autogenerate a string): "
17+
read uniqueSuffixString
18+
19+
echo "Provide Big Huge Thesaurus API Key: "
20+
read bigHugeThesaurusApiKey
21+
22+
az login --service-principal --username $servicePrincipalAppId --password $servicePrincipalPassword --tenant $servicePrincipalTenantId
23+
az account set --subscription $subscriptionId
24+
25+
# Creating Event Grid Topic
26+
27+
echo "Creating Event Grid Topic..."
28+
az group create -n ContentReactor-Events -l westus2
29+
EVENT_GRID_TOPIC_NAME=contentreactor$uniqueSuffixString
30+
az group deployment create -g ContentReactor-Events --template-file $HOME/events/deploy/template.json --mode Complete --parameters uniqueResourceNameSuffix=$uniqueSuffixString
31+
sleep 2
32+
# Categories Microservice Deploy
33+
34+
echo "Starting deploy of Categories Microservice..."
35+
az group create -n ContentReactor-Categories -l westus2
36+
az group deployment create -g ContentReactor-Categories --template-file $HOME/categories/deploy/microservice.json --parameters uniqueResourceNameSuffix=$uniqueSuffixString eventsResourceGroupName=ContentReactor-Events eventGridTopicName=$EVENT_GRID_TOPIC_NAME bigHugeThesaurusApiKey=$bigHugeThesaurusApiKey --mode Complete
37+
38+
CATEGORIES_API_NAME=crcatapi$uniqueSuffixString
39+
CATEGORIES_WORKER_API_NAME=crcatwapi$uniqueSuffixString
40+
41+
echo "Creating Cosmos DB entries..."
42+
COSMOS_DB_ACCOUNT_NAME=crcatdb$uniqueSuffixString
43+
az cosmosdb database create --name $COSMOS_DB_ACCOUNT_NAME --db-name Categories --resource-group ContentReactor-Categories
44+
az cosmosdb collection create --name $COSMOS_DB_ACCOUNT_NAME --db-name Categories --collection-name Categories --resource-group ContentReactor-Categories --partition-key-path "/userId" --throughput 1000
45+
46+
echo "Deploying Categories Functions..."
47+
az webapp deployment source config-zip --resource-group ContentReactor-Categories --name $CATEGORIES_API_NAME --src $HOME/categories/src/ContentReactor.Categories/ContentReactor.Categories.Api/bin/Release/netstandard2.0/ContentReactor.Categories.Api.zip
48+
az webapp deployment source config-zip --resource-group ContentReactor-Categories --name $CATEGORIES_WORKER_API_NAME --src $HOME/categories/src/ContentReactor.Categories/ContentReactor.Categories.WorkerApi/bin/Release/netstandard2.0/ContentReactor.Categories.WorkerApi.zip
49+
50+
echo "Deploying Event Grid Subscription for Categories"
51+
az group deployment create -g ContentReactor-Events --template-file $HOME/categories/deploy/eventGridSubscriptions.json --parameters eventGridTopicName=$EVENT_GRID_TOPIC_NAME microserviceResourceGroupName=ContentReactor-Categories microserviceFunctionsWorkerApiAppName=$CATEGORIES_WORKER_API_NAME
52+
sleep 5
53+
54+
# Images Microservice Deploy
55+
56+
echo "Starting deploy of Images Microservice..."
57+
az group create -n ContentReactor-Images -l westus2
58+
az group deployment create -g ContentReactor-Images --template-file $HOME/images/deploy/microservice.json --parameters uniqueResourceNameSuffix=$uniqueSuffixString eventsResourceGroupName=ContentReactor-Events eventGridTopicName=$EVENT_GRID_TOPIC_NAME --mode Complete
59+
60+
IMAGES_API_NAME=crimgapi$uniqueSuffixString
61+
IMAGES_WORKER_API_NAME=crimgwapi$uniqueSuffixString
62+
sleep 1
63+
echo "Creating Images Blob Storage..."
64+
IMAGES_BLOB_STORAGE_ACCOUNT_NAME=crimgblob$uniqueSuffixString
65+
az storage container create --account-name $IMAGES_BLOB_STORAGE_ACCOUNT_NAME --name fullimages
66+
az storage container create --account-name $IMAGES_BLOB_STORAGE_ACCOUNT_NAME --name previewimages
67+
68+
echo "Creating CORS Policy for Blob Storage"
69+
az storage cors clear --account-name $IMAGES_BLOB_STORAGE_ACCOUNT_NAME --services b
70+
az storage cors add --account-name $IMAGES_BLOB_STORAGE_ACCOUNT_NAME --services b --methods POST GET PUT --origins "*" --allowed-headers "*" --exposed-headers "*"
71+
72+
echo "Deploying Images Functions..."
73+
az webapp deployment source config-zip --resource-group ContentReactor-Images --name $IMAGES_API_NAME --src $HOME/images/src/ContentReactor.Images/ContentReactor.Images.Api/bin/Release/netstandard2.0/ContentReactor.Images.Api.zip
74+
sleep 2
75+
az webapp deployment source config-zip --resource-group ContentReactor-Images --name $IMAGES_WORKER_API_NAME --src $HOME/images/src/ContentReactor.Images/ContentReactor.Images.WorkerApi/bin/Release/netstandard2.0/ContentReactor.Images.WorkerApi.zip
76+
77+
echo "Deploying Event Grid Subscription for Images"
78+
az account set --subscription $subscriptionId
79+
az group deployment create -g ContentReactor-Events --template-file $HOME/images/deploy/eventGridSubscriptions.json --parameters eventGridTopicName=$EVENT_GRID_TOPIC_NAME microserviceResourceGroupName=ContentReactor-Images microserviceFunctionsWorkerApiAppName=$IMAGES_WORKER_API_NAME
80+
sleep 5
81+
82+
# Audio Microservice Deploy
83+
84+
echo "Starting deploy of Audio Microservice..."
85+
az group create -n ContentReactor-Audio -l westus2
86+
az group deployment create -g ContentReactor-Audio --template-file $HOME/audio/deploy/microservice.json --parameters uniqueResourceNameSuffix=$uniqueSuffixString eventsResourceGroupName=ContentReactor-Events eventGridTopicName=$EVENT_GRID_TOPIC_NAME --mode Complete
87+
88+
AUDIO_API_NAME=craudapi$uniqueSuffixString
89+
AUDIO_WORKER_API_NAME=craudwapi$uniqueSuffixString
90+
91+
echo "Creating Audio Blob Storage..."
92+
AUDIO_BLOB_STORAGE_ACCOUNT_NAME=craudblob$uniqueSuffixString
93+
az storage container create --account-name $AUDIO_BLOB_STORAGE_ACCOUNT_NAME --name audio
94+
95+
echo "Creating CORS Policy for Blob Storage"
96+
az storage cors clear --account-name $AUDIO_BLOB_STORAGE_ACCOUNT_NAME --services b
97+
az storage cors add --account-name $AUDIO_BLOB_STORAGE_ACCOUNT_NAME --services b --methods POST GET PUT --origins "*" --allowed-headers "*" --exposed-headers "*"
98+
99+
echo "Deploying Audio Functions..."
100+
az webapp deployment source config-zip --resource-group ContentReactor-Audio --name $AUDIO_API_NAME --src $HOME/audio/src/ContentReactor.Audio/ContentReactor.Audio.Api/bin/Release/netstandard2.0/ContentReactor.Audio.Api.zip
101+
sleep 3
102+
az webapp deployment source config-zip --resource-group ContentReactor-Audio --name $AUDIO_WORKER_API_NAME --src $HOME/audio/src/ContentReactor.Audio/ContentReactor.Audio.WorkerApi/bin/Release/netstandard2.0/ContentReactor.Audio.WorkerApi.zip
103+
104+
echo "Deploying Event Grid Subscription for Audio"
105+
az group deployment create -g ContentReactor-Events --template-file $HOME/audio/deploy/eventGridSubscriptions.json --parameters eventGridTopicName=$EVENT_GRID_TOPIC_NAME microserviceResourceGroupName=ContentReactor-Audio microserviceFunctionsWorkerApiAppName=$AUDIO_WORKER_API_NAME
106+
sleep 5
107+
108+
# Text Microservice Deploy
109+
110+
echo "Starting deploy of Text Microservice..."
111+
az group create -n ContentReactor-Text -l westus2
112+
az group deployment create -g ContentReactor-Text --template-file $HOME/text/deploy/microservice.json --parameters uniqueResourceNameSuffix=$uniqueSuffixString eventsResourceGroupName=ContentReactor-Events eventGridTopicName=$EVENT_GRID_TOPIC_NAME --mode Complete
113+
114+
echo "Creating Text Blob Storage..."
115+
TEXT_BLOB_STORAGE_ACCOUNT_NAME=crtxtdb$uniqueSuffixString
116+
az cosmosdb database create --name $TEXT_BLOB_STORAGE_ACCOUNT_NAME --db-name Text --resource-group ContentReactor-Text
117+
az cosmosdb collection create --name $TEXT_BLOB_STORAGE_ACCOUNT_NAME --db-name Text --collection-name Text --resource-group ContentReactor-Text --partition-key-path "/userId" --throughput 1000
118+
119+
echo "Deploying Text Functions..."
120+
TEXT_API_NAME=crtxtapi$uniqueSuffixString
121+
az webapp deployment source config-zip --resource-group ContentReactor-Text --name $TEXT_API_NAME --src $HOME/text/src/ContentReactor.Text/ContentReactor.Text.Api/bin/Release/netstandard2.0/ContentReactor.Text.Api.zip
122+
123+
# Deploy Proxy
124+
echo "Starting deploy of Proxy..."
125+
az group create -n ContentReactor-Proxy -l westus2
126+
az group deployment create -g ContentReactor-Proxy --template-file $HOME/proxy/deploy/template.json --parameters uniqueResourceNameSuffix=$uniqueSuffixString categoriesMicroserviceApiAppName=$CATEGORIES_API_NAME imagesMicroserviceApiAppName=$IMAGES_API_NAME audioMicroserviceApiAppName=$AUDIO_API_NAME textMicroserviceApiAppName=$TEXT_API_NAME --mode Complete
127+
PROXY_API_NAME=crapiproxy$uniqueSuffixString
128+
az webapp deployment source config-zip --resource-group ContentReactor-Proxy --name $PROXY_API_NAME --src $HOME/proxy/proxies/proxies.zip
129+
130+
# Deploy Web
131+
echo "Starting deploy of Web..."
132+
az group create -n ContentReactor-Web -l westus2
133+
134+
az group deployment create --name ContentReactorWeb-Deployment --resource-group ContentReactor-Web --template-file $HOME/web/deploy/template.json --parameters uniqueResourceNameSuffix=$uniqueSuffixString functionAppProxyName=crapiproxy$uniqueSuffixString
135+
WEB_APP_NAME=crweb$uniqueSuffixString
136+
webInstrumentationKey=$(az resource show --namespace microsoft.insights --resource-type components --name $WEB_APP_NAME-ai -g ContentReactor-Web --query properties.InstrumentationKey)
137+
sed -i -e 's/\"%INSTRUMENTATION_KEY%\"/'"$webInstrumentationKey"'/g' $HOME/web/src/signalr-web/SignalRMiddleware/EventApp/src/environments/environment.ts
138+
139+
cd $HOME/web/src/signalr-web/SignalRMiddleware/EventApp
140+
npm install
141+
npm run ubuntu-dev-build
142+
143+
cd $HOME/web/src/signalr-web/SignalRMiddleware/SignalRMiddleware
144+
dotnet publish -c Release
145+
146+
cd $HOME/web/src/signalr-web/SignalRMiddleware/SignalRMiddleware/bin/Release/netcoreapp2.1/publish/
147+
zip -r SignalRMiddleware.zip .
148+
149+
az webapp deployment source config-zip --resource-group ContentReactor-Web --name $WEB_APP_NAME --src $HOME/web/src/signalr-web/SignalRMiddleware/SignalRMiddleware/bin/Release/netcoreapp2.1/publish/SignalRMiddleware.zip
150+
az group deployment create -g ContentReactor-Events --template-file $HOME/web/deploy/eventGridSubscriptions.json --parameters eventGridTopicName=$EVENT_GRID_TOPIC_NAME appServiceName=$WEB_APP_NAME

scripts/readme.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Content Reactor: Build and Deployment Scripts
2+
3+
The build.sh and deploy.sh scripts are meant to be run in Ubuntu WSL. Here are the pre-requisite installations before these scripts can be run:
4+
5+
1. Install Ubuntu WSL or you can use a Ubuntu bash shell
6+
2. Run fromdos command on both these scripts to convert them from dos to unix.
7+
8+
sudo apt-get update
9+
10+
sudo apt-get install tofrodos
11+
12+
3. The command 'which node' should point to a node installation in ubuntu (eg: /usr/bin/node)
13+
14+
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash
15+
16+
sudo apt-get install -y nodejs
17+
18+
4. The command 'which npm' should point to an npm installation in ubuntu (eg: /usr/bin/npm)
19+
5. Make sure 'node --version' returns a Node.js version > 8 (eg: v8.11.3)
20+
6. Make sure dotnet cli is installed and points to version 2.1.x. See install instructions [here](https://www.microsoft.com/net/learn/get-started/linux/ubuntu16-04)
21+
7. Install latest [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-apt?view=azure-cli-latest)
22+
8. [Create an Azure Service Principal](https://docs.microsoft.com/en-us/cli/azure/create-an-azure-service-principal-azure-cli?view=azure-cli-latest) with password for your subscription id and note down the following
23+
Note: Before creating a service principal, make sure you set your preferred subscription id through Azure CLI
24+
1. Service Principal App Id
25+
2. Service Principal App Password
26+
3. Tenant ID
27+
4. Your azure subscription id (you can do "az account list" command to get the id of the subscription you need)
28+
9. Big Huge Thesaurus is an external API used by one of the microservices in this sample. Make sure you get a thesaurus key [here](https://words.bighugelabs.com/api.php)
29+
30+
From the root folder of the repository execute the following commands on the Ubuntu WSL:
31+
1. sh scripts/build.sh
32+
2. sh scripts/deploy.sh
33+
34+

setup.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,21 @@ For example, to build the categories microservice, you would execute the followi
6060

6161
## Building Web Manually
6262

63-
The front end and the signalR middleware is in the signalr-web/SignalRMiddleware folder. This folder has a solution file which can be built using Visual Studio Version 15.7.0 Preview 2.0
63+
The front end and the signalR middleware is in the signalr-web/SignalRMiddleware folder. This folder has a solution file which can be built using Visual Studio Version 15.7.0 and above
6464
The build takes care of building the angular component and bundling this with the ASP.NET WebApp.
6565

6666
Note: Please make sure that your build host or your local machine has the latest versions of node.js and npm installed.
6767

68-
Note: The ASP.NET app works on a preview version of .NET Core.
69-
The instructions to install the preview locally can be found [here](https://blogs.msdn.microsoft.com/webdev/2018/02/27/asp-net-core-2-1-0-preview1-using-asp-net-core-previews-on-azure-app-service/)
70-
7168
Build the ASP.NET Web Application using the following steps:
7269

7370
1. Build the Angular app:
74-
Go to web/src/signalr-web/SignalRMiddleware/EventApp and perform `npm install`
71+
Go to web/src/signalr-web/SignalRMiddleware/EventApp and perform `npm install` followed by `npm run dev`
7572

7673
2. Restore NuGet packages:
7774
`dotnet restore web/src/signalr-web/SignalRMiddleware/SignalRMiddleware.sln`
7875

7976
3. Build MVC App: This will bundle Angular app and ASP.NET app using MSBuild
80-
`msbuild.exe web\src\signalr-web\SignalRMiddleware\SignalRMiddleware.sln`
77+
`dotnet build web\src\signalr-web\SignalRMiddleware\SignalRMiddleware.sln`
8178

8279
4. Zip the contents of web\src\signalr-web\SignalRMiddleware\SignalRMiddleware\obj\Release\netcoreapp2.1
8380

@@ -361,8 +358,6 @@ The web app is deployed into its own resource group. It has its own ARM template
361358

362359
4. **Deploy Event Subscriptions ARM Template:** Use the _Azure Resource Group Deployment_ task, with the _Action_ set to `Create or update resource group`. Set the _Template_ to the location of the `eventGridSubscriptions.json` file, e.g. `$(System.DefaultWorkingDirectory)/web/deploy/eventGridSubscriptions.json`. Set the _Overridable template parameters_ to the following: `eventGridTopicName={event-grid-topic-name} appServiceName={app-service-name}`
363360

364-
> Note: Since this is built on preview, template.json installs a Preview runtime. Re-deploying might cause conflicts because of this runtime. One way to resolve this is to delete and re-create the resource group for web with a different name.
365-
366361
### Deploying Web Application Manually
367362

368363
1. Deploy the web app's ARM template:

0 commit comments

Comments
 (0)