Giter Club home page Giter Club logo

microsoftlearning / eshoponweb Goto Github PK

View Code? Open in Web Editor NEW
112.0 7.0 633.0 3.54 MB

Repository maintained by AZ-400 course and Learn content community. Project used for AZ-400 Labs. Forked from: https://github.com/dotnet-architecture/eShopOnWeb Sample - ASP.NET Core 8.0 reference application, powered by Microsoft, demonstrating a layered application architecture with monolithic deployment model.

License: MIT License

Bicep 5.53% Dockerfile 0.30% C# 69.21% HTML 18.93% CSS 3.17% SCSS 2.85% JavaScript 0.01%
az-400 devops github github-actions bicep pipelines

eshoponweb's Introduction

Build Status

Microsoft eShopOnWeb ASP.NET Core Reference Application

Sample ASP.NET Core reference application, powered by Microsoft, demonstrating a single-process (monolithic) application architecture and deployment model. If you're new to .NET development, read the Getting Started for Beginners guide.

A list of Frequently Asked Questions about this repository can be found here.

Overview Video

Steve "ardalis" Smith recorded a live stream providing an overview of the eShopOnWeb reference app in October 2020.

eBook

This reference application is meant to support the free .PDF download ebook: Architecting Modern Web Applications with ASP.NET Core and Azure, updated to ASP.NET Core 8.0. Also available in ePub/mobi formats.

You can also read the book in online pages at the .NET docs here: https://docs.microsoft.com/dotnet/architecture/modern-web-apps-azure/

The eShopOnWeb sample is related to the eShopOnContainers sample application which, in that case, focuses on a microservices/containers-based application architecture. However, eShopOnWeb is much simpler in regards to its current functionality and focuses on traditional Web Application Development with a single deployment.

The goal for this sample is to demonstrate some of the principles and patterns described in the eBook. It is not meant to be an eCommerce reference application, and as such it does not implement many features that would be obvious and/or essential to a real eCommerce application.

VERSIONS

The main branch is currently running ASP.NET Core 8.0.

Older versions are tagged.

Topics (eBook TOC)

  • Introduction
  • Characteristics of Modern Web Applications
  • Choosing Between Traditional Web Apps and SPAs
  • Architectural Principles
  • Common Web Application Architectures
  • Common Client Side Technologies
  • Developing ASP.NET Core MVC Apps
  • Working with Data in ASP.NET Core Apps
  • Testing ASP.NET Core MVC Apps
  • Development Process for Azure-Hosted ASP.NET Core Apps
  • Azure Hosting Recommendations for ASP.NET Core Web Apps

Running the sample using Azd template

The store's home page should look like this:

eShopOnWeb home page screenshot

The Azure Developer CLI (azd) is a developer-centric command-line interface (CLI) tool for creating Azure applications.

You need to install it before running and deploying with Azure Developer CLI.

Windows

powershell -ex AllSigned -c "Invoke-RestMethod 'https://aka.ms/install-azd.ps1' | Invoke-Expression"

Linux/MacOS

curl -fsSL https://aka.ms/install-azd.sh | bash

And you can also install with package managers, like winget, choco, and brew. For more details, you can follow the documentation: https://aka.ms/azure-dev/install.

After logging in with the following command, you will be able to use the azd cli to quickly provision and deploy the application.

azd auth login

Then, execute the azd init command to initialize the environment.

azd init -t dotnet-architecture/eShopOnWeb 

Run azd up to provision all the resources to Azure and deploy the code to those resources.

azd up 

According to the prompt, enter an env name, and select subscription and location, these are the necessary parameters when you create resources. Wait a moment for the resource deployment to complete, click the web endpoint and you will see the home page.

Notes:

  1. Considering security, we store its related data (id, password) in the Azure Key Vault when we create the database, and obtain it from the Key Vault when we use it. This is different from directly deploying applications locally.
  2. The resource group name created in azure portal will be rg-{env name}.

You can also run the sample directly locally (See below).

Running the sample locally

Most of the site's functionality works with just the web application running. However, the site's Admin page relies on Blazor WebAssembly running in the browser, and it must communicate with the server using the site's PublicApi web application. You'll need to also run this project. You can configure Visual Studio to start multiple projects, or just go to the PublicApi folder in a terminal window and run dotnet run from there. After that from the Web folder you should run dotnet run --launch-profile Web. Now you should be able to browse to https://localhost:5001/. The admin part in Blazor is accessible to https://localhost:5001/admin

Note that if you use this approach, you'll need to stop the application manually in order to build the solution (otherwise you'll get file locking errors).

After cloning or downloading the sample you must setup your database. To use the sample with a persistent database, you will need to run its Entity Framework Core migrations before you will be able to run the app.

You can also run the samples in Docker (see below).

