Help Center/ Cloud Application Engine/ Best Practices/ Deploying ASP.NET Core Applications to CAE
Updated on 2024-08-30 GMT+08:00

Deploying ASP.NET Core Applications to CAE

CAE source code deployment supports Docker running. You can configure a Dockerfile, install the build environment in this file, and define build commands. In this way, more projects programmed in various languages can be deployed in CAE.

This topic uses the ASP.NET Core application as an example.

Prerequisites

An environment has been created. For details, see Creating an Environment and Application Management.

Forking Sample Source Code

Use your account to log in to GitHub and fork the sample source code repository to your personal account.

Source code address: https://github.com/Azure-Samples/dotnetcore-docs-hello-world.

Parsing Dockerfile

Dockerfile file in the sample repository.

# Specify the basic image as mcr.microsoft.com/dotnet/sdk:7.0, which is used as the build environment of the ASP.NET Core project.
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
# Specify the working directory.
WORKDIR /source

# Copy the source code from the build host to the basic image and specify the working directory and build command.
COPY . ./dotnetcore-docs-hello-world/
WORKDIR /source/dotnetcore-docs-hello-world
RUN dotnet publish -c release -o /app 

# Specify the new basic image as mcr.microsoft.com/dotnet/aspnet:7.0 and copy the build product generated in step 2 to the new basic image.
FROM mcr.microsoft.com/dotnet/aspnet:7.0
WORKDIR /app
COPY --from=build /app ./

# Set the environment variable PORT and declare that the container port is 80.
ENV PORT 80
EXPOSE 80

# Specify the container startup command.
ENTRYPOINT ["dotnet", "dotnetcoresample.dll"]

Setting GitHub Repository Authorization

You can set GitHub repository authorization so that build projects and application components can use the authorization information to access the GitHub source code repository.

  1. Log in to CAE.
  2. Choose System Settings.

  3. Click Edit in the Source Code Repository Authorizations module.
  4. Click Create Authorization, select the required source code repository by referring to Table 1, and set parameters.

    Table 1 Authorization parameters

    Parameter

    Description

    Authorization

    Authorization name, which cannot be changed after being created.

    Repository Type

    The following official repositories are supported:

    1. Select GitHub.
    2. Select Method.
      • OAuth: Complete the authorization creation as prompted.
      • Token: Enter the obtained private token.

  5. Click Confirm. The GitHub code repository is authorized.

    Figure 1 Authorizing GitHub code repository

Creating and Configuring Components

  1. In the navigation pane on the left, choose Components.
  2. Select the created application and environment from the drop-down lists in the upper part of the page, and click Create Component.
  3. Configure the component by referring to Table 2.

    Table 2 Basic component information

    Parameter

    Description

    Component

    Enter a component name. In this practice, enter test-dotnet.

    Version

    Enter a component version.

    In this practice, enter 1.0.0.

    Specifications

    Select instance specifications, for example, 0.5 Core and 1 GiB.

    Instances

    Set it to 1.

    Code Source

    Choose Source code repository > GitHub. Select the authorization created in Setting GitHub Repository Authorization and select the sample code repository.

    Figure 2 Configuring basic information

  4. Set Language/Runtime System to Docker and Dockerfile Address to ./Dockerfile.linux.

    Figure 3 Configuring the Dockerfile

  5. Click Configure Component. The Component Configuration page is displayed.
  6. Go to Access Mode and click Edit.
  7. In the Access Component from Another Environment area, click Load Balancing > Add Load Balancer.

    Configure load balancing by referring to Figure 4.
    Figure 4 Configuring load balancing

  8. Click OK.
  9. Click Set and Deploy Component in the upper part of the page. In the dialog box that is displayed on the right, click OK. The configuration takes effect after the deployment is complete.

Viewing Application Details

  1. In the navigation pane on the left, choose Components to return to the components page.
  2. Click the public network access address in the Access Address column of the test-dotnet component.

  3. Access the static page of the application.