Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit 4c8f14a

Browse files
anthonychujldeen
authored andcommitted
NET 5 and Bridge to Kubernetes Support
1 parent 2c69caa commit 4c8f14a

19 files changed

+468
-137
lines changed

.devcontainer/Dockerfile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#-------------------------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
4+
#-------------------------------------------------------------------------------------------------------------
5+
6+
FROM mcr.microsoft.com/dotnet/core/sdk:2.1
7+
8+
# Avoid warnings by switching to noninteractive
9+
ENV DEBIAN_FRONTEND=noninteractive
10+
ENV ASPNETCORE_URLS=http://0.0.0.0:5000
11+
12+
# This Dockerfile adds a non-root 'vscode' user with sudo access. However, for Linux,
13+
# this user's GID/UID must match your local user UID/GID to avoid permission issues
14+
# with bind mounts. Update USER_UID / USER_GID if yours is not 1000. See
15+
# https://aka.ms/vscode-remote/containers/non-root-user for details.
16+
ARG USERNAME=vscode
17+
ARG USER_UID=1000
18+
ARG USER_GID=$USER_UID
19+
20+
# Configure apt and install packages
21+
RUN apt-get update \
22+
&& apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \
23+
#
24+
# Verify git, process tools, lsb-release (common in install instructions for CLIs) installed
25+
&& apt-get -y install git iproute2 procps lsb-release \
26+
#
27+
# Install node
28+
&& apt-get -y install curl gnupg build-essential \
29+
&& curl -sL https://deb.nodesource.com/setup_10.x | bash - \
30+
&& apt-get -y install nodejs \
31+
#
32+
# Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user.
33+
&& groupadd --gid $USER_GID $USERNAME \
34+
&& useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
35+
# [Optional] Add sudo support for the non-root user
36+
&& apt-get install -y sudo \
37+
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\
38+
&& chmod 0440 /etc/sudoers.d/$USERNAME \
39+
#
40+
# Clean up
41+
&& apt-get autoremove -y \
42+
&& apt-get clean -y \
43+
&& rm -rf /var/lib/apt/lists/*
44+
45+
# Switch back to dialog for any ad-hoc use of apt-get
46+
ENV DEBIAN_FRONTEND=

.devcontainer/devcontainer.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or the definition README at
2+
// https://github.com/microsoft/vscode-dev-containers/tree/master/containers/dotnetcore-2.1
3+
{
4+
"name": "TailwindTraders-Website",
5+
"dockerComposeFile": "docker-compose.yml",
6+
"service": "web",
7+
"workspaceFolder": "/workspace",
8+
9+
// Use 'settings' to set *default* container specific settings.json values on container create.
10+
// You can edit these settings after create using File > Preferences > Settings > Remote.
11+
"settings": {
12+
"terminal.integrated.shell.linux": "/bin/bash"
13+
},
14+
15+
// Uncomment the next line if you want to publish any ports.
16+
// "appPort": [],
17+
18+
// Uncomment the next line to run commands after the container is created.
19+
// "postCreateCommand": "dotnet restore"
20+
21+
// Uncomment the next line to use a non-root user. On Linux, this will prevent
22+
// new files getting created as root, but you may need to update the USER_UID
23+
// and USER_GID in .devcontainer/Dockerfile to match your user if not 1000.
24+
// "runArgs": [ "-u", "vscode" ],
25+
26+
// Add the IDs of extensions you want installed when the container is created in the array below.
27+
"extensions": [
28+
"ms-vscode.csharp"
29+
]
30+
}

.devcontainer/docker-compose.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#-------------------------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
4+
#-------------------------------------------------------------------------------------------------------------
5+
6+
version: '3'
7+
services:
8+
web:
9+
# Uncomment the next line to use a non-root user. On Linux, this will prevent
10+
# new files getting created as root, but you may need to update the USER_UID
11+
# and USER_GID in .devcontainer/Dockerfile to match your user if not 1000.
12+
# user: node
13+
14+
build:
15+
context: .
16+
dockerfile: Dockerfile
17+
volumes:
18+
- ..:/workspace
19+
ports:
20+
- 5000:5000
21+
22+
# Overrides default command so things don't shut down after the process ends.
23+
command: sleep infinity
24+
25+
links:
26+
- mongo
27+
- sql
28+
29+
mongo:
30+
image: mongo
31+
restart: unless-stopped
32+
33+
sql:
34+
image: mcr.microsoft.com/mssql/server:2017-latest
35+
restart: unless-stopped
36+
environment:
37+
- ACCEPT_EULA=Y
38+
- SA_PASSWORD=Twtraders123456!
39+

.vscode/launch.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
// Use IntelliSense to find out which attributes exist for C# debugging
3+
// Use hover for the description of the existing attributes
4+
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": ".NET Core Launch (web)",
9+
"type": "coreclr",
10+
"request": "launch",
11+
"preLaunchTask": "build",
12+
"program": "${workspaceFolder}/Source/Tailwind.Traders.Web/bin/Debug/netcoreapp2.1/Tailwind.Traders.Web.dll",
13+
"args": [],
14+
"cwd": "${workspaceFolder}/Source/Tailwind.Traders.Web",
15+
"stopAtEntry": false,
16+
"serverReadyAction": {
17+
"action": "openExternally",
18+
"pattern": "^\\s*Now listening on:\\s+(https?://\\S+)"
19+
},
20+
"env": {
21+
"ASPNETCORE_ENVIRONMENT": "Development"
22+
},
23+
"sourceFileMap": {
24+
"/Views": "${workspaceFolder}/Views"
25+
}
26+
},
27+
{
28+
"name": ".NET Core Attach",
29+
"type": "coreclr",
30+
"request": "attach",
31+
"processId": "${command:pickProcess}"
32+
}
33+
]
34+
}

.vscode/tasks.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "build",
6+
"command": "dotnet",
7+
"type": "process",
8+
"args": [
9+
"build",
10+
"${workspaceFolder}/Source/Tailwind.Traders.Web/Tailwind.Traders.Web.csproj",
11+
"/property:GenerateFullPaths=true",
12+
"/consoleloggerparameters:NoSummary"
13+
],
14+
"problemMatcher": "$msCompile"
15+
},
16+
{
17+
"label": "publish",
18+
"command": "dotnet",
19+
"type": "process",
20+
"args": [
21+
"publish",
22+
"${workspaceFolder}/Source/Tailwind.Traders.Web/Tailwind.Traders.Web.csproj",
23+
"/property:GenerateFullPaths=true",
24+
"/consoleloggerparameters:NoSummary"
25+
],
26+
"problemMatcher": "$msCompile"
27+
},
28+
{
29+
"label": "watch",
30+
"command": "dotnet",
31+
"type": "process",
32+
"args": [
33+
"watch",
34+
"run",
35+
"${workspaceFolder}/Source/Tailwind.Traders.Web/Tailwind.Traders.Web.csproj",
36+
"/property:GenerateFullPaths=true",
37+
"/consoleloggerparameters:NoSummary"
38+
],
39+
"problemMatcher": "$msCompile"
40+
}
41+
]
42+
}

Demo.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Apps 30 Demo Commands
2+
3+
### Environment Variables Used
4+
5+
```
6+
resourceGroup=live-igniteapps30
7+
location=eastus
8+
subName="Ignite The Tour"
9+
cosmosDBName=liveapps30twtnosqlge
10+
sqlDBName=liveapps30twtsql
11+
webappName=liveigniteapps30
12+
acrName=liveigniteapps30acr
13+
adminUser=twtadmin
14+
adminPassword=twtapps30pD
15+
```
16+
17+
### Resource Group Creation
18+
19+
`az group create --subscription "$subName" --name $resourceGroup --location $location`
20+
21+
### VNet Creation
22+
23+
`az network vnet create --name igniteapps30vnet --subscription "$subName" --resource-group $resourceGroup --subnet-name default`
24+
25+
### CosmosDB Creation
26+
27+
`az cosmosdb create --name $cosmosDBName --resource-group $resourceGroup --kind MongoDB --subscription "$subName"`
28+
29+
# SQL Server Creation
30+
31+
`az sql server create --location $location --resource-group $resourceGroup --name $sqlDBName --admin-user $adminUser --admin-password $adminPassword --subscription "$subName"`
32+
33+
# SQL Server Firewall Rule
34+
35+
`az sql server firewall-rule create --resource-group $resourceGroup --server $sqlDBName --name azure --start-ip-address 0.0.0.0 --end-ip-address 0.0.0.0 --subscription "$subName"`
36+
37+
# SQL Server DB Creation
38+
39+
`az sql db create --resource-group $resourceGroup --server $sqlDBName --name tailwind --subscription "$subName"`
40+
41+
# Azure Container Registry Creation
42+
43+
`az acr create --resource-group $resourceGroup --name $acrName --sku Basic --subscription "$subName" --admin-enabled true`
44+
45+
`az appservice plan create -g $resourceGroup -n $webappName --is-linux --sku S1`
46+
47+
# Build our image
48+
49+
```
50+
cd igniteapps30/TailwindTraders-Website/Source/Tailwind.Traders.Web/
51+
az acr build --subscription "Ignite The Tour" --registry $acrName --image $webappName .
52+
```
53+
54+
# Create our App Service Service Plan
55+
56+
`az appservice plan create -g $resourceGroup -n $webappName --is-linux --sku S1`
57+
58+
# Create our App Service Container Web App
59+
60+
`az webapp create --resource-group $resourceGroup --plan $webappName --name $webappName --deployment-container-image-name $acrName.azurecr.io/$webappName:ca1`
61+
62+
# Configure loggin on our web app
63+
64+
`az webapp log config -n $webappName -g $resourceGroup --web-server-logging filesystem`
65+
66+
# Speficy which image to use for our web app
67+
68+
`REGISTRY_PASSWORD=$(az acr credential show -n $acrName -o tsv --query 'passwords[0].value')`
69+
70+
`az webapp config container set --name $webappName --resource-group $resourceGroup --docker-custom-image-name liveigniteapps30acr.azurecr.io/$webappName:ca1 --docker-registry-server-url https://liveigniteapps30acr.azurecr.io --docker-registry-server-user liveigniteapps30acr --docker-registry-server-password $REGISTRY_PASSWORD`
71+
72+
# Get our Cosmos and SQL Connection strings
73+
74+
`cosmosConnectionString=$(az cosmosdb list-connection-strings --name $cosmosDBName --resource-group $resourceGroup --query 'connectionStrings[0].connectionString' -o tsv --subscription "$subName")`
75+
76+
`sqlConnectionString=$(az sql db show-connection-string --server $sqlDBName --name tailwind -c ado.net --subscription "$subName" | jq -r .)`
77+
78+
**Note:** Be sure to update the sqlConnection String with your
79+
80+
# Configure environment variables for our webapp to work properly
81+
82+
`az webapp config appsettings set --resource-group $resourceGroup --name $webappName --settings apiUrl=/api/v1 ApiUrlShoppingCart=/api/v1 productImagesUrl=https://raw.githubusercontent.com/microsoft/TailwindTraders-Backend/master/Deploy/tailwindtraders-images/product-detail SqlConnectionString="sqlConnectionString" MongoConnectionString="$cosmosConnectionString"`

Deploy/DeployWebAKS.ps1

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Param(
1111
[parameter(Mandatory = $false)][string]$tlsHost = "",
1212
[parameter(Mandatory = $false)][string]$tlsSecretName = "",
1313
[parameter(Mandatory = $false)][string]$appInsightsName = "",
14-
[parameter(Mandatory = $false)][bool]$build = $false,
14+
[parameter(Mandatory = $false)][string]$build = $false,
1515
[parameter(Mandatory = $false)][string]$subscription = ""
1616
)
1717

@@ -46,8 +46,8 @@ function validate {
4646
}
4747

4848
function buildPushImageDocker() {
49-
$sourceFolder = $(./Join-Path-Recursively.ps1 -pathParts .., Source)
50-
Write-Host "Source Folder $sourceFolder" -ForegroundColor Yellow
49+
Push-Location $($MyInvocation.InvocationName | Split-Path)
50+
$sourceFolder = $(./Join-Path-Recursively.ps1 -pathParts .., Source)
5151

5252
Write-Host "Getting info from ACR $resourceGroup/$acrName" -ForegroundColor Yellow
5353
$acrCredentials = $(az acr credential show -g $resourceGroup -n $acrName -o json | ConvertFrom-Json)
@@ -83,7 +83,7 @@ function createHelmCommand([string]$command, $chart) {
8383
$newcmd = $command
8484

8585
if (-not [string]::IsNullOrEmpty($tlsSecretNameToUse)) {
86-
$newcmd = "$newcmd --set ingress.protocol=https --set ingress.tls[0].secretName=$tlsSecretNameToUse --set ingress.tls[0].hosts='{$aksHost}'"
86+
$newcmd = "$newcmd --set ingress.protocol=https --set ingress.tls[0].secretName=$tlsSecretNameToUse --set ingress.tls[0].hosts={$aksHost}"
8787
}
8888
else {
8989
$newcmd = "$newcmd --set ingress.protocol=http"
@@ -104,8 +104,6 @@ Write-Host " Images tag: $tag" -ForegroundColor Red
104104
Write-Host " TLS/SSL environment to enable: $tlsEnv" -ForegroundColor Red
105105
Write-Host " --------------------------------------------------------"
106106

107-
Push-Location $($MyInvocation.InvocationName | Split-Path)
108-
109107
if ($build -and ([string]::IsNullOrEmpty($acrName))) {
110108
$acrName = $(az acr list --resource-group $resourceGroup --subscription $subscription -o json | ConvertFrom-Json).name
111109
}
@@ -122,15 +120,7 @@ else {
122120
$aksHost = $tlsHost
123121
}
124122

125-
if ($build) {
126-
# Connecting kubectl to AKS
127-
Write-Host "Retrieving Aks Name" -ForegroundColor Yellow
128-
$aksName = $(az aks list -g $resourceGroup -o json | ConvertFrom-Json).name
129-
Write-Host "The name of your AKS: $aksName" -ForegroundColor Yellow
130-
131-
Write-Host "Retrieving credentials" -ForegroundColor Yellow
132-
az aks get-credentials -n $aksName -g $resourceGroup
133-
123+
if ($build) {
134124
buildPushImageDocker
135125
}
136126

Documents/Devspaces.md

Lines changed: 0 additions & 21 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ And it will return your base [TailwindTraders-Backend](https://github.com/Micros
4545

4646
Please follow these steps to deploy the web in the same AKS where Backend is running instead of deploying to an App Service.
4747

48-
**Note**: Website supports [Devspaces deployment](./Documents/Devspaces.md).
48+
**Note**: Website supports [Bridge to Kubernetes Deployment](https://github.com/Microsoft/TailwindTraders-Backend/README.md#running-using-bridge-to-kubernetes).
4949

5050
## Pre-Requisites:
5151

0 commit comments

Comments
 (0)