Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Note

Draft content

The step-by-step instructions on this page enables enable you to create a Docker image of the application that you built using the Canvas Technology platform.

Note

These instructions are applicable for Tomcat server only. It is assumed that a Docker Container running on Linux environment is available for this procedure.

Let’s name the application name is ‘Test’. Ensure that you change ‘Test’ to your application’s name when performing the following steps.When a new application is created using the Canvas Technology Platform, that application’s project will contain folders as shown in the following screen shot. Here, let’s assume that the application name is Demo. You can notice in the screen shot that the folders are prefixed with the application name, e.g. DemoDBScripts, DemoLib etc.

...

Perform the following steps to enable docker build for your application:

  1. In the application project folder, open the build properties file (e.g. buildDemo.properties) and enable docker build as follows:

    Code Block
    languagetext
    BUILD_DOCKER_IMAGE = Y
  2. Perform this step if you are using Oracle database only. In the build properties file (e.g. buildDemo.properties), uncomment the following property:

    Code Block
    languagetext
    DB = oracle
  3. Open the ..\Docker_Dependencies\Dockerfile file and update as follows:

    Image Added


    Ensure to change the contents of Dockerfile according to your application name and work folder in the indicated places:

    Code Block
    languagebash
    FROM canvasintellect/tomcat
    COPY demo /usr/local/tomcat/webapps/demo    #Note: Replace 'demo' with your application WAR name.
    COPY ./server.xml /usr/local/tomcat/conf
    COPY ./context.xml /usr/local/tomcat/conf
    COPY ./Demo /usr/local/Demo    #Note: Here the work folder name is 'Demo', change it to your application work folder name.
    COPY ./initial.sh /usr/local/tomcat/
    USER root
    EXPOSE 8080
    RUN chown -R 1000370000:0 /usr/local/Demo \ 
        && chmod -R og+rw /usr/local/Demo    #Note: Change the user and grant permission for your application work folder.
    RUN chmod -R 777 /usr/local/Demo
    RUN chown -R 1000370000:0 /usr/local/tomcat/webapps/demo \
        && chmod -R og+rw /usr/local/tomcat/webapps/demo    #Note: Change the user and grant permission for your application WAR
    RUN chmod -R 777 /usr/local/tomcat/webapps/demo
    RUN chmod 777 /usr/local/tomcat/initial.sh
    USER 1000370000
    ENTRYPOINT [ "/usr/local/tomcat/initial.sh"]
  4. Ensure that the contents of ..\Docker_Dependencies\docker-build.sh file are as follows:

    Image Added


    Contents of docker-build.sh file:

    Code Block
    languagebash
    sudo docker build -t $2:$3 $1
  5. If using MySQL schema, add the application datasource entries in the ..\Docker_Dependencies\mysql\server.xml and ..\Docker_Dependencies\mysql\context.xml files as follows:

    Image Added


    Entries in server.xml for MySQL. Here, since the application name is Demo, the Datasource names are DemoCanvasDataSource and DemoAppDataSource. Ensure to change these accordingly to your application’s datasource names:

    Code Block
    languagexml
    <Resource 
      auth="Container"
      driverClassName="com.mysql.cj.jdbc.Driver"
      factory="org.objectweb.jotm.datasource.DataSourceFactory"
      maxactive="50"
      maxidle="25"
      maxwait="-1"
      name="jdbc/DemoCanvasDataSource"
      password="{db_pass}"
      type="javax.sql.DataSource"
      url="jdbc:mysql://{db_ip}:{db_port}/{db_schema}"
      username="{db_user}"
    />
    
    <Resource 
      auth="Container"
      driverClassName="com.mysql.cj.jdbc.Driver"
      factory="org.objectweb.jotm.datasource.DataSourceFactory"
      maxactive="50"
      maxidle="25"
      maxwait="-1"
      name="jdbc/DemoAppDataSource"
      password="{db_pass}"
      type="javax.sql.DataSource"
      url="jdbc:mysql://{db_ip}:{db_port}/{db_schema}"
      username="{db_user}"
    />


    Entries in context.xml for MySQL. Here, since the application name is Demo, the Datasource names are DemoCanvasDataSource and DemoAppDataSource. Ensure to change these accordingly to your application’s datasource names:

    Code Block
    languagexml
    <ResourceLink 
      global="jdbc/DemoCanvasDataSource"
      name="jdbc/DemoCanvasDataSource"
      type="javax.sql.DataSource"
    />
    
    <ResourceLink 
      global="jdbc/DemoAppDataSource"
      name="jdbc/DemoAppDataSource"
      type="javax.sql.DataSource"
    />
  6. If using Oracle schema, add the application datasource entries in ..\Docker_Dependencies\oracle\server.xml and ..\Docker_Dependencies\oracle\context.xml files as follows:

    Image Added


    Entries in server.xml for Oracle. Here, since the application name is Demo, the Datasource names are DemoCanvasDataSource and DemoAppDataSource. Ensure to change these accordingly to your application’s datasource names:

    Code Block
    languagexml
    <Resource 
      auth="Container"
      driverClassName="oracle.jdbc.OracleDriver"
      factory="org.objectweb.jotm.datasource.DataSourceFactory"
      maxactive="10"
      maxidle="10"
      maxwait="-1"
      name="jdbc/DemoAppDataSource"
      password="{db_pwd}"
      type="javax.sql.DataSource"
      url="jdbc:oracle:thin:@{db_ip}:{db_port}/{db_SIR}"
      username="{db_schema}"
    />
    
    <Resource 
      auth="Container"
      driverClassName="oracle.jdbc.OracleDriver"
      factory="org.objectweb.jotm.datasource.DataSourceFactory"
      maxactive="10"
      maxidle="10"
      maxwait="-1"
      name="jdbc/DemoCanvasDataSource"
      password="{db_pwd}"
      type="javax.sql.DataSource"
      url="jdbc:oracle:thin:@{db_ip}:{db_port}/{db_SIR}"
      username="{db_schema}"
    />


    Entries in context.xml for Oracle. Here, since the application name is Demo, the Datasource names are DemoCanvasDataSource and DemoAppDataSource. Ensure to change these accordingly to your application’s datasource names:

    Code Block
    languagexml
    <ResourceLink 
      global="jdbc/DemoCanvasDataSource"
      name="jdbc/DemoCanvasDataSource"
      type="javax.sql.DataSource"
    />
    
    <ResourceLink 
      global="jdbc/DemoAppDataSource"
      name="jdbc/DemoAppDataSource"
      type="javax.sql.DataSource"
    />
  7. In the build.xml file and add the following codes under <target name="-buildDemo"> tag.

    Code Block
    languagexml
    <!-- Step 4: Check to build the docker Image -->
    	<antcall target="-check.dockerImage"/>
  8. In the build.xml file and add the following codes under <target name="-setProperties" depends="-setLocalBuildProps"> tag. Here, the application name is Demo. Ensure to replace it with your application name and the folder paths in the same case:

    Code Block
    languagexml
    <property 
      name="DEMO_DOCKER_FILE"
      value="${DEMO_SRC_HOME}/Demo/Docker_Dependencies/Dockerfile"
    />
    <property 
      name="DEMO_DOCKER_BUILD_FILE"
      value="${DEMO_SRC_HOME}/Demo/Docker_Dependencies/docker-build.sh"
    />
    
    <property 
      name="imagename"
      value="demo"
    />

  9. In the build.xml file and add the following codes after <target name="-createChecksumReport"> tag. Here, the application name is Demo. Ensure to replace it with your application name and the folder paths in the same case:

    Code Block
    languagexml
    <target name="-check.dockerImage">
    	<if>
    	   equals arg1="${BUILD_DOCKER_IMAGE}" arg2="Y" />
    	<then>
    	   <echo> File Exists </echo>
    	   <antcall target="-check.Operating System"/>
    	</then>
    	<else>
    	   <echo> Application WAR file is not build properly. Please build the application and try again to dockerize it.</echo>
    	   <antcall target="-createChecksumReport">
    		<param name="SOURCE_DIR" value="${DIST_ROOT}" />
    	   </antcall>
    	</else>
    	</if>
    </target>
    
    <target name="-check.Operating System">
    	<condition property="is.windows">
    		<os family="windows"/>
    	</condition>
    	<condition property="is.unix">
    		<os family="unix"/>
    	</condition>
    	<if>
       <isset property="is.windows"/>
    	<then>
    	   <echo>Docker image build process is not supported for Windows environment.</echo>
    	   <antcall target="-createChecksumReport">
    		<param name="SOURCE_DIR" value="${DIST_ROOT}" />
    	   </antcall>
    	</then>
    </if>
    <if>
       <isset property="is.unix"/>
    <then>
    	   <antcall target="-check.docker"/>
    	</then>
        </if>
    </target>
    
    <target name="-check.docker">
    <exec executable="docker" outputproperty="output">
       <arg value ="-v"/>
    </exec> 
    <if>
       <contains string="${output}" substring="Docker version"/>
    <then>
       <antcall target="-configchange"/>
    </then>
    <else>
       <echo> Please install Docker and try again for building the docker image.</echo>
       <antcall target="-createChecksumReport">
       <param name="SOURCE_DIR" value="${DIST_ROOT}" />
       </antcall>
    </else>
    </if>
    </target>
    
    <target name="-configchange">
    	<unzip src="${DIST_ROOT}/demo.war" dest="${DIST_ROOT}/demo"/>
    	<delete file="${DIST_ROOT}/demo.war"/>
    	<unzip src="${DIST_ROOT}/demo/WEB-INF/lib/DemoResources.jar" dest="${DIST_ROOT}/change"/>
    <replace file="${DIST_ROOT}/change/DemoImplementation.properties" token="D:/Canvas/Demo" value="/usr/local/Demo"/>     	
    <if>
    	   <equals arg1="${DB}" arg2="oracle" />
    	<then>
    		<replace file="${DIST_ROOT}/change/Demodatabaseconfig.properties" token="mysql" value="oracle"/>
    	</then>
    	</if>
    	  <jar destfile="${DIST_ROOT}/demo/WEB-INF/lib/DemoResources.jar" basedir="${DIST_ROOT}/change"/>
       <delete dir="${DIST_ROOT}/change"/>
       <jar destfile="${DIST_ROOT}/demo.war">
    		<fileset dir="${DIST_ROOT}/demo">
    			<include name="**/*.*" />
    		</fileset>
    	   </jar>
    	   <copy file="${DEMO_SRC_HOME}/Demo/Docker_Dependencies/mysql/server.xml" todir="${DIST_ROOT}"/>
    		<copy file="${DEMO_SRC_HOME}/Demo/Docker_Dependencies/mysql/context.xml" todir="${DIST_ROOT}"/>
    		<copy file="${DEMO_SRC_HOME}/Demo/Docker_Dependencies/mysql/initial.sh" todir="${DIST_ROOT}"/>
    		<copy todir="${DIST_ROOT}/Demo" preservelastmodified="true" verbose="true">
    			<fileset dir="${DEMO_SRC_HOME}/Demo/ToBeCopiedOutside/"/>
    	   </copy>
    	<if>
    	   <equals arg1="${DB}" arg2="oracle" />
    	<then>
    		<delete file="${DIST_ROOT}/server.xml"/>
    		<delete file="${DIST_ROOT}/context.xml"/>
    		<delete file="${DIST_ROOT}/initial.sh"/>
    		<copy file="${DEMO_SRC_HOME}/Demo/Docker_Dependencies/oracle/server.xml" todir="${DIST_ROOT}"/>
    		<copy file="${DEMO_SRC_HOME}/Demo/Docker_Dependencies/oracle/context.xml" todir="${DIST_ROOT}"/>
    		<copy file="${DEMO_SRC_HOME}/Demo/Docker_Dependencies/oracle/initial.sh" todir="${DIST_ROOT}"/>
    	</then>
    	</if>
    		<antcall target="-build.dockerimage"/>
    </target>
    
    <target name="-build.dockerimage">
    	<copy file="${DEMO_DOCKER_FILE}" todir="${DIST_ROOT}"/>
    	<chmod file="${DEMO_DOCKER_BUILD_FILE}" perm="777"/>
    		<exec executable="${DEMO_DOCKER_BUILD_FILE}">
    			<arg value="${DIST_ROOT}"/>
    			<arg value="${imagename}"/>
    			<arg value="${buildVersion}"/>
    		</exec>
    	<delete file="${DIST_ROOT}/Dockerfile"/>
    	<delete file="${DIST_ROOT}/initial.sh"/>	   
    	<delete dir="${DIST_ROOT}/demo"/>
    	<delete file="${DIST_ROOT}/server.xml"/>
    	<delete file="${DIST_ROOT}/context.xml"/>
    	<delete dir="${DIST_ROOT}/Demo"/>
    	<antcall target="-createChecksumReport">
    		<param name="SOURCE_DIR" value="${DIST_ROOT}" />
    	</antcall>
    </target>

  10. In the CanvasApplicationContext.json file in ..\Dependencies\canvas\CTResources.jar, add your application’s context root as follows. Here, the application name is Demo. Ensure to replace it with your application name in the same case:

    Code Block
    languagejson
    {
    	“contextRoot : “demo”,
    	“applicationId : “DEMO”,
    	“displayName” : “Demo”,
    	“isService” : “N”
    },
  11. Ensure that the following JOTM related JARs are located in the ..\Demo\Dependencies\Supporting_Jars\Database_Drivers folder:

    Image Added