Multi-instance development environment: symlinking hybris folders


The problem statement

The Hybris distribution needs around 3 Gb on your disk and consists of 30000 folders and around 134000 files. There was a need to have several hybris instances preconfigured for the specific purposes. There is nothing complicated to create a fresh copy to have a completely separate instance. However, this process takes time and the newly created distributive takes more than 3 Gb of my SSD. It could be endured, but it makes me wait each time while 134000 files and 30000 folders are copying from one place to another. Sometimes I need to check some assumptions on the fresh hybris installation. However, once I changed something in the configuration, that instance can’t be longer called “fresh”, because these changes can irreversibly affect the initial state of the system. For example, some changes in the configuration can have the consequence of creating additional files in hybris folders. These files may affect the next run or another configuration. Hybris 6.1 has a feature named HybrisPlatformRole API, but it is not a solution for the task above because it changes the configuration of the instance. You won’t be able to work with two instances of hybris in parallel because they use the same filesystem, same
data
 folder etc. To avoid these problems I create a fresh copy of hybris each time I need to  be free from the influence of these files and the database state. The faster I am able to create a fresh copy and test my code on it, the more effective I will be.

The solution

The approach explained below will allow you to create a fresh copy of hybris on the same HDD in 1 minute. This copy will take ~500 Mb because it shares some of the files with another instance. For example, for the acceleratorfacades module two folders are skipped, all root files are copied, the remaining folders are symlinked to the original location. As a result, the cloned copy of the extension is much smaller than if you copy all folders. hybriscopy.png

Results

Creating a new clone takes about a minute + initialization (8min).

Configuration

To use the cloned version in parallel to the source version, you need to make the following changes in the configuration (local.properties):
  • Ports
    • WEB (HTTP, SSL)
      • tomcat.http.port=19001
      • tomcat.ssl.port=19002
    • SOLR
      • solrserver.instances.default.port=18983
    • JMX
      • tomcat.jmx.port=19003
      • tomcat.jmx.server.port=19004
    • Debug:
      • tomcat.debugjavaoptions=-Xverify:none  -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=18000,suspend=n -Dlog4j.configuration=log4j_init_tomcat.properties -Djava.util.logging.config.file=jdk_logging.properties
  • URLs
    • storefront extension
      • website.*
      • media.*
  • Database credentials (if any)
You need to change a port of SOLR server in Facet Search Configuration. The example
INSERT_UPDATE SolrEndpointUrl;solrServerConfig(name)[unique=true];url[unique=true];master[unique=true,default=false]
 ;$serverConfigName;http://localhost:18983/solr;true

Creating a clone

Linux

Download the Bash version here. It is similar to the Windows version.

Windows

Download the Windows version here.  You can find some excerpts to domonstrate the concept.

create.sh

Change first two lines in the script below. SOURCE is a folder where hybris 6.1 is installed. TARGET is a folder to create.
set SOURCE=c:\hybris\h61
set TARGET=c:\hybris\h61_6
call create_auto0.bat %SOURCE% %TARGET%
call create_auto1.bat %SOURCE% %TARGET%
call create_auto2.bat %SOURCE% %TARGET%
call create_auto3.bat %SOURCE% %TARGET%

create_auto0.bat

This script creates a base folder structure. Some folders are symlinks to the source hybris folders. Don’t copy the script below. Use this link instead.
@echo off
set SOURCE=%1
set TARGET=%2

mkdir %TARGET%
mkdir %TARGET%\hybris
mkdir %TARGET%\hybris\bin
mkdir %TARGET%\hybris\bin\platform

echo Creating symlinks for extensions...

mkdir %TARGET%\hybris\bin\ext-template\yempty
mkdir %TARGET%\hybris\bin\ext-template\yhacext
xcopy /E /Q /Y %SOURCE%\hybris\bin\ext-template\yempty\*.* %TARGET%\hybris\bin\ext-template\yempty\
xcopy /E /Q /Y %SOURCE%\hybris\bin\ext-template\yhacext\*.* %TARGET%\hybris\bin\ext-template\yhacext\

echo Creating symlinks for other folders

mklink /j %TARGET%\build-tools %SOURCE%\build-tools
mklink /j %TARGET%\c4c-integration %SOURCE%\c4c-integration
mklink /j %TARGET%\hybris-ems %SOURCE%\hybris-ems
mklink /j %TARGET%\hybris-Mobile-Apps-SDK %SOURCE%\hybris-Mobile-Apps-SDK
mklink /j %TARGET%\hybris-sbg %SOURCE%\hybris-sbg
mklink /j %TARGET%\installer %SOURCE%\installer
mklink /j %TARGET%\licenses %SOURCE%\licenses

echo Creating symlinks for platform folders...
mklink /j %TARGET%\hybris\bin\platform\apache-ant-1.9.1 %SOURCE%\hybris\bin\platform\apache-ant-1.9.1

mkdir %TARGET%\hybris\data\acceleratorservices
mkdir %TARGET%\hybris\data\backoffice
mkdir %TARGET%\hybris\data\luceneindex
mkdir %TARGET%\hybris\data\media
mkdir %TARGET%\hybris\data\solr
mkdir %TARGET%\hybris\log
mkdir %TARGET%\hybris\log\solr
mkdir %TARGET%\hybris\log\solrstats
mkdir %TARGET%\hybris\log\tomcat
mkdir %TARGET%\hybris\roles
mkdir %TARGET%\hybris\temp

