Skip to content

Cr10 #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 25 commits into from
Closed

Cr10 #34

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b856ced
Remove pages YAML file
Sep 11, 2024
fe0f0a5
Added workflow
fatihdurgut Sep 11, 2024
46ecb87
fix the issue
fatihdurgut Sep 11, 2024
2c36513
Refactor message entity and add validation
fatihdurgut Sep 12, 2024
72f7b1d
Refactor message entity and add validation
fatihdurgut Sep 12, 2024
c097096
Update Newtonsoft.Json package to version 13.0.3
fatihdurgut Sep 12, 2024
1aed13f
Merge pull request #7 from fatihdurgut/CR6
fatihdurgut Sep 12, 2024
0a698b9
Refactor main.bicep file and update resource definitions
fatihdurgut Sep 12, 2024
45e29f1
Refactor deploy.yml to add support for choosing target environment
fatihdurgut Sep 12, 2024
147cd7c
first version
fatihdurgut Sep 12, 2024
24577f7
test
fatihdurgut Sep 12, 2024
5580a92
Refactor validation error message for message length limit
fatihdurgut Sep 12, 2024
8e1a0ab
Refactor deploy.yml to add support for choosing target environment
fatihdurgut Sep 12, 2024
b449641
Refactor validation error message for message length limit
fatihdurgut Sep 12, 2024
f6a98a9
Refactor Dockerfile to use .NET 8.0 SDK and ASP.NET runtime
fatihdurgut Sep 12, 2024
54be685
Refactor Dockerfile to use .NET 8.0 SDK and ASP.NET runtime
fatihdurgut Sep 12, 2024
9be762c
Refactor RazorPagesTestSample Index.cshtml
fatihdurgut Sep 12, 2024
7860c95
Refactor dotnet-deploy-3.yml to update image registry URL
fatihdurgut Sep 12, 2024
d24203b
Refactor RazorPagesTestSample Index.cshtml to fix formatting of the "…
fatihdurgut Sep 12, 2024
6d09875
Refactor dotnet-deploy.yml to update image registry URL
fatihdurgut Sep 12, 2024
e2771ac
Fix formatting of "Add a message" panel title in Index.cshtml
fatihdurgut Sep 12, 2024
891047a
Refactor Index.cshtml to update the "Add a message" panel title
fatihdurgut Sep 12, 2024
ddd8bd8
Refactor dotnet-deploy.yml to update image registry URL
fatihdurgut Sep 12, 2024
30cd197
Refactor Index.cshtml to update the "Add a message" panel title
fatihdurgut Sep 12, 2024
deb50d7
Update "Add a message" panel title in Index.cshtml
fatihdurgut Sep 12, 2024
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
40 changes: 40 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Azure Bicep-Advanced

on:
workflow_dispatch:
inputs:
appenv:
type: choice
description: Choose the target environment
options:
- dev
- test
- prod

jobs:
build-and-deploy:
runs-on: ubuntu-latest
permissions:
contents: read
pages: write
id-token: write
steps:
# Checkout code
- uses: actions/checkout@main

# Log into Azure
- uses: azure/[email protected]
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
enable-AzPSSession: true

# Deploy ARM template
- name: Run ARM deploy
uses: azure/arm-deploy@v1
with:
subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
resourceGroupName: ${{ secrets.AZURE_RG }}
template: ./src/InfrastructureAsCode/main.bicep
parameters: environment=${{ github.event.inputs.appenv }}
136 changes: 136 additions & 0 deletions .github/workflows/dotnet-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
name: .NET CI

env:
registryName: qkycf2fsjozsgmpnpreg.azurecr.io
repositoryName: techexcel/dotnetcoreapp
dockerFolderPath: ./src/Application/src/RazorPagesTestSample
tag: ${{github.run_number}}

