Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/docker_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,9 @@ jobs:
run: |
cd docker
make -e TARGET=kaui -e VERSION=$KAUI_VERSION rebuild
- name: Build kaui image (self-contained cloudsmith template)
run: |
cd docker/templates/kaui
sed -e "s/__VERSION__/$KAUI_VERSION/" cloudsmith/Dockerfile.template > cloudsmith/Dockerfile
sed -e "s/__VERSION__/$KAUI_VERSION/" tagged/kpm.yml.template > tagged/kpm.yml
docker buildx build --load --no-cache --target final -f cloudsmith/Dockerfile --build-arg KILLBILL_CLOUD_REF=$BRANCH_NAME -t killbill/kaui-cloudsmith:$KAUI_VERSION .
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ ansible/hosts
ansible-container/ansible-deployment
docker/templates/kaui/latest/Dockerfile
docker/templates/kaui/tagged/Dockerfile
docker/templates/kaui/tagged/kpm.yml
docker/templates/kaui/cloudsmith/Dockerfile
docker/templates/killbill/latest/Dockerfile
docker/templates/killbill/tagged/Dockerfile
docker/templates/killbill/tagged/kpm.yml
Expand Down
18 changes: 18 additions & 0 deletions docker/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ toc::[]
* `killbill/kaui:latest`: Empty base Kaui image. It runs `kpm install` on startup. If no custom `kpm.yml` file is specified, the latest version of Kaui is downloaded.
* `killbill/kaui:0.X.Y`: Image with a specific version of Kaui installed.
* `killbill/killbill:build`: Official build environment for all published Kill Bill artifacts (useful for developers).
* `docker.cloudsmith.io/killbill/docker/kaui:X.Y.Z`: Image with a specific version of Kaui 5.x installed, built on JDK 21 / Tomcat 11 and published to the private Cloudsmith Docker repository. See <<build-kaui-cloudsmith,Build a Kaui image for Cloudsmith>>.

[[tips-and-tricks]]
### Tips and tricks
Expand Down Expand Up @@ -145,6 +146,23 @@ docker push killbill/$TARGET:$VERSION
docker logout
....

[[build-kaui-cloudsmith]]
### Build a Kaui image for Cloudsmith

Kaui images for Cloudsmith are built from a single, self-contained multi-stage template (`templates/kaui/cloudsmith/Dockerfile.template`), on top of the JDK 21 / Tomcat 11 base. No intermediate `killbill/base` or `killbill/kaui:latest` image is needed. Kaui itself is downloaded from Maven Central at build time. Only Kaui 5.x is supported: Kaui 4.x uses `javax.servlet` and does not deploy on Tomcat 11.

....
cd docker/templates/kaui
export VERSION=5.0.4
sed -e "s/__VERSION__/$VERSION/" cloudsmith/Dockerfile.template > cloudsmith/Dockerfile
sed -e "s/__VERSION__/$VERSION/" tagged/kpm.yml.template > tagged/kpm.yml
docker buildx build --target final -f cloudsmith/Dockerfile \
--build-arg KILLBILL_CLOUD_REF=master \
-t docker.cloudsmith.io/killbill/docker/kaui:$VERSION .
....

`KILLBILL_CLOUD_REF` is the killbill-cloud branch, tag or commit the Ansible roles are fetched from.

### Custom ansible playboook

