Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Current »

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

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

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:

    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:

    DB = oracle
  3. Open the ../Docker_Dependencies/Dockerfile file and update as follows:



    FROM canvasintellect/tomcat
    COPY demo /usr/local/tomcat/webapps/demo  #note: please change my warname demo into your warname name
    COPY ./server.xml /usr/local/tomcat/conf
    COPY ./context.xml /usr/local/tomcat/conf
    COPY ./Demo /usr/local/Demo  #note: here my Workfolder name is Demo please change my Workfolder name  into your Workfolder 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  #change the user And Grant permission for Workfolder 
    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 #change the user And Grant permission for warfile
    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:



    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:


    server.xml entries for MySQL:

    <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}"
    />


    Context.xml entries for MySQL:

    <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


    server.xml entries for Oracle:

    <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}"
    />


    Context.xml entries for Oracle:

    <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:

    <!-- 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">

    <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"> code section:

    <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> demo war file not build. Please Build the demo and try again to dockerize the demo</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>For Windows System Environment docker image build process is not supported </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:

    {
    	“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:


  • No labels