echo Copying platform...
mkdir %TARGET%\hybris\bin\platform\bootstrap
xcopy /E /Q /Y %SOURCE%\hybris\bin\platform\bootstrap\*.* %TARGET%\hybris\bin\platform\bootstrap\
xcopy /Q /Y %SOURCE%\hybris\bin\platform\*.* %TARGET%\hybris\bin\platform\
mklink /j %TARGET%\hybris\bin\platform\resources %SOURCE%\hybris\bin\platform\resources
mklink /j %TARGET%\hybris\bin\platform\lib %SOURCE%\hybris\bin\platform\lib
mkdir %TARGET%\hybris\bin\platform\ext
xcopy /E /Q /Y %SOURCE%\hybris\bin\platform\ext %TARGET%\hybris\bin\platform\ext
mklink /j %TARGET%\hybris\bin\platform\tcServer %SOURCE%\hybris\bin\platform\tcServer
mkdir %TARGET%\hybris\bin\platform\tomcat\conf
xcopy /E /Q /Y %SOURCE%\hybris\bin\platform\tomcat\conf\*.* %TARGET%\hybris\bin\platform\tomcat\conf
mkdir %TARGET%\hybris\bin\platform\tomcat\lib
xcopy /E /Q /Y %SOURCE%\hybris\bin\platform\tomcat\lib\*.* %TARGET%\hybris\bin\platform\tomcat\lib
mkdir %TARGET%\hybris\bin\platform\tomcat\work
xcopy /E /Q /Y %SOURCE%\hybris\bin\platform\tomcat\work\*.* %TARGET%\hybris\bin\platform\tomcat\work
copy /E /Q /Y %SOURCE%\hybris\bin\platform\tomcat\tomcat_context.tpl %TARGET%\hybris\bin\platform\tomcat\tomcat_context.tpl

mkdir %TARGET%\hybris\bin\custom
mklink /j %TARGET%\hybris\bin\platform\tomcat\bin %SOURCE%\hybris\bin\platform\tomcat\bin

create_auto1.bat

Don’t copy the script below. Use this link instead.
@echo off
set SOURCE=%1
set TARGET=%2

mkdir %TARGET%
mkdir %TARGET%\hybris
mkdir %TARGET%\hybris\bin
mkdir %TARGET%\hybris\bin\platform
mkdir %TARGET%\hybris\bin\ext-accelerator\acceleratorcms
mkdir %TARGET%\hybris\bin\ext-accelerator\acceleratorcmshmc
mkdir %TARGET%\hybris\bin\ext-accelerator\acceleratorfacades
mkdir %TARGET%\hybris\bin\ext-accelerator\acceleratorservices


.... (800 lines)  download the full scripts

copy %SOURCE%\hybris\bin\ext-template\yhacext\*.* %TARGET%\hybris\bin\ext-template\yhacext\
copy %SOURCE%\hybris\bin\ext-template\yoccaddon\*.* %TARGET%\hybris\bin\ext-template\yoccaddon\
copy %SOURCE%\hybris\bin\ext-template\ysmarteditmodule\*.* %TARGET%\hybris\bin\ext-template\ysmarteditmodule\
copy %SOURCE%\hybris\bin\ext-template\ywebservices\*.* %TARGET%\hybris\bin\ext-template\ywebservices\

create_auto2.bat

Don’t copy the script below. Use this link instead.
@echo off
set SOURCE=%1
set TARGET=%2

mklink /j %TARGET%\hybris\bin\ext-accelerator\acceleratorcms\resources %SOURCE%\hybris\bin\ext-accelerator\acceleratorcms\resources
mklink /j %TARGET%\hybris\bin\ext-accelerator\acceleratorcms\src %SOURCE%\hybris\bin\ext-accelerator\acceleratorcms\src
mklink /j %TARGET%\hybris\bin\ext-accelerator\acceleratorcms\testsrc %SOURCE%\hybris\bin\ext-accelerator\acceleratorcms\testsrc
mklink /j %TARGET%\hybris\bin\ext-accelerator\acceleratorcmshmc\hmc %SOURCE%\hybris\bin\ext-accelerator\acceleratorcmshmc\hmc
mklink /j %TARGET%\hybris\bin\ext-accelerator\acceleratorcmshmc\resources %SOURCE%\hybris\bin\ext-accelerator\acceleratorcmshmc\resources
(1484 lines) download the full scripts
mklink /j %TARGET%\hybris\bin\ext-content\smartedit\src %SOURCE%\hybris\bin\ext-content\smartedit\src
mklink /j %TARGET%\hybris\bin\ext-content\smartedit\testsrc %SOURCE%\hybris\bin\ext-content\smartedit\testsrc
mklink /j %TARGET%\hybris\bin\ext-content\smartedit\web %SOURCE%\hybris\bin\ext-content\smartedit\web

create_auto2.bat

@echo off
set SOURCE=%1
set TARGET=%2

xcopy /E /I /H %SOURCE%\hybris\bin\ext-content\bmecat\bin %TARGET%\hybris\bin\ext-content\bmecat\bin
xcopy /E /I /H %SOURCE%\hybris\bin\ext-content\bmecat\doc %TARGET%\hybris\bin\ext-content\bmecat\doc
xcopy /E /I /H %SOURCE%\hybris\bin\ext-content\bmecat\resources %TARGET%\hybris\bin\ext-content\bmecat\resources
(125 lines) download the full scripts
xcopy /E /I /H %SOURCE%\hybris\bin\ext-backoffice\backoffice\resources %TARGET%\hybris\bin\ext-backoffice\backoffice\resources
xcopy /E /I /H %SOURCE%\hybris\bin\ext-backoffice\backoffice\testsrc %TARGET%\hybris\bin\ext-backoffice\backoffice\testsrc
xcopy /E /I /H %SOURCE%\hybris\bin\ext-backoffice\backoffice\web %TARGET%\hybris\bin\ext-backoffice\backoffice\web
© Rauf Aliev, October 2016

Leave a Reply