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

Deploying an Application on ECS

Purchasing and Configuring an ECS

This section uses Elastic Cloud Server (ECS). You can also use your own Linux host that runs Ubuntu 16.04 OS.

  1. Buy an ECS.

    The following table lists mandatory configurations. You can also select other configurations as necessary.

    Table 1 Configuring an ECS purchase

    Category

    Configuration Item

    Suggestion

    Configure Basic Settings

    Billing Mode

    Select Pay-per-use.

    Instance

    CPU Architecture

    Select x86.

    Specifications

    Select 2 vCPUs and 8 GiB memory or higher.

    OS

    Image

    Choose Public image > Ubuntu > Ubuntu 16.04 server 64bit.

    Public Network Access

    EIP

    Select Auto assign.

    Billed By

    Select Bandwidth.

    Instance Management

    Login Mode

    Select Password.

    Password

    Enter a custom password.

  2. Configure security group rules.

    Use ports 5000 and 5001 to verify the sample project. Therefore, add an inbound rule that allows access over ports 5000 and 5001.

    The procedure is as follows:

    1. Log in to the ECS list page, locate the ECS purchased in step 1, and click the ECS name.
    2. Click the Security Groups tab, and add an inbound rule with Protocol set to TCP and Port Range set to 5000-5001 by referring to Configuring Security Group Rules.

Adding a Target Host to the Project

Before deploying applications to ECSs, add the target hosts to the basic resources of the project.

  1. Go to the Phoenix Mall project and choose Settings > General > Basic Resources from the navigation pane.
  2. Click Create Host Cluster, configure the following information, and click Save.

    Table 2 Creating a host cluster

    Parameter

    Suggestion

    Cluster Name

    Enter host-group.

    OS

    Select Linux.

    Host Connection Mode

    Select Direct Connection.

    Execution Resource Pool

    Select Official.

  3. Click Add Host, configure the following information, and click OK.

    Table 3 Adding a host

    Configuration Item

    Suggestion

    Add Hosts by

    Select Adding IP.

    Host Name

    Keep this name same as the name of the purchased ECS.

    IP

    Enter the EIP generated when buying the ECS.

    Authorization

    Select Password.

    Username

    Enter root.

    Password

    Enter the password set when buying the ECS.

    SSH Port

    Enter 22.

  4. A host record is displayed on the page. If Succeed is displayed in the Verification Result column, the host is added successfully.

    If the host fails to be added, check the host configuration based on the failure details.

Installing Dependency Tools on ECS

The sample program depends on Docker and Docker-Compose, which must be installed on the target ECS.

  1. Go to the Phoenix Mall project, choose CICD > Deploy, and find the phoenix-sample-predeploy application in the list.
  2. Click and choose Edit from the drop-down list.
  3. Click the Environment Management tab and configure the host environment.

    1. Click Create Environment, configure the following information, and click Save.
      Table 4 Creating an environment

      Parameter

      Value

      Environment

      Enter phoenix-env.

      Resource Type

      Select Host.

      OS

      Select Linux.

      If you do not have permission to create environments, contact the administrator to grant you permissions on the permission management page of the application.

    2. Click Import Host. In the displayed dialog box, select the configured host cluster and host and click Import.
    3. When a message indicating that the import is successful is displayed, close the window.

  4. On the Deployment Actions tab page, edit the actions of the application.

    In action Install Docker, select phoenix-env from the Environment drop-down list. If a dialog box is displayed, asking you to confirm whether you want to change the environment to phoenix-env for the subsequent actions, click OK.

  5. Click Save & Deploy to start the deployment task.

    If a message is displayed indicating successful deployment, the task is successfully executed.

  6. Log in to the ECS and check whether the dependency tools are successfully installed:

    • Run the docker -v command to check the Docker image version.
    • Run the docker-compose -v command to check the Docker-Compose version.

    If the command output similar to Figure 1 is displayed, the installation is successful.

    Figure 1 Checking the Docker and Docker-Compose versions

Configuring and Executing an Application

During deployment, configure the ECS in the environment list of the application and set the build task phoenix-sample-ci as the deployment source.

  1. Go to the Phoenix Mall project, choose CICD > Deploy, and find the phoenix-sample-standalone application in the list.
  2. Click and choose Edit from the drop-down list.
  3. Click the Environment Management tab and configure the host environment.

    1. Click Create Environment, configure the following information, and click Save.
      Table 5 Creating an environment

      Parameter

      Value

      Environment

      Enter phoenix-env.

      Resource Type

      Select Host.

      OS

      Select Linux.

    2. Click Import Host. In the displayed dialog box, select the configured host cluster and host and click Import.
    3. When a message indicating that the import is successful is displayed, close the window.

  4. On the Deployment Actions tab page, edit the actions of the application.

    1. Click Select a Deployment Source. Set the deployment source by referring to Table 6.
      Table 6 Configuring the deployment source

      Configuration Item

      Suggestion

      Source

      Select Build task.

      Build Task

      Select phoenix-sample-ci.

      Environment

      Select phoenix-env.

      If a dialog box is displayed, asking you to confirm whether you want to change the environment to phoenix-env for the subsequent actions, click OK.

    2. Retain the default settings in actions Decompress Files and Run Shell Commands.

  5. Click the Parameters tab and set parameters based on the SWR login command.

    Obtain the login command from the console.

  6. Click Save & Deploy to start deployment.

    If a message is displayed indicating that the deployment is successful, continue with the next step. If the deployment fails, rectify the fault based on the failed action and the error information in logs.

  7. Verify the deployment result.

    1. Open a browser, enter http://IP:5000 in the address box, and press Enter. IP indicates the elastic IP address of the ECS. The Phoenix Mall homepage is displayed.
    2. Enter http://IP:5001 and press Enter. IP indicates the elastic IP address of the ECS. The Phoenix Mall dashboard is displayed.

Releasing Resources

To avoid unnecessary fees, delete the ECS after the practice.

If you need to create a pipeline after the deployment, you can delete the ECS after completing the pipeline practice.