cancel
Showing results for 
Search instead for 
Did you mean: 

Improving Docker image for Alfresco Community repository

mikel_asla
Star Contributor
Star Contributor

Exciting days for Docker fans, Alfresco Community Edition 201804 EA is the first community release available as Docker images. Don't panic if you don't feel this excitement, you can still produce the traditional distribution ZIP file thanks to the acs-community-packaging project. If you don't even want to use maven, you can download the binary from artifacts.alfresco.com.

On top of that, Alfresco is focusing now on a new deployment paradigm with Kubernetes and Helm charts. This great technologies are out of the scope of this text, my goal on this post is to share some test I've done with the alfresco-content-repository-community image only from the docker perspective.

 When I first tried the Docker Compose and Kubernetes + Helm solutions on the acs-community-deployment project, I  was surprised about the size of the alfresco-content-repository-community Docker image, is 1,9 Gb when you download it, compressed size on the Dockerhub image registry is about 710MB. Enterprise is quite different here, on the host is 768MB and compressed on Dockerhub is about 405MB. So i decided to make some tests to see if I could make it smaller.

The result of the tests looks pretty cool, smaller container for the Community (6.0.5-ea) than Alfresco has published for Enterprise (6.0.0-RC4). The deployed image is 446MB and the compressed size on registry 393MB. That's 1,5 Gb less than the current published community image.

First I wanted to understand better the difference between both Community vs Enterprise repository image size.

The main difference is that the Community version of the image has libreoffice, imagemagick and alfresco-pdf-renderer command line tools installed along with the repository war (on top of tomcat + java). The enterprise is using another approach, they have built some docker images for each libreoffice, imagemagick and alfresco-pdf-renderer as microservices (spring-boot apps) wrapping this command line tools. This means now Alfresco supports this new properties to connect to external applications as remote services.

alfresco-pdf-renderer.url=http://alfresco-pdf-renderer:8090/
jodconverter.url=http://libreoffice:8090/
img.url=http://imagemagick:8090/‍‍‍‍‍‍‍‍‍

So the first try was to test if the 201804EA release was accepting this new properties or was only a Enterprise only feature. I don't know what's going to happen on next GA, but by now both work the same.

Secondly, I wanted to make use of the multi-stage building feature present in Docker since version 17.05. I used once on a project to produce tiny images for production and the results were awesome. 

The idea of docker multi-stage building is very simple, Dockerfile API supports multiple FROM statements on the same Dockerfile. Each chunk between FROM statements is called a build stage and we can copy stuff from one another as needed. The image you build is only the last chunk, the previous ones are thrown away (intermediate build stages). As simple as good. Instead of doing complicate commands or spent hours finding the bits you can remove and so on, we can do something like this

Without multi-state building

FROM somebase
RUN apt-update && apt-install <a lot of dev libs> 
RUN <build your application artifact>
RUN <remove a lot of things>‍‍‍‍‍‍‍‍‍‍‍‍

Multi-state building

FROM somebase as builder
RUN apt-update && apt-install <a lot of dev libs>
RUN <build your application artifact>

FROM tomcat:7-jre8
COPY --from=builder <path/to/artifact> <path/to/webapps>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

The results are more small and simple to maintain. On this particular example, the final size of the image is the size of tomcat:7-jre8 image plus the size of the artifact, nothing more. And we didn't spent time optimizing the image, as we have delegated that to the oficial base image we're using on the last stage. That's what official base image are for.

This is the resulting Dockerfile

FROM debian:stretch as dist

LABEL maintainer "mikel.asla@keensoft.es"
LABEL version "201804-EA-alpine"
LABEL description "This is alfresco-docker-template version 201804-EA dist stage"

ENV ALF_ARTIFACT_ID=alfresco-content-services-community-distribution \
ALF_VERSION=6.0.5-ea \
ALF_DOWNLOAD_URL=https://artifacts.alfresco.com/nexus/service/local/repositories/releases/content/org/alfresco

RUN set -x \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
unzip \
wget \
\
&& mkdir -p /tmp/alfresco \
&& wget --no-check-certificate
    $ALF_DOWNLOAD_URL/$ALF_ARTIFACT_ID/$ALF_VERSION/$ALF_ARTIFACT_ID-$ALF_VERSION.zip \
&& unzip $ALF_ARTIFACT_ID-$ALF_VERSION.zip -d /tmp/alfresco

FROM openjdk:8-jre as amps_install

LABEL maintainer "mikel.asla@keensoft.es"
LABEL version "201804-EA-alpine"
LABEL description "This is alfresco-docker-template version 201804-EA amps_install stage"

ENV DIST /tmp/alfresco/alfresco-content-services-community-distribution-6.0.5-ea

WORKDIR /tmp

COPY --from=dist $DIST/bin/alfresco-mmt.jar alfresco-mmt.jar
COPY --from=dist $DIST/web-server/webapps/alfresco.war alfresco.war
COPY --from=dist $DIST/amps/alfresco-share-services.amp alfresco-share-services.amp

RUN set -x \
&& java -jar alfresco-mmt.jar install alfresco-share-services.amp alfresco.war -nobackup

FROM tomcat:7-jre8-alpine

LABEL maintainer "mikel.asla@keensoft.es"
LABEL version "201804-EA-alpine"
LABEL description "This is alfresco-docker-template version 201804-EA final stage"

ENV DIST /tmp/alfresco/alfresco-content-services-community-distribution-6.0.5-ea

COPY --from=dist $DIST/web-server/lib/postgresql-42.2.1.jar /usr/local/tomcat/lib/postgresql-42.2.1.jar
COPY --from=dist $DIST/web-server/webapps/ROOT.war /usr/local/tomcat/webapps/ROOT.war
COPY --from=amps_install /tmp/alfresco.war /usr/local/tomcat/webapps/alfresco.war

RUN set -x \
&& cd webapps \
&& rm -rf ROOT manager docs examples host-manager \
&& mkdir alfresco ROOT \
&& unzip alfresco.war -d alfresco \
&& unzip ROOT.war -d ROOT \
&& rm -rf *.war
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

You can find this Dockerfile along with a docker-compose.yml file to test it inside our alfresco-docker-templates project. Just enter the 201804-EA__alpine folder and type

docker-compose up‍‍‍

After everything is deployed check your local images to see the following awesome line

$ docker images

REPOSITORY            TAG        IMAGE ID          CREATED        SIZE
201804ea_alfresco    latest    2869666c6237      10 minutes ago     446MB‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Alfresco Community also worths quality docker images. Let's see what happens on next GA release, stay tuned!

0 REPLIES 0