百度智能云

All Product Document

          Cloud-Native Application Platform CNAP

          Image Production

          There are two ways to make an application image: One is a basic image based on a packaged monitoring function (recommended), and the other is an operating system-based image (such as centos7). Just choose one.


          Preliminary Preparation

          1. Environmental preparation

          • Open the Image Repository on the CCE product, create a namespace, and record the username and password, and the namespace name.
          • A machine with Docker installed and configured.

          2. Basic image

          Basic image contains probes by default

          Environment type Description Mirror address
          centos7.1 versus jdk8 centos7.1 pre-installed jdk8 hub.baidubce.com/cnap-public/microservice-springcloud:probe1.0.0.1_centos7.1_java8
          ubuntu18.04 versus jdk8 ubuntu 18.04 pre-installed jdk8 hub.baidubce.com/cnap-public/microservice-springcloud:probe1.0.0.0_ubuntu18.04_java8

          Basic image description

          *jdk8Installation path: /home/java *ProbeInstallation path: /home/emcprobe *start.shPath: /home

          Basic image use"ENTRYPOINT"Set the container entry. When using the basic image (from), you need to use the "CMD["param1","param2"...]"format to pass the startup command for the user program. The basic image will accept the CMD command as a parameter to start the user program.

          Writie Dockerfile

          Take the environment based on centos7 and jdk8 Take the creation of provider-demo as an example: Dockerfile only needs to reference the basic image provided above and write its own startup command into CMD.

          Applications using the monitoring function

          Operation steps:

          1. Go to the directory where the Docker machine stores the user program such as /home/appimage.
          2. Create a Dockerfile with the following content:

            #Basic image mirror address
            FROM hub.baidubce.com/cnap-public/microservice-springcloud:probe1.0.0.1_centos7.1_java8
            # Install the application package in the /home/app/lib directory (recommended)
            COPY {BMS_JAR_NAME} /home/app/lib/
            # Application startup command
            CMD ["java","-jar","/home/app/lib/{BMS_JAR_NAME}"]

            Note: Replace {BMS_JAR_NAME} with the name of the package that needs to be deployed. The CMD command is only passed as a parameter to the basic image ENTRYPOINT command

          Create Image Using Dockerfile

          Run the docker build command in the directory where the Dockerfile is located (/home/appimage) to create an image:

          docker build -t hub.baidubce.com/[namespace]/[ImageName]:[Image Version]. 

          namespace is the name of the namespace created in the environment preparation; ImageName is the name of the image specified by the user to create;

          Note: the "." after the command

          When finishing the creation, you can check whether the image is created by using the docker image ls or docker images command:

          docker image ls
          docker images

          Push the Image to the Image Library

          After finishing the image production, push the produced image to Baidu AI Cloud Image Repository:

          docker push hub.baidubce.com/[namespace]/[ImageName]:[Image Version] 

          After the image is created and pushed, it can be deployed on the CNAP.

          II. Basic Image Based on the Operating System


          Preliminary preparation

          1. Environmental preparation

          • Open the Image Repository on the CCE product, create a namespace, and record the username and password, and the namespace name.
          • A machine with Docker installed and configured.

          2. Code preparation

          Take the creation of provider-demo as an example:

          File Description Download link
          provider-demo-1.0-SNAPSHOT.jar The user's spring cloud microservice (provider) or common java application package None (user code)
          Monitoring probe package Support the display of monitoring information emcprobe.tar.gz

          Place the two files in the same directory of the Docker machine such as the /home/appimage directory. The following will use this directory as an example for image production.

          Writie Dockerfile

          2.1 Applications using the monitoring function**

          Operation steps:

          1. Go to the directory where the Docker machine stores user programs and Phoenix Eye probe packages such as /home/appimage.
          2. Create a Dockerfile with the following content:

            FROM centos:7
            # Describe image creator information, which can be customized 
            MAINTAINER BAIDU
            # Set the time zone so that the user can use log printing to get the correct time
            RUN rm -f /etc/localtime & cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
            RUN echo "Asia/Shanghai" > /etc/timezone
            # Install the JDK (need to manually download the jdk package and place it in the same directory as the Dockerfile) 
            ADD jdk-8u191-linux-x64.tar.gz /home/java
            # Set JAVA_HOME 
            ENV JAVA_HOME /home/java/jdk1.8.0_191
            ENV PATH $PATH:$JAVA_HOME/bin
            # Install lsof command for application diagnosis
            RUN yum update -y && yum install -y lsof
            # Set the workspace for deploying applications. Customizable. Probes are deployed in the application's flat directory
            ENV APP_HOME /home/app
            # Set the jar package name for the jar package copy. E.g. provider.jar.
            ENV JAR_NAME {BMS_JAR_NAME}
            # Install the probe package for application monitoring
            ADD emcprobe.tar.gz $APP_HOME/..
            # Install the application package
            COPY start.sh ${APP_HOME}/bin/
            COPY ${JAR_NAME} ${APP_HOME}/lib/
            # Configure the working directory
            WORKDIR ${APP_HOME}
            # Launch the application
            CMD ["/bin/bash","-c","exec ./bin/start.sh"]

            Note: Replace {BMS_JAR_NAME} with the name of the package that needs to be deployed

          The application path in the Dockerfile can be customized, and the monitoring probe will be deployed in the application's flat directory. For example, the default application path is /home/app, and the monitoring probe path is /home/emcprobe. Therefore, please do not use '/' as the root directory of the application. start.sh is the application's startup script, which contains the de-registration logic and also calls the startup script of the monitoring probe. It is recommended to refer to this script to complete your own startup script writing, or use the script directly for quick access. start.sh needs to be placed in the same directory as Dockerfile. The reference of start.sh is as follows:

          #!/bin/bash
          # Used to log off the service in the registration center; if it is removed, the service offline may be delayed 
          trap "{ stop; sleep 0.5; exit 255; }" EXIT
          # For application monitoring 
          export EM_APP_HOME=${APP_HOME}
          export PID_FILE=${EM_APP_HOME}/log/instance.pid
          cd ${EM_APP_HOME}
          # Application launch logic 
          function start_app(){
              mkdir -p ${EM_APP_HOME}/log/
              # Application startup parameters can be customized. You need to write pid to file after startup to use the monitoring function 
              $JAVA_HOME/bin/java -jar ${EM_APP_HOME}/lib/${JAR_NAME} &
              echo $! > ${PID_FILE}
          }
          
          # The method goes offline for specific services 
          function stop(){
              echo "start to kill user process"
              if [ -f ${EM_APP_HOME}/log/instance.pid ]; then
                  ps aux | awk -vpid=$(cat ${PID_FILE}) '$2==pid {print}' | grep $(cat ${PID_FILE}) &> /dev/null
                  if [ $? -ne 0 ]; then
                      echo "already stopped!"
                      return
                  fi
                  echo  "stopping process "
                  kill $(cat ${PID_FILE})
          
                  for ((i=0;i<40;i++)); do
                      if [ $i -eq 30 ]; then
                          kill -9 $(cat ${PID_FILE})
                      fi
                      ps aux | awk -vpid=$(cat ${PID_FILE}) '$2==pid {print}' | grep $(cat ${PID_FILE}) &> /dev/null
                      if [ $? -eq 0 ]; then
                          echo -n .
                          sleep 0.5
                      else
                          echo " [done]!"
                          rm ${EM_APP_HOME}/log/instance.pid
                          break
                      fi
                  done
              fi
          }
          # Launch the application 
          start_app
          # Start the monitoring probe 
          cd ${EM_APP_HOME}/../emcprobe
          bash ./bin/start.sh

          Create Image Using Dockerfile

          Run the docker build command in the directory where the Dockerfile is located (/home/appimage) to create an image:

          docker build -t hub.baidubce.com/[namespace]/[ImageName]:[Image Version]. 

          namespace is the name of the namespace created in the environment preparation; ImageName is the name of the image specified by the user to create;

          Note: the "." after the command

          When finishing the creation, you can check whether the image is created by using the docker image ls or docker images command:

          docker image ls
          docker images

          Push the Image to the Image Library

          After finishing the image production, push the produced image to Baidu AI Cloud Image Repository:

          docker push hub.baidubce.com/[namespace]/[ImageName]:[Image Version] 

          After the image is created and pushed, it can be deployed on the CNAP.

          III. Historical versions


          2020-7-23 2.2.0.1 latest version

          • Optimize trace message generation: remove trace messages related to micro-service framework related heartbeats, pull configuration requests, and spring annotation related plug-ins
          • Support brand new topology display, adapt to http and rpc call scenarios | Environment type | Description | Mirror address | | ------------------------- | ---------------------------------------------- | ------------------------------------------------------------ | | centos7.1 and jdk8 | centos7.1 pre-installed jdk8 | hub.baidubce.com/cnap-public/microservice-springcloud:probe2.2.0.1_centos7.1_java8 | | ubuntu18.04 and jdk8 | ubuntu 18.04 pre-installed jdk8 | hub.baidubce.com/cnap-public/microservice-springcloud:probe2.2.0.1_ubuntu18.04_java8 | | Monitoring probe package | Support the display of monitoring information | emcprobe-2-2-0-1.tar.gz |

          2020-6-5 2.1.1.2

          • Add okhttp3 plugin
          Environment type Description Mirror address
          centos7.1 and jdk8 centos7.1 pre-installed jdk8 hub.baidubce.com/cnap-public/microservice-springcloud:probe2.1.1.2_centos7.1_java8
          ubuntu18.04 and jdk8 ubuntu 18.04 pre-installed jdk8 hub.baidubce.com/cnap-public/microservice-springcloud:probe2.1.1.2_ubuntu18.04_java8
          Monitoring probe package Support the display of monitoring information emcprobe-2-1-1-2.tar.gz
          Previous
          Spring-cloud-application Access
          Next
          Distributed Transaction Access