Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Manual Deployment
on:
workflow_dispatch

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Login to Azure
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
enable-AzPSSession: true

- name: Deploy ARM Template
uses: Azure/arm-deploy@v1
with:
subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
resourceGroupName: ${{ secrets.AZURE_RG }}
template: ./InfrastructureAsCode/main.bicep
parameters: environment=${{ env.targetEnv }}
60 changes: 60 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# The name of the job is what will display on the GitHub repository in the Actions tab.
name: First Workflow

# The 'on' section tells GitHub under what conditions we want to run this workflow.
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows
# Common scenarios include:
# workflow-dispatch (manual execution)
# issues
# push
# pull_request
# schedule
on:
workflow_dispatch:
issues:
types: [opened]

env: # Define environment variables for the entire workflow
MY_ENV_VAR: "Hello, World!"

# This section covers the work to perform.
# We include one or more jobs in this section.
jobs:
# Each individual job will include details like execution order,
# pre-requisite jobs, and execution platform.
job1:
# We can run jobs on GitHub hosted VM runners in Windows, Ubuntu, and Mac OS.
# We can also run jobs on self-hosted hardware.
runs-on: ubuntu-latest

# Each job contains one or more steps. A step needs to have at least a name and a command.
steps:
- name: Step one
# The 'run' command executes a shell or command script. Because this is Ubuntu, the
# default run command will be /bin/bash
run: echo "Log from step one"
# This section does not appear in the solution file but demonstrates how to set
# custom variables that will be available in the run script.
env:
VARIABLE_NAME: value
- name: Step two
run: echo "Log from step two"

job2:
# Job 2 will only run after job 1 completes.
# Removing this 'needs' section would make the jobs run simultaneously.
needs: job1
runs-on: ubuntu-latest

steps:
- name: Cowsays
# The 'uses' command executes a remote GitHub action.
# A command like mscoutermarsh/cowsays-action means you can
# find this code at https://github.com/mscoutermarsh/cowsays-action
uses: mscoutermarsh/cowsays-action@master
# The 'with' block includes parameters that the workflow will pass
# to this action. Parameters are all in key-value format.
with:
# text: 'Ready for prod--ship it!'
text: ${{ env.MY_ENV_VAR }}
color: 'magenta'
2 changes: 1 addition & 1 deletion Application/src/RazorPagesTestSample/Data/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Message

[Required]
[DataType(DataType.Text)]
[StringLength(200, ErrorMessage = "There's a 200 character limit on messages. Please shorten your message.")]
[StringLength(250, ErrorMessage = "There's a 250 character limit on messages. Please shorten your message.")]
public string Text { get; set; }
}
#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,37 @@ public async Task DeleteMessageAsync_NoMessageIsDeleted_WhenMessageIsNotFound()
}
}
#endregion

[Theory]
[InlineData(150)]
[InlineData(199)]
[InlineData(200)]
[InlineData(201)]
[InlineData(249)]
[InlineData(250)]
[InlineData(251)]
[InlineData(300)]
public void TestMessageLength(int length)
{
// Arrange
var message = new Message();
message.Text = new string('a', length);

// Act
var context = new ValidationContext(message, null, null);
var results = new List<ValidationResult>();

// Assert
if (length > 250)
{
Assert.False(Validator.TryValidateObject(message, context, results, true));
Assert.Equal("There's a 250 character limit on messages. Please shorten your message.", results[0].ErrorMessage);
}
else
{
Assert.True(Validator.TryValidateObject(message, context, results, true));
}
}

}
}
34 changes: 31 additions & 3 deletions InfrastructureAsCode/main.bicep
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
// Environment parameter for the web app
@description('Environment of the web app')
param environment string = 'dev'

// Location parameter for services
@description('Location of services')
param location string = resourceGroup().location

// Generate a unique name for the web app
var webAppName = '${uniqueString(resourceGroup().id)}-${environment}'

// Generate a unique name for the app service plan
var appServicePlanName = '${uniqueString(resourceGroup().id)}-mpnp-asp'

// Generate a unique name for the log analytics workspace
var logAnalyticsName = '${uniqueString(resourceGroup().id)}-mpnp-la'

// Generate a unique name for the application insights
var appInsightsName = '${uniqueString(resourceGroup().id)}-mpnp-ai'

// SKU for the app service plan
var sku = 'S1'

// Generate a unique name for the container registry
var registryName = '${uniqueString(resourceGroup().id)}mpnpreg'

// SKU for the container registry
var registrySku = 'Standard'

// Image name for the Docker container
var imageName = 'techboost/dotnetcoreapp'
var startupCommand = ''

// Startup command for the web app
var startupCommand = ''

// Resource for the log analytics workspace
resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2021-12-01-preview' = {
name: logAnalyticsName
location: location
Expand All @@ -29,6 +48,7 @@ resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2021-12
}
}

// Resource for the application insights
resource appInsights 'Microsoft.Insights/components@2020-02-02-preview' = {
name: appInsightsName
location: location
Expand All @@ -39,6 +59,7 @@ resource appInsights 'Microsoft.Insights/components@2020-02-02-preview' = {
}
}

// Resource for the container registry
resource containerRegistry 'Microsoft.ContainerRegistry/registries@2020-11-01-preview' = {
name: registryName
location: location
Expand All @@ -50,6 +71,7 @@ resource containerRegistry 'Microsoft.ContainerRegistry/registries@2020-11-01-pr
}
}

// Resource for the app service plan
resource appServicePlan 'Microsoft.Web/serverFarms@2020-12-01' = {
name: appServicePlanName
location: location
Expand All @@ -62,6 +84,7 @@ resource appServicePlan 'Microsoft.Web/serverFarms@2020-12-01' = {
}
}

// Resource for the app service app (web app)
resource appServiceApp 'Microsoft.Web/sites@2020-12-01' = {
name: webAppName
location: location
Expand Down Expand Up @@ -95,11 +118,16 @@ resource appServiceApp 'Microsoft.Web/sites@2020-12-01' = {
name: 'APPINSIGHTS_INSTRUMENTATIONKEY'
value: appInsights.properties.InstrumentationKey
}
]
}
]
}
}
}

// Output for the application name
output application_name string = appServiceApp.name

// Output for the application URL
output application_url string = appServiceApp.properties.hostNames[0]

// Output for the container registry name
output container_registry_name string = containerRegistry.name