Updated on 2023-01-16 GMT+08:00

Deploying the Application

This section describes how to deploy the application.

Deploying the Application

  1. To obtain the image, go to the BCS console and choose Use Cases. Download Bank_Image in the SDK Demo for a Bank Consortium Blockchain area.
  2. Ensure that the docker and unzip commands exist before logging in to ECS.

    Run the cd /root/bankuniondemo command to upload the downloaded image to the directory.

    Run the vi startserver.sh command to create the startserver.sh file. Add the following content to the startserver.sh file and save the file:

    #!/bin/sh
    # Obtain the current path.
    path=`pwd`
    # Obtain the IP address.
    localip=`ifconfig eth0 | grep "inet addr" | awk '{ print $2}' | awk -F: '{print $2}'`
    
    # Check whether unzip and docker commands exist.
    if type unzip > /dev/null 2>&1; then
        echo "Unzip command is exists!"
    else
        echo "No unzip command, please install unzip before start this demo"
        exit 1
    fi
    
    if type docker > /dev/null 2>&1; then
        echo "Docker exists!"
    else
        echo "No docker, please install docker before start this demo"
        exit 1
    fi
    
    # Check whether the certificate directory exists.
    if [ -e ./crypto ];then
    rm -rf crypto
    fi
    
    # Decompress the certificate file.
    echo "Start unziping certificate ...."
    
    cerzip=$(ls|grep .zip)
    for i in $cerzip;
    do
    unzip -n $i -d crypto/
    done
    echo "Unzip certificate Done!!"
    
    # Configure the certificate path.
    Folder="$path/crypto"  
    for file in ${Folder}/*
    do  
        temp_file=`basename $file`  
    
        mv -f $path/crypto/$temp_file/* $path/crypto/
    done
    
    # Check whether the required certificate files are ready.
    echo "Start checking if the required files are ready"
    if [ -e $path/democraticBank.yaml ]&&[ -e $path/civilizationBank.yaml ]&&[ -e $path/harmoniousBank.yaml ];then
    echo "Check required yaml files OK!!"
    else
    echo "Please check if the required yaml files are ready!!"
    exit
    fi
    
    # Restart the system if the password is forgotten.
    read -p "Is this the first time you deploy the application? If yes please insert 'y', if you want to reset your password please insert 'n': " choice
    echo $choice
    if [ $choice = "n" ];then
    docker rm $(docker stop $(docker ps -a -q --filter ancestor=bank --format="{{.ID}}"))
    echo "Resetting password..."
    fi
    
    # Set the password.
    read -p "Please set your password: " test
    echo $test
    if [ ${#test} -lt 4 -o ${#test} -gt 24 ];then echo "password length should in [4, 24].";exit;fi
    
    #load images
    if [ -e $path/bankv3.tar.gz ];then
    echo "Start loading images..."
    docker load -i bankv3.tar.gz
    echo "Api-server images is exists,Skip load!"
    fi
    
    # Start the service.
    echo "Start server ....."
    docker run --env TESTPWD=$test -p 8080:8080 -d -it -v $path/crypto:/opt/bank/src/bank/conf/crypto -v $path/democraticBank.yaml:/opt/bank/src/bank/conf/democraticBank.yaml -v $path/harmoniousBank.yaml:/opt/bank/src/bank/conf/harmoniousBank.yaml -v $path/civilizationBank.yaml:/opt/bank/src/bank/conf/civilizationBank.yaml bank
    
    RET_CODE=`echo $?`
    if [ $RET_CODE -eq 0 ]; then 
         echo "Start server success!"
         echo -e "please login \033[32mhttp://EIP:8080/adminLogin \033[0mto visit Bank Management System"
         echo -e "or login \033[32mhttp://EIP:8080/userLogin \033[0mto visit Bank Customer System"
    else
         echo "Failed to start server! Please check if everything ok"
    fi

    Run the following script:

    bash startserver.sh

  3. After you see "Is this the first time you deploy the application?", enter y for yes, or enter n if you want to change the password. Then, insert your password (123456 is used as an example in the following figure).

    The command output is similar to the following:

    Figure 1 Command output

  4. Run the following command to check whether the container has started:

    docker ps

    If the following information is displayed, the container has started. Otherwise, check the configuration.

    Figure 2 Message displayed

Adding a Security Group

  • If you deploy the bankuniondemo application on your own server, skip this procedure.
  • If you deploy the bankuniondemo application on an ECS on Huawei Cloud, create a security group and then add security group rules to enable access to port 8080 of the server. For details, see Creating a Security Group. Table 1 describes the security group rule.
    Table 1 Parameters of a security group rule

    Parameter

    Setting

    Description

    Protocol

    Select TCP.

    Specifies the network protocol.

    Direction

    Set the inbound rules.

    Specifies the direction in which the security group rule takes effect. Inbound rules control external access to the ECS.

    Port number range

    Create a rule, and set the port to 8080.

    Specifies the port range for which a rule takes effect.

    Source

    Select IP Address, and enter 0.0.0.0/0.

    This parameter is required for inbound rules.

  • The EIP must be the IP address of the server where the bankuniondemo application is deployed or the EIP of the ECS.