Configuring the sample to use SQL Server

  1. By default, the project uses a real database. If you want an in memory database, you can add in the appsettings.json file in the Web folder

    {
       "UseOnlyInMemoryDatabase": true
    }
  2. Ensure your connection strings in appsettings.json point to a local SQL Server instance.

  3. Ensure the tool EF was already installed. You can find some help here

    dotnet tool update --global dotnet-ef
    
  4. Open a command prompt in the Web folder and execute the following commands:

    dotnet restore
    dotnet tool restore
    dotnet ef database update -c catalogcontext -p ../Infrastructure/Infrastructure.csproj -s Web.csproj
    dotnet ef database update -c appidentitydbcontext -p ../Infrastructure/Infrastructure.csproj -s Web.csproj
    

    These commands will create two separate databases, one for the store's catalog data and shopping cart information, and one for the app's user credentials and identity data.

  5. Run the application.

    The first time you run the application, it will seed both databases with data such that you should see products in the store, and you should be able to log in using the [email protected] account.

    Note: If you need to create migrations, you can use these commands:

    -- create migration (from Web folder CLI)
    dotnet ef migrations add InitialModel --context catalogcontext -p ../Infrastructure/Infrastructure.csproj -s Web.csproj -o Data/Migrations
    
    dotnet ef migrations add InitialIdentityModel --context appidentitydbcontext -p ../Infrastructure/Infrastructure.csproj -s Web.csproj -o Identity/Migrations
    

Running the sample in the dev container

This project includes a .devcontainer folder with a dev container configuration, which lets you use a container as a full-featured dev environment.

You can use the dev container to build and run the app without needing to install any of its tools locally! You can work in GitHub Codespaces or the VS Code Dev Containers extension.

Learn more about using the dev container in its readme.

Running the sample using Docker

You can run the Web sample by running these commands from the root folder (where the .sln file is located):

docker-compose build
docker-compose up

You should be able to make requests to localhost:5106 for the Web project, and localhost:5200 for the Public API project once these commands complete. If you have any problems, especially with login, try from a new guest or incognito browser instance.

You can also run the applications by using the instructions located in their Dockerfile file in the root of each project. Again, run these commands from the root of the solution (where the .sln file is located).

Community Extensions

We have some great contributions from the community, and while these aren't maintained by Microsoft we still want to highlight them.

eShopOnWeb VB.NET by Mohammad Hamdy Ghanem

eshoponweb's People

Contributors

chakra146 avatar dependabot[bot] avatar fimdim avatar luizmacedo avatar maartenvandiemen avatar mjclopes avatar petender avatar peterschoellhorn avatar rob-foulkrod avatar unaihuete93 avatar yashints avatar zhukang6553 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

eshoponweb's Issues

Cannot deploy workflow eShopOnWeb Build and Test

I'm following tutorial from Implementing GitHub Actions for CI/CD
Student lab manual
, and during task 3 (Review GitHub Workflow execution) deployment with workflow eShopOnWeb Build and Test (file .github/workflows/eshoponweb-cicd.yml) fails with the following error :

  • Job in error : "Deploy"
  • Step in error : "deploy"
  • ARM deployment error: ERROR: ***"status":"Failed","error":***"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.","details":[***"code":"Conflict","message":"***\r\n \"Code\": \"Conflict\",\r\n \"Message\": \"No available instances to satisfy this request. App Service is attempting to increase capacity. Please retry your request later. If urgent, this can be mitigated by deploying this to a new resource group.\",\r\n \"Target\": null,\r\n \"Details\": [\r\n ***\r\n \"Message\": \"No available instances to satisfy this request. App Service is attempting to increase capacity. Please retry your request later. If urgent, this can be mitigated by deploying this to a new resource group.\"\r\n ***,\r\n ***\r\n \"Code\": \"Conflict\"\r\n ***,\r\n ***\r\n \"ErrorEntity\": ***\r\n \"ExtendedCode\": \"03029\",\r\n \"MessageTemplate\": \"No available instances to satisfy this request. App Service is attempting to increase capacity. Please retry your request later. If urgent, this can be mitigated by deploying this to a new resource group.\",\r\n \"Parameters\": [],\r\n \"Code\": \"Conflict\",\r\n \"Message\": \"No available instances to satisfy this request. App Service is attempting to increase capacity. Please retry your request later. If urgent, this can be mitigated by deploying this to a new resource group.\"\r\n ***\r\n ***\r\n ],\r\n \"Innererror\": null\r\n***"***]***

After first investigation, it seems that the Azure Service Plan has been created with the Windows OS instead of Linux

App targeting .Net 6 vs Packages targeting .Net 7

Getting the main and trying to run the docker-compose build command produces this:

image

As .Net 7 has gone prod a few days ago, it seems some referenced packages have been upgraded but the target .Net version has not.

