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

Commit

Permalink
Merge pull request #223 from jldeen/feature/net5andbridge2k8s
Browse files Browse the repository at this point in the history
+ Support for .NET 5 and Bridge to Kubernetes
  • Loading branch information
Borja García authored Feb 3, 2021
2 parents 0eb78f3 + fdb1369 commit b358225
Show file tree
Hide file tree
Showing 24 changed files with 463 additions and 152 deletions.
46 changes: 46 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------

FROM mcr.microsoft.com/dotnet/core/sdk:2.1

# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive
ENV ASPNETCORE_URLS=http://0.0.0.0:5000

# This Dockerfile adds a non-root 'vscode' user with sudo access. However, for Linux,
# this user's GID/UID must match your local user UID/GID to avoid permission issues
# with bind mounts. Update USER_UID / USER_GID if yours is not 1000. See
# https://aka.ms/vscode-remote/containers/non-root-user for details.
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# Configure apt and install packages
RUN apt-get update \
&& apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \
#
# Verify git, process tools, lsb-release (common in install instructions for CLIs) installed
&& apt-get -y install git iproute2 procps lsb-release \
#
# Install node
&& apt-get -y install curl gnupg build-essential \
&& curl -sL https://deb.nodesource.com/setup_10.x | bash - \
&& apt-get -y install nodejs \
#
# Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user.
&& groupadd --gid $USER_GID $USERNAME \
&& useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
# [Optional] Add sudo support for the non-root user
&& apt-get install -y sudo \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\
&& chmod 0440 /etc/sudoers.d/$USERNAME \
#
# Clean up
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

# Switch back to dialog for any ad-hoc use of apt-get
ENV DEBIAN_FRONTEND=
30 changes: 30 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or the definition README at
// https://github.com/microsoft/vscode-dev-containers/tree/master/containers/dotnetcore-2.1
{
"name": "TailwindTraders-Website",
"dockerComposeFile": "docker-compose.yml",
"service": "web",
"workspaceFolder": "/workspace",

// Use 'settings' to set *default* container specific settings.json values on container create.
// You can edit these settings after create using File > Preferences > Settings > Remote.
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},

// Uncomment the next line if you want to publish any ports.
// "appPort": [],

// Uncomment the next line to run commands after the container is created.
// "postCreateCommand": "dotnet restore"

// Uncomment the next line to use a non-root user. On Linux, this will prevent
// new files getting created as root, but you may need to update the USER_UID
// and USER_GID in .devcontainer/Dockerfile to match your user if not 1000.
// "runArgs": [ "-u", "vscode" ],

// Add the IDs of extensions you want installed when the container is created in the array below.
"extensions": [
"ms-vscode.csharp"
]
}
39 changes: 39 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------

version: '3'
services:
web:
# Uncomment the next line to use a non-root user. On Linux, this will prevent
# new files getting created as root, but you may need to update the USER_UID
# and USER_GID in .devcontainer/Dockerfile to match your user if not 1000.
# user: node

build:
context: .
dockerfile: Dockerfile
volumes:
- ..:/workspace
ports:
- 5000:5000

# Overrides default command so things don't shut down after the process ends.
command: sleep infinity

links:
- mongo
- sql

mongo:
image: mongo
restart: unless-stopped

sql:
image: mcr.microsoft.com/mssql/server:2017-latest
restart: unless-stopped
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=Twtraders123456!

2 changes: 1 addition & 1 deletion .github/workflows/aks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Docker build and push
working-directory: Source/Tailwind.Traders.Web
run: |
docker build . --build-arg sdkTag=3.1 --build-arg runtimeTag=3.1 -t tailwindtraders/web:gh-${{ github.sha }} -t latest
docker build . --build-arg sdkTag=5.0 --build-arg runtimeTag=5.0 -t tailwindtraders/web:gh-${{ github.sha }} -t latest
docker push tailwindtraders/web:gh-${{ github.sha }}
- uses: azure/login@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/container_appservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Docker build and push
working-directory: Source/Tailwind.Traders.Web
run: |
docker build . --build-arg sdkTag=3.1 --build-arg runtimeTag=3.1 -t tailwindtraders/web:gh-${{ github.sha }} -t latest
docker build . --build-arg sdkTag=5.0 --build-arg runtimeTag=5.0 -t tailwindtraders/web:gh-${{ github.sha }} -t latest
docker push tailwindtraders/web:gh-${{ github.sha }}
# - uses: azure/appservice-settings@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr_build_check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
- name: Docker build
working-directory: Source/Tailwind.Traders.Web
run: |
docker build . --build-arg sdkTag=3.1 --build-arg runtimeTag=3.1 -t tailwindtraders/web:gh-${{ github.sha }} -t latest
docker build . --build-arg sdkTag=5.0 --build-arg runtimeTag=5.0 -t tailwindtraders/web:gh-${{ github.sha }} -t latest
6 changes: 3 additions & 3 deletions .github/workflows/tt-website.cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Docker build
working-directory: Source/Tailwind.Traders.Web
run: |
docker build . --build-arg sdkTag=3.1 --build-arg runtimeTag=3.1 -t tailwindtraders/web:gh-${{ github.sha }} -t latest
docker build . --build-arg sdkTag=5.0 --build-arg runtimeTag=5.0 -t tailwindtraders/web:gh-${{ github.sha }} -t latest
main-build:
if: ${{ github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event.pull_request.merged == true) }}
Expand All @@ -31,7 +31,7 @@ jobs:
- name: Docker build
working-directory: Source/Tailwind.Traders.Web
run: |
docker build . --build-arg sdkTag=3.1 --build-arg runtimeTag=3.1 -t tailwindtraders/web:gh-${{ github.sha }} -t latest
docker build . --build-arg sdkTag=5.0 --build-arg runtimeTag=5.0 -t tailwindtraders/web:gh-${{ github.sha }} -t latest
nightly-build-and-deploy:
if: ${{ github.event_name == 'schedule' }}
Expand All @@ -53,7 +53,7 @@ jobs:
- name: Docker build and push
working-directory: Source/Tailwind.Traders.Web
run: |
docker build . --build-arg sdkTag=3.1 --build-arg runtimeTag=3.1 -t tailwindtraders/web:gh-${{ github.sha }} -t latest
docker build . --build-arg sdkTag=5.0 --build-arg runtimeTag=5.0 -t tailwindtraders/web:gh-${{ github.sha }} -t latest
docker push tailwindtraders/web:gh-${{ github.sha }}
- uses: azure/webapps-deploy@v2
Expand Down
34 changes: 34 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/Source/Tailwind.Traders.Web/bin/Debug/netcoreapp2.1/Tailwind.Traders.Web.dll",
"args": [],
"cwd": "${workspaceFolder}/Source/Tailwind.Traders.Web",
"stopAtEntry": false,
"serverReadyAction": {
"action": "openExternally",
"pattern": "^\\s*Now listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
42 changes: 42 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/Source/Tailwind.Traders.Web/Tailwind.Traders.Web.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/Source/Tailwind.Traders.Web/Tailwind.Traders.Web.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/Source/Tailwind.Traders.Web/Tailwind.Traders.Web.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}
82 changes: 82 additions & 0 deletions Demo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Apps 30 Demo Commands

