Hybris development with Docker for windows

Overview

Install Docker in Windows

Install Hybris in Docker

Useful Docker Commands that you need to familiarize

Word of Caution

Faster performance for running Hybris in Windows system

Observations with Docker Hybris

 

Overview

This covers the setup of Hybris in Docker for Windows for the developer . This will help in building and starting of the application faster and more performant compared to Windows in local machine.Most of the developers work in Windows OS and 8/16 GB RAM and Hybris can be very slow in that configuration. With Docker , Hybris build and server start can be significantly faster .

As per this solution, Hybris will start in a new container named as hybris_docker. Solr will start in the same container where hybris is starting. MySQL will be a separate container hybris_sql and the volume is mounted in the Linux VM. The volume for media is also mounted in Linux VM. Hence with container start/stop the data will persist.

Install Docker in Windows

  1. Create an user in Docker hub(https://hub.docker.com/) – (Ignore if you already have )
  2. Download the docker for windows from (https://store.docker.com/editions/community/docker-ce-desktop-windows ) Make sure to download stable CE version.
  3. Install Docker .Do not select the checkbox for Windows Container. We will be running it in Linux Container. You should be able to see docker symbol in taskbar.
  4. Right click on the Docker in task bar and got to settings. Give the below specifications for starting Docker :

CPU : 2

Memory : 3584 MB for 8 GB RAM. If you have 16 GB , please allocate more than 6GB for docker . Also if you custom folder increases, 3584 MB might not suffice and you might need to increase it.

  1. It might ask you to restart your system to enable virtualization. If still it gives error, take it to ITS for enabling virtualization .If you see Docker is running then Bingo!!! You are ready to deploy your first application in Docker .If you get any error message related to memory, you need to cleanup by uninstalling some of the applications to make some space .

Install Hybris in Docker 

  • Copy the following files in the location where hybris is unzipped.
    1. Dockerfile
    2. .dockerignore
    3. mysql-connector-java-5.1.46.jar

            Dockerfile

 

FROM primetoninc/jdk:1.8


#Copy Hybris zip in container inside /src directory
COPY DockerHybris/hybris.zip /src/hybris.zip

# Navigate to /src directory
WORKDIR /src

# Unzip hybris.zip
RUN unzip hybris.zip

# navigate to the platform directory
WORKDIR /src/hybris/bin/platform/

# Add exec permission to .sh files
RUN find ./ -type f -iname "*.sh" -exec chmod +x {} \;

COPY DockerHybris/mysql-connector-java-5.1.46.jar lib/dbdriver/mysql-connector-java-5.1.46.jar

# Expose http port
EXPOSE 9001

# Expose https port
EXPOSE 9002

# Expose solr port
EXPOSE 8983
EXPOSE 2198

# Expose Debug port
EXPOSE 8000

# Run ant (also ant initialize if it's needed)
RUN . ./setantenv.sh && \
sleep 5 && \
echo develop | ant


# navigate to the directory
WORKDIR /src/hybris

#CACHE_DATE timestamp to take code change
ARG CACHE_DATE=2016-01-01
RUN echo "$CACHE_DATE"

# build-clean / build
ENV buildType build

# debug
ENV debug n

#initialize
ENV initialize n


#Add the custom code from host to container inside bin/custom
ADD hybris/bin/custom bin/custom

#Copy the local, localextensions , schema.xml and solrconfig.xml in container

COPY /hybris/config/local.properties config/local.properties
COPY /hybris/config/localextensions.xml config/localextensions.xml
COPY /hybris/config/solr/instances/default/configsets/default/conf/env/dev/schema.xml config/solr/instances/default/configsets/default/conf/schema.xml
COPY /hybris/config/solr/instances/default/configsets/default/conf/env/dev/solrconfig.xml config/solr/instances/default/configsets/default/conf/solrconfig.xml

# copy the wrapper script from host to container
COPY DockerHybris/wrapperScript.sh /src/wrapperScript.sh
WORKDIR /src/

# Run wrapper script
CMD ["sh", "-c", "./wrapperScript.sh ${buildType} ${debug} ${initialize}"]

     .dockerignore

This file will have the list of file and folder names that needs to be excluded from sending to the docker server as part of build context . It can change as per requirement .

# Items that don't need to be in a Docker image.
# Anything not used by the build system should go here.
installer?
licenses?
hybris-Mobile-Apps-SDK
hybris-ems
c4c-integration
build-tools
hybris/bin/ext*
hybris/bin/platform
hybris/config/languages
hybris/config/licence
hybris/config/solr/instances/default/configsets/backoffice
hybris/config/solr/instances/default/hsperfdata*
hybris/config/tcServer
hybris/config/tomcat
hybris/data
hybris/log
hybris/roles
hybris/temp
Dockerfile
README.md
README
.dockerignore

mysql-connector-java-5.1.46.jar – Download this jar and keep it inside the folder as specified.

  • Copy the DockerHybris folder inside the location where hybris is unzipped.
  • Copy the hybris zip inside the DockerHybris folder. Hybris zip is the original zip downloaded from Hybris. Rename the zip file as ‘hybris.zip’.
  • It should have the following files :
    • mysql-connector-java-5.1.46.jar – Jar for Hybris to connect to DB
    • start-hybris-container.bat – Batch file to start Hybris image in docker container
    • start-sql-container.bat – Batch file to start sql image in docker container
    • sh – script to build and start the hybris server
    • zip – complete hybris zip file .
  • Changes in local.properties:
#Solr Configuration. 

solrserver.instances.default.autostart=false

solrserver.instances.default.mode=standalone

solrserver.instances.default.hostname=localhost

solrserver.instances.default.port=8983

solrserver.instances.default.memory=1024m

solr.endpoint.url=http://localhost:8983/solr




mysql.optional.tabledefs=CHARSET=utf8 COLLATE=utf8_bin

## A type of MySQL database tables, for example InnoDB for transactional or MyISAM for non-transactional tables

mysql.tabletype=InnoDB

db.url=jdbc:mysql://hybris_sql/isahybris?useConfigs=maxPerformance&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true

db.driver=com.mysql.jdbc.Driver

db.username=admin

db.password=admin




#Disable Cron job in local

cronjob.timertask.loadonstartup=false






media.default.storage.strategy=localFileMediaStorageStrategy

media.default.hashing.depth=2

// Where media files are written. Instead of below location you can also use '/usr/var/media' or '\\hostname\shared_folder'

media.replication.dirs=/var/lib/media

media.read.dir=/var/lib/media

 

  • Navigate to DockerHybris folder and execute the below command :
    1. start-sql-container.bat (this is one timer to start the sql db server)
    2. start-hybris-container.bat {buildType}

buildType can be clean or build

example : start-hybris-container.bat clean

start-sql-container.bat

docker rm hybris_sql
docker run --name hybris_sql -v my-datavolume:/var/lib/mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=admin -e MYSQL_USER=admin -e MYSQL_DATABASE=isahybris -e MYSQL_PASSWORD=admin -d mysql:8.0

start-hybris-container.bat

Update the dockerId  in the script below . This script will start the Hybris docker container .

SET cur_dir=%~dp0
SET PSScript=%Temp%\~tmpRandom4Digit.ps1
IF EXIST "%PSScript%" DEL /Q /F "%PSScript%"

ECHO $fRandom = Get-Random -Maximum 9999 -Minimum 0000>>"%PSScript%"
ECHO $Random = "{0:0000}" -f $fRandom>>"%PSScript%"
ECHO ECHO $Random>>"%PSScript%"

SET PowerShellDir=C:\Windows\System32\WindowsPowerShell\v1.0 
CD /D "%PowerShellDir%" 
FOR /F "DELIMS=" %%A IN ('Powershell -ExecutionPolicy Bypass -Command "& '%PSScript%'"') DO SET "RAND=%%A"

echo %RAND%
cd %cur_dir%/..
cls

docker build -t {dockerId}/hybris-6.7:0.1.0 -f Dockerfile --build-arg CACHE_DATE=%RAND% .

if %errorlevel% neq 0 (
echo Oops !!!! There is an error .
cd %cur_dir%
exit /b
)

docker stop hybris_docker
docker rm hybris_docker
docker run --name hybris_docker -v media-volume:/var/lib/media --link hybris_sql:mysql -p 9002:9002 -p 9001:9001 -p 8983:8983 -p 8000:8000 -e buildType=%1 -e debug=y -e initialize=n {dockerId}/hybris-6.7:0.1.0


if %errorlevel% neq 0 (
echo Oops !!!! There is an error .
cd %cur_dir%
exit /b
)
cd %cur_dir%
  • Wait for few minutes till hybris starts up.
  • Initialize the system once started. And now you can see your application up.
  • If you want to stop the containers , you can invoke the following commands :
    • docker stop docker_hybris

 

Useful Docker Commands that you need to familiarize

  • docker ps : Show the running docker containers .
  • docker image ls : show the running images
  • docker rmi –f {image id} : remove the image forcefully
  • docker stop {container Id} : stop a container
  • docker rm {container Id} : Remove a container
  • docker exec –it {containerName} bash : Navigate inside a container

 

 

Word of Caution

Monitor the CPU, Memory and Disk from Task Manager as these vary from system to system . In order to get the best performance, try to minimize these numbers by not running too many application during the Initialization and server startup.

 

Faster performance for running Hybris in Windows system

              While analyzing I have come across some of the steps which can make the application faster even in 8 GB RAM .

  • Use Eclipse Photon in place of Oxygen. It is faster and consume less memory
  • Reducing Disk IO

Disk IO can reach 100% at times and can make the system slow during Initialization / Update or any DB operations .This can be controlled by the following process. This step is optional for you:

Step 1. Press Windows logo key + R at the same time, and type in services.msc.

Step 2. Locate Windows Search option, double-click it to enter its Properties window.

Step 3. Change the Startup type to Disabled. Then click Apply and OK to save your change.

  • Disable Cron Job

Add the below line in local properties to disable the cron job during restart

cronjob.timertask.loadonstartup=false

  • Use IE instead of Chrome (I know I am asking too much …..)
  • Try to close the eclipse during system initialization or update.

             

Observations with Docker Hybris

System specifications:

RAM : 8GB

Application Running: Skype /Outlook .

Closed Eclipse and Chrome.

Eclipse version use: Photon (~500MB RAM used during debugging)

 

Execution type In Windows In Docker with Windows
ant all  5-6 mins 2-3 mins
Ant clean all 6- 7 minutes 3-3.5 mins
Restart 14 -16 minutes 4-5 mins
Initialization 30 -45 minutes 30-45 mins

GitHub Link :

https://github.com/jokumar/DockerHybris

 

Digiprove sealCopyright secured by Digiprove © 2019 Geeks 18

Be the first to comment

Leave a Reply

Your email address will not be published.


*