You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@turbine.apache.org by gk...@apache.org on 2021/07/13 15:14:17 UTC

[turbine-archetypes] 02/05: update eclipse project, fix resource basedir in pom, dockerfile commands more concise, fix myapp location due to using now docker-resources / webapp in target folder, add metadata-complete (optional)

This is an automated email from the ASF dual-hosted git repository.

gk pushed a commit to branch docker5x
in repository https://gitbox.apache.org/repos/asf/turbine-archetypes.git

commit e55a118c289069bdd9b342c919f0664db290df9d
Author: Georg Kallidis <gk...@apache.org>
AuthorDate: Tue Jul 13 08:39:05 2021 +0200

    update eclipse project, fix resource basedir in pom, dockerfile commands more concise, fix myapp location due to using now docker-resources / webapp in target folder, add metadata-complete (optional)
---
 .project                                           |  6 +-
 src/main/resources/archetype-resources/pom.xml     | 75 +++++++++++++++-----
 .../src/main/docker-resources/app/Dockerfile       | 18 +++++
 .../src/main/docker-resources/app/settings.xml     | 69 ++++++++++++++++++
 .../src/main/docker-resources/db/Dockerfile        | 65 +++++++++++++++++
 .../src/main/docker-resources/docker-compose.yml   | 82 ++++++++++++++++++++++
 .../src/main/webapp/WEB-INF/web.xml                |  2 +-
 7 files changed, 295 insertions(+), 22 deletions(-)

diff --git a/.project b/.project
index 3342dbf..f0019d6 100644
--- a/.project
+++ b/.project
@@ -1,12 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <projectDescription>
-  <name>turbine-webapp-5.0</name>
-  <comment>This archetype sets up a web application project based on Apache Turbine 5.0. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
+  <name>turbine-webapp-5.1</name>
+  <comment>This archetype sets up a web application project based on Apache Turbine 5.x and Torque 5.x. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
   <projects/>
   <buildSpec>
     <buildCommand>
       <name>org.eclipse.m2e.core.maven2Builder</name>
-    </buildCommand>    
+    </buildCommand>
   </buildSpec>
   <natures>
     <nature>org.eclipse.m2e.core.maven2Nature</nature>
diff --git a/src/main/resources/archetype-resources/pom.xml b/src/main/resources/archetype-resources/pom.xml
index 4e22b7c..61b92b6 100644
--- a/src/main/resources/archetype-resources/pom.xml
+++ b/src/main/resources/archetype-resources/pom.xml
@@ -47,10 +47,33 @@ under the License.
                     <include>**/*.xml</include>
                 </includes>
             </resource>
+<<<<<<< HEAD
             <!-- (target) resource and filtering is not used  at all ? 
             at least removed setting absolute path e.g. with #var("project.build.directory"), 
             which does thrown an exception with mvn eclipse:eclipse - path is then incorrectly relativized.
                 --> 
+=======
+            <!-- (target) resource and filtering is not used  at all ?
+            at least removed setting absolute path e.g. with #var("project.build.directory"),
+            which does thrown an exception with mvn eclipse:eclipse - path is then incorrectly relativized.
+            "Can't canonicalize system path"
+            -->
+            <resource>
+                <directory>src/main/docker-resources</directory>
+                <filtering>true</filtering>
+                <includes>
+                    <include>**/*</include>
+                </includes>
+                <targetPath>../docker-resources</targetPath>
+            </resource>
+            <resource>
+                <directory>src/main/data</directory>
+                <includes>
+                    <include>**/*</include>
+                </includes>
+                <targetPath>../data</targetPath>
+            </resource>
+>>>>>>> bf803e1 (update eclipse project, fix resource basedir in pom, dockerfile commands more concise, fix myapp location due to using now docker-resources / webapp in target folder, add metadata-complete (optional))
             <resource> 
                 <targetPath>../torque/schema</targetPath>
                 <filtering>true</filtering>
@@ -172,6 +195,19 @@ under the License.
                         <X-Compile-Target-JDK>#var("maven.compile.target")</X-Compile-Target-JDK>
                     </manifestEntries>
                 </archive>
+<<<<<<< HEAD
+=======
+                 <webResources>
+                      <resource>
+                        <directory>#var("project.basedir")/src/main/webapp/WEB-INF</directory>
+                        <filtering>true</filtering>
+                        <targetPath>WEB-INF</targetPath>
+                        <includes>
+                          <include>jetty-env.xml</include>
+                        </includes>
+                      </resource>
+                    </webResources>
+>>>>>>> bf803e1 (update eclipse project, fix resource basedir in pom, dockerfile commands more concise, fix myapp location due to using now docker-resources / webapp in target folder, add metadata-complete (optional))
                 <!-- containerConfigXML>WEB-INF/build/context.xml</containerConfigXML -->
             </configuration>
           </plugin>
@@ -254,9 +290,14 @@ under the License.
             <httpConnector>
               <port>8081</port>
             </httpConnector>
-            <!--webApp>
-              <contextPath>/app</contextPath>
-            </webApp-->
+            <webApp>
+                  <resourceBases>
+                      <resourceBase>#var("project.build.directory")/#var("project.build.finalName")</resourceBase>
+                  </resourceBases>
+                  <!--contextPath>/app</contextPath-->
+            </webApp>
+            <classesDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</classesDirectory>
+            <webAppSourceDirectory>${project.build.directory}/${project.build.finalName}</webAppSourceDirectory>
           </configuration>
         </plugin>
       </plugins>
@@ -315,10 +356,6 @@ under the License.
           <version>#var("turbine.core")</version>
           <!-- should be resolved after upgrade to torque-4.1 -->
           <exclusions>
-            <exclusion>
-                <groupId>commons-beanutils</groupId>
-                <artifactId>commons-beanutils-core</artifactId>
-            </exclusion>
           </exclusions>
       </dependency>
       <dependency>
@@ -411,11 +448,13 @@ under the License.
         <fulcrum.security>2.0.0</fulcrum.security>
         <fulcrum.yaafi>1.0.8</fulcrum.yaafi>
         <fulcrum.testcontainer>1.0.9</fulcrum.testcontainer>
-        <!--torque.version>5.1-SNAPSHOT</torque.version>
-        <fulcrum.intake>2.0.1-SNAPSHOT</fulcrum.intake>
-        <fulcrum.security>2.0.0-SNAPSHOT</fulcrum.security-->
-
-        <turbine.core>5.1-SNAPSHOT</turbine.core>
+        <turbine.core>5.0</turbine.core>
+        <!--
+            <torque.version>5.1-SNAPSHOT</torque.version>
+            <fulcrum.intake>2.0.1-SNAPSHOT</fulcrum.intake>
+            <fulcrum.security>2.0.0-SNAPSHOT</fulcrum.security>
+            <turbine.core>5.1-SNAPSHOT</turbine.core>
+        -->
         <skipTests>true</skipTests>
         <docker>false</docker>
         <turbine_database_url>${turbine_database_url}</turbine_database_url>
@@ -432,10 +471,10 @@ under the License.
                         <groupId>org.mortbay.jetty</groupId>
                         <artifactId>maven-jetty-plugin</artifactId>
                         <configuration>
-                          <httpConnector>
-                            <port>8081</port>
-                            <idleTimeout>60000</idleTimeout>
-                          </httpConnector>
+                            <httpConnector>
+                                <port>8081</port>
+                                <idleTimeout>60000</idleTimeout>
+                            </httpConnector>
                         </configuration>
                     </plugin>
                 </plugins>
@@ -486,8 +525,8 @@ under the License.
               </build>
             <properties>
                 <turbine_database_url>jdbc:mysql://db:3306/</turbine_database_url>
-                <!-- to provide e.g. local snapshot builds -->
-                <app_volume_local_repo>#var("settings.localRepository")</app_volume_local_repo>
+                <!-- read from #var("settings.localRepository") to provide e.g. local snapshot builds -->
+                <app_volume_local_repo>${settings.localRepository}</app_volume_local_repo>
                 <docker>true</docker>
             </properties>
         </profile>
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
new file mode 100644
index 0000000..ba732c5
--- /dev/null
+++ b/src/main/resources/archetype-resources/src/main/docker-resources/app/Dockerfile
@@ -0,0 +1,18 @@
+FROM maven:3-jdk-8 
+
+# cft hub.docker.com/r/library/maven
+# not used, as in docker-compose m2repo is set
+ADD ./docker-resources/app/settings.xml /usr/share/maven/ref/settings.xml
+
+# Set our working directory inside the image
+
+#ADD pom.xml /myapp/pom.xml
+#ADD src/ /myapp/src/
+
+WORKDIR /myapp
+
+# build app outside docker
+# no build stage volumes: https://github.com/moby/moby/issues/38366
+# run build process outside, requires having maven and java installed in host system.
+# uncomment only, if you have NO snapshots and you a reason to build it inside the container
+# RUN mvn -f /myapp/pom.xml clean package
diff --git a/src/main/resources/archetype-resources/src/main/docker-resources/app/settings.xml b/src/main/resources/archetype-resources/src/main/docker-resources/app/settings.xml
new file mode 100644
index 0000000..87fe023
--- /dev/null
+++ b/src/main/resources/archetype-resources/src/main/docker-resources/app/settings.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0    
+	 http://maven.apache.org/xsd/settings-1.0.0.xsd">
+<!--settings-->
+  <!-- localRepository set -->
+ <localRepository>/m2repo</localRepository>
+ <usePluginRegistry>false</usePluginRegistry>
+ <offline>false</offline>
+ <pluginGroups>
+    <pluginGroup>org.mortbay.jetty</pluginGroup>
+ </pluginGroups> 
+ <profiles>
+	   <profile>
+      <id>nexus</id>
+      <!--Enable snapshots for the built in central repo to direct -->
+      <!--all requests to nexus via the mirror -->
+      <repositories>
+        <repository>
+          <id>releases</id>
+          <url>http://central</url>
+          <releases><enabled>true</enabled></releases>
+          <snapshots><enabled>false</enabled></snapshots>
+        </repository>
+        <repository>
+          <releases><enabled>true</enabled></releases>
+          <snapshots><enabled>true</enabled></snapshots>
+          <id>snapshots</id>
+          <url>http://snapshots</url>
+        </repository>
+      </repositories>
+     <pluginRepositories>
+        <pluginRepository>
+          <id>releases</id>
+          <url>http://central</url>
+          <releases><enabled>true</enabled></releases>
+          <snapshots><enabled>true</enabled></snapshots>
+        </pluginRepository>
+		 <pluginRepository>
+         <releases><enabled>true</enabled></releases>
+          <snapshots><enabled>true</enabled></snapshots>
+          <id>snapshots</id>
+          <url>http://snapshots</url>
+        </pluginRepository>
+      </pluginRepositories>
+    </profile>
+    <profile> 
+      <id>repo1</id>
+      <activation>
+        <activeByDefault>false</activeByDefault>
+      </activation>
+      <pluginRepositories>
+        <pluginRepository>
+          <id>central</id>
+          <name>Maven Plugin Repository</name>
+          <url>http://repo1.maven.org/maven2</url>
+          <layout>default</layout>
+          <snapshots>
+            <enabled>false</enabled>
+          </snapshots>
+          <releases>
+            <updatePolicy>never</updatePolicy>
+          </releases>
+        </pluginRepository>
+     </pluginRepositories> 
+    </profile>
+  </profiles>
+</settings>
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/Dockerfile
new file mode 100644
index 0000000..932a800
--- /dev/null
+++ b/src/main/resources/archetype-resources/src/main/docker-resources/db/Dockerfile
@@ -0,0 +1,65 @@
+#using multi-stage
+
+# mariadb use docker-entrypoint 
+FROM mysql:latest as builder
+
+# That file does the DB initialization but also runs mysql daemon, by removing the last line it will only init
+RUN ["/bin/sed", "-i", "s/exec \"$@\"/echo \"not running $@\"/", "/usr/local/bin/docker-entrypoint.sh"]
+
+#
+# check where and what configurations are read with e.g.
+# docker-compose run db /usr/sbin/mysqld --verbose --help | grep -A 1 "Default options"
+# docker run <image> /usr/sbin/mysqld --verbose --help | grep -A 1 "Default options"
+
+ARG DB_CONTEXT
+ARG MYSQL_DATABASE
+ARG MYSQL_ROOT_PASSWORD
+ARG MYSQL_RANDOM_ROOT_PASSWORD
+ARG MYSQL_USER
+ARG MYSQL_PASSWORD
+ARG MYSQL_ONETIME_PASSWORD
+
+# mount in docker-compose
+ADD #var("DB_CONTEXT:-.")/mysql/conf/my.cnf /etc/
+# mysql requires to be restricted
+RUN chmod a-w /etc/my.cnf
+
+# for logs
+RUN mkdir -p /mysql/log
+RUN chmod -R a+w /mysql
+
+
+COPY generated-sql/torque/mysql /generated-sql-init
+# dependent sql should be name sorted after init.sql
+# add what you need, avoid duplicate keys
+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
+
+# required, to create
+
+ENV DB_CONTEXT ${DB_CONTEXT}
+ENV MYSQL_DATABASE ${MYSQL_DATABASE}
+ENV MYSQL_ROOT=root
+ENV MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
+
+ENV MYSQL_USER=${MYSQL_USER}
+ENV MYSQL_PASSWORD=${MYSQL_PASSWORD}
+ENV MYSQL_HOST=
+ENV MYSQL_RANDOM_ROOT_PASSWORD ${MYSQL_RANDOM_ROOT_PASSWORD}
+ENV MYSQL_ONETIME_PASSWORD=${MYSQL_ONETIME_PASSWORD}
+
+# Need to change the datadir to something else that /var/lib/mysql because the parent docker file defines it as a volume.
+# https://docs.docker.com/engine/reference/builder/#volume :
+#       Changing the volume from within the Dockerfile: If any build steps change the data within the volume after
+#       it has been declared, those changes will be discarded.
+
+RUN ["/usr/local/bin/docker-entrypoint.sh", "mysqld", "--datadir", "/initialized-db"]
+
+FROM mysql:latest
+
+# my.cnf setting data-dir 
+COPY --from=builder /initialized-db /var/lib/mysql
+
+
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
new file mode 100644
index 0000000..5ae1d2a
--- /dev/null
+++ b/src/main/resources/archetype-resources/src/main/docker-resources/docker-compose.yml
@@ -0,0 +1,82 @@
+# service configuration for our dockerized Java app
+version: '3'
+
+services:
+  app:
+    # use the Dockerfile next to this file
+    build:
+        context: ../
+        dockerfile: ./docker-resources/app/Dockerfile
+    # uncomment, if no remote debugging app is required
+    environment:
+        - MAVEN_OPTS=-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9000
+    
+    # this runs the app server in the container
+    #command: mvn clean package jetty:run -Pdocker
+    command: mvn jetty:run -Pdocker
+    ports:
+      - "8081:8081"
+      # remote debugging port, uncomment if not needed
+      - "9000:9000"
+
+    # makes the app container aware of the DB container   
+    depends_on:
+      - db 
+    # 
+    #expose:
+    #  - "3000"
+
+    volumes:
+      # project root wtih pom.xml and src folder
+      - ../../:/myapp
+      # or use local sapp/ettings.xml
+      - '#var("app_volume_local_repo"):/m2repo'
+
+  db:
+      # set the build context 
+    build: 
+      context: ../
+      dockerfile: ./docker-resources/db/Dockerfile
+      args:
+        - DB_CONTEXT=./docker-resources/db
+        - MYSQL_DATABASE=turbine
+        #- MYSQL_ROOT_PASSWORD=default
+        - MYSQL_RANDOM_ROOT_PASSWORD=yes
+        - MYSQL_USER=db_user
+        - MYSQL_PASSWORD=db_password
+        - MYSQL_ONETIME_PASSWORD=false
+    
+    environment:
+      - MYSQL_DATABASE=turbine
+      - MYSQL_HOST= 
+      #- MYSQL_ROOT_PASSWORD=default
+      - MYSQL_RANDOM_ROOT_PASSWORD=yes
+      - MYSQL_USER=db_user
+      - MYSQL_PASSWORD=db_password
+      - DB_CONTEXT=./docker-resources/db
+      - MYSQL_ONETIME_PASSWORD=false
+      #- MYSQL_ALLOW_EMPTY_PASSWORD=yes
+      
+    volumes:
+      - "./db/mysql/init:/docker-entrypoint-initdb.d"   
+      - "/db/mysql/conf:/etc/mysql/conf.d"
+      - "./db/mysql/data:/data" 
+      # default mysql persistent data
+      - mysql_log:/mysql/log:rw 
+      - db_data:/var/lib/mysql:rw  
+    restart: always     
+    ports:
+      # host: container
+      - "13306:3306"
+      
+    #networks:
+    #  - db
+    #command: [mysqld, --character-set-server=utf8mb4, --collation-server=utf8mb4_unicode_ci]
+    command: --default-authentication-plugin=mysql_native_password
+
+volumes:
+  db_data:
+  mysql_log:
+  
+#networks:
+#  db:
diff --git a/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml b/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
index 62fa581..eadf3ee 100644
--- a/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
+++ b/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
@@ -13,7 +13,7 @@
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                              http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
-         version="3.1">
+         version="3.1" metadata-complete="true">
 	<!-- ======================================================================== -->
 	<!-- -->
 	<!-- Web Application descriptor -->