SLING-9638 - Update Starter Docker image to be based on the feature model
Add a basic docker image + documentation.
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..2c2b22c
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,44 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+FROM docker.io/openjdk:17-slim
+
+LABEL org.opencontainers.image.authors="dev@sling.apache.org"
+
+EXPOSE 8080
+
+RUN mkdir -p /opt/sling/artifacts
+COPY src/main/container /opt/sling
+COPY target/dependency/org.apache.sling.feature.launcher.jar /opt/sling
+COPY target/artifacts/ /opt/sling/artifacts/
+
+RUN groupadd -r sling && \
+ useradd --no-log-init -r -g sling sling && \
+ mkdir /opt/sling/launcher && \
+ chown sling:sling /opt/sling/launcher
+
+# ensure all files are readable by the sling user
+# for some reason some jar files are 0600 and others are 0644
+RUN find /opt/sling/artifacts -type f | xargs chmod 0644
+
+VOLUME /opt/sling/launcher
+
+USER sling:sling
+
+WORKDIR /opt/sling
+ENTRYPOINT [ "/opt/sling/bin/launch.sh" ]
+CMD ["oak_tar"]
diff --git a/README.md b/README.md
index bf7ccb5..24b6570 100644
--- a/README.md
+++ b/README.md
@@ -56,6 +56,30 @@
Your own feature files can be added to the feature list.
+## Docker image
+
+This module can optionally build a Docker image. This is achieved by running a build with the `-Ddocker.skip=false` argument. By default, the image is built as `apache/sling:snapshot`. The tag can be overrriden using the `docker.label` Maven property.
+
+```
+$ mvn clean package -Ddocker.skip=false -Ddocker.label=local
+$ docker run --rm -p 8080 apache/sling:local
+```
+
+By default the iamge launches the `oak_tar` aggregate. The aggregate to launch can be selected by passing an additional argument to the image, e.g.:
+
+```
+$ docker run --rm -p 8080 apache/sling:snapshot oak_mongo
+```
+
+Currently only the `oak_tar` and `oak_mongo` aggregates are supported.
+
+For persisting the runtime data is is recommended to mount `/opt/sling/launcher` as a volume, for instance:
+
+```
+$ docker volume create sling-launcher
+$ docker run --rm -p 8080 -v sling-launcher:/opt/sling/launcher apache/sling:snapshot
+```
+
## Helper scripts
The `scripts` directory contains helper scripts that will aid with local development by simplifying the use of tools external to the Sling Starter.
diff --git a/pom.xml b/pom.xml
index b233a2a..7f50ffe 100644
--- a/pom.xml
+++ b/pom.xml
@@ -51,6 +51,7 @@
<!-- skip index generation for all builds except for CI and release -->
<bnd.index.generation.skip>true</bnd.index.generation.skip>
<docker.skip>true</docker.skip>
+ <docker.label>snapshot</docker.label>
<mongo.container.image>mongo:4.4.6</mongo.container.image>
<it.startTimeoutSeconds>60</it.startTimeoutSeconds>
<!-- used for reproducible builds (https://maven.apache.org/guides/mini/guide-reproducible-builds.htm), automatically updated during release -->
@@ -121,7 +122,14 @@
<classifier>oak_mongo_far</classifier>
<includeClassifier>oak_mongo</includeClassifier>
</archive>
- </archives>
+ </archives>
+ <repositories>
+ <repository>
+ <includeClassifier>oak_tar</includeClassifier>
+ <includeClassifier>oak_mongo</includeClassifier>
+ <includeClassifier>docker</includeClassifier>
+ </repository>
+ </repositories>
</configuration>
<executions>
<execution>
@@ -134,6 +142,13 @@
<goal>attach-featurearchives</goal>
</goals>
</execution>
+ <execution>
+ <id>create-repository</id>
+ <phase>package</phase>
+ <goals>
+ <goal>repository</goal>
+ </goals>
+ </execution>
</executions>
</plugin>
<plugin>
@@ -234,6 +249,13 @@
</wait>
</run>
</image>
+ <image>
+ <name>apache/sling:${docker.label}</name>
+ <build>
+ <dockerFile>Dockerfile</dockerFile>
+ <contextDir>${project.basedir}</contextDir>
+ </build>
+ </image>
</images>
<stopMode>kill</stopMode>
</configuration>
@@ -254,6 +276,13 @@
<goal>stop</goal>
</goals>
</execution>
+ <execution>
+ <id>build-docker-image</id>
+ <phase>package</phase>
+ <goals>
+ <goal>build</goal>
+ </goals>
+ </execution>
</executions>
</plugin>
<!-- launch the Sling instances to test -->
diff --git a/src/main/container/bin/launch.sh b/src/main/container/bin/launch.sh
new file mode 100755
index 0000000..826d763
--- /dev/null
+++ b/src/main/container/bin/launch.sh
@@ -0,0 +1,39 @@
+#!/bin/bash -e
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+
+feature_name="${1}"
+feature=$(find artifacts -name "*${feature_name}*.slingosgifeature")
+
+if [[ ! -f "${feature}" ]]; then
+ echo "[ERROR] Did not find any feature file matching name ${feature_name}. Aborting"
+ exit 1
+fi
+
+docker_feature=$(find artifacts -name "*docker.slingosgifeature")
+
+echo "[INFO] Selected ${feature} for launching"
+echo "[INFO] Automatically appended ${docker_feature}"
+
+feature="${feature},${docker_feature}"
+
+exec java -jar org.apache.sling.feature.launcher.jar \
+ -c artifacts \
+ -CC "org.apache.sling.commons.log.LogManager=MERGE_LATEST" \
+ -f ${feature}
\ No newline at end of file
diff --git a/src/main/features/docker/docker.json b/src/main/features/docker/docker.json
new file mode 100644
index 0000000..4fc79c0
--- /dev/null
+++ b/src/main/features/docker/docker.json
@@ -0,0 +1,7 @@
+{
+ "configurations":{
+ "org.apache.sling.commons.log.LogManager":{
+ "org.apache.sling.commons.log.file":""
+ }
+ }
+}
\ No newline at end of file