Setting CI/CD for gitLab

Enonic version: 7.2.3
OS: Windows 10

I would like to set up CI/CD pipeline of my Enonic application for our team. I have read the following articles, but they didn’t give me the answer.

What I did:

  • I installed the Enonic CLI on my PC (windows 10) and I created Headless app
  • I’m able to build it and run on my own PC using Enonic CLI
  • Then I pushed the sources of the Enonic app to gitLab repo

The goal
Now I would like to set up the CI/CD of my Enonic project in gitLab, which will build the application, create a docker image and deploy the docker image to target environment (Ubuntu). Finally start the image in the target environment.

My idea is to use existing docker image enonic/enonic-ci for building my application. Then store the result of the build (jar file) as an artifact in gitLab. Finally use docker image enonic/xp-app as a base image for my application and copy the artifact (jar file) to folder enonic-xp/home/deploy. This docker image (with my application) I wanted to use in the target environment.
The question is would it work? Is there a better approach how to create docker image during pipeline? What is the best practice for creating Enonic application docker image during CI pipelien?

I tried to build my Enonic application as described above (see the log o fthe build below) but the jar file was not found. There is the log of gitLab pipeline and my gitlab-ci.yml below.

Please help me to set up the correct process of the CI pipeline, thank you in advance

Hi Pcermak!

I can at least tell you that you should normally not need to deploy a whole new docker image, as you only need to push an app to your running XP instance/cluster. You should instead aim to install the application using the CLI commands available inside the CI image. This means that the running XP instance needs to expose port 2609 (I think) to the CI server. Thats it.

Hi tsi,

thank you for your response. It means that the XP instance doesn’t run inside a docker container on the target environment? If so that is not what we want to achieve. We want to have our Enonic application dockerized similar to this example: Enonic docker getting start

Start by deploying XP as a docker image, based on this: https://hub.docker.com/r/enonic/xp.
The documentation you are linking to is old.

With XP running, you can simply deploy your XP apps to the docker instance without having to restart anyrhing. Are you planning to run a single server, or a cluster?

Thank you, I’ll try it. We would like to start simply with 1 single server and test how everything works. Later maybe cluster in Kubernetes…

FYI! A new and improved docker image will be released with XP 7.3 (due this month) together with updated documentation!

Hi tsi,

I would need some help again. It’s clear to me now, that I have to start the XP image first and deploy my app to it. I pulled the image: “docker pull enonic/xp” and I started it up by docker-compose: “docker-compose -f docker-compose-xp.yml up -d”. where the content of docker-compose-xp.yml is below. I took it from “https://github.com/enonic/docker-xp7” and updated.

version: “2”
services:
exp:
image: enonic/xp:latest
ports:
- “1099:1099”
- “2609:2609”
- “3000:3000” # Profiling test
- “3001:3001” # Profiling test
- “4848:4848”
- “5005:5005” # Remote debugging test
- “8080:8080”
environment:
TAKE_FILE_OWNERSHIP: 0
JAVA_OPTS: “-XX:+CMSParallelRemarkEnabled -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=60 -XX:+ScavengeBeforeFullGC -XX:+CMSScavengeBeforeRemark -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=3000 -Dcom.sun.management.jmxremote.rmi.port=3001 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=127.0.0.1 -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=*:5005”
SU_PASS_HASH: “5b722b307fce6c944905d132691d5e4a2214b7fe92b738920eb3fce3a90420a19511c3010a0e7712b054daef5b57bad59ecbd93b3280f210578f547f4aed4d25”
volumes:
- repo_index:/enonic-xp/home/repo/index
- repo_blob:/enonic-xp/home/repo/blob
- snapshots:/enonic-xp/home/snapshots
- work:/enonic-xp/home/work
#- ./mounts/data:/enonic-xp/home/data
- ./mounts/config:/enonic-xp/home/config:ro
user: “1000”
labels:
io.enonic.backup.prescripts: “/usr/local/bin/backup.sh”
volumes:
repo_index:
labels:
io.enonic.backup.data: “true”
repo_blob:
labels:
io.enonic.backup.data: “true”
snapshots:
labels:
io.enonic.backup.data: “true”
work:

When the XP container starts the XP fails with this error:

07:21:31.439 INFO c.e.x.l.i.framework.FrameworkService - Starting Enonic XP…
ERROR: Unable to create cache directory: /enonic-xp/home/work/osgi/cache
ERROR: Error creating bundle cache.
java.lang.RuntimeException: Unable to create cache directory.
at org.apache.felix.framework.cache.BundleCache.(BundleCache.java:135)
at org.apache.felix.framework.Felix.init(Felix.java:703)
at org.apache.felix.framework.Felix.init(Felix.java:641)
at com.enonic.xp.launcher.impl.framework.FrameworkService.doStart(FrameworkService.java:147)
at com.enonic.xp.launcher.impl.framework.FrameworkService.start(FrameworkService.java:122)
at com.enonic.xp.launcher.impl.LauncherImpl.start(LauncherImpl.java:109)
at com.enonic.xp.launcher.LauncherMain.launchConsole(LauncherMain.java:34)
at com.enonic.xp.launcher.LauncherMain.launch(LauncherMain.java:24)
at com.enonic.xp.launcher.LauncherMain.main(LauncherMain.java:49)
07:21:31.673 ERROR c.e.x.l.i.framework.FrameworkService - Error creating bundle cache.
org.osgi.framework.BundleException: Error creating bundle cache.
at org.apache.felix.framework.Felix.init(Felix.java:708)
at org.apache.felix.framework.Felix.init(Felix.java:641)
at com.enonic.xp.launcher.impl.framework.FrameworkService.doStart(FrameworkService.java:147)
at com.enonic.xp.launcher.impl.framework.FrameworkService.start(FrameworkService.java:122)
at com.enonic.xp.launcher.impl.LauncherImpl.start(LauncherImpl.java:109)
at com.enonic.xp.launcher.LauncherMain.launchConsole(LauncherMain.java:34)
at com.enonic.xp.launcher.LauncherMain.launch(LauncherMain.java:24)
at com.enonic.xp.launcher.LauncherMain.main(LauncherMain.java:49)
Caused by: java.lang.RuntimeException: Unable to create cache directory.
at org.apache.felix.framework.cache.BundleCache.(BundleCache.java:135)
at org.apache.felix.framework.Felix.init(Felix.java:703)
… 7 common frames omitted

What am I doing wrong?

For now you can use this: [email protected]:enonic-cloud/docker-compose3-enonic-xp.git with any version below 7.3, I think it should just work out of the box.

But as TSI mentions, a better Dockerfile is arriving very soon which is compatible with most container solutions unlike our current one.

I have a public resource to share with you.
These are the images we use here at my company:
https://hub.docker.com/r/leanon/enonic-xp/tags

For example, we use this one for development:
https://hub.docker.com/layers/leanon/enonic-xp/7.2.3/images/sha256-2522f5119894dd35946d20ea276f730eccdfc8c23b0a1f4a994cc9f77c6bd9aa?context=explore

And here’s the .gitlab-ci.yml (we use three enonic instances with CI/CD: review, staging and master)
https://codeshare.io/G7mdyo

Here’s my local/dev docker structure:
local_docker_dev

And the Makefile to speed up the things

1 Like

Hello ff9will,

thank you for sharing the gitlab-ci file it’s very useful. Unfortunately I have problem to start the xp container. I tried the official xp from enonic as well as your leanon/enonic-xp. there is always an error when it starts. Can you please help me with starting the xp image - maybe share the docker-compose file for starting it? I used the docker-compose which I published above in this topic and several modification but always with the same result. :-(. thanks

@pcermak
I just saw that you’re using the version “2” of docker-compose config.
Try updating you docker configuration to version 3 or newer.

Here’s my docker version:
docker_version

And here’s one of my docker-compose.yml files:
https://codeshare.io/GbOdY7

Other details

My local/dev docker structure:
local_docker_dev

My Dockerfile
dockerfile

My launcher.sh

If you need any of those files above, I can share them with you. But I don’t think they will be actually useful since you’re using the Windows version of docker.

1 Like

Hi, I finally started up the enonic XP container :-). You were right I used older docker, so firstly I updated the docker. Then I started with this project https://github.com/enonic/docker-xp7 and I built it. I had to add these commends before ENTRYPOINT in the Dockerfile, otherwise the script docker-entrypoint.sh failed when the container starts.
RUN \
chmod +x /usr/local/bin/docker-entrypoint.sh && \
sed -i -e 's/\r$//' /usr/local/bin/docker-entrypoint.sh

(The reason probably was that I cloned the project to windows and there remain the ‘/r/n’ EOF)

Then I slightly change the docker-compose.yml

Then I run docker-compose and XP started up fine :-).
I tried to install my application to the XP container from local machine by using command:
enonic project install
It works as well and the application was deployed. So now I have to set the CI/CD pipeline in gtlab

1 Like