on:
push:
branches: [ main ]
paths: src/Application/**
pull_request:
branches: [ main ]
paths: src/Application/**
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0

- name: Restore dependencies
run: dotnet restore ./src/Application/src/RazorPagesTestSample/RazorPagesTestSample.csproj
- name: Build
run: dotnet build --no-restore ./src/Application/src/RazorPagesTestSample/RazorPagesTestSample.csproj
- name: Test
run: dotnet test --no-build --verbosity normal ./src/Application/tests/RazorPagesTestSample.Tests/RazorPagesTestSample.Tests.csproj

- uses: actions/github-script@v6
if: failure()
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
let body = "${{ env.build_name }} Workflow Failure \n Build Number: ${{ github.run_number }} \n Build Log: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} \n SHA: [${{ github.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) \n";
github.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: "${{ env.build_name }} Workflow ${{ github.run_number }} Failed! ",
body: body
});

dockerBuildPush:
runs-on: ubuntu-latest
needs: build

steps:
- uses: actions/checkout@v3

- name: Docker Login
# You may pin to the exact commit or the version.
# uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
uses: docker/[email protected]
with:
# Server address of Docker registry. If not set then will default to Docker Hub
registry: ${{ secrets.ACR_LOGIN_SERVER }}
# Username used to log against the Docker registry
username: ${{ secrets.ACR_USERNAME }}
# Password or personal access token used to log against the Docker registry
password: ${{ secrets.ACR_PASSWORD }}
# Log out from the Docker registry at the end of a job
logout: true

- name: Docker Build
run: docker build -t $registryName/$repositoryName:$tag --build-arg build_version=$tag $dockerFolderPath

- name: Docker Push
run: docker push $registryName/$repositoryName:$tag

deploy-to-dev:

runs-on: ubuntu-latest
needs: dockerBuildPush
environment:
name: dev
url: https://qkycf2fsjozsg-dev.azurewebsites.net/

steps:
- name: 'Login via Azure CLI'
uses: azure/[email protected]
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- uses: azure/webapps-deploy@v2
with:
app-name: 'qkycf2fsjozsg-dev'
images: qkycf2fsjozsgmpnpreg.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}}

deploy-to-test:

runs-on: ubuntu-latest
needs: deploy-to-dev
environment:
name: test
url: https://qkycf2fsjozsg-test.azurewebsites.net/

steps:
- uses: actions/checkout@v3

- name: 'Login via Azure CLI'
uses: azure/[email protected]
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- uses: azure/webapps-deploy@v2
with:
app-name: 'qkycf2fsjozsg-test'
images: qkycf2fsjozsgmpnpreg.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}}

deploy-to-prod:

runs-on: ubuntu-latest
needs: deploy-to-test
environment:
name: prod
url: https://qkycf2fsjozsg-prod.azurewebsites.net/

steps:
- uses: actions/checkout@v3

- name: 'Login via Azure CLI'
uses: azure/[email protected]
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- uses: azure/webapps-deploy@v2
with:
app-name: 'qkycf2fsjozsg-prod'
images: qkycf2fsjozsgmpnpreg.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}}
23 changes: 23 additions & 0 deletions .github/workflows/first-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: First Workflow

on:
workflow_dispatch:
issues:
types: [opened]

jobs:
job1:
runs-on: ubuntu-latest

steps:
- name: Step one
run: echo "Log from step one"
- name: Step two
run: echo "Log from step two"

job2:
runs-on: ubuntu-latest

steps:
- name: Step two
run: echo "Log from step two"
62 changes: 0 additions & 62 deletions .github/workflows/pages.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"sarif-viewer.connectToGithubCodeScanning": "off"
}
20 changes: 10 additions & 10 deletions Solution/Exercise-03/Task-3/dotnet-deploy-3.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: .NET CI

env:
registryName: {your_registry_name}.azurecr.io
registryName: qkycf2fsjozsgmpnpreg.azurecr.io
repositoryName: techexcel/dotnetcoreapp
dockerFolderPath: ./src/Application/src/RazorPagesTestSample
tag: ${{github.run_number}}
Expand Down Expand Up @@ -67,7 +67,7 @@ jobs:
needs: dockerBuildPush
environment:
name: dev
url: https://{your_prefix}-dev.azurewebsites.net/
url: https://qkycf2fsjozsg-dev.azurewebsites.net/

steps:
- name: 'Login via Azure CLI'
Expand All @@ -77,16 +77,16 @@ jobs:

- uses: azure/webapps-deploy@v2
with:
app-name: '{your_prefix}-dev'
images: {your_registry_name}.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}}
app-name: 'qkycf2fsjozsg-dev'
images: registryName.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}}

deploy-to-test:

runs-on: ubuntu-latest
needs: deploy-to-dev
environment:
name: test
url: https://{your_prefix}-test.azurewebsites.net/
url: https://qkycf2fsjozsg-test.azurewebsites.net/

steps:
- uses: actions/checkout@v3
Expand All @@ -98,16 +98,16 @@ jobs:

- uses: azure/webapps-deploy@v2
with:
app-name: '{your_prefix}-test'
images: {your_registry_name}.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}}
app-name: 'qkycf2fsjozsg-test'
images: registryName.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}}

deploy-to-prod:

runs-on: ubuntu-latest
needs: deploy-to-test
environment:
name: prod
url: https://{your_prefix}-prod.azurewebsites.net/
url: https://qkycf2fsjozsg-prod.azurewebsites.net/

steps:
- uses: actions/checkout@v3
Expand All @@ -119,5 +119,5 @@ jobs:

- uses: azure/webapps-deploy@v2
with:
app-name: '{your_prefix}-prod'
images: {your_registry_name}.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}}
app-name: 'qkycf2fsjozsg-prod'
images: registryName.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}}
21 changes: 16 additions & 5 deletions src/Application/src/RazorPagesTestSample/Data/Message.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
using System.ComponentModel.DataAnnotations;

namespace RazorPagesTestSample.Data
/// <summary>
/// Represents a message entity with an ID and text content.
/// </summary>
namespace RazorPagesTestSample
{
#region snippet1
public class Message
{
/// <summary>
/// Gets or sets the unique identifier for the message.
/// </summary>
public int Id { get; set; }

/// <summary>
/// Gets or sets the text content of the message.
/// </summary>
/// <remarks>
/// The text content is required and must be a string with a maximum length of 250 characters.
/// </remarks>
[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
}

}
18 changes: 18 additions & 0 deletions src/Application/src/RazorPagesTestSample/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build-env /app/out .
# Default ASP.NET port changed with .NET 8.0
ENV ASPNETCORE_HTTP_PORTS=80
ENTRYPOINT ["dotnet", "RazorPagesTestSample.dll"]
Loading
Loading