All Products
Search
Document Center

Create images for applications

Last Updated: Jun 24, 2019

This topic describes how to create custom images in HSF:

Note: Before creating an image for a Container Service Kubernetes application, read Restrictions on creating images and create an image accordingly.

Create a standard Dockerfile

Dockerfile is a configuration file in text format. You can use a Dockerfile to quickly create a custom image.A custom Dockerfile defines all instructions in the runtime environment for EDAS applications, including the instructions on downloading, installing, and starting JDK, Tomcat, WAR, and JAR packages.

By modifying the Dockerfile, you can replace the JDK version, modify the Tomcat configuration, change the runtime environment, and make other changes.

The following example (which is updated from time to time to introduce the latest EDAS features) shows how to create and deploy an application in EDAS.

Sample Dockerfile used to deploy applications on Ali-Tomcat with a WAR package

  1. FROM centos:7
  2. MAINTAINER EDAS R&D team<edas-dev@list.alibaba-inc.com>
  3. # Install and package the required software
  4. RUN yum -y install wget unzip
  5. # Prepare JDK or Tomcat system variables and paths
  6. ENV JAVA_HOME /usr/java/latest
  7. ENV CATALINA_HOME /home/admin/taobao-tomcat
  8. ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin
  9. # Set EDAS Container or Pandora Container version
  10. ENV EDAS_CONTAINER_VERSION V3.5.0
  11. LABEL pandora V3.5.0
  12. # Download and install JDK 8
  13. RUN wget http://edas-hz.oss-cn-hangzhou.aliyuncs.com/agent/prod/files/jdk-8u191-linux-x64.rpm -O /tmp/jdk-8u191-linux-x64.rpm && \
  14. yum -y install /tmp/jdk-8u191-linux-x64.rpm && \
  15. rm -rf /tmp/jdk-8u191-linux-x64.rpm
  16. # Download and install Ali-Tomcat 7.0.85 to the /home/admin/taobao-tomcat directory
  17. RUN wget http://edas-hz.oss-cn-hangzhou.aliyuncs.com/edas-container/7.0.85/taobao-tomcat-production-7.0.85.tar.gz -O /tmp/taobao-tomcat.tar.gz && \
  18. mkdir -p ${CATALINA_HOME} && \
  19. tar -xvf /tmp/taobao-tomcat.tar.gz -C ${CATALINA_HOME} && \
  20. mv ${CATALINA_HOME}/taobao-tomcat-production-7.0.59.3/* ${CATALINA_HOME}/ && \
  21. rm -rf /tmp/taobao-tomcat.tar.gz ${CATALINA_HOME}/taobao-tomcat-production-7.0.59.3 && \
  22. chmod +x ${CATALINA_HOME}/bin/*sh
  23. # Download and install EDAS Container or Pandora Container based on environment variables
  24. RUN wget http://edas-hz.oss-cn-hangzhou.aliyuncs.com/edas-plugins/edas.sar.${EDAS_CONTAINER_VERSION}/taobao-hsf.tgz -O /tmp/taobao-hsf.tgz && \
  25. tar -xvf /tmp/taobao-hsf.tgz -C ${CATALINA_HOME}/deploy/ && \
  26. rm -rf /tmp/taobao-hsf.tgz
  27. # Download and deploy the EDAS demo WAR package
  28. RUN wget http://edas.oss-cn-hangzhou.aliyuncs.com/demo/hello-edas.war -O /tmp/ROOT.war && \
  29. unzip /tmp/ROOT.war -d ${CATALINA_HOME}/deploy/ROOT/ && \
  30. rm -rf /tmp/ROOT.war
  31. # Set the Tomcat installation directory as the container startup directory, start Tomcat in run mode, and output the catalina log on the standard CLI.
  32. WORKDIR $CATALINA_HOME
  33. CMD ["catalina.sh", "run"]

Sample Dockerfile used to deploy applications on Ali-Tomcat with a JAR package

  1. FROM centos:7
  2. MAINTAINER EDAS R&D team<edas-dev@list.alibaba-inc.com>
  3. # Install and package the required software
  4. RUN yum -y install wget unzip
  5. # Prepare JDK or Tomcat system variables and paths
  6. ENV JAVA_HOME /usr/java/latest
  7. ENV CATALINA_HOME /home/admin/taobao-tomcat
  8. ENV PATH $PATH:$JAVA_HOME/bin
  9. # Set EDAS Container or Pandora Container version
  10. ENV EDAS_CONTAINER_VERSION V3.5.0
  11. LABEL pandora V3.5.0
  12. # Download and install JDK 8
  13. RUN wget http://edas-hz.oss-cn-hangzhou.aliyuncs.com/agent/prod/files/jdk-8u191-linux-x64.rpm -O /tmp/jdk-8u191-linux-x64.rpm && \
  14. yum -y install /tmp/jdk-8u191-linux-x64.rpm && \
  15. rm -rf /tmp/jdk-8u191-linux-x64.rpm
  16. # Download and install EDAS Container or Pandora Container based on environment variables
  17. RUN mkdir -p ${CATALINA_HOME}/deploy/
  18. RUN wget http://edas-hz.oss-cn-hangzhou.aliyuncs.com/edas-plugins/edas.sar.${EDAS_CONTAINER_VERSION}/taobao-hsf.tgz -O /tmp/taobao-hsf.tgz && \
  19. tar -xvf /tmp/taobao-hsf.tgz -C ${CATALINA_HOME}/deploy/ && \
  20. rm -rf /tmp/taobao-hsf.tgz
  21. # Download and deploy the EDAS demo JAR package
  22. RUN mkdir -p /home/admin/app/ && wget http://edas.oss-cn-hangzhou.aliyuncs.com/demoapp/fatjar-test-case-provider-0.0.1-SNAPSHOT.jar -O /home/admin/app/provider.jar
  23. # Include the startup command in the startup script start.sh
  24. RUN echo '$JAVA_HOME/bin/java -jar $CATALINA_OPTS -Djava.security.egd=file:/dev/./urandom -Dcatalina.logs=$CATALINA_HOME/logs -Dpandora.location=$CATALINA_HOME/deploy/taobao-hsf.sar "/home/admin/app/provider.jar" --server.context-path=/ --server.port=8080 --server.tomcat.uri-encoding=ISO-8859-1 --server.tomcat.max-threads=400' > /home/admin/start.sh && chmod +x /home/admin/start.sh
  25. WORKDIR $CATALINA_HOME
  26. CMD ["/bin/bash", "/home/admin/start.sh"]

Customize the Dockerfile

You can configure the following custom settings in the preceding standard Dockerfile.

Upgrade JDK

Change the download and installation methods in the standard Dockerfile.The following uses JDK 8 as an example.

  1. # Download and install JDK 8
  2. RUN wget http://edas-hz.oss-cn-hangzhou.aliyuncs.com/agent/prod/files/jdk-8u191-linux-x64.rpm -O /tmp/jdk-8u191-linux-x64.rpm && \
  3. yum -y install /tmp/jdk-8u191-linux-x64.rpm && \
  4. rm -rf /tmp/jdk-8u191-linux-x64.rpm

Upgrade EDAS Container

When using a WAR package and Tomcat, upgrade EDAS Container to use new middleware features or fix known bugs.The upgrade procedure is as follows:

  1. Log on to the EDAS console.In the left-side navigation pane, choose Application Management > Applications. On the Applications page, click Create Application in the upper-right corner. On the Application Information page, check Application Runtime Environment and the latest EDAS Container version (3. X.X).
  2. For more information about Pandora Container versions, see Container versions.
  3. Replace the version number in the Dockerfile, such as 3.5.0.
  4. Re-create and publish an application image.
  1. # Set EDAS Container or Pandora Container version
  2. ENV EDAS_CONTAINER_VERSION V3.5.0

Add the EDAS runtime environment to Tomcat startup parameters

For the environment variables, see Environment variables during application runtime. EDAS provides the JVM environment variable EDAS_CATALINA_OPTS, which contains the minimum parameters required during runtime.Ali-Tomcat provides the custom JVM parameter configuration option JAVA_OPTS for setting Xmx, Xms, and other parameters.

  1. # Set the JVM parameters of the EDAS application
  2. ENV CATALINA_OPTS ${EDAS_CATALINA_OPTS}
  3. # Set the JVM parameters
  4. ENV JAVA_OPTS="\
  5. -Xmx3550m \
  6. -Xms3550m \
  7. -Xmn2g \
  8. -Xss128k"

Upload an image to the image repository

After the image is created, you can upload the local image to Alibaba Cloud Docker registry.

For example, run the following command to push the packaged local image to the remote server for deployment:

  1. docker push registry.cn-hangzhou.aliyuncs.com/edas/demo-frontend-service:20181111

Restrictions on creating images

Observe the following specifications and constraints when creating a custom image by using a Dockerfile:

Tenant and encryption information

The tenant and encryption information is used for the user authentication and credential encryption of EDAS applications.

Resources

Resource type Resource name Description
Secret edas-certs Encryption dictionary, which stores EDAS tenant information

Environment variables

Environment variable key Type Description
tenantId String EDAS tenant ID
accessKey String Access Key ID for authentication
secretKey String Access Key Secret for authentication

Local files

Path Type Description
/home/admin/.spas_key/default File EDAS tenant authentication information, which includes the preceding environment variable information

Service information

The service information includes the EDAS domain and port to be connected to during runtime.

Resources

Resource type Resource name Description
ConfigMap edas-envs EDAS service information

Environment variables

Environment variable key Type Description
EDAS_ADDRESS_SERVER_DOMAIN String Service domain or IP address of the configuration center
EDAS_ADDRESS_SERVER_PORT String Service port of the configuration center
EDAS_CONFIGSERVER_CLIENT_PORT String CS service port

Environment variables during application runtime (required)

The following environment variables are provided during EDAS deployment to ensure the proper running of applications. For this reason, do not overwrite the current configuration.

Environment variable key Type Description
POD_IP String POD IP
EDAS_APP_ID String EDAS application ID
EDAS_ECC_ID String EDAS ECC ID
EDAS_PROJECT_NAME String Same as EDAS_APP_ID, which is used to parse the trace
EDAS_JM_CONTAINER_ID String Same as EDAS_ECC_ID, which is used to parse the trace
EDAS_CATALINA_OPTS String CATALINA_OPTS parameter, which is required during middleware operation
CATALINA_OPTS String Same as EDAS_CATALINA_OPTS, which is the default Tomcat startup parameter