### Environment Variables Used

```
resourceGroup=live-igniteapps30
location=eastus
subName="Ignite The Tour"
cosmosDBName=liveapps30twtnosqlge
sqlDBName=liveapps30twtsql
webappName=liveigniteapps30
acrName=liveigniteapps30acr
adminUser=twtadmin
adminPassword=twtapps30pD
```

### Resource Group Creation

`az group create --subscription "$subName" --name $resourceGroup --location $location`

### VNet Creation

`az network vnet create --name igniteapps30vnet --subscription "$subName" --resource-group $resourceGroup --subnet-name default`

### CosmosDB Creation

`az cosmosdb create --name $cosmosDBName --resource-group $resourceGroup --kind MongoDB --subscription "$subName"`

# SQL Server Creation

`az sql server create --location $location --resource-group $resourceGroup --name $sqlDBName --admin-user $adminUser --admin-password $adminPassword --subscription "$subName"`

# SQL Server Firewall Rule

`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"`

# SQL Server DB Creation

`az sql db create --resource-group $resourceGroup --server $sqlDBName --name tailwind --subscription "$subName"`

# Azure Container Registry Creation

`az acr create --resource-group $resourceGroup --name $acrName --sku Basic --subscription "$subName" --admin-enabled true`

`az appservice plan create -g $resourceGroup -n $webappName --is-linux --sku S1`

# Build our image

```
cd igniteapps30/TailwindTraders-Website/Source/Tailwind.Traders.Web/
az acr build --subscription "Ignite The Tour" --registry $acrName --image $webappName .
```

# Create our App Service Service Plan

`az appservice plan create -g $resourceGroup -n $webappName --is-linux --sku S1`

# Create our App Service Container Web App

`az webapp create --resource-group $resourceGroup --plan $webappName --name $webappName --deployment-container-image-name $acrName.azurecr.io/$webappName:ca1`

# Configure loggin on our web app

`az webapp log config -n $webappName -g $resourceGroup --web-server-logging filesystem`

# Speficy which image to use for our web app

`REGISTRY_PASSWORD=$(az acr credential show -n $acrName -o tsv --query 'passwords[0].value')`

`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`

# Get our Cosmos and SQL Connection strings

`cosmosConnectionString=$(az cosmosdb list-connection-strings --name $cosmosDBName --resource-group $resourceGroup --query 'connectionStrings[0].connectionString' -o tsv --subscription "$subName")`

`sqlConnectionString=$(az sql db show-connection-string --server $sqlDBName --name tailwind -c ado.net --subscription "$subName" | jq -r .)`

**Note:** Be sure to update the sqlConnection String with your

# Configure environment variables for our webapp to work properly

`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"`
20 changes: 5 additions & 15 deletions Deploy/DeployWebAKS.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Param(
[parameter(Mandatory = $false)][string]$tlsHost = "",
[parameter(Mandatory = $false)][string]$tlsSecretName = "",
[parameter(Mandatory = $false)][string]$appInsightsName = "",
[parameter(Mandatory = $false)][bool]$build = $false,
[parameter(Mandatory = $false)][string]$build = $false,
[parameter(Mandatory = $false)][string]$subscription = ""
)

Expand Down Expand Up @@ -46,8 +46,8 @@ function validate {
}

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

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

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

Push-Location $($MyInvocation.InvocationName | Split-Path)

if ($build -and ([string]::IsNullOrEmpty($acrName))) {
$acrName = $(az acr list --resource-group $resourceGroup --subscription $subscription -o json | ConvertFrom-Json).name
}
Expand All @@ -122,15 +120,7 @@ else {
$aksHost = $tlsHost
}

if ($build) {
# Connecting kubectl to AKS
Write-Host "Retrieving Aks Name" -ForegroundColor Yellow
$aksName = $(az aks list -g $resourceGroup -o json | ConvertFrom-Json).name
Write-Host "The name of your AKS: $aksName" -ForegroundColor Yellow

Write-Host "Retrieving credentials" -ForegroundColor Yellow
az aks get-credentials -n $aksName -g $resourceGroup

if ($build) {
buildPushImageDocker
}

Expand Down
Loading

0 comments on commit b358225

Please sign in to comment.