This is an automated email from the ASF dual-hosted git repository. gk pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/turbine-archetypes.git
commit 356c100c4b66d15eea1191391d023a2b20698a80 Author: Georg Kallidis <[email protected]> AuthorDate: Thu Oct 17 16:02:41 2024 +0200 Prepare Turbine 7.0 archetype. Fixes in container generation, by default Mariadb database is used, but changing it is quite easy (using db property); Use podman-compose by default, which provides greater flexiblity than docker. Add archetype properties db and connectionProperties. Update to Jakarta libs --- README.md | 8 +- pom.xml | 165 ++++++++++++--------- .../META-INF/maven/archetype-metadata.xml | 9 +- ...R-README.md => DOCKER-PODMAN-COMPOSE-README.md} | 101 ++++++++----- .../resources/archetype-resources/docs/README.md | 36 +++-- src/main/resources/archetype-resources/pom.xml | 58 ++++---- .../src/main/docker-resources/app/Dockerfile | 2 +- .../docker-resources/db/{ => mariadb}/Dockerfile | 24 +-- .../docker-resources/db/{ => mysql}/Dockerfile | 1 + .../src/main/docker-resources/db/mysql/conf/my.cnf | 2 +- .../src/main/docker-resources/docker-compose.yml | 47 +++--- .../WEB-INF/{jetty-env.xml => jetty-ee10-env.xml} | 13 +- .../resources/projects/first/archetype.properties | 4 +- 13 files changed, 286 insertions(+), 184 deletions(-) diff --git a/README.md b/README.md index 15cffd2..3d589b0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # turbine-webapp-6.0 -Maven Archetype to generate a webapp utilizing Turbine 6.0 and Torque 5.1 +Maven Archetype to generate a webapp utilizing Turbine 7.0 and Torque 6.0 ## Getting Started @@ -9,17 +9,17 @@ These instructions will get you a copy of the project up and running on your loc ### Prerequisites * Java 11 JDK or later (since Turbine 5.2), before Java 8. -* [MySQL](https://www.mysql.com/) - Database Server or [Docker](https://docs.docker.com/get-docker/) +* [MySQL](https://www.mysql.com/) - Database Server or Container like [Docker](https://docs.docker.com/get-docker/) or Podman. * [Maven](https://maven.apache.org/) - Dependency Management -You should have Java 11 or later installed. The archetype sets up a new application using MySQL as the default database store. However, you can adjust this to use any database supported by Apache Torque 5.1. If not using Docker, you should therefore be at least have a database instance where you have access rights to create a new database schema and populate it with the tables the application generates. Finally, this is a maven archetype, so of course you should install a local versio [...] +You should have Java 17 or later installed. The archetype sets up a new application using MySQL as the default database store. However, you can adjust this to use any database supported by Apache Torque 5.1. If not using Docker, you should therefore be at least have a database instance where you have access rights to create a new database schema and populate it with the tables the application generates. Finally, this is a maven archetype, so of course you should install a local versio [...] ### Installing Eclipse integration: -You need to first add the Apache maven archetypes to your IDE so that you can take advantage of using the turbine-webapp-6.0 plugin to generate a new web application. +You need to first add the Apache maven archetypes to your IDE so that you can take advantage of using the turbine-webapp-7.0 plugin to generate a new web application. The location of the remote catalog file is: http://repo.maven.apache.org/maven2/archetype-catalog.xml diff --git a/pom.xml b/pom.xml index 22ac713..9693654 100644 --- a/pom.xml +++ b/pom.xml @@ -23,13 +23,13 @@ <parent> <groupId>org.apache</groupId> <artifactId>apache</artifactId> - <version>32</version> + <version>33</version> <relativePath/> <!-- like turbine parent --> </parent> <groupId>org.apache.turbine</groupId> <artifactId>turbine-webapp-7.0-SNAPSHOT</artifactId> - <version>3.0.0</version> + <version>4.0.0</version> <packaging>maven-archetype</packaging> <name>Archetype - Turbine 7.0 WebApp</name> @@ -46,10 +46,14 @@ </scm> <properties> - <turbine_database_url>jdbc:mysql://localhost:3306/</turbine_database_url> - <docker>false</docker> - <app_volume_local_repo>not_used</app_volume_local_repo> - <project.build.outputTimestamp>10</project.build.outputTimestamp> + <docker>false</docker> + <app_volume_local_repo>not_used</app_volume_local_repo> + <project.build.outputTimestamp>10</project.build.outputTimestamp> + <!-- defaults just for archetype --> + <turbine_database_url>jdbc:mysql://localhost:3306/</turbine_database_url> + <turbine_database_driver>com.mysql.cj.jdbc.Driver</turbine_database_driver> + <connectionProperties>serverTimezone=${turbine_database_timezone}&useSSL=false&verifyServerCertificate=false&requireSSL=false</connectionProperties> + <db>mysql</db> </properties> <build> @@ -75,9 +79,6 @@ </pluginManagement> <plugins> - - - <!-- filtering for docker --> <plugin> <artifactId>maven-resources-plugin</artifactId> @@ -96,15 +97,15 @@ <directory>src/test/resources</directory> <filtering>true</filtering> </resource> - </resources> - </configuration> + </resources> + </configuration> </execution> </executions> </plugin> </plugins> </build> - <profiles> + <profiles> <!-- to test in integration-test --> <profile> <id>docker</id> @@ -114,69 +115,97 @@ </property> </activation> <properties> - <turbine_database_url>jdbc:mysql://db:3306/</turbine_database_url> <!-- to provide your locale maven repo, required if you need local snapshot builds --> <app_volume_local_repo>${settings.localRepository}</app_volume_local_repo> <docker>true</docker> </properties> </profile> + <profile> + <id>mariadb</id> + <activation> + <property> + <name>mariadb</name> + </property> + </activation> + <properties> + <turbine_database_url>jdbc:mariadb://db:3306/</turbine_database_url> + <turbine_database_driver>org.mariadb.jdbc.Driver</turbine_database_driver> + <connectionProperties>useSSL=false</connectionProperties> + <db>mariadb</db> + </properties> + </profile> + + <profile> + <id>mysql</id> + <activation> + <property> + <name>mysql</name> + </property> + </activation> + <properties> + <turbine_database_url>jdbc:mysql://localhost:3306/</turbine_database_url> + <turbine_database_driver>com.mysql.cj.jdbc.Driver</turbine_database_driver> + <connectionProperties>serverTimezone=${turbine_database_timezone}&useSSL=false&verifyServerCertificate=false&requireSSL=false</connectionProperties> + <db>mysql</db> + </properties> + </profile> + <profile> - <id>apache-release</id> - <properties> - <dependency.check.skip>true</dependency.check.skip> - </properties> - <build> - <plugins> - <plugin> - <artifactId>maven-release-plugin</artifactId> - <configuration> - <releaseProfiles>apache-release</releaseProfiles> - <mavenExecutorId>forked-path</mavenExecutorId> - </configuration> - </plugin> - <plugin> - <artifactId>maven-install-plugin</artifactId> - <configuration> - </configuration> - </plugin> - <plugin> - <groupId>net.nicoulaj.maven.plugins</groupId> - <artifactId>checksum-maven-plugin</artifactId> - <version>1.11</version> - <configuration> - <algorithms> - <algorithm>SHA-512</algorithm> - </algorithms> - <!-- generate only sha for binaries and source zip/tar files from assembly --> - <excludeMainArtifact>true</excludeMainArtifact> - </configuration> - <executions> - <execution> - <goals> - <goal>artifacts</goal> - </goals> - </execution> - </executions> - </plugin> - <!-- force signatures to be created and uploaded on deploy --> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-gpg-plugin</artifactId> - <version>3.2.4</version> - <executions> - <execution> - <id>sign-artifacts</id> - <phase>verify</phase> - <goals> - <goal>sign</goal> - </goals> - </execution> - </executions> - </plugin> - - </plugins> - </build> + <id>apache-release</id> + <properties> + <dependency.check.skip>true</dependency.check.skip> + </properties> + <build> + <plugins> + <plugin> + <artifactId>maven-release-plugin</artifactId> + <configuration> + <releaseProfiles>apache-release</releaseProfiles> + <mavenExecutorId>forked-path</mavenExecutorId> + </configuration> + </plugin> + <plugin> + <artifactId>maven-install-plugin</artifactId> + <configuration> + </configuration> + </plugin> + <plugin> + <groupId>net.nicoulaj.maven.plugins</groupId> + <artifactId>checksum-maven-plugin</artifactId> + <version>1.11</version> + <configuration> + <algorithms> + <algorithm>SHA-512</algorithm> + </algorithms> + <!-- generate only sha for binaries and source zip/tar files from assembly --> + <excludeMainArtifact>true</excludeMainArtifact> + </configuration> + <executions> + <execution> + <goals> + <goal>artifacts</goal> + </goals> + </execution> + </executions> + </plugin> + <!-- force signatures to be created and uploaded on deploy --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-gpg-plugin</artifactId> + <version>3.2.4</version> + <executions> + <execution> + <id>sign-artifacts</id> + <phase>verify</phase> + <goals> + <goal>sign</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> </profile> </profiles> diff --git a/src/main/resources/META-INF/maven/archetype-metadata.xml b/src/main/resources/META-INF/maven/archetype-metadata.xml index 9809418..adb7a0e 100644 --- a/src/main/resources/META-INF/maven/archetype-metadata.xml +++ b/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -58,8 +58,15 @@ <defaultValue>${settings.localRepository}</defaultValue> </requiredProperty> <requiredProperty key="docker"> - <defaultValue>${docker}</defaultValue> + <defaultValue>false</defaultValue> </requiredProperty> + <requiredProperty key="connectionProperties"> + <defaultValue>useSSL=false</defaultValue> + </requiredProperty> + <requiredProperty key="db"> + <defaultValue>mysql</defaultValue> + </requiredProperty> + </requiredProperties> <fileSets> <fileSet filtered="true" packaged="true"> diff --git a/src/main/resources/archetype-resources/docs/DOCKER-README.md b/src/main/resources/archetype-resources/docs/DOCKER-PODMAN-COMPOSE-README.md similarity index 70% rename from src/main/resources/archetype-resources/docs/DOCKER-README.md rename to src/main/resources/archetype-resources/docs/DOCKER-PODMAN-COMPOSE-README.md index f7a2566..9ef24ca 100644 --- a/src/main/resources/archetype-resources/docs/DOCKER-README.md +++ b/src/main/resources/archetype-resources/docs/DOCKER-PODMAN-COMPOSE-README.md @@ -4,24 +4,45 @@ This is to help developers to get fast a running development environment for deb To use it in production you may need to carefully review all configurations and adjust. -This Docker environment is to test/develop a Turbine app using a docker test database. +The Container based environment is to test/develop a Turbine app using a container based test database. -The build should take place outside the docker container. +The build should take place outside the container. -It is based on one docker-compose.yml file and two Dockerfiles. +It is based on one docker-compose.yml file and two Dockerfiles and could be run with podman-compose (after some checks are done, see below).. -Docker compose uses currently two customized services: **app** (maven:3-jdk-11) and **db** (mysql:latest). +Docker compose uses currently two customized services: **app** (maven:latest) and **db** (mariadb:10.10). + +## Podman und Podman-compose + +- If using Podman (podman-compose) you have to add registry docker.io/library/ in etc/containers/registries.conf (or add a namespace before tag name in FROM of DOCKERFILE). +- To allow inter container communication you should enable in /etc/containers/container.conf + + [network] + network_backend = "netavark" + +- In docker-compose.yml networks has to be enabled because of this. + + (tested for Debian bookworm, podman 4.3.1, running in root-less environment). You could check, that it is set by running + + podman info | grep network + +. And just replace below docker compose with podman-compose (most commands)! ## Note -- Mysql is replaced by Mariadb. + +- reference database is now Mariadb (mySQL may be used also after some adaptions in DOCKERFILE, but it is not tested in the first place). - Instead of using maven as the app service a Jetty container might be the better choice as currently console reloading might not work. To be able to use other maven tasks (in the container) in this case makes this nevertheless a reasonable choice. # Prepare -To run the build with maven do this outside of the container using following mvn command: +To run the build from the archetypes root use the following mvn command: - mvn install -Pdocker + mvn install -Pdocker,mysql +or + mvn install -Pdocker,mariadb + +IMPORTANT: You habe to enable the profile mariadb or mysql to define the backend. ### Build Note @@ -37,7 +58,7 @@ If you have already generated this with mvn archetype:generate within the same h Important: Check that /m2repo is properly mapped to your local maven repository in docker-compose.yml! -### Note if building from Repo source - Integration Test +### Note if building from Archetypes Repo source - Integration Test This generates in target folder a structure like this: @@ -54,11 +75,17 @@ If running from integrationtest, you find the docker files in integrationtest/ta docker compose build --no-cache docker compose up --detach -** A first time build of the app service might take a couple of minutes. ** +or + + podman-compose down + podman-compose up -d + podman-compose start + +** A first time build of the app service should not take more than a couple of minutes. ** You might check the process with - docker compose logs -f app + podman-compose logs -f app docker compose logs -f db The logs should show "mysqld: ready for connections" and "Started Jetty Server". @@ -112,7 +139,7 @@ Start both services in one step (add -d for detached mode) docker-compose up -.. or doing it in background, requires second start command +.. or doing it in background, requires to start the services explicitely docker-compose up -d docker-compose start @@ -131,7 +158,7 @@ You could follow the logs with docker-compose logs -f app or docker-compose logs - If services are already installed, activate/start by docker-compose up - Example Logs: +##### Example Logs for Docker: [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.25-1debian10 started. [Note] [Entrypoint]: Switching to dedicated user 'mysql' @@ -158,13 +185,33 @@ You could follow the logs with docker-compose logs -f app or docker-compose logs [INFO] [INFO] --- torque-maven-plugin:5.1-SNAPSHOT:generate (torque-om) @ integrationtest --- [main] INFO | org.apache.torque.generator.control.Controller - readConfiguration() : Starting to read configuration files - -- Starting the app service will build the app and start jetty with Maven on port 8081. + +##### Podman Example Results + + + 'podman', '--version', ''] + using podman version: 4.3.1 + ** excluding: set() + ['podman', 'inspect', '-t', 'image', '-f', '{{.Id}}', 'docker-resources_db'] + ['podman', 'inspect', '-t', 'image', '-f', '{{.Id}}', 'docker-resources_app'] + podman volume inspect docker-resources_db_data_turbine || podman volume create docker-resources_db_data_turbine + ['podman', 'volume', 'inspect', 'docker-resources_db_data_turbine'] + ['podman', 'network', 'exists', 'docker-resources_back-tier'] + podman run --name=docker-resources_db_1 -d --label io.podman.compose.config-hash=123 --label io.podman.compose.project=docker-resources --label io.podman.compose.version=0.0.1 --label com.docker.compose.project=docker-resources --label com.docker.compose.project.working_dir=..pes/target/test-classes/projects/first/project/integrationtest/target/docker-resources --label com.docker.compose.project.config_files=docker-compose.yml --label com.docker.compose.container-number=1 --label com [...] + a7a1baf00a9ba0ed9fae5727fe015b21350fcd90c92ea6676fed1f32e9387ceb + exit code: 0 + ['podman', 'network', 'exists', 'docker-resources_back-tier'] + podman run --name=docker-resources_app_1 -d --label io.podman.compose.config-hash=123 --label io.podman.compose.project=docker-resources --label io.podman.compose.version=0.0.1 --label com.docker.compose.project=docker-resources --label com.docker.compose.project.working_dir=./target/test-classes/projects/first/project/integrationtest/target/docker-resources --label com.docker.compose.project.config_files=docker-compose.yml --label com.docker.compose.container-number=1 --label com.do [...] + 4e9e9701de26a7033cd8c100184317ab63a57e477fa0a8ee3937a851ca0c3503 + exit code: 0 + + +- Starting the app service will build the app and start jetty on port 8081. This command is set as a **command** in the app service in docker compose. Currently the docker-compose is generated once more, if starting the containers, this will overwrite m2repo and may result in errors. -If not yet done, build on the host with mvn clean install -f ../pom.xml -Pdocker. +If not yet done, build on the host with mvn clean install -f ../pom.xml -Pdocker,mariadb. ### Lifecycle (developers only) @@ -227,9 +274,9 @@ Run in project root ### Db Service - docker-compose run --rm db /bin/bash + podman-compose run --rm db /bin/bash -Extract data in db service +Extract data in db service (check password in docker-compose.yml or elsewhere). mysql -u root -h db -P 3306 -p @@ -279,7 +326,7 @@ In the container, check: - If you generated the project with windows shell, but run the docker form wsl you have to regenerate docker-compose.yml with unix pathes running this command again - mvn install -Pdocker + mvn install -Pdocker,mariab ### More Internals, Helpful Docker commands @@ -294,24 +341,6 @@ If you want to run from Dockerfile .. docker rmi $(docker images -q) -### Still more docker commands ... - -```sh - docker volume inspect <containerid> - - // delete intermediate images, volumes - docker rmi $(docker images --filter "dangling=true" -q) - docker volume rm $(docker volume ls -qf dangling=true) - - # or delete while building - docker build --rm - - # cleans all containers - docker system prune - - # stops all running containers - docker stop $(docker ps -a -q) -``` ## License diff --git a/src/main/resources/archetype-resources/docs/README.md b/src/main/resources/archetype-resources/docs/README.md index b13c815..516a1fe 100644 --- a/src/main/resources/archetype-resources/docs/README.md +++ b/src/main/resources/archetype-resources/docs/README.md @@ -8,7 +8,7 @@ These instructions will get you a copy of the project up and running on your loc ### Prerequisites -* Java 11 JDK or later (Turbine 5.2 and later), before Java 8 +* Java 17 JDK or later (Turbine 6.0 and later), before Java 8 * [MySQL](https://www.mysql.com/) - Database Server or [Docker] (https://docs.docker.com/get-docker/) * [Maven](https://maven.apache.org/) - Dependency Management @@ -16,7 +16,7 @@ You should have Java 11 or later installed. The archetype sets up a new applica ## About this archetype -Turbine Version: Turbine 5.2 Turbine-webapp-5.x +Turbine Version: Turbine 6.02 Turbine-webapp-6.x ### Integration Test (if you checked out this [Archetype Generate Repository](https://github.com/apache/turbine-archetypes.git)) @@ -66,7 +66,7 @@ mvn archetype:generate \ -Dturbine_database_name=helloworld \ -Dturbine_database_timezone=UTC \ -Dturbine_database_url=jdbc:mysql://localhost:3306/ \ - -Dgoals=generate-sources,integration-test + -Dgoals=generate-sources,integration-test ``` #### Docker integration @@ -87,7 +87,25 @@ You may use (add -U to get a fresh copy) to avoid declaring the *archetype* variables. -This requires you provide a local catalog in $HOME\.m2\archetype-catalog.xml. Find further information here: https://maven.apache.org/archetype/archetype-models/archetype-catalog/archetype-catalog.html. +This requires you provide a local catalog in $HOME\.m2\archetype-catalog.xml, e.g. + + <?xml version="1.0" encoding="UTF-8"?> + <archetype-catalog xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.0.0 http://maven.apache.org/xsd/archetype-catalog-1.0.0.xsd" + xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <archetypes> + <archetype> + <groupId>org.apache.turbine</groupId> + <artifactId>turbine-webapp-7.0-SNAPSHOT</artifactId> + <version>4.0.0</version> + <description>This archetype sets up a web application project based on Apache Turbine 7.x</description> + </archetype> + </archetypes> + </archetype-catalog> + + + + Find further information here: https://maven.apache.org/archetype/archetype-models/archetype-catalog/archetype-catalog.html. ##### Example @@ -134,7 +152,7 @@ mvn clean install If you get an error like *"The driver has not received any packets"* probably the database is not up and running or the port may be another one. Last step on the command line is run the server by invoking -mvn -Pjetty +mvn jetty:run - Now you can launch your new Turbine application by default [http://localhost:8081/app] (check port in pom.xml, if needed). @@ -198,7 +216,7 @@ your eclipse environment. You even could debug the app by setting the environment variable to something like this ``` -set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n +set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=0.0.0.0:8787,server=y,suspend=n ``` before running the jetty server. @@ -207,13 +225,13 @@ before running the jetty server. Be aware of settings and some smaller restrictions, which mostly will be fixed in the upcoming releases. -- Keep groups/roles lower case (which should be fixed in current Fulcrum Security 2.x/Turbine 5.x) -- abstract classes and managers are included (because of some minor bugs in Fulcrum Security 1.1.0, same as above) +- Keep groups/roles lower case (fixed in current Fulcrum Security 2.x/Turbine 5.x) +- abstract classes and managers are included (resolved after Fulcrum Security 1.1.0, same as above) - LogoutUser action is included as an custom example - LoginUser action is included (to check for anonymous user, may be fixed in future release) - OM (Torque Object Mapper) stub classes are included (until configurable in schema with Torque version 5.1) - TurbineConfiguration returns a Commons configuration object, even if field is not assignable (fixed in Turbine 5.x, you can then assign e.g. to String instead, cft. SecureScreen) -- Database connection is done initially by default with JNDI. If you want to change it, check Torque.properties and (1) for Tomcat, META-INF/context.xml or (2) for Jetty, WEB-INF/jetty-env.xml. +- Database connection is done initially by default with JNDI. If you want to change it, check Torque.properties and (1) for Tomcat, META-INF/context.xml or (2) for Jetty, WEB-INF/jetty-env.xml (or ee version). ## License diff --git a/src/main/resources/archetype-resources/pom.xml b/src/main/resources/archetype-resources/pom.xml index 6c91ea7..1d5f7bb 100644 --- a/src/main/resources/archetype-resources/pom.xml +++ b/src/main/resources/archetype-resources/pom.xml @@ -18,6 +18,8 @@ specific language governing permissions and limitations under the License. *# #set($dollar = '$') +#set($amp = '&') +#set($close = ';') #macro (var $label)${dollar}{${label}}#end <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> @@ -25,7 +27,7 @@ under the License. <parent> <groupId>org.apache.turbine</groupId> <artifactId>turbine-parent</artifactId> - <version>12</version> + <version>14-SNAPSHOT</version> <relativePath/> </parent> @@ -189,7 +191,7 @@ under the License. <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> - <version>3.3.2</version> + <version>3.4.0</version> <configuration> <archive> <manifestEntries> @@ -203,7 +205,7 @@ under the License. <filtering>true</filtering> <targetPath>WEB-INF</targetPath> <includes> - <include>jetty-env.xml</include> + <include>jetty-ee10-env.xml</include> </includes> </resource> <resource> @@ -226,10 +228,8 @@ under the License. <configuration> <!-- Please update with your database configuration --> <driver>${turbine_database_driver}</driver> - - <!-- The serverTimezone parameter is required for MySQL. - You may need to remove it for other databases --> - <url>#var("turbine_database_url")#var("turbine_database_name")?serverTimezone=${turbine_database_timezone}&useSSL=false&verifyServerCertificate=false&requireSSL=false</url> + <!-- default mariadb parameters now --> + <url>#var("turbine_database_url")#var("turbine_database_name")?useSSL=false</url> <username>${turbine_database_user}</username> <password>${turbine_database_password}</password> <onError>continue</onError> @@ -276,10 +276,9 @@ under the License. </plugin> <!-- Jetty plugin mvn jetty:run will startup the application --> <plugin> - <groupId>org.eclipse.jetty</groupId> - <artifactId>jetty-maven-plugin</artifactId> - <!-- latest version that is working --> - <version>9.4.51.v20230217</version> + <groupId>org.eclipse.jetty.ee10</groupId> + <artifactId>jetty-ee10-maven-plugin</artifactId> + <version>12.0.14</version> <configuration> <!-- https://www.eclipse.org/jetty/documentation/jetty-9/index.html#jars-scanned-for-annotations --> <scanIntervalSeconds>10</scanIntervalSeconds> @@ -288,7 +287,7 @@ under the License. <idleTimeout>60000</idleTimeout> </httpConnector> <webApp> - <jettyEnvXml>${project.build.directory}/${project.build.finalName}/WEB-INF/jetty-env.xml</jettyEnvXml> + <jettyEnvXml>${project.build.directory}/${project.build.finalName}/WEB-INF/jetty-ee10-env.xml</jettyEnvXml> </webApp> </configuration> </plugin> @@ -305,9 +304,9 @@ under the License. <!-- use profile with the database driver of your choice --> <!-- Allow lookup of #var("web:rootDir") in log4j2 file --> <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-web</artifactId> - <version>#var("log4j2.version")</version> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-jakarta-web</artifactId> + <version>#var("log4j2.version")</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> @@ -390,7 +389,7 @@ under the License. <artifactId>jackson-datatype-json-org</artifactId> <!-- version>${jackson.version}</version--> <!-- https://github.com/FasterXML/jackson/wiki/Jackson-Release-2.11.3 --> - <version>2.11.3</version> + <version>2.17.2</version> </dependency> <!-- if activating useJsonPath include jayway dependency --> <!-- dependency> @@ -424,14 +423,14 @@ under the License. <maven.compile.target>17</maven.compile.target> <maven.surefire.version>3.2.5</maven.surefire.version> <project.build.sourceEncoding>utf-8</project.build.sourceEncoding> - <log4j2.version>2.22.0</log4j2.version> + <log4j2.version>2.24.1</log4j2.version> <mysql.version>8.0.33</mysql.version> - <mariadb.version>3.2.0</mariadb.version><!-- v3 requries java 11 and adapter name mariab instead of mysql --> + <mariadb.version>3.4.1</mariadb.version><!-- v3 requries java 11 and adapter name mariab instead of mysql --> <driverClassName>${turbine_database_driver}</driverClassName> <fulcrum.intake>3.0.1-SNAPSHOT</fulcrum.intake> <fulcrum.parser>3.0.1-SNAPSHOT</fulcrum.parser> <fulcrum.security>3.0.1-SNAPSHOT</fulcrum.security> - <fulcrum.yaafi>2.0.1-SNAPSHOT</fulcrum.yaafi> + <fulcrum.yaafi>2.0.1</fulcrum.yaafi> <fulcrum.json>2.0.2-SNAPSHOT</fulcrum.json> <fulcrum.cache>2.0.1-SNAPSHOT</fulcrum.cache> <fulcrum.testcontainer>2.0.1-SNAPSHOT</fulcrum.testcontainer> @@ -450,6 +449,7 @@ under the License. <properties> <driverClassName>org.mariadb.jdbc.Driver</driverClassName> <turbine_database_url>jdbc:mariadb://localhost:3306/</turbine_database_url> + <connectionProperties>useSSL=false</connectionProperties> </properties> <dependencies> <dependency> @@ -480,12 +480,10 @@ under the License. </profile> <profile> <id>mysql</id> - <activation> - <activeByDefault>true</activeByDefault> - </activation> <properties> <driverClassName>${turbine_database_driver}</driverClassName> - <turbine_database_url>${turbine_database_url}</turbine_database_url> + <turbine_database_url>${turbine_database_url}</turbine_database_url> + <connectionProperties>serverTimezone=${turbine_database_timezone}&useSSL=false&verifyServerCertificate=false&requireSSL=false</connectionProperties> </properties> <dependencies> <dependency> @@ -504,6 +502,9 @@ under the License. <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>sql-maven-plugin</artifactId> + <configuration> <!-- The serverTimezone parameter is required for MySQL.You may need to remove it for other databases --> + <url>#var("turbine_database_url")#var("turbine_database_name")?serverTimezone=${turbine_database_timezone}&useSSL=false&verifyServerCertificate=false&requireSSL=false</url> + </configuration> <dependencies> <dependency> <groupId>com.mysql</groupId> @@ -523,7 +524,7 @@ under the License. </activation> <build> <plugins> - <plugin> + <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>sql-maven-plugin</artifactId> <executions> @@ -544,11 +545,14 @@ under the License. </plugins> </build> <properties> - <!-- hard code docker compose service id and port by default --> - <turbine_database_url>jdbc:mysql://db:3306/</turbine_database_url> + <!-- requires profile mysql or mariadb activated --> + <turbine_database_url>${turbine_database_url}</turbine_database_url> + <turbine_database_driver>${turbine_database_driver}</turbine_database_driver> + <connectionProperties><![CDATA[${connectionProperties}]]></connectionProperties> <!-- read from #var("settings.localRepository") to provide e.g. local snapshot builds --> - <app_volume_local_repo>${settings.localRepository}</app_volume_local_repo> + <app_volume_local_repo>#var("settings.localRepository")</app_volume_local_repo> <docker>true</docker> + <db>${db}</db> </properties> </profile> </profiles> diff --git a/src/main/resources/archetype-resources/src/main/docker-resources/app/Dockerfile b/src/main/resources/archetype-resources/src/main/docker-resources/app/Dockerfile index f202fe7..a0937c9 100644 --- a/src/main/resources/archetype-resources/src/main/docker-resources/app/Dockerfile +++ b/src/main/resources/archetype-resources/src/main/docker-resources/app/Dockerfile @@ -1,4 +1,4 @@ -FROM maven:3-jdk-11 +FROM maven:latest # cft hub.docker.com/r/library/maven # not used, as in docker-compose m2repo is set diff --git a/src/main/resources/archetype-resources/src/main/docker-resources/db/Dockerfile b/src/main/resources/archetype-resources/src/main/docker-resources/db/mariadb/Dockerfile similarity index 70% copy from src/main/resources/archetype-resources/src/main/docker-resources/db/Dockerfile copy to src/main/resources/archetype-resources/src/main/docker-resources/db/mariadb/Dockerfile index 505c179..f54050b 100644 --- a/src/main/resources/archetype-resources/src/main/docker-resources/db/Dockerfile +++ b/src/main/resources/archetype-resources/src/main/docker-resources/db/mariadb/Dockerfile @@ -1,4 +1,5 @@ # mariadb uses docker-entrypoint +# podman requires docker.io/library in registries.conf FROM mariadb:10.10 # That file does the DB initialization but also runs mysql daemon, by removing the last line it will only init @@ -10,20 +11,20 @@ FROM mariadb:10.10 # docker run <image> /usr/sbin/mysqld --verbose --help | grep -A 1 "Default options" ARG DB_CONTEXT -ARG MYSQL_ROOT -ARG MYSQL_ROOT_PASSWORD -ARG MYSQL_DATABASE -ARG MYSQL_USER -ARG MYSQL_PASSWORD +ARG MARIADB_ROOT +ARG MARIADB_ROOT_PASSWORD +ARG MARIADB_DATABASE +ARG MARIADB_USER +ARG MARIADB_PASSWORD # required, to create ENV DB_CONTEXT ${DB_CONTEXT} -ENV MYSQL_ROOT=${MYSQL_ROOT} -ENV MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} +ENV MARIADB_ROOT=${MARIADB_ROOT} +ENV MARIADB_ROOT_PASSWORD=${MARIADB_ROOT_PASSWORD} -ENV MYSQL_DATABASE=${MYSQL_DATABASE} -ENV MYSQL_USER=${MYSQL_USER} -ENV MYSQL_PASSWORD=${MYSQL_PASSWORD} +ENV MARIADB_DATABASE=${MARIADB_DATABASE} +ENV MARIADB_USER=${MARIADB_USER} +ENV MARIADB_PASSWORD=${MARIADB_PASSWORD} COPY generated-sql/torque/mysql /generated-sql-init # dependent sql should be name sorted after init.sql @@ -33,4 +34,7 @@ RUN cat /generated-sql-init/*.sql > /docker-entrypoint-initdb.d/init.sql COPY data/sample-mysql-data /generated-sql-post-init RUN cat /generated-sql-post-init/*.sql > /docker-entrypoint-initdb.d/post_init.sql +# --chomd=600 --chown=mysql:mysql throws error COPY ${DB_CONTEXT}/mysql/conf/ /etc/mysql/conf.d + +USER mysql diff --git a/src/main/resources/archetype-resources/src/main/docker-resources/db/Dockerfile b/src/main/resources/archetype-resources/src/main/docker-resources/db/mysql/Dockerfile similarity index 95% rename from src/main/resources/archetype-resources/src/main/docker-resources/db/Dockerfile rename to src/main/resources/archetype-resources/src/main/docker-resources/db/mysql/Dockerfile index 505c179..30b8237 100644 --- a/src/main/resources/archetype-resources/src/main/docker-resources/db/Dockerfile +++ b/src/main/resources/archetype-resources/src/main/docker-resources/db/mysql/Dockerfile @@ -1,4 +1,5 @@ # mariadb uses docker-entrypoint +# podman requires docker.io/library in registries.conf FROM mariadb:10.10 # That file does the DB initialization but also runs mysql daemon, by removing the last line it will only init diff --git a/src/main/resources/archetype-resources/src/main/docker-resources/db/mysql/conf/my.cnf b/src/main/resources/archetype-resources/src/main/docker-resources/db/mysql/conf/my.cnf index 74dc782..659895b 100644 --- a/src/main/resources/archetype-resources/src/main/docker-resources/db/mysql/conf/my.cnf +++ b/src/main/resources/archetype-resources/src/main/docker-resources/db/mysql/conf/my.cnf @@ -30,7 +30,7 @@ collation_server=utf8mb4_unicode_ci default-character-set=utf8mb4 -tee=/mysql/log/log.out +tee=/var/log/mysql/log.out [mysqld_safe] diff --git a/src/main/resources/archetype-resources/src/main/docker-resources/docker-compose.yml b/src/main/resources/archetype-resources/src/main/docker-resources/docker-compose.yml index 254b413..2e1a954 100644 --- a/src/main/resources/archetype-resources/src/main/docker-resources/docker-compose.yml +++ b/src/main/resources/archetype-resources/src/main/docker-resources/docker-compose.yml @@ -3,21 +3,27 @@ version: '3.7' services: app: + networks: + - back-tier # use the Dockerfile next to this file build: - context: ../ - dockerfile: ./docker-resources/app/Dockerfile - # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=9000,server=y,suspend=y, if remote debugging app is required + context: ../ + dockerfile: ./docker-resources/app/Dockerfile + # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=0.0.0.0:9000,server=y,suspend=y, if remote debugging app is required environment: - MAVEN_OPTS= # this runs the app server in the container, be sure not to filter resources once again! - command: mvn -Pjetty + command: [ mvn, jetty:run, "-Pdocker,${db}" ] ports: - "8081:8081" # remote debugging port, uncomment if not needed - "9000:9000" + + # podman required to support to allow outside pod not using localhost, but service name + # networks: "container:docker-resources_db_1" + restart: always # makes the app container aware of the DB container depends_on: - db @@ -32,39 +38,40 @@ services: - '#var("app_volume_local_repo"):/m2repo' db: - # set the build context + networks: + - back-tier + # set the build context build: context: ../ - dockerfile: ./docker-resources/db/Dockerfile + dockerfile: ./docker-resources/db/${db}/Dockerfile args: DB_CONTEXT: ./docker-resources/db - MYSQL_ROOT: root - MYSQL_ROOT_PASSWORD: changeit - MYSQL_DATABASE: ${turbine_database_name} - MYSQL_USER: ${turbine_database_user} - MYSQL_PASSWORD: ${turbine_database_password} - - # no environment needed here, only if using image in this file - + MARIADB_ROOT: root + MARIADB_ROOT_PASSWORD: changeit + MARIADB_DATABASE: ${turbine_database_name} + MARIADB_USER: ${turbine_database_user} + MARIADB_PASSWORD: ${turbine_database_password} + + # no environment needed here, only if using image in this file volumes: - - ./db/mysql/init:/docker-entrypoint-initdb.d + # reading generated SQL is done in DOCKERFILE + #- ./db/mysql/init:/docker-entrypoint-initdb.d # may activate on *nix #- ./db/mysql/conf:/etc/mysql/conf.d - ./db/mysql/data:/data #- ./db/mysql/log:/mysql/log - db_data_${turbine_database_name}:/var/lib/mysql:rw - restart: always + # restart: always ports: # host: container - "13306:3306" - #networks: - # - db command: [mysqld, --default-authentication-plugin=mysql_native_password] # this might work only for *nix, check with docker image inspect db volumes: db_data_${turbine_database_name}: -#networks: -# db: +networks: + back-tier: + diff --git a/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/jetty-env.xml b/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/jetty-ee10-env.xml similarity index 65% rename from src/main/resources/archetype-resources/src/main/webapp/WEB-INF/jetty-env.xml rename to src/main/resources/archetype-resources/src/main/webapp/WEB-INF/jetty-ee10-env.xml index 7497f55..ec6faff 100644 --- a/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/jetty-env.xml +++ b/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/jetty-ee10-env.xml @@ -1,20 +1,21 @@ -<Configure class="org.eclipse.jetty.webapp.WebAppContext"> +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://eclipse.dev/jetty/configure_10_0.dtd"> +<Configure class="org.eclipse.jetty.ee10.webapp.WebAppContext" id="wac"> <New id="Turbine" class="org.eclipse.jetty.plus.jndi.Resource"> - <Arg></Arg> <!-- reference to WebAppContext requires jetty 9.x only --> + <Arg><Ref refid="wac"/></Arg> <!-- scope --> <Arg>${turbine_database_jndipath}</Arg> <Arg> - <New class="org.apache.commons.dbcp.BasicDataSource"> + <New class="org.apache.commons.dbcp2.BasicDataSource"> <Set name="driverClassName">${turbine_database_driver}</Set> <Set name="url">${turbine_database_url}${turbine_database_name}</Set> <Set name="username">${turbine_database_user}</Set> <Set name="password">${turbine_database_password}</Set> - <Set name="connectionProperties">serverTimezone=${turbine_database_timezone};useUnicode=true;characterEncoding=utf8;useSSL=false;allowPublicKeyRetrieval=true</Set> + <Set name="connectionProperties">${connectionProperties}</Set> <Set name="validationQuery">SELECT 1</Set> </New> </Arg> </New> - <Set name="extraClasspath"></Set> <Call name="setAttribute"> <Arg>org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern</Arg> <Arg>.*/spring-[^/]*\.jar$</Arg> @@ -22,6 +23,6 @@ <Call name="setAttribute"> <Arg>org.eclipse.jetty.annotations.multiThreaded</Arg> <Arg type="Boolean">false</Arg> - </Call> + </Call> </Configure> diff --git a/src/test/resources/projects/first/archetype.properties b/src/test/resources/projects/first/archetype.properties index a6065d1..fa9e5de 100644 --- a/src/test/resources/projects/first/archetype.properties +++ b/src/test/resources/projects/first/archetype.properties @@ -7,10 +7,12 @@ turbine_intake_file=intake.xml turbine_database_name=turbine turbine_database_adapter=auto turbine_database_jndipath=jdbc/turbine -turbine_database_driver=com.mysql.cj.jdbc.Driver +turbine_database_driver=${turbine_database_driver} turbine_database_timezone=UTC turbine_database_url=${turbine_database_url} +connectionProperties=${connectionProperties} turbine_database_user=db_user turbine_database_password=db_password app_volume_local_repo=${app_volume_local_repo} docker=${docker} +db=${db}
