diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..8630e46c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +/build +/jbake-dist/build +.gradle diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..4359ce50 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,36 @@ +FROM gradle:6.8-jdk11 as builder + +LABEL maintainer="https://jbake.org/community/team.html" + +ENV JBAKE_HOME=/opt/jbake + +RUN mkdir -p ${JBAKE_HOME} +COPY . /usr/src/jbake + +RUN set -o errexit -o nounset \ + && echo "Building JBake" \ + && cd /usr/src/jbake \ + && gradle --no-daemon installDist \ + && cp -r jbake-dist/build/install/jbake/* $JBAKE_HOME \ + && rm -r ~/.gradle /usr/src/jbake + +FROM adoptopenjdk/openjdk11:alpine-jre + +ENV JBAKE_USER=jbake +ENV JBAKE_HOME=/opt/jbake +ENV PATH ${JBAKE_HOME}/bin:$PATH + +RUN adduser -D -u 1000 -g "" ${JBAKE_USER} ${JBAKE_USER} + +USER ${JBAKE_USER} + +COPY --from=builder /opt/jbake /opt/jbake + +WORKDIR /mnt/site + +VOLUME ["/mnt/site"] + +ENTRYPOINT ["jbake"] +CMD ["-b"] + +EXPOSE 8820 diff --git a/README.asciidoc b/README.asciidoc index d16971b6..e0a6a992 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -54,6 +54,43 @@ Talk to other users of JBake on the forum: * http://groups.google.com/group/jbake-user[Forum] +== Docker Image + +The image uses the official https://hub.docker.com/r/adoptopenjdk/openjdk11/[adoptopenjdk/openjdk11:alpine] image +for building a distribution of JBake and +https://hub.docker.com/r/adoptopenjdk/openjdk11/[adoptopenjdk/openjdk11:alpine-jre] for runtime. + +=== Build + +To build the Docker image: + +---- +$ docker build -t jbake/jbake:latest . +---- + +=== Usage + +To execute JBake via Docker run this from project directory: + +---- +$ docker run --rm -u jbake -v "$PWD":/mnt/site jbake/jbake:latest +---- + +This command will execute using the jbake user to avoid running as root and will mount the current working directory as `/mnt/site` +in the Docker container where JBake is expecting your project files to be. By default the Docker image will execute a bake `-b` only. + +If you want to bake and serve your project using the Docker image then you'll need to override the default command: + +---- +$ docker run --rm -u jbake -v "$PWD":/mnt/site -p 8820:8820 jbake/jbake:latest -b -s +---- + +This command will also expose port 8820 from the container, you'll also need to set the following option in your `jbake.properties` file: + +---- +server.hostname=0.0.0.0 +---- + == Build System The project uses http://gradle.org[Gradle] 4.9+ as the build system.