From 2e7a3ea68fffee8d9c11ebf224edaa8e15d50568 Mon Sep 17 00:00:00 2001 From: Mathew McBride Date: Fri, 2 May 2025 12:07:36 +1000 Subject: [PATCH 1/2] Add a docker-compose file for local development and testing --- Dockerfile | 29 +++++++++++++ docker-compose.yml | 42 +++++++++++++++++++ init-container/healthcheck.sh | 6 +++ init-container/init.sh | 30 +++++++++++++ .../resources/container.service.properties | 16 +++++++ .../resources/container.service.properties | 16 +++++++ 6 files changed, 139 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 init-container/healthcheck.sh create mode 100644 init-container/init.sh create mode 100644 xconf-angular-admin/src/main/resources/container.service.properties create mode 100644 xconf-dataservice/src/main/resources/container.service.properties diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..8e50109b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +FROM docker.io/alpine:latest as initdbpermfix + +COPY init-container/init.sh /tmp +COPY init-container/healthcheck.sh /tmp +RUN chmod +x /tmp/init.sh && chmod +x /tmp/healthcheck.sh + +FROM docker.io/cassandra:4.1.8 as initdb +COPY --from=initdbpermfix /tmp/init.sh /usr/bin +COPY --from=initdbpermfix /tmp/healthcheck.sh /usr/bin +COPY xconf-angular-admin/src/test/resources/schema.cql /tmp +HEALTHCHECK --start-period=60s CMD "/usr/bin/healthcheck.sh" +ENTRYPOINT ["/usr/bin/init.sh"] + +FROM docker.io/maven:3.9.9-amazoncorretto-8-debian-bookworm as builder +RUN apt-get -y update && apt-get -y install git +RUN useradd -m -s /bin/bash build +COPY . /tmp/build +RUN chown -R build:build /tmp/build +USER build +RUN cd /tmp/build && \ + cp xconf-angular-admin/src/main/resources/container.service.properties xconf-angular-admin/src/main/resources/service.properties && \ + cp xconf-dataservice/src/main/resources/container.service.properties xconf-dataservice/src/main/resources/service.properties && \ + mvn -DskipTests=true clean install + +FROM docker.io/jetty:9.4.57-jre8 as angular +COPY --from=builder /tmp/build/xconf-angular-admin/target/xconfAdminService2.war /var/lib/jetty/webapps/admin.war + +FROM docker.io/jetty:9.4.57-jre8 as dataservice +COPY --from=builder /tmp/build/xconf-dataservice/target/xconf-dataservice.war /var/lib/jetty/webapps/ROOT.war diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..defec925 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,42 @@ +version: '3.9' + +services: + cassandra: + image: docker.io/cassandra:4.1.8 + restart: always + healthcheck: + test: ["CMD-SHELL", "[ $$(nodetool statusgossip) = running ]"] + interval: 30s + timeout: 10s + retries: 5 + initdb: + build: + context: . + target: initdb + restart: always + depends_on: + cassandra: + condition: service_healthy + healthcheck: + test: ["CMD-SHELL", "/usr/bin/healthcheck.sh"] + start_period: 60s + xconfangular: + build: + context: . + target: angular + ports: + - 19093:8080 + restart: always + depends_on: + initdb: + condition: service_healthy + xconfdata: + build: + context: . + target: dataservice + ports: + - 19092:8080 + restart: always + depends_on: + initdb: + condition: service_healthy diff --git a/init-container/healthcheck.sh b/init-container/healthcheck.sh new file mode 100644 index 00000000..1f8635c9 --- /dev/null +++ b/init-container/healthcheck.sh @@ -0,0 +1,6 @@ +#!/bin/sh +if (echo 'USE "demo";' | /opt/cassandra/bin/cqlsh cassandra 9042); then + exit 0 +else + exit 1 +fi \ No newline at end of file diff --git a/init-container/init.sh b/init-container/init.sh new file mode 100644 index 00000000..60e43f91 --- /dev/null +++ b/init-container/init.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +cd /opt/cassandra/bin + +while true; do + if (echo "help" | ./cqlsh cassandra 9042); then + # Check database here + if (echo 'USE "demo";' | ./cqlsh cassandra 9042); then + echo "Database present, exiting" + break + else + echo "No demo database, doing db init" + ./cqlsh -f /tmp/schema.cql cassandra 9042 + echo "Demo schema loaded" + break + fi + else + echo "Cassandra not available yet, sleeping 5 seconds" + sleep 5 + fi +done + +# The healthchecks will be a trigger for the +# docker-compose runtime to start the angular and dataservice +# containers +# This container will just sit in the background once it's +# job is finished. +while true; do + sleep 3600 +done \ No newline at end of file diff --git a/xconf-angular-admin/src/main/resources/container.service.properties b/xconf-angular-admin/src/main/resources/container.service.properties new file mode 100644 index 00000000..d2a41a2d --- /dev/null +++ b/xconf-angular-admin/src/main/resources/container.service.properties @@ -0,0 +1,16 @@ +cassandra.keyspaceName=demo +cassandra.contactPoints=cassandra +cassandra.username= +cassandra.password= +cassandra.port=9042 +cassandra.authKey= + +dataaccess.cache.tickDuration=60000 +dataaccess.cache.retryCountUntilFullRefresh=10 +dataaccess.cache.changedKeysTimeWindowSize=900000 +dataaccess.cache.reloadCacheEntries=false +dataaccess.cache.reloadCacheEntriesTimeout=1 +dataaccess.cache.reloadCacheEntriesTimeUnit=DAYS +dataaccess.cache.numberOfEntriesToProcessSequentially=10000 +dataaccess.cache.keysetChunkSizeForMassCacheLoad=500 +dataaccess.cache.changedKeysCfName=XconfChangedKeys4 \ No newline at end of file diff --git a/xconf-dataservice/src/main/resources/container.service.properties b/xconf-dataservice/src/main/resources/container.service.properties new file mode 100644 index 00000000..d2a41a2d --- /dev/null +++ b/xconf-dataservice/src/main/resources/container.service.properties @@ -0,0 +1,16 @@ +cassandra.keyspaceName=demo +cassandra.contactPoints=cassandra +cassandra.username= +cassandra.password= +cassandra.port=9042 +cassandra.authKey= + +dataaccess.cache.tickDuration=60000 +dataaccess.cache.retryCountUntilFullRefresh=10 +dataaccess.cache.changedKeysTimeWindowSize=900000 +dataaccess.cache.reloadCacheEntries=false +dataaccess.cache.reloadCacheEntriesTimeout=1 +dataaccess.cache.reloadCacheEntriesTimeUnit=DAYS +dataaccess.cache.numberOfEntriesToProcessSequentially=10000 +dataaccess.cache.keysetChunkSizeForMassCacheLoad=500 +dataaccess.cache.changedKeysCfName=XconfChangedKeys4 \ No newline at end of file From 17ea246364d084a682fd99254d6eeab969c9eaab Mon Sep 17 00:00:00 2001 From: Mathew McBride Date: Wed, 14 May 2025 15:50:28 +1000 Subject: [PATCH 2/2] README: add information on docker-compose file --- README.md | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 11e14ca6..4fc87d38 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ * [Architecture](#architecture) * [Run application](#run-application) * [Local run](#local-run) + * [Using docker-compose](#using-docker-compose) * [Configuration](#configuration) * [mTLS support](#mtls-support) * [Endpoints](#endpoints) @@ -69,6 +70,46 @@ jetty:run -DappConfig=${path-to-service-properties} -f pom.xml NOTE: XConf UI is compiled using `frontend-maven-plugin` during `run` and `install` phase +### Using docker or podman-compose + +[docker-compose](https://docs.docker.com/compose/) or +[podman-compose](https://docs.podman.io/en/latest/markdown/podman-compose.1.html)* +can be used to quickly create an XConf environment for testing purposes. +This includes a working Cassandra database server, the Angular-based frontend +and backend API server. + +* `podman-compose` users: please use a recent version of podman-compose (at least `v1.4.0`), +as earlier versions do not implement the healthcheck based service dependencies +needed to defer service start until the Cassandara DB is ready. + +To bring up the test environment: + +``` +# docker-compose +docker-compose up -d +# or podman-compose +podman-compose up -d +``` + +The status of the test environment can be viewed with the `ps` subcommand: + +``` +$ docker-compose ps + Name Command State Ports +----------------------------------------------------------------------------------------------------------------------------- +xconfserver_cassandra_1 docker-entrypoint.sh cassa ... Up (healthy) 7000/tcp, 7001/tcp, 7199/tcp, 9042/tcp, 9160/tcp +xconfserver_initdb_1 /usr/bin/init.sh Up (healthy) 7000/tcp, 7001/tcp, 7199/tcp, 9042/tcp, 9160/tcp +xconfserver_xconfangular_1 /docker-entrypoint.sh java ... Up 0.0.0.0:19093->8080/tcp,:::19093->8080/tcp +xconfserver_xconfdata_1 /docker-entrypoint.sh java ... Up 0.0.0.0:19092->8080/tcp,:::19092->8080/tcp +``` + +The frontend application will be port forwarded from port `19093`, while the API will be forwarded from port `19092`. + +The default administrator credentials are `admin/admin`. + +Please be aware that the docker-compose file included is only intended for local development use, +the security settings on the included components are not appropriate for an internet-facing instance. + ## Configuration ### mTLS support To enable mTLS support to connect to cassandra endpoint following properties should be used: @@ -329,4 +370,4 @@ freeArg typed key. fixedArg value meaning. If rule has only one condition there are no `compoundParts`, `relation` field is empty. -If there are more than one condition - they are located in `compoundParts` object. First condition does not have any relation, next one has a relation. \ No newline at end of file +If there are more than one condition - they are located in `compoundParts` object. First condition does not have any relation, next one has a relation.