Updated on 2024-11-15 GMT+08:00

Deploying a Microservice Using Source Code

Scenarios

ServiceStage allows you to quickly deploy microservices in containers (such as CCE) or VMs (such as ECS), and supports source code deployment, JAR/WAR package deployment, and Docker image package deployment. In addition, ServiceStage allows you to deploy, upgrade, roll back, start, stop, and delete applications developed in different programming languages, such as Java, PHP, Node.js, and Python.

In this practice, backend components developed in Java and frontend components developed in Node.js are used.

User Story

In this practice, you can deploy an application in containers and register microservice instances with the ServiceComb engine. The following components need to be created for the weathermap application:
  1. Frontend component: weathermapweb, which is developed in Node.js.
  2. Backend components: weather, fusionweather, forecast, and edge-service, which are developed based on Java.

The procedures for deploying a microservice are as follows:

  1. Creating and Deploying a Backend Application Component
  2. Setting the Access Mode of the edge-service Component
  3. Creating and Deploying a Frontend Component
  4. Confirming the Deployment Result
  5. Setting the Access Mode
  6. Accessing an Application

Creating and Deploying a Backend Application Component

You need to create and deploy four application components (weather, forecast, fusionweather, and edge-service), which correspond to the four software packages generated by the backend build jobs.

  1. Log in to ServiceStage.
  2. Choose Application Management.
  3. Click Create Component in the Operation column of the application created in Creating an Application (for example, weathermap).
  4. In the Basic Information area, set the following mandatory parameters. Retain the default values for other parameters.

    Parameter

    Description

    Component Name

    Enter the name of the corresponding backend component (for example, weather).

    Component Version

    Click Generate. By default, the version number is generated based on the time when you click Generate. The format is yyyy.mmdd.hhmms, where s is the ones place of the second in the timestamp. For example, if the timestamp is 2022.0803.104321, the version number is 2022.0803.10431.

    Environment

    Select the environment created in Creating an Environment, for example, env-test.

    Application

    Select the application created in Creating an Application, for example, weathermap.

  5. In the Component Package area, set the following mandatory parameters. Retain the default values for other parameters.

    Parameter

    Description

    Stack

    Select Java.

    Source Code/Software Package

    1. Select Source code repository.
    2. Select GitHub,
    3. Authorization: Select the authorization information created in Setting GitHub Repository Authorization.
    4. Username/Organization: Select the username used to log in to GitHub in Registering a GitHub Account and Forking the Weather Forecast Source Code.
    5. Repository: Select the name of the weather forecast source code repository that has been forked to your GitHub account. For example, weathermap.
    6. Branch: Select master.

  6. In the Build Job area, set mandatory build parameters.

    1. Command: Retain the default value.
    2. Dockerfile Address: Set this parameter by referring to the following table.

      Component Name

      Dockerfile Address

      weather

      ./weather/

      forecast

      ./forecast/

      fusionweather

      ./fusionweather/

      edge-service

      ./edge-service/

    3. Organization: Select the organization created in Creating an Organization.
    4. Environment: Select Use current environment.
    5. Retain the default values for other parameters.
    Figure 1 Configuring build parameters

  7. Click Next.
  8. In the Resources area, set Instances for each component and retain the default values for other parameters.

    Component Name

    Instances

    weather

    2

    forecast

    1

    fusionweather

    1

    edge-service

    1

  9. Bind the ServiceComb engine.

    • After a component is deployed, the microservice will be registered with the bound ServiceComb engine.
    • All components must be registered with the same ServiceComb engine.
    1. Choose Cloud Service Settings > Microservice Engine.
    2. Click Bind Microservice Engine.
    3. Select the managed exclusive ServiceComb engine in the current environment.
    4. Click OK.

  10. Click Create and Deploy.

Setting the Access Mode of the edge-service Component

  1. Click in the upper left corner to return to the Application Management page.
  2. Click the application created in Creating an Application (for example, weathermap). The Overview page is displayed.
  3. In the Component List area, locate the row that contains edge-service and click View Access Mode in the External Access Address column.
  4. Click Add Service in the TCP/UDP Route Configuration area and set parameters by referring to the following table.

    Parameter

    Description

    Service Name

    Retain the default value.

    Access Mode

    Select Public network access.

    Access Type

    Select Elastic IP address.

    Service Affinity

    Retain the default value.

    Protocol

    Select TCP.

    Container Port

    Enter 3010.

    Access Port

    Select Automatically generated.

    Figure 2 Setting the access mode of the edge-service component

  5. Click OK.