> docker-compose build
[+] Building 10.9s (20/25)
 => [eshoppublicapi internal] load build definition from Dockerfile                                                                                                                                                                    0.0s
 => => transferring dockerfile: 777B                                                                                                                                                                                                   0.0s
 => [eshopwebmvc internal] load build definition from Dockerfile                                                                                                                                                                       0.0s
 => => transferring dockerfile: 762B                                                                                                                                                                                                   0.0s
 => [eshoppublicapi internal] load .dockerignore                                                                                                                                                                                       0.0s
 => => transferring context: 34B                                                                                                                                                                                                       0.0s
 => [eshopwebmvc internal] load .dockerignore                                                                                                                                                                                          0.0s
 => => transferring context: 34B                                                                                                                                                                                                       0.0s
 => [eshoppublicapi internal] load metadata for mcr.microsoft.com/dotnet/sdk:6.0                                                                                                                                                       0.1s
 => [eshopwebmvc internal] load metadata for mcr.microsoft.com/dotnet/aspnet:6.0                                                                                                                                                       0.1s
 => [eshopwebmvc runtime 1/3] FROM mcr.microsoft.com/dotnet/aspnet:6.0@sha256:503e677aba012b6a4516d054135669ee6074111da5ce1dd0e2847027b2c78a3b                                                                                         0.0s
 => [eshopwebmvc internal] load build context                                                                                                                                                                                          0.8s
 => => transferring context: 7.38MB                                                                                                                                                                                                    0.8s
 => [eshopwebmvc build 1/7] FROM mcr.microsoft.com/dotnet/sdk:6.0@sha256:3dfedfc30f95c93c3e1d41a2d376f4d3d6fef665888859b616c3b46dde695b73                                                                                              0.0s
 => CACHED [eshopwebmvc runtime 2/3] WORKDIR /app                                                                                                                                                                                      0.0s
 => CACHED [eshoppublicapi final 1/2] WORKDIR /app                                                                                                                                                                                     0.0s
 => [eshoppublicapi internal] load build context                                                                                                                                                                                       0.8s
 => => transferring context: 7.38MB                                                                                                                                                                                                    0.8s
 => CACHED [eshopwebmvc build 2/7] WORKDIR /app                                                                                                                                                                                        0.0s
 => [eshoppublicapi build 3/6] COPY . .                                                                                                                                                                                                2.0s
 => CACHED [eshopwebmvc build 3/7] COPY *.sln .                                                                                                                                                                                        0.0s
 => [eshopwebmvc build 4/7] COPY . .                                                                                                                                                                                                   2.0s
 => [eshoppublicapi build 4/6] WORKDIR /app/src/PublicApi                                                                                                                                                                              0.0s
 => [eshopwebmvc build 5/7] WORKDIR /app/src/Web                                                                                                                                                                                       0.0s
 => ERROR [eshopwebmvc build 6/7] RUN dotnet restore                                                                                                                                                                                   7.8s
 => ERROR [eshoppublicapi build 5/6] RUN dotnet restore                                                                                                                                                                                7.8s
------
 > [eshopwebmvc build 6/7] RUN dotnet restore:
#0 1.092   Determining projects to restore...
#0 3.769   Restored /app/src/BlazorShared/BlazorShared.csproj (in 2.08 sec).
#0 5.498   Restored /app/src/ApplicationCore/ApplicationCore.csproj (in 3.82 sec).
#0 6.468   Restored /app/src/Infrastructure/Infrastructure.csproj (in 4.79 sec).
#0 6.661   Restored /app/src/BlazorAdmin/BlazorAdmin.csproj (in 4.98 sec).
#0 7.659 /app/src/Web/Web.csproj : error NU1202: Package Microsoft.AspNetCore.Authentication.JwtBearer 7.0.0 is not compatible with net6.0 (.NETCoreApp,Version=v6.0). Package Microsoft.AspNetCore.Authentication.JwtBearer 7.0.0 supports: net7.0 (.NETCoreApp,Version=v7.0)
#0 7.674   Failed to restore /app/src/Web/Web.csproj (in 5.99 sec).
------
------
 > [eshoppublicapi build 5/6] RUN dotnet restore:
#0 1.021   Determining projects to restore...
#0 4.001   Restored /app/src/BlazorShared/BlazorShared.csproj (in 2.38 sec).
#0 5.680   Restored /app/src/ApplicationCore/ApplicationCore.csproj (in 4.07 sec).
#0 6.048   Restored /app/src/Infrastructure/Infrastructure.csproj (in 4.44 sec).
#0 7.515 /app/src/PublicApi/PublicApi.csproj : error NU1202: Package Microsoft.AspNetCore.Authentication.JwtBearer 7.0.0 is not compatible with net6.0 (.NETCoreApp,Version=v6.0). Package Microsoft.AspNetCore.Authentication.JwtBearer 7.0.0 supports: net7.0 (.NETCoreApp,Version=v7.0)
#0 7.527   Failed to restore /app/src/PublicApi/PublicApi.csproj (in 5.91 sec).
------
failed to solve: executor failed running [/bin/sh -c dotnet restore]: exit code: 1

