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 2019/01/15 10:28:46 UTC

[turbine-archetypes] branch docker updated: cleanup and fix build process; explicitely build artifacts outside container, current focus on integrationtest project build

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

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


The following commit(s) were added to refs/heads/docker by this push:
     new 583091d  cleanup and fix build process; explicitely build artifacts outside container, current focus on integrationtest project build
583091d is described below

commit 583091d4762f456c964f9f03b2865440632dad59
Author: Georg Kallidis <ge...@fu-berlin.de>
AuthorDate: Tue Jan 15 11:28:30 2019 +0100

    cleanup and fix build process; explicitely build artifacts outside container, current focus on integrationtest project build
---
 .../docker-resources/app/Dockerfile                |  4 +-
 .../docker-resources/db/Dockerfile                 | 23 +++++---
 .../docker-resources/docker-compose.yml            | 23 +++++---
 .../archetype-resources/docker-resources/readme.md | 66 +++++++++++++---------
 4 files changed, 74 insertions(+), 42 deletions(-)

diff --git a/src/main/resources/archetype-resources/docker-resources/app/Dockerfile b/src/main/resources/archetype-resources/docker-resources/app/Dockerfile
index c241859..e1022d2 100644
--- a/src/main/resources/archetype-resources/docker-resources/app/Dockerfile
+++ b/src/main/resources/archetype-resources/docker-resources/app/Dockerfile
@@ -10,6 +10,8 @@ ADD src/ /myapp/src/
 
 WORKDIR /myapp
 
-# build app outside docker, if you use snapshots
+# 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/docker-resources/db/Dockerfile b/src/main/resources/archetype-resources/docker-resources/db/Dockerfile
index 45dacda..555e234 100644
--- a/src/main/resources/archetype-resources/docker-resources/db/Dockerfile
+++ b/src/main/resources/archetype-resources/docker-resources/db/Dockerfile
@@ -1,7 +1,7 @@
 #using multi-stage
 
 # mariadb use docker-entrypoint 
-FROM mysql:latest  as builder
+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"]
@@ -12,6 +12,13 @@ RUN ["/bin/sed", "-i", "s/exec \"$@\"/echo \"not running $@\"/", "/usr/local/bin
 # 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/
 
@@ -31,15 +38,17 @@ ADD ./target/generated-sql/torque/mysql/*.sql ./data/
 ADD ./docs/sample-mysql-data/*.sql ./data/
 
 # required, to create
-ENV DB_CONTEXT #var("DB_CONTEXT")
 
-ENV MYSQL_DATABASE=${turbine_database_name}
+ENV DB_CONTEXT ${DB_CONTEXT}
+ENV MYSQL_DATABASE ${MYSQL_DATABASE}
 ENV MYSQL_ROOT=root
-ENV MYSQL_ROOT_PASSWORD=default
-ENV MYSQL_USER=${turbine_database_user}
-ENV MYSQL_PASSWORD=${turbine_database_password}
+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 yes
+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 :
diff --git a/src/main/resources/archetype-resources/docker-resources/docker-compose.yml b/src/main/resources/archetype-resources/docker-resources/docker-compose.yml
index acbf359..bbe4ca2 100644
--- a/src/main/resources/archetype-resources/docker-resources/docker-compose.yml
+++ b/src/main/resources/archetype-resources/docker-resources/docker-compose.yml
@@ -12,7 +12,8 @@ services:
         - 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 clean package jetty:run -Pdocker
+    command: mvn jetty:run
     ports:
       - "8081:8081"
       - "8080:8080"
@@ -38,16 +39,24 @@ services:
       context: ../
       dockerfile: ./docker-resources/db/Dockerfile
       args:
-        - DB_CONTEXT=${DB_CONTEXT}
+        - 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_database_name}
+      - MYSQL_DATABASE=turbine
       - MYSQL_HOST= 
-      - MYSQL_ROOT_PASSWORD=default
-      - MYSQL_USER=${turbine_database_user}
-      - MYSQL_PASSWORD=${turbine_database_password}
+      #- MYSQL_ROOT_PASSWORD=default
+      - MYSQL_RANDOM_ROOT_PASSWORD=yes
+      - MYSQL_USER=db_user
+      - MYSQL_PASSWORD=db_password
       - DB_CONTEXT=./docker-resources/db
-      #- MYSQL_RANDOM_ROOT_PASSWORD=yes
+      - MYSQL_ONETIME_PASSWORD=false
+      #- MYSQL_ALLOW_EMPTY_PASSWORD=yes
       
     volumes:
       - "./db/mysql/init:/docker-entrypoint-initdb.d" 
diff --git a/src/main/resources/archetype-resources/docker-resources/readme.md b/src/main/resources/archetype-resources/docker-resources/readme.md
index 2453ed3..2f4c711 100644
--- a/src/main/resources/archetype-resources/docker-resources/readme.md
+++ b/src/main/resources/archetype-resources/docker-resources/readme.md
@@ -1,6 +1,10 @@
 # Introduction
 
-This docker environment is to test/develop a Turbine app using a docker test database. 
+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.
 
@@ -10,9 +14,21 @@ Docker compose uses two services: **app** (maven:3-jdk-8) and **db** (mysql:late
 - 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.
 
-# Installation
+# Prepare
+
+To run the build with maven do this outside of the container using following mvn command:
+
+```
+mvn clean 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.
 
-- Change into docker resource folder
+
+# Installation (running the app)
+
+- Change into the projects docker resource folder
 
 ```sh
 cd docker-resources
@@ -23,8 +39,8 @@ cd docker-resources
 - Check services in docker-compose.yml (volumes) 
 ``` 
 docker-compose config
-```   
-- Check **src/main/webapp/WEB-INF/jetty-env.xml**. It should reference the service name (db) not localhost.
+```
+- Check database service call in **src/main/webapp/WEB-INF/jetty-env.xml**. It should reference the service name (db), not localhost - as it is also set in maven docker profile.
 
 ```xml
 <Set name="url">jdbc:mysql://db:3306/turbine</Set>
@@ -32,30 +48,22 @@ docker-compose config
 
 ## Cleanup or restart (optional)
 
-- Optionally Check system, Cleanup
-
-    docker-compose ps
-    docker-compose down
-    docker-compose down -v
+- 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
-  
-- or remove by
-    docker-compose down and docker-compose down -v
 
-- Starting the app service will build the app and start jetty as a Maven install + Jetty start. 
-This command is set as a **command** in the app service in docker compose.
-The docker profile should be activated by default (if not add -Pdocker). 
+- 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. 
 
-Optionally test the build process on the host with mvn clean install -f ../pom.xml.
+If not yet done, build on the host with mvn clean install -f ../pom.xml -Pdocker.
 
 ### Build Services
 
- - Set DB_CONTEXT=./docker-resources/db if not yet done for the db service on docker-compose.yml or provide as cli argument:
+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, e.g. 5.6.
 
-    docker-compose build --no-cache --build-arg DB_CONTEXT=./docker-resources/db
-     .. or just build it
+ - Build it
  
 ```sh
     docker-compose build --no-cache
@@ -68,8 +76,7 @@ Optionally test the build process on the host with mvn clean install -f ../pom.x
     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. 
+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).
 
 
@@ -85,9 +92,9 @@ docker-compose -d up
 docker-compose start
 ``` 
 
-This will start first the db service, then the app service. Jetty is run and exposes the webapp to **http://localhost:8081/app**.
+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.
+You could follow the logs with docker-compose logs -f app or docker-compose logs -f db.
 
 #### Lifecycle (developers only)
 
@@ -126,17 +133,22 @@ ls -la /myapp // should list pom.xml ...
 
 ### Powershell
 
-- Replace in volume path backslashes to slashes "/" in docker-compose.yml in localRepository
+- 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: for db  Cannot start service db: driver failed programming external connectivity on endpoint docker-resources_db_1 ..
+- 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 on your machine & restart it.
+  - If error still there, restart Docker Desktop on your machine.
 
 ### Windows Subsystem for Linux (WSL)