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
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.
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?
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.
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
For now you can use this: git@github.com: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.
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
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.
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 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