```
Expand Down
191 changes: 191 additions & 0 deletions docker/templates/kaui/cloudsmith/Dockerfile.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
# Self-contained multi-stage Dockerfile for pinned Kaui 5.x images built on JDK 21 / Tomcat 11 (Jakarta). It is
# the Kaui counterpart of docker/templates/killbill/cloudsmith/Dockerfile.template and is meant to be pushed to the
# private Cloudsmith Docker repository (docker.cloudsmith.io/killbill/docker/kaui) rather than Docker Hub.
#
# Why this exists?
# - killbill/kaui:<version> on Docker Hub is built FROM killbill/kaui:latest, itself built FROM killbill/base:latest.
# Those public images are no longer refreshed, so tagged images built on top of them would silently ignore the
# JDK 21 / Tomcat 11 base used by master.
# - Avoid publishing intermediate `killbill/base:*` and `killbill/kaui:latest` images just to have parent images.
# docker buildx's multi-stage build (FROM ... AS <stage>) keeps that intermediate state private, with a single
# `docker buildx build` invocation.
# - Unlike Kill Bill, Kaui is published to Maven Central, so no BuildKit secret is needed.
# - Kaui 4.x is NOT supported by this template: it still uses the `javax.servlet` API and fails to deploy on Tomcat 11
# (`NoClassDefFoundError: javax/servlet/ServletContextListener`). Use the tagged template on the Tomcat 9 line for 4.x.
#
# This intentionally duplicates the *Dockerfile instructions* normally split across:
# docker/templates/base/latest/Dockerfile (stage: base)
# docker/templates/kaui/latest/Dockerfile.template (stage: shell)
# docker/templates/kaui/tagged/Dockerfile.template (stage: final)
#
# Build context is docker/templates/kaui/. __VERSION__ in this file and in tagged/kpm.yml.template must be substituted
# before the build (same as docker/dockerTemplate.sh does for the tagged/ template), e.g.:
# cd docker/templates/kaui
# sed -e "s/__VERSION__/5.0.4/" cloudsmith/Dockerfile.template > cloudsmith/Dockerfile
# sed -e "s/__VERSION__/5.0.4/" tagged/kpm.yml.template > tagged/kpm.yml
# docker buildx build --target final -f cloudsmith/Dockerfile --build-arg KILLBILL_CLOUD_REF=master -t kaui:5.0.4 .

# ---------------------------------------------------------------------------
# Stage: base (mirrors docker/templates/base/latest/Dockerfile)
# ---------------------------------------------------------------------------
FROM ubuntu:24.04 AS builder-base
LABEL maintainer="killbilling-users@googlegroups.com"

USER root

ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
ENV PYTHONIOENCODING=utf8

ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install --no-install-recommends -y \
ansible \
apt-utils \
curl \
gettext-base \
git \
less \
libapr1 \
mysql-client \
net-tools \
openjdk-21-jdk-headless \
python3-lxml \
sudo \
unzip \
vim && \
rm -rf /var/lib/apt/lists/*

# Configure default JAVA_HOME path
RUN ln -s java-21-openjdk-$(dpkg --print-architecture) /usr/lib/jvm/default-java
ENV JAVA_HOME=/usr/lib/jvm/default-java
ENV JSSE_HOME=$JAVA_HOME/jre/

ENV TOMCAT_OWNER=tomcat
ENV TOMCAT_GROUP=tomcat
ENV TOMCAT_HOME=/var/lib/tomcat
RUN adduser $TOMCAT_OWNER \
--home $TOMCAT_HOME \
--disabled-password \
--gecos '' && \
usermod -aG sudo $TOMCAT_GROUP && \
echo "$TOMCAT_OWNER:$TOMCAT_OWNER" | chpasswd && \
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

USER $TOMCAT_OWNER
WORKDIR $TOMCAT_HOME

# Install ansible roles dependencies.
# KILLBILL_CLOUD_REF is a git ref (branch/tag/SHA) of the killbill-cloud repository, used by
# ansible-galaxy below to fetch the ansible roles that install Tomcat/Java/KPM. This Dockerfile
# has no opinion on which ref that should be - the caller (e.g. the Kaui release workflow)
# decides that.
ARG KILLBILL_CLOUD_REF
RUN ansible-galaxy collection install community.general && \
ansible-galaxy install git+https://git@github.com/killbill/killbill-cloud.git,$KILLBILL_CLOUD_REF
ENV KILLBILL_CLOUD_ANSIBLE_ROLES=$TOMCAT_HOME/.ansible/roles/killbill-cloud/ansible
ENV ENV_HOST_IP=localhost
ENV ANSIBLE_OPTS="-i localhost, \
-e ansible_connection=local \
-e ansible_python_interpreter=/usr/bin/python3 \
-e java_home=$JAVA_HOME \
-vv"

# Install KPM
ENV NEXUS_URL=https://repo1.maven.org
ARG NEXUS_REPOSITORY
ENV NEXUS_REPOSITORY=${NEXUS_REPOSITORY:-maven2}
ENV KPM_INSTALL_DIR=/opt
RUN ansible-playbook $ANSIBLE_OPTS \
-e kpm_install_dir=$KPM_INSTALL_DIR \
-e kpm_path=$KPM_INSTALL_DIR/kpm-latest \
-e kpm_owner=$TOMCAT_OWNER \
-e kpm_group=$TOMCAT_GROUP \
-e nexus_url=$NEXUS_URL \
-e nexus_repository=$NEXUS_REPOSITORY \
$KILLBILL_CLOUD_ANSIBLE_ROLES/kpm.yml
ENV PATH="/opt/kpm-latest:${PATH}"

# Install Tomcat (without native libraries)
ENV CATALINA_BASE=$TOMCAT_HOME
ENV CATALINA_HOME=/usr/share/tomcat
ENV CATALINA_PID=$CATALINA_BASE/tomcat.pid
ENV CATALINA_TMPDIR=/var/tmp
ENV TOMCAT_INSTALL_DIR=/opt
ENV TOMCAT_NATIVE_LIBDIR=$CATALINA_HOME/native-jni-lib
ENV LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$TOMCAT_NATIVE_LIBDIR
RUN ansible-playbook $ANSIBLE_OPTS \
-e tomcat_install_dir=$TOMCAT_INSTALL_DIR \
-e tomcat_native_libdir=$TOMCAT_NATIVE_LIBDIR \
-e tomcat_owner=$TOMCAT_OWNER \
-e tomcat_group=$TOMCAT_GROUP \
-e tomcat_home=$TOMCAT_HOME \
-e catalina_home=$CATALINA_HOME \
-e catalina_base=$CATALINA_BASE \
--skip-tags native \
$KILLBILL_CLOUD_ANSIBLE_ROLES/tomcat.yml

# Build Tomcat native libraries
FROM builder-base AS builder-tomcat
USER $TOMCAT_OWNER
RUN ansible-playbook $ANSIBLE_OPTS \
-e tomcat_install_dir=$TOMCAT_INSTALL_DIR \
-e tomcat_native_libdir=$TOMCAT_NATIVE_LIBDIR \
-e tomcat_owner=$TOMCAT_OWNER \
-e tomcat_group=$TOMCAT_GROUP \
-e tomcat_home=$TOMCAT_HOME \
-e catalina_home=$CATALINA_HOME \
-e catalina_base=$CATALINA_BASE \
-t native \
$KILLBILL_CLOUD_ANSIBLE_ROLES/tomcat.yml

FROM builder-base AS base
COPY --from=builder-tomcat /usr/share/tomcat/native-jni-lib /usr/share/tomcat/native-jni-lib

# ---------------------------------------------------------------------------
# Stage: shell (mirrors docker/templates/kaui/latest/Dockerfile.template)
# ---------------------------------------------------------------------------
FROM base AS shell
LABEL maintainer="killbilling-users@googlegroups.com"

ENV KAUI_INSTALL_DIR=/var/lib/kaui

RUN sudo mkdir -p $KAUI_INSTALL_DIR $KAUI_INSTALL_DIR/bundles
RUN sudo chown -R $TOMCAT_OWNER:$TOMCAT_GROUP $KAUI_INSTALL_DIR

COPY ./latest/setenv2.sh $CATALINA_BASE/bin

ENV KPM_INSTALL_CMD="ansible-playbook $ANSIBLE_OPTS \
-e kpm_install_dir=$KPM_INSTALL_DIR \
-e kpm_path=$KPM_INSTALL_DIR/kpm-latest \
-e kpm_yml=$KAUI_INSTALL_DIR/kpm.yml \
-e kaui_kpm_yml=$KAUI_INSTALL_DIR/kpm.yml \
-e tomcat_owner=$TOMCAT_OWNER \
-e tomcat_group=$TOMCAT_GROUP \
-e catalina_base=$CATALINA_BASE \
$KILLBILL_CLOUD_ANSIBLE_ROLES/kaui.yml"

# Install Logstash dependencies
ENV LOGSTASH_ENABLED=true
RUN ansible-playbook $ANSIBLE_OPTS $KILLBILL_CLOUD_ANSIBLE_ROLES/kaui_json_logging.yml --tags download

# ---------------------------------------------------------------------------
# Stage: final (mirrors docker/templates/kaui/tagged/Dockerfile.template)
# ---------------------------------------------------------------------------
FROM shell AS final
LABEL maintainer="killbilling-users@googlegroups.com"

ENV KAUI_VERSION=__VERSION__

# Pinned kpm.yml (version baked in, not resolved at runtime like the "latest" shell image), generated from
# tagged/kpm.yml.template by substituting __VERSION__.
COPY ./tagged/kpm.yml $KAUI_INSTALL_DIR

# Install Kaui at build time. Run both the main playbook and the one enabling structured logging.
RUN $KPM_INSTALL_CMD $KILLBILL_CLOUD_ANSIBLE_ROLES/kaui_json_logging.yml

# Override start script (no need for Ansible scripts to be run)
COPY ./tagged/kaui.sh $KAUI_INSTALL_DIR

EXPOSE 8080
CMD ["/var/lib/kaui/kaui.sh"]
Loading