Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Write a script (I use ant for such java projects) that promotes/copies to your production environment exactly what you want.</p> <p>In my case, the ant scripts:</p> <ol> <li>Create a tmp directory, </li> <li>Copies specific files from the source trees into the new file structure (often exactly the same as the source, just not <em>in</em> the source folders, and excluding .svn and other files I wouldn't want (.java files rather than .class files or jars etc)</li> <li>Compiles and jars what's needed</li> <li>Does search/replace in configuration files (to allow deployment to staging, dev, qa or production environments which may differ </li> <li>Zips the whole thing up and copies (scp) to the target server if remote</li> <li>Stops any existing running applications</li> <li>unpacks the new version</li> <li>Starts the new application</li> </ol> <p>I have, on some projects, options to upload just changed files rather than redeploying whole applications, but that's a design choice you'll get to make yourself. For the larger projects I've worked on I've gravitated to deploying the <em>whole</em> project for each update rather than copying individual files/changes to the server. This way I can ensure the integrity of the build process and the production environment and not have to worry about random files possibly being out of sync with the rest of the project.</p> <p>Generally for anything other than trivially simple project, you'll want a real make/build environment ... which you'll have to write your self.</p> <p>Ant</p> <p>Maven</p> <p>shell scripts</p> <p>make</p> <p>all are possible solutions.</p> <p><code> </p> <pre><code>&lt;!-- **************** USAGE (DEFAULT) --&gt; &lt;target name="usage"&gt; &lt;!-- echo detailed usage instructions here --&gt; &lt;/target&gt; &lt;!-- ************************************************** --&gt; &lt;!-- ******************* WAS 4.0 WORKER TARGETS --&gt; &lt;target name="init" depends="validenvironment"&gt; &lt;tstamp/&gt; &lt;echo&gt;Build of ${ant.project.name} started at ${TSTAMP} on ${TODAY} &lt;/echo&gt; &lt;/target&gt; &lt;target name="inittomcat"&gt; &lt;delete dir="tomcatdeploy" /&gt; &lt;mkdir dir="tomcatdeploy" /&gt; &lt;/target&gt; &lt;target name="initapache"&gt; &lt;delete dir="apacheconfig" /&gt; &lt;mkdir dir="apacheconfig" /&gt; &lt;/target&gt; &lt;!-- validates that you've specified an environment (production, dev, staging etc.) from an allowed list --&gt; &lt;target name="validenvironment"&gt; &lt;condition property="valid.environment"&gt; &lt;or&gt; &lt;equals arg1="${penvironment}" arg2="dev" /&gt; &lt;equals arg1="${penvironment}" arg2="qa" /&gt; &lt;equals arg1="${penvironment}" arg2="staging" /&gt; &lt;equals arg1="${penvironment}" arg2="prod" /&gt; &lt;/or&gt; &lt;/condition&gt; &lt;fail message="Invalid target ${penvironment}." unless="valid.environment" /&gt; &lt;/target&gt; &lt;!-- validates that you've specified a target server to deploy to. Only checks to see if the propery is set, not actual values --&gt; &lt;target name="validserver"&gt; &lt;condition property="valid.server"&gt; &lt;isset property="pserver" /&gt; &lt;/condition&gt; &lt;fail message="Invalid server ${pserver}. You must specifiy a server for this target." unless="valid.server" /&gt; &lt;/target&gt; &lt;target name="initwar"&gt; &lt;delete dir="tmp/war" /&gt; &lt;mkdir dir="tmp/war" /&gt; &lt;mkdir dir="tmp/war/WEB-INF" /&gt; &lt;mkdir dir="tmp/war/WEB-INF/classes" /&gt; &lt;mkdir dir="tmp/war/WEB-INF/lib" /&gt; &lt;mkdir dir="tmp/war/tags" /&gt; &lt;mkdir dir="tmp/war/images" /&gt; &lt;mkdir dir="tmp/war/javascript" /&gt; &lt;mkdir dir="tmp/war/html" /&gt; &lt;mkdir dir="tmp/war/components" /&gt; &lt;/target&gt; &lt;target name="war" depends="initwar" if="penvironment"&gt; &lt;echo&gt;Compiling source files...&lt;/echo&gt; &lt;ant antfile="build.xml" dir="classes/" target="compile" inheritAll="false" &gt; &lt;property name="penvironment" value="${penvironment}" /&gt; &lt;/ant&gt; &lt;echo&gt;Compile done.&lt;/echo&gt; &lt;copy todir="tmp/war/WEB-INF/classes" preservelastmodified="true" &gt; &lt;fileset dir="classes/build" includes="**/*.class" /&gt; &lt;/copy&gt; &lt;copy todir="tmp/war/WEB-INF/controller_jsp" preservelastmodified="true" &gt; &lt;fileset dir="controller" includes="**/*.*" /&gt; &lt;/copy&gt; &lt;copy todir="tmp/war/WEB-INF" preservelastmodified="true" &gt; &lt;fileset dir="build" includes="**/*.xsl" /&gt; &lt;/copy&gt; &lt;copy todir="tmp/war/WEB-INF/lib" preservelastmodified="true" &gt; &lt;fileset dir="build/lib${penv}" includes="**/*.*" /&gt; &lt;/copy&gt; &lt;copy todir="tmp/war/html" preservelastmodified="true" &gt; &lt;fileset dir="html" includes="**/*.*" /&gt; &lt;/copy&gt; &lt;copy todir="tmp/war/components" preservelastmodified="true" &gt; &lt;fileset dir="components" includes="**/*.*" /&gt; &lt;/copy&gt; &lt;copy todir="tmp/war/" preservelastmodified="true" &gt; &lt;fileset dir="root" includes="**/*.*" /&gt; &lt;/copy&gt; &lt;copy todir="tmp/war/pages" preservelastmodified="true" &gt; &lt;fileset dir="pages" includes="**/*.*" /&gt; &lt;/copy&gt; &lt;copy todir="tmp/war/tags" preservelastmodified="true" &gt; &lt;fileset dir="tags" includes="**/*.*" /&gt; &lt;/copy&gt; &lt;copy todir="tmp/war/images" preservelastmodified="true" &gt; &lt;fileset dir="images" includes="**/*.*" /&gt; &lt;/copy&gt; &lt;copy todir="tmp/war/javascript" preservelastmodified="true" &gt; &lt;fileset dir="javascript" includes="**/*.*" /&gt; &lt;/copy&gt; &lt;!-- copy the web.xml for the target environment into the temp war directory --&gt; &lt;copy tofile="tmp/war/WEB-INF/web.xml" file="xonfig/$penvironment}.web.xml" preservelastmodified="true" &gt; &lt;/copy&gt; &lt;!-- now replace all properties in the web.xml file with their values from ${penvironment}.properties --&gt; &lt;echo&gt;Replacing all properties in the web.xml file with their values from ${penvironment}.properties&lt;/echo&gt; &lt;replace file="tmp/war/WEB-INF/web.xml" propertyFile="config/${penvironment}.properties"&gt; &lt;replacefilter token="%%HOSTNAME%%" property="webxml.hostname" /&gt; &lt;/replace&gt; &lt;copy tofile="tmp/war/WEB-INF/application.properties" file="config/application.properties" preservelastmodified="true" &gt; &lt;/copy&gt; &lt;!-- now replace all properties in the application.properties file with their values from ${penvironment}.properties --&gt; &lt;echo&gt;Replacing all properties in the crm.properties file with their values from ${penvironment}.properties&lt;/echo&gt; &lt;replace encoding="ISO-8859-1" file="tmp/war/WEB-INF/application.properties" propertyFile="build/${penvironment}.properties"&gt; &lt;replacefilter token="%%HOSTNAME%%" property="hostname" /&gt; &lt;replacefilter token="%%EMAILADDRESS%%" property="emailaddress" /&gt; &lt;replacefilter token="%%LOGFILE%%" property="logfile" /&gt; &lt;replacefilter token="%%LOGLEVEL%%" property="loglevel" /&gt; &lt;replacefilter token="%%DEFAULTPAGE%%" property="defaultpage" /&gt; &lt;replacefilter token="%%MAILSERVER%%" property="mailserver" /&gt; &lt;replacefilter token="%%SUPPORTEDLANGUAGES%%" property="supportedlanguages" /&gt; &lt;replacefilter token="%%LDAPHOST%%" property="ldaphost" /&gt; &lt;replacefilter token="%%LDAPHOSTBACKUP%%" property="ldaphostbackup" /&gt; &lt;replacefilter token="%%LDAPPORT%%" property="ldapport" /&gt; &lt;replacefilter token="%%LDAPVER%%" property="ldapver" /&gt; &lt;replacefilter token="%%LDAPDC%%" property="ldapdc" /&gt; &lt;replacefilter token="%%LDAPPW%%" property="ldappw" /&gt; &lt;replacefilter token="%%LDAPUSERDC%%" property="ldapuserdc" /&gt; &lt;replacefilter token="%%LDAPSEARCH%%" property="ldapsearch" /&gt; &lt;replacefilter token="%%DATASCHEMA%%" property="dataschema" /&gt; &lt;/replace&gt; &lt;copy tofile="tmp/war/WEB-INF/navigation.properties" file="config/${penvironment}.maxnavigation.properties" preservelastmodified="true" &gt; &lt;/copy&gt; &lt;copy todir="tmp/war/WEB-INF" preservelastmodified="true" &gt; &lt;fileset dir="config/bundle" includes="**/*.*" /&gt; &lt;/copy&gt; &lt;!-- Create war file NOT USED right now as we're building this directly into the tomcat directory--&gt; &lt;!--jar jarfile="tmp/${penvironment}.war" basedir="tmp/war" --&gt; &lt;/target&gt; &lt;target name="buildtomcat" depends="war,inittomcat,validenvironment" if="penvironment"&gt; &lt;mkdir dir="tmp/tomcatdeploy/${penvironment}" /&gt; &lt;delete&gt; &lt;fileset dir="tomcat/6.x/logs" includes="**/*.log"/&gt; &lt;/delete&gt; &lt;copy todir="tmp/tomcatdeploy/${penvironment}/tomcat" preservelastmodified="true" &gt; &lt;fileset dir="tomcat/6.x" includes="**/*.*" /&gt; &lt;/copy&gt; &lt;mkdir dir="tmp/tomcatdeploy/${ppenvironment}/tomcat/logs" /&gt; &lt;mkdir dir="tmp/tomcatdeploy/${penvironment}/tomcat/webapps/${tomcat.contextroot}" /&gt; &lt;copy todir="tmp/tomcatdeploy/${penvironment}/tomcat/webapps/${tomcat.contextroot}" preservelastmodified="true" &gt; &lt;fileset dir="tmp/war" includes="**/*.*" /&gt; &lt;/copy&gt; &lt;!-- now copy the tomcat config files --&gt; &lt;copy tofile="tmp/tomcatdeploy/${penvironment}/tomcat/conf/context.xml" overwrite="true" file="config/context.xml" preservelastmodified="true" &gt; &lt;/copy&gt; &lt;!-- now replace all variables in context.xml --&gt; &lt;replace encoding="ISO-8859-1" file="tmp/tomcatdeploy/${penvironment}/tomcat/conf/context.xml" token="%%JDBCNAME%%" value="${context.jdbcname}" /&gt; &lt;replace encoding="ISO-8859-1" file="tmp/tomcatdeploy/${penvironment}/tomcat/conf/context.xml" token="%%JDBCUSER%%" value="${context.jdbcuser}" /&gt; &lt;replace encoding="ISO-8859-1" file="tmp/tomcatdeploy/${penvironment}/tomcat/conf/context.xml" token="%%JDBCPASSWORD%%" value="${context.jdbcpassword}" /&gt; &lt;replace encoding="ISO-8859-1" file="tmp/tomcatdeploy/${penvironment}/tomcat/conf/context.xml" token="%%JDBCDRIVER%%" value="${context.jdbcdriver}" /&gt; &lt;replace encoding="ISO-8859-1" file="tmp/tomcatdeploy/${penvironment}/tomcat/conf/context.xml" token="%%JDBCURL%%" value="${context.jdbcurl}" /&gt; &lt;!-- now replace all variables / ports in server.xml --&gt; &lt;copy tofile="tmp/tomcatdeploy/${penvironment}/tomcat/conf/server.xml" overwrite="true" file="config/server.xml" preservelastmodified="true" &gt; &lt;/copy&gt; &lt;!-- deleted for this example --&gt; &lt;!-- END replace all variables / ports in server.xml --&gt; &lt;!-- Now, replace CONTEXT in catalina.sh and catalina.bat --&gt; &lt;replace encoding="ISO-8859-1" file="tmp/tomcatdeploy/${penvironment}/tomcat/bin/catalina.sh" propertyFile="/config/${penvironment}.properties"&gt; &lt;replacefilter token="%%CONTEXT%%" property="tomcat.contextroot" /&gt; &lt;/replace&gt; &lt;replace encoding="ISO-8859-1" file="tmp/tomcatdeploy/${penvironment}/tomcat/bin/catalina.bat" propertyFile="/config/${penvironment}.properties"&gt; &lt;replacefilter token="%%CONTEXT%%" property="tomcat.contextroot" /&gt; &lt;/replace&gt; &lt;/target&gt; &lt;target name="deployfullapplication" depends="validenvironment,validserver" &gt; &lt;antcall target="deploytomcat" /&gt; &lt;antcall target="deployapacheconfig" /&gt; &lt;antcall target="restartapache" /&gt; &lt;/target&gt; &lt;target name="deploytomcat" depends="buildtomcat" &gt; &lt;!-- zip the tomcatdeploy directoyr up --&gt; &lt;zip destfile="tmp/${penvironment}.zip" basedir="tmp/tomcatdeploy" /&gt; &lt;!-- now scp to the server --&gt; &lt;echo&gt;Copying "tmp/${penvironment}.zip" to "${webuser}@${pserver}:/opt/www"&lt;/echo&gt; &lt;scp remoteToDir="${webuser}@${pserver}:/opt/www" file="tmp/${penvironment}.zip" verbose="true" failonerror="true" trust="true"&gt; &lt;/scp&gt; &lt;!-- now kill existing process on the server --&gt; &lt;antcall target="stoptomcat" /&gt; &lt;!-- now archive the existing deployed application on the server to ${penvironment}.${currenttimestamp} --&gt; &lt;antcall target="archivetomcat" /&gt; &lt;!-- now uncompress the zipped archive into the deployed location /opt/www/${penvironment} --&gt; &lt;antcall target="unzipremotetomcat" /&gt; &lt;!-- now start the application --&gt; &lt;antcall target="starttomcat" /&gt; &lt;!-- cool. thats it. good job. --&gt; &lt;!-- all the remote tasks have been deleted in this example.... just to get the idea of what to do. --&gt; &lt;/target&gt; &lt;target name="restarttomcat" depends="validenvironment,validserver" &gt; &lt;antcall target="stoptomcat"/&gt; &lt;antcall target="starttomcat"/&gt; &lt;/target&gt; &lt;target name="starttomcat" unless="pnostart" if="pserver" depends="validenvironment,validserver"&gt; &lt;!-- all the remote tasks have been deleted in this example.... just to get the idea of what to do. --&gt; &lt;/target&gt; &lt;target name="unzipremotetomcat" if="pserver" depends="validenvironment,validserver"&gt; &lt;!-- all the remote tasks have been deleted in this example.... just to get the idea of what to do. --&gt; &lt;/target&gt; &lt;target name="archivetomcat" if="pserver" depends="validenvironment,validserver"&gt; &lt;!-- all the remote tasks have been deleted in this example.... just to get the idea of what to do. --&gt; &lt;/target&gt; &lt;target name="stoptomcat" unless="pnokill" if="pserver" depends="validenvironment,validserver"&gt; &lt;!-- all the remote tasks have been deleted in this example.... just to get the idea of what to do. --&gt; &lt;/target&gt; &lt;target name="killtomcatprocessonecall" depends="validenvironment,validserver"&gt; &lt;!-- all the remote tasks have been deleted in this example.... just to get the idea of what to do. --&gt; &lt;/target&gt; &lt;target name="restartapache" depends="validenvironment,validserver" &gt; &lt;!-- all the remote tasks have been deleted in this example.... just to get the idea of what to do. --&gt; &lt;/target&gt; &lt;target name="deployapacheconfig" depends="configapache,validserver"&gt; &lt;!-- all the remote tasks have been deleted in this example.... just to get the idea of what to do. --&gt; &lt;/target&gt; &lt;target name="configapache" if="penv" depends="init,validenvironment"&gt; &lt;mkdir dir="tmp/apacheconfig" /&gt; &lt;mkdir dir="tmp/apacheconfig/vhosts.d" /&gt; &lt;mkdir dir="tmp/apacheconfig/ssl.crt" /&gt; &lt;mkdir dir="tmp/apacheconfig/ssl.key" /&gt; &lt;mkdir dir="tmp/apacheconfig/extra" /&gt; &lt;mkdir dir="tmp/apacheconfig/passwords" /&gt; &lt;echo&gt;Copying http base config files...&lt;/echo&gt; &lt;copy tofile="tmp/apacheconfig/vhosts.d/${penvironment}.conf" file="config/apache/vhosts/http.conf" preservelastmodified="true" /&gt; &lt;echo&gt;http only replace in http config file...&lt;/echo&gt; &lt;replace encoding="ISO-8859-1" file="tmp/apacheconfig/vhosts.d/${penvironment}.conf" propertyFile="config/${penvironment}.properties"&gt; &lt;replacefilter token="%%SERVERADMIN%%" property="httpd.serveradmin" /&gt; &lt;replacefilter token="%%LOGFILE%%" property="httpd.logfile" /&gt; &lt;replacefilter token="%%HOSTNAME%%" property="httpd.hostname" /&gt; &lt;replacefilter token="%%ROOT%%" property="httpd.root" /&gt; &lt;replacefilter token="%%HOSTIP%%" value="*" /&gt; &lt;replacefilter token="%%PORT%%" value="80" /&gt; &lt;replacefilter token="%%PROTOCOL%%" value="http" /&gt; &lt;replacefilter token="%%SSL%%" value="off" /&gt; &lt;replacefilter token="%%SSLCERT%%" value="" /&gt; &lt;replacefilter token="%%SSLKEY%%" value="" /&gt; &lt;replacefilter token="%%SSLCACERT%%" value="" /&gt; &lt;replacefilter token="%%CONTEXTROOT%%" property="tomcat.contextroot" /&gt; &lt;replacefilter token="%%AJPPORT%%" property="port.ajp13" /&gt; &lt;replacefilter token="%%DEFAULTPAGE%%" property="http.defaultpage" /&gt; &lt;replacefilter token="%%ERRORPAGE%%" property="http.errorpage" /&gt; &lt;/replace&gt; &lt;condition property="dossl"&gt; &lt;and&gt; &lt;isset property="${penvironment}.ssl.ip" /&gt; &lt;/and&gt; &lt;/condition&gt; &lt;antcall target="apachessl" /&gt; &lt;/target&gt; &lt;target name="apachessl" if="dossl"&gt; &lt;copy tofile="tmp/apacheconfig/vhosts.d/${penvironment}.s.conf" file="apache/vhosts/http.conf" preservelastmodified="true" /&gt; &lt;echo&gt;https only replace in https config file...&lt;/echo&gt; &lt;replace encoding="ISO-8859-1" file="tmp/apacheconfig/vhosts.d/${penvironment}.s.conf" propertyFile="config/${penvironment}.properties"&gt; &lt;replacefilter token="%%SERVERADMIN%%" property="httpd.serveradmin" /&gt; &lt;replacefilter token="%%LOGFILE%%" property="httpd.logfile" /&gt; &lt;replacefilter token="%%HOSTNAME%%" property="httpd.hostname" /&gt; &lt;replacefilter token="%%ROOT%%" property="httpd.root" /&gt; &lt;replacefilter token="%%PORT%%" value="443" /&gt; &lt;replacefilter token="%%PROTOCOL%%" value="https" /&gt; &lt;replacefilter token="%%SSL%%" property="httpd.ssl" /&gt; &lt;replacefilter token="%%SSLCERT%%" property="https.sslcert" /&gt; &lt;replacefilter token="%%SSLKEY%%" property="https.sslkey" /&gt; &lt;replacefilter token="%%SSLCACERT%%" property="https.sslcacert" /&gt; &lt;replacefilter token="%%CONTEXTROOT%%" property="tomcat.contextroot" /&gt; &lt;replacefilter token="%%AJPPORT%%" property="port.ajp13" /&gt; &lt;replacefilter token="%%JKWORKER%%" property="tomcat.jkworker" /&gt; &lt;replacefilter token="%%DEFAULTPAGE%%" property="http.defaultpage" /&gt; &lt;replacefilter token="%%ERRORPAGE%%" property="http.errorpage" /&gt; &lt;/replace&gt; &lt;copy tofile="tmp/apacheconfig/ssl.crt/${penvironment}.cert" file="config/apache/ssl.crt/${penvironment}.cert" failonerror="false" preservelastmodified="true" /&gt; &lt;copy tofile="tmp/apacheconfig/ssl.crt/verisign.intermediate.cert" file="config/apache/ssl.crt/verisign.intermediate.cert" failonerror="false" preservelastmodified="true" /&gt; &lt;copy tofile="tmp/apacheconfig/ssl.crt/network.solutions.ca.cert" file="config/apache/ssl.crt/network.solutions.ca.cert" failonerror="false" preservelastmodified="true" /&gt; &lt;copy tofile="tmp/apacheconfig/ssl.key/${penvironment}.key" file="config/apache/ssl.key/${penvironment}.key" failonerror="false" preservelastmodified="true" /&gt; &lt;/target&gt; </code></pre> <p> </code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload