Home / Optimize the Site Compilation Process

Optimize the Site Compilation Process

Overview

The default steps to compile a site are:

  1. Create a template from the site:

    1. Downloads the site, theme, and components used during site compilation.

      Note: This does not download the content as all content calls during compilation are made back to the original server.

  2. Compile the template:

    1. Runs the compile template command with the following set of default options

      • --type published
      • --verbose
      • --ignoreErrors
    2. Deletes any existing static files.

    3. Uploads the new set of static HTML files.

  3. Publish the static HTML files, typically together with the whole site.

You may want to change the behavior during compilation. For example, if you have a multilingual site, you may want the default locale to be included in the URL (--includeLocale) or you may want to stop on error rather than uploading and publishing the rest of the site (remove the --ignoreErrors option). Or you may want to optimize the compilation process in order to reduce the set of files that are downloaded during the template creation step or control which detail pages to create.

Oracle Content Management provides two sets of files that can be added to the site to affect how the site is compiled:

Use compile_config.json

Use compile_config.json to override the set of default parameters passed to the cec compile-template command during the site compilation process. For example, to include the default locale in the URL for the site, you would have a compile_config.json file that contains:

{
    options: {
        "includeLocale": true
    }
}

You can test your compile_config.json file with the toolkit by adding the file to:

cec-install/src/templates/yourTemplate/compile_config.json

If the file exists when you run the cec compile-template command in the toolkit for you site, you’ll see the following output depending on your compile_config.json entries:

Compile Configuration File:  { options: { includeLocale: true, noDetailPages: true } }
 option override: --includeLocale=true
 option override: --noDetailPages=true

Upload compile_config.json

Once you’ve set up your compile_config.json file to do what you want, you need to upload it to the site on the Oracle Content Management server, so that it will be used when the site is compiled. To upload the file, you can use the following toolkit command to upload it to you specific site:

cec upload-file ./compile_config.json -f site:yourSiteName/

Remove compile_config.json

If you want to revert to the default behavior, remove the compile_config.json from your site:

cec delete-file site:yourSiteName/compile_config.json

Use compile_site.sh

Use the compile_site.sh file if you want to take complete control of the compilation process no matter if you’re using the compilation server in Content Toolkit that you installed, or the built-in compilation server. To get started, when you run cec install, a compile_site.sh file is created in the cec-install/samples folder. You can run this file directly to test it out. For example:

> cd cec-install
> cp samples/compile_site.sh .
> ./compile_site.sh
 
usage: compile_site.sh
 -s --sitename siteName*
 -t --templatename templateName
 -r --server registered server*
 -f --folder cec install folder*
 -j --jobid compilation job ID when called from the server
 -c --channeltoken site's channel token (use dummy token for standard sites)*
 -u --securesite [ true | false ] is the site a secure site
 -b --publishedversion [ true | false ] compile the published version of the site
  
example:
compile_site.sh -s sampleSite -r sampleServer -f `pwd` -c sampleChannelToken

The compile_site.sh file is a bash script and has examples within it of how to alter the script.

Optimize Compilation

When you compile a site, a lot of the time is spent waiting for content queries to return results. Rather than having the processor sitting idle during these calls, you can load up the machine to work on other tasks that can improve the compilation time. For example, if you had a site that had several languages, you could look at compiling several languages in parallel. To try that, change the seeded sample from:

cec compile-template ${TEMPLATE_NAME} -s ${REGISTERED_SERVER} -c  ${CHANNEL_TOKEN} -n ${SITE_NAME} ${SECURE_SITE_OPTION} -t published -v -i > job1.log 2>&1 &
 
# after spawning multiple processes, wait for all to complete and catch any failures
COMPILE_FAIL_COUNT=0
for processId in `jobs -p`
do
    wait $processId || let "COMPILE_FAIL_COUNT+=1"
done
 
# write out the compilation logs to stdout for each compilation job
# note: update with each background job log file - cat job1.log job2.log job3.log
cat job1.log
rm -f job1.log

to:

cec compile-template ${TEMPLATE_NAME} -s ${REGISTERED_SERVER} -c  ${CHANNEL_TOKEN} -n ${SITE_NAME} ${SECURE_SITE_OPTION} -t published -v -i -l -g en,en-US > job1.log 2>&1 &
cec compile-template ${TEMPLATE_NAME} -s ${REGISTERED_SERVER} -c  ${CHANNEL_TOKEN} -n ${SITE_NAME} ${SECURE_SITE_OPTION} -t published -v -i -l -g fr-FR,de-DE > job2.log 2>&1 &
cec compile-template ${TEMPLATE_NAME} -s ${REGISTERED_SERVER} -c  ${CHANNEL_TOKEN} -n ${SITE_NAME} ${SECURE_SITE_OPTION} -t published -v -i -l -g es-ES,es-MX > job3.log 2>&1 &
 
# after spawning multiple processes, wait for all to complete and catch any failures
COMPILE_FAIL_COUNT=0
for processId in `jobs -p`
do
    wait $processId || let "COMPILE_FAIL_COUNT+=1"
done
 
# write out the compilation logs to stdout for each compilation job
# note: update with each background job log file - cat job1.log job2.log job3.log
cat job1.log job2.log job3.log
rm -f job1.log job2.log job3.log

compile_site.sh and compile_config.json

While the compile_site.sh allows you to take complete control of the compilation flow, if the site you’re compiling does have a compile_config.json file, then that will still be used by any cec compile-template command.

Upload compile_site.sh

Once you’ve set up your compile_site.sh file to do what you want, you need to upload it to the site on the OCM server, so that it will be used when the site is compiled. To upload the file, use the following Content Toolkit command to upload it to you specific site:

cec upload-file ./compile_site.sh -f site:yourSiteName/

Remove compile_site.sh

If you want to revert to the default behavior, remove the compile_site.sh file from your site:

cec delete-file site:yourSiteName/compile_site.sh