Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Hybris With Docker for Development in Windows Machine

DZone's Guide to

Hybris With Docker for Development in Windows Machine

This tutorial will show you how you can install Hybris using Docker for virutualization and persistence on a Windows machine.

· Cloud Zone ·
Free Resource

Site24x7 - Full stack It Infrastructure Monitoring from the cloud. Sign up for free trial.

Overview

This document covers the setup of Hybris in Docker for Windows. In general, the Hybris build and server startup in a Windows machine takes close to an hour in 16GB RAM. With the increase in extensions, the time varies further. This affects the local development a considerable time. This solution will help in building and starting of the application faster and more performant in Windows. As per the 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.

Please note this document helps in setting up the standard Hybris environment. If you already have an existing Hybris project running, this document can help you migrate to Docker container with subtle changes. All the steps might not work in existing projects and might need Docker knowledge to do the subtle changes.

Install Docker in Windows

  1. Create a user in Docker hub  – (Ignore if you already have )
  2. Download Docker for 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 the taskbar.
  4. Right click on the Docker in the taskbar 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 it still gives an error, take it to your IT support team for enabling virtualization.If you see Docker is running then great! You are ready to deploy your first application in Docker. If you get any error message related to memory, you need to clean up 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

2

  • Download the Hybris zip from the SAP website and unzip it in a location in your machine.
  • Now Copy the DockerHybris folder inside the location where Hybris is unzipped. You can find the folder in the following link : https://github.com/jokumar/DockerHybris
  • 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 :
    1. mysql-connector-java-5.1.46.jar — Jar for Hybris to connect to DB
    2. start-hybris-container.bat — Batch file to start Hybris image in Docker container
    3. start-sql-container.bat — Batch file to start the SQL image in Docker container
    4. wrapperScript.sh — script to build and start the Hybris server
    5. hybris.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
  • Change Docker ID in start-hybris-server.bat. Search for "joy1987" and replace it with your Docker ID.
    1. 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)
      3. example : start-hybris-container.bat clean  
  • Wait for few minutes until 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

Working Jrebel with Docker

  • Jrebel is a development plugin for faster development which helps in developing without a server restart. It has support with Hybris. I am not covering how to setup Jrebel for Hybris as it is already covered in Jrebel documentation.

In this document, I am listing down the steps to set up the Jrebel with Hybris. In the Docker file, add the following line after this step :  RUN unzip hybris.zip 

Changes in Dockerfile:

$   RUN wget -O jrebel.zip http://dl.zeroturnaround.com/jrebel-stable-nosetup.zip && \
               unzip jrebel.zip && \
               mv jrebel /opt/jrebel && \
               rm jrebel.zip


In local property do the following change depending on debugging or normal server startup: Changes in local.properties:


$    #jrebel
        #tomcat.javaoptions=-agentpath:/opt/jrebel/lib/libjrebel64.so -Drebel.remoting_plugin=true
        tomcat.debugjavaoptions =-agentpath:/opt/jrebel/lib/libjrebel64.so -Drebel.remoting_plugin=true -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=n


  • Once you have successfully configured JRebel in Docker and container has started, you should see the following banner during Hybris server startup:
    $   JRebel:  #####################################################
    JRebel:
    JRebel:  JRebel Legacy Agent 7.0.6
    JRebel:  (c) Copyright ZeroTurnaround AS, Estonia, Tartu.
    JRebel:
    JRebel:  Over the last 1 days JRebel prevented
    JRebel:  at least 1 redeploys/restarts saving you
    JRebel:  about 0 hours.
    JRebel:
    JRebel:  Server is running with JRebel remote server support.
    JRebel:
    JRebel:  #####################################################
    - Open Help > JRebel > Configuration. Select the Remote servers tab. You will be presented with the following view:

6

  • Test the connection by providing the Hybris server URL :

7

  • Now make sure to generate all the remote XML for custom projects.

8

  • Make sure to build the Docker image again so as to copy all the custom files to the container. Without the remote XML, the container will not update the projects.
  • Make a change in your file and it will reflect in the container immediately without the server restart.

Useful Docker Commands That You Need to Familiarize Yourself With

  •  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
  • Delete Untagged images:  docker images | ConvertFrom-String | where {$.P2 -eq " "} | % { docker rmi $.P3 }  

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 applications 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 consumes 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.

 

3


4


5

  • 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 it is tough to do )
    • 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)

Please Note:

  • Symbolic Link will not work . You should have the original custom folder inside hybris.
  •  -force option  is not working with Hybris 6.1 for starting solr. use  -force  for Hybris 6.7. Use " ./solr start -p 8983 " instead of " ./solr start -force -p 8983 " for Hybris 6.1 in  wrapperScript.sh  (line #6)

All the Best !!

Site24x7 - Full stack It Infrastructure Monitoring from the cloud. Sign up for free trial.

Topics:
hybris ,docker ,windows ,tutorial ,installation

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}