Creating and Deploying a Frontend Component

  1. Click in the upper left corner to return to the Application Management page.
  2. Click Create Component in the Operation column of the application created in Creating an Application (for example, weathermap).
  3. In the Basic Information area, set the following mandatory parameters. Retain the default values for other parameters.

    Parameter

    Description

    Component Name

    Enter the frontend component name weathermapweb.

    Component Version

    Click Generate. By default, the version number is generated based on the time when you click Generate. The format is yyyy.mmdd.hhmms, where s is the ones place of the second in the timestamp. For example, if the timestamp is 2022.0803.104321, the version number is 2022.0803.10431.

    Environment

    Select the environment created in Creating an Environment, for example, env-test.

    Application

    Select the application created in Creating an Application, for example, weathermap.

  4. In the Component Package area, set the following mandatory parameters. Retain the default values for other parameters.

    Parameter

    Description

    Stack

    Select Node.js.

    Source Code/Software Package

    1. Select Source code repository.
    2. Select GitHub,
    3. Authorization: Select the authorization information created in Setting GitHub Repository Authorization.
    4. Username/Organization: Select the username used to log in to GitHub in Registering a GitHub Account and Forking the Weather Forecast Source Code.
    5. Repository: Select the name of the weather forecast source code repository that has been forked to your GitHub account. For example, weathermap.
    6. Branch: Select master.

  5. In the Build Job area, set mandatory build parameters.

    1. Command: Retain the default value.
    2. Dockerfile Address: Set this parameter by referring to the following table.

      Component Name

      Dockerfile Address

      weathermapweb

      ./weathermapweb/

    3. Organization: Select the organization created in Creating an Organization.
    4. Environment: Select Use current environment.
    5. Retain the default values for other parameters.

  6. Click Next to add an environment variable.

    1. Choose Container Settings > Environment Variable.
    2. Click Add Environment Variable to configure environment variables.

      Type

      Name

      Variable/Variable Reference

      Add manually

      SERVICE_ADDR

      Access address generated in Setting the Access Mode of the edge-service Component.

  7. Click Create and Deploy.

Confirming the Deployment Result

  1. Click in the upper left corner to return to the Application Management page.
  2. Choose Cloud Service Engine > Microservice Catalog.
  3. Select the ServiceComb engine where the microservice application is deployed from the Microservice Engine drop-down list.
  4. Select the application (for example, weathermap) created in Creating an Application from Microservice List.

    If the number of instances of each microservice is the same as listed in the following table, the deployment is successful.

    Component Name

    Instances

    weather

    2

    forecast

    1

    fusionweather

    1

    edge-service

    1

Setting the Access Mode

  1. Choose Application Management.
  2. Click the application created in Creating an Application (for example, weathermap). The Overview page is displayed.
  3. In the Component List area, locate the row that contains weathermapweb and click View Access Mode in the External Access Address column.
  4. Click Add Service in the TCP/UDP Route Configuration area and set parameters by referring to the following table.

    Parameter

    Description

    Service Name

    Retain the default value.

    Access Mode

    Select Public network access.

    Access Type

    Select Elastic IP address.

    Service Affinity

    Retain the default value.

    Protocol

    Select TCP.

    Container Port

    Enter 3000.

    Access Port

    Select Automatically generated.

    Figure 3 Setting the access mode

  5. Click OK.

    Figure 4 Access address

Accessing an Application

  1. Click in the upper left corner to return to the Application Management page.
  2. Click the application created in Creating an Application (for example, weathermap). The Overview page is displayed.
  3. In the Component List area, locate the row that contains weathermapweb and click View Access Mode in the External Access Address column.

    If the following page is displayed, the weather forecast microservice application is successfully deployed.

    Figure 5 Application deployed successfully
    • The data is real-time data.
    • When you access the application for the first time, it takes some time for the weather system to be ready. If the preceding page is not displayed, refresh the page.