From be22ed4fe35624d1edf87938d05d9eef7a09ad00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Sat, 7 May 2022 16:35:50 +0200 Subject: [PATCH] feat: better docker-compose --- .env | 19 ++++++++ .gitignore | 2 +- build.gradle | 8 +--- docker-compose.yml | 109 ++++++++++++++++++++------------------------- 4 files changed, 70 insertions(+), 68 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000..2e0057f --- /dev/null +++ b/.env @@ -0,0 +1,19 @@ +# Paths +INIT_PATH=./workdir/init/ +DEPLOYMENT_PATH=./build/libs/ +DATABASE_INIT_PATH=./workdir/db/init/ +DATABASE_DATA_PATH=./mysql-volume/ + +# Wildfly config +WILDFLY_VERSION=23.0.0.Final +WILDFLY_DEBUG=false +WILDFLY_ADMIN_USER=admin +WILDFLY_ADMIN_PASS=pass + +# MySQL config +MYSQL_VERSION=8.0 +MYSQL_DATABASE=pixel +MYSQL_USER=mysql +MYSQL_PASSWORD=mysql +MYSQL_ROOT_PASSWORD=pass +MYSQL_CONNECTOR_VERSION=8.0.23 diff --git a/.gitignore b/.gitignore index ae41428..5fccfe8 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,4 @@ build bin # Ignore docker volume directory -mariadb +mysql-volume diff --git a/build.gradle b/build.gradle index 54a06a2..54afc9f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,6 @@ plugins { id 'java' id 'war' - id "org.wildfly.build.provision" version "0.0.11" -} - -provision { - variables['wildfly.version'] = '11.0.0.Final' } repositories { @@ -24,7 +19,7 @@ dependencies { implementation 'com.google.code.gson:gson:2.8.6' implementation 'org.hibernate:hibernate-core:5.4.30.Final' - implementation 'mysql:mysql-connector-java:8.0.24' + // implementation 'mysql:mysql-connector-java:8.0.24' // des fonctions pratiques implementation 'org.apache.commons:commons-lang3:3.0' @@ -36,7 +31,6 @@ dependencies { // pour des getters/setters auto compileOnly 'org.projectlombok:lombok:1.18.24' annotationProcessor 'org.projectlombok:lombok:1.18.24' - testCompileOnly 'org.projectlombok:lombok:1.18.24' testAnnotationProcessor 'org.projectlombok:lombok:1.18.24' } diff --git a/docker-compose.yml b/docker-compose.yml index 0b0e609..8b4636a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,71 +1,60 @@ -version: "3" +version: "2" services: wildfly: - image: quay.io/wildfly/wildfly container_name: wildfly hostname: wildfly - ports: - - 8080:8080 - - 9990:9990 - volumes: - - ./build/libs/:/opt/jboss/wildfly/standalone/deployments/ + image: kaaass/wildfly-mysql environment: - - WILDFLY_USERNAME=admin - - WILDFLY_PASSWORD=password - - DB_PORT=3306 - - DB_HOST=mariadb - command: > - bash -c ' - - ( - sleep 15 && - /opt/jboss/wildfly/bin/jboss-cli.sh \ - --connect controller=127.0.0.1 \ - --command=" \ - data-source add \ - --jndi-name=java:/MySqlDS \ - --name=MySQLDS \ - --connection-url=jdbc:mysql://$$DB_HOST:$$DB_PORT/mydatabase \ - --driver-name=backend.war_com.mysql.cj.jdbc.Driver_8_0 \ - --user-name=$$WILDFLY_USERNAME \ - --password=$$WILDFLY_PASSWORD \ - " - )& - - /opt/jboss/wildfly/bin/add-user.sh admin password --silent && - - /opt/jboss/wildfly/bin/standalone.sh -b 0.0.0.0 -bmanagement 0.0.0.0' + - WILDFLY_DEBUG=${WILDFLY_DEBUG} + - WILDFLY_USER=${WILDFLY_ADMIN_USER} + - WILDFLY_PASS=${WILDFLY_ADMIN_PASS} + - DB_NAME=${MYSQL_DATABASE} + - DB_USER=${MYSQL_USER} + - DB_PASS=${MYSQL_PASSWORD} + - DB_URI=db:3306 depends_on: - mariadb: - condition: service_healthy - restart: always - - mariadb: - image: mariadb - container_name: mariadb - hostname: mariadb - environment: - - MYSQL_USER=user - - MYSQL_PASSWORD=mypassword - - MYSQL_DATABASE=mydatabase - - MYSQL_ROOT_PASSWORD=rootpassword - ports: - - 3306:3306 + # db: + # condition: service_healthy + - db volumes: - - ./mariadb/:/var/lib/mysql/ - healthcheck: - test: - [ - "CMD-SHELL", - 'mysqladmin -p$$MYSQL_ROOT_PASSWORD -h localhost ping | grep "mysqld is alive" || exit 1', - ] - interval: 2s - retries: 10 - restart: always + - ${DEPLOYMENT_PATH}:/opt/jboss/wildfly/standalone/deployments/:rw + # - ${INIT_PATH}:/opt/jboss/wildfly/customization/init.d + ports: + - "8080:8080" # application + - "9990:9990" # admin console + - "8787:8787" # java debug + restart: unless-stopped + db: + container_name: db + hostname: db + image: "mysql:${MYSQL_VERSION}" + environment: + - MYSQL_DATABASE=${MYSQL_DATABASE} + - MYSQL_USER=${MYSQL_USER} + - MYSQL_PASSWORD=${MYSQL_PASSWORD} + - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} + volumes: + # - ${DATABASE_INIT_PATH}:/docker-entrypoint-initdb.d/ # init database + - ${DATABASE_DATA_PATH}:/var/lib/mysql/ # data storage + ports: + - "13306:3306" + # cap_add: + # - SYS_NICE + # healthcheck: + # test: + # [ + # "CMD-SHELL", + # 'mysqladmin -p$$MYSQL_ROOT_PASSWORD -h localhost ping | grep "mysqld is alive" || exit 1', + # ] + # interval: 2s + # retries: 20 + restart: unless-stopped volumes: - wildfly_data: - driver: local - mariadb: + db-data: driver: local + +networks: + default: + driver: bridge