eshoponweb-cd-webapp-docker.yml auth error

I configured all stuff like this https://microsoftlearning.github.io/AZ400-DesigningandImplementingMicrosoftDevOpsSolutions/Instructions/Labs/AZ400_M03_L06_Deploying_Docker_containers_to_Azure_App_Service_web_apps.html and I've got this error on CD:

##[error]The template deployment failed with error: 'Authorization failed for template resource '2ed8cxxxx' of type 'Microsoft.Authorization/roleAssignments'. The client '645391xxxxxx' with object id '6453xxxxxx' does not have permission to perform action 'Microsoft.Authorization/roleAssignments/write' at scope '/subscriptions/61xxxxxx/resourceGroups/rg-container-DISERTATIE/providers/Microsoft.ContainerRegistry/registries/cr7srn37wjafkx2/providers/Microsoft.Authorization/roleAssignments/2ed8c4axxxxxxx'.'.

Push Docker Compose fails

By initializing the first time the eshoponweb-ci-dockercompose pipeline it fails at the Push Docker Compose task.

fail2

Service connection was validated:

image

The default pipeline file was only adjusted to the appropriate resource group and subscription ID
image

Bug in PR 82

I posted about an error/bug under the actual PR#82, might have been the wrong place.

But the LABS are no longer working :(

I posted my bug report here:
#82

It this part in Program.cs that breaks running the example, why do we need SQL, and KeyVault?

else{
    // Configure SQL Server (prod)
    var credential = new ChainedTokenCredential(new AzureDeveloperCliCredential(), new DefaultAzureCredential());
    builder.Configuration.AddAzureKeyVault(new Uri(builder.Configuration["AZURE_KEY_VAULT_ENDPOINT"] ?? ""), credential);
    builder.Services.AddDbContext<CatalogContext>(c =>
    {
        var connectionString = builder.Configuration[builder.Configuration["AZURE_SQL_CATALOG_CONNECTION_STRING_KEY"] ?? ""];
        c.UseSqlServer(connectionString, sqlOptions => sqlOptions.EnableRetryOnFailure());
    });
    builder.Services.AddDbContext<AppIdentityDbContext>(options =>
    {
        var connectionString = builder.Configuration[builder.Configuration["AZURE_SQL_IDENTITY_CONNECTION_STRING_KEY"] ?? ""];
        options.UseSqlServer(connectionString, sqlOptions => sqlOptions.EnableRetryOnFailure());
    });
}

Please fix, I need the labs for next time teaching AZ-400 as an MCT

buildandtest action referencing an unknown path in the main branch

Inside of the .github/workflows/eshoponweb-cicd.yml there is a part of the code that references the env variable TEMPLATE-FILE. This variable has the following value .azure/bicep/webapp.bicep.

Now in the main branch, there is no such path, and therefore, the GitHub Actions fails on deploying the app via the bicep template giving the following warning
image
Which results in this error:
image

Making my own directories following .azure/bicep/ and leaving it at that did not resolve the issue.

This is an issue for the people following the Microsoft Learn course as described here:
https://microsoftlearning.github.io/AZ400-DesigningandImplementingMicrosoftDevOpsSolutions/Instructions/Labs/AZ400_M03_L05_Implementing_GitHub_Actions_for_CI_CD.html
image

I would think we need to point towards this bicep.template: infra/webapp.bicep. https://github.com/MicrosoftLearning/eShopOnWeb/blob/main/infra/webapp.bicep

Steps to reproduce

1: Head to Actions
2: Run the following workflow (from the main branch from your fork) https://github.com/MicrosoftLearning/eShopOnWeb/actions/workflows/eshoponweb-cicd.yml
3: See that the warning appears at the 2nd deploy step from bicep
4: Error occurs from the deploy step pointing out there was not a bicep-template found.

Used in AZ-400 Labs

Hi There,

it came to my attention, this repo's branch includes dependabot or something branch, which gives issues in Training Labs in AZ-400 delivery. All labs in AZ-400 uses this Repo for the Labs, which defined in Lab Step to import this repo. 3 weeks ago, this repo was fine, but this week ( 27th May ), certain labs , the one need to create pipelines , fails because student stucks in Merge Conflict loop during a pull request lab within Azure DevOps. Update the labs or do something. Thank you.

Wrong value of templateFile in eshoponweb-cd-webapp-dockercompose.yml

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.