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:19 UTC

[turbine-archetypes] 04/05: added missing db resources, fixed pom merge, pass docker variable from archetype, add docker outputs, add scanIntervalSeconds

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 d292503f5060a3e9846772164714bb0efe8c8169
Author: Georg Kallidis <gk...@apache.org>
AuthorDate: Tue Jul 13 14:04:17 2021 +0200

    added missing db resources, fixed pom merge, pass docker variable from archetype, add docker outputs, add scanIntervalSeconds
---
 .../META-INF/maven/archetype-metadata.xml          |   3 +
 .../archetype-resources/docs/DOCKER-README.md      | 219 +++++++++++++++++++++
 .../resources/archetype-resources/docs/README.md   |   6 +-
 src/main/resources/archetype-resources/pom.xml     |   5 +-
 .../src/main/docker-resources/db/mysql/conf/my.cnf |  34 ++++
 .../main/docker-resources/db/mysql/init/data.sql   |   0
 .../src/main/docker-resources/db/mysql/log/log.out |   0
 .../src/main/docker-resources/docker-compose.yml   |   2 +-
 8 files changed, 265 insertions(+), 4 deletions(-)

diff --git a/src/main/resources/META-INF/maven/archetype-metadata.xml b/src/main/resources/META-INF/maven/archetype-metadata.xml
index e08af95..749675b 100644
--- a/src/main/resources/META-INF/maven/archetype-metadata.xml
+++ b/src/main/resources/META-INF/maven/archetype-metadata.xml
@@ -57,6 +57,9 @@
      <requiredProperty key="app_volume_local_repo">
         <defaultValue>${settings.localRepository}</defaultValue>
      </requiredProperty>
+     <requiredProperty key="docker">
+        <defaultValue>${docker}</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-README.md
new file mode 100644
index 0000000..9ccca34
--- /dev/null
+++ b/src/main/resources/archetype-resources/docs/DOCKER-README.md
@@ -0,0 +1,219 @@
+# Introduction
+
+This is to help developers to get fast a running development environment for debugging.
+
+This Docker environment is to test/develop a Turbine app using a docker test database. 
+
+The build should take place outside the docker container.
+
+It is based on one docker-compose.yml file and two Dockerfiles.
+
+Docker compose uses currently two services: **app** (maven:3-jdk-8) and **db** (mysql:latest). 
+
+## Note
+- Mysql should easily be replacable by Mariadb. 
+- Instead of using maven as the app service a Jetty container might be the better choice as currently console reloading might not work.
+
+# Prepare
+
+To run the build with maven do this outside of the container using following mvn command:
+
+```
+mvn install -Pdocker
+```
+
+N.B.: This builds the integrationtest project in target/test-classes/projects/first/project/integrationtest with docker enabled configuration. 
+Running the build inside the container is not required and may be problematic, unless you use only public available dependencies.
+
+
+# Installation (running the app)
+
+- Change into the projects target/docker resource folder
+
+```sh
+cd  target/docker-resources
+``` 
+
+## Check Docker Compose file (optional)
+
+- Check services in docker-compose.yml (volumes) 
+``` 
+docker-compose config
+```
+
+N.B. You may use the command *docker compose* or *docker-compose*, but will slightly different results.
+
+- Check database service call in ** target/<projectname>/WEB-INF/jetty-env.xml**. It should reference the service name (db), not localhost - as it is also set in maven docker profile.
+
+- To change velocity templates check webapp in ** src/main/webapp**. 
+
+```xml
+<Set name="url">jdbc:mysql://db:3306/turbine</Set>
+```
+
+## Cleanup or restart (optional)
+
+- Optionally Check system or cleanup, e.g. with docker-compose down, docker-compose down -v or docker sytem prune (removes any container on system).
+
+- If services are already installed, activate/start by 
+    docker-compose up
+    
+ Example Logs:
+  
+    [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.25-1debian10 started.
+    [Note] [Entrypoint]: Switching to dedicated user 'mysql'
+    [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.25-1debian10 started.
+
+    [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.25) starting as process 1
+    [System] [MY-013576] [InnoDB] InnoDB initialization has started.
+    [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
+     [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
+    [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
+    [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
+    [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
+    [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.25'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.
+    
+    Listening for transport dt_socket at address: 9000
+
+    [INFO] Scanning for projects...
+    [INFO]
+    [INFO] ------< org.apache.turbine.test.integrationtest:integrationtest >-------
+    [INFO] Building My Turbine Web Application 1.0.0-SNAPSHOT
+    [INFO] --------------------------------[ war ]---------------------------------
+    [INFO]
+    [INFO] >>> jetty-maven-plugin:9.4.43.v20210629:run (default-cli) > test-compile @ integrationtest >>>
+    [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. 
+This command is set as a **command** in the app service in docker compose. 
+
+If not yet done, build on the host with mvn clean install -f ../pom.xml -Pdocker.
+
+### Build Services
+
+The app service uses later a volume, which maps to the local maven repository, which you may need/not need.
+The db service uses mysql-latest (currently 8.x), you may replace it with a fixed release tag.
+
+ - Build it
+ 
+```sh
+    docker-compose build --no-cache
+```
+
+ .. optionally build it separately
+    docker-compose build --no-cache --build-arg DB_CONTEXT=./docker-resources/db db
+    
+ .. building app service first/only requires removing the dependency in docker-compose.yml(comment depends_on: db)
+    docker-compose build --no-cache app
+
+DB_CONTEXT is set to allow starting the db container standalone (in folder db, e.g. with docker build --tag my-db .)
+to test it.  CAVEAT: The db service is build and populated until now with hard coded data. 
+It is a dependency for the service app (see app/Dockerfile).
+
+
+### Starting Services
+
+Start both services in one step
+``` 
+docker-compose up
+```    
+.. or doing it in background, requires second start command
+``` 
+docker-compose -d up
+docker-compose start
+``` 
+
+This will start first the db service, then the app service. Jetty is run exposing the webapp to **http://localhost:8081/app**.
+By default remote debugging is activated (port 9000), which could be removed/commented in docker-compose.yml.
+You could follow the logs with docker-compose logs -f app or docker-compose logs -f db.
+
+#### Lifecycle (developers only)
+
+- If you generate the archetype itself, you might have to stop the services before cleaning up (docker-compose stop).
+
+## Debugging Services: Db, App
+
+### Db Service 
+``` 
+docker-compose run --rm db /bin/sh --build-arg DB_CONTEXT=./docker-resources/db
+``` 
+Extract data in db service
+
+```sh
+ mysql -u root -h db -P 3306 -p
+```
+.. or 
+
+    docker-compose exec db mysql -u root --password=... -e "show databases;" --build-arg DB_CONTEXT=./docker-resources/db
+    docker-compose exec db sh -c 'exec mysqldump --all-databases -uroot -p...' --build-arg DB_CONTEXT=./docker-resources/db > dump.sql
+
+### App Service
+
+This will start app and db (as it depends on app):
+```sh
+docker-compose run --rm app /bin/sh 
+``` 
+In the container, check:
+```sh
+ls -la /myapp // should list pom.xml ...
+```
+
+# System Specific Informations
+
+## Windows
+
+### Powershell
+
+- Use Powershell
+
+- Replace in volume mapping for host repo path (maven localRepository) backslashes with slashes "/" in docker-compose.yml.
+
+- check COMPOSE_CONVERT_WINDOWS_PATHS, https://docs.docker.com/compose/reference/envvars/#compose_convert_windows_paths
+
+- If a image download fails, try Docker->Network->Update DNS to 8.8.8.8
+
+- ERROR, when starting docker-compose up/start:
+ "for db  Cannot start service db: driver failed programming external connectivity on endpoint docker-resources_db_1 or
+ERROR: for docker-resources_db_1  Cannot start service db: driver failed programming external connectivity on endpoint docker-resources_db_1 ... 
+Error starting userland proxy: mkdir /port/tcp:0.0.0.0:13306:tcp:...:3306: input/output error"
+
+  - Check if containers not already running.
+  - Remove containers (if any): docker rm $(docker ps -a -q)
+  - If error still there, restart Docker Desktop on your machine.
+
+### Windows Subsystem for Linux (WSL)
+
+- Check file permissions of archetype generated files (chmod -R a+rw docker-resources, chmod -R a+rw src .
+
+- https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly
+
+
+## More Internals, Helpful Docker commands
+
+### Resetting / Preparation (optional)
+
+    docker-compose rm -v
+
+### Delete all images
+
+    docker rmi $(docker images -q)
+
+### Still more docker commands ...
+
+  docker ps  
+ 
+  // 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)
diff --git a/src/main/resources/archetype-resources/docs/README.md b/src/main/resources/archetype-resources/docs/README.md
index 7d9fc0b..808c903 100644
--- a/src/main/resources/archetype-resources/docs/README.md
+++ b/src/main/resources/archetype-resources/docs/README.md
@@ -26,6 +26,10 @@ under the License.
 
 Turbine Version: Turbine 5.1.
 
+### Docker Setup
+
+See DOCKER-README.md
+
 ### Local database Setup
 
 First, you should have a local database installed and configured prior to 
@@ -136,7 +140,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 jetty:run         
+mvn -Pjetty
 
 - Now you can launch your new Turbine application by default [http://localhost:8081/app] (check port in pom.xml, if needed).
 
diff --git a/src/main/resources/archetype-resources/pom.xml b/src/main/resources/archetype-resources/pom.xml
index 3bc2122..100afa5 100644
--- a/src/main/resources/archetype-resources/pom.xml
+++ b/src/main/resources/archetype-resources/pom.xml
@@ -399,8 +399,7 @@ under the License.
         <fulcrum.cache>2.0.0</fulcrum.cache>
         <fulcrum.testcontainer>1.0.9</fulcrum.testcontainer>
         <torque.version>5.1-SNAPSHOT</torque.version>
-         <turbine.core>5.1-SNAPSHOT</turbine.core>
-        
+         <turbine.core>5.1-SNAPSHOT</turbine.core>     
         <!--
              <torque.version>5.0</torque.version>
             <turbine.core>5.0</turbine.core>
@@ -428,6 +427,8 @@ under the License.
                         <artifactId>jetty-maven-plugin</artifactId>
                          <version>9.4.43.v20210629</version>
                          <configuration>
+                           <!-- https://www.eclipse.org/jetty/documentation/jetty-9/index.html#jars-scanned-for-annotations -->
+                            <scanIntervalSeconds>10</scanIntervalSeconds>
                             <httpConnector>
                                 <port>8081</port>
                                 <idleTimeout>60000</idleTimeout>
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
new file mode 100644
index 0000000..940f84b
--- /dev/null
+++ b/src/main/resources/archetype-resources/src/main/docker-resources/db/mysql/conf/my.cnf
@@ -0,0 +1,34 @@
+# read https://hub.docker.com/_/mysql/
+# 
+
+[mysqld]
+
+#
+# * Basic Settings
+#
+#user            = mysql
+#pid-file        = /var/run/mysqld/mysqld.pid
+#socket          = /var/run/mysqld/mysqld.sock
+
+character-set-server=utf8
+
+# in mysql image VOLUME /var/lib/mysql and any changes to this directory 
+# during build process might got lost after the build step is done 
+# match db_data in docker-compose
+
+datadir     = /initialized-db
+
+#tmpdir          = /tmp
+
+# default 0.0.0.0,  if this is 127.0.0.1 and using docker this restricts listening to only inside container, 
+# which does not make sense in docker-compose services 
+# skip-networking,
+#bind-address = 0.0.0.0
+
+[mysql]
+tee=/mysql/log/log.out
+
+[mysqld_safe]
+#socket          = /var/run/mysqld/mysqld.sock
+nice            = 0
+
diff --git a/src/main/resources/archetype-resources/src/main/docker-resources/db/mysql/init/data.sql b/src/main/resources/archetype-resources/src/main/docker-resources/db/mysql/init/data.sql
new file mode 100644
index 0000000..e69de29
diff --git a/src/main/resources/archetype-resources/src/main/docker-resources/db/mysql/log/log.out b/src/main/resources/archetype-resources/src/main/docker-resources/db/mysql/log/log.out
new file mode 100644
index 0000000..e69de29
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 5ae1d2a..89fb5e8 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
@@ -13,7 +13,7 @@ services:
     
     # this runs the app server in the container
     #command: mvn clean package jetty:run -Pdocker
-    command: mvn jetty:run -Pdocker
+    command: mvn -Pjetty
     ports:
       - "8081:8081"
       # remote debugging port, uncomment if not needed