FEAT: tout fonctionne inch

This commit is contained in:
Laureηt 2022-05-10 22:22:52 +02:00
parent aa247464bb
commit ffd8c9f57a
No known key found for this signature in database
GPG key ID: D88C6B294FD40994
11 changed files with 190 additions and 37 deletions

19
.env
View file

@ -1,19 +0,0 @@
# 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

2
.gitignore vendored
View file

@ -7,4 +7,4 @@ bin
.sass-cache
# Ignore docker volume directory
mysql-volume
docker/mariadb-volume/

View file

@ -18,8 +18,8 @@ dependencies {
// Pour pouvoir parser le JSON
implementation 'com.google.code.gson:gson:2.8.6'
// pour permettre la persistence des données dans une db
implementation 'org.hibernate:hibernate-core:5.4.30.Final'
// implementation 'mysql:mysql-connector-java:8.0.24'
// des fonctions pratiques
implementation 'org.apache.commons:commons-lang3:3.0'

9
docker/.env Normal file
View file

@ -0,0 +1,9 @@
# Wildfly config
WILDFLY_ADMIN_USER=admin
WILDFLY_ADMIN_PASS=pass
# MySQL config
MYSQL_DATABASE=pixel
MYSQL_USER=mysql
MYSQL_PASSWORD=mysql
MYSQL_ROOT_PASSWORD=pass

23
docker/Dockerfile Normal file
View file

@ -0,0 +1,23 @@
FROM quay.io/wildfly/wildfly
# Enviorment variables
ENV WILDFLY_USER admin
ENV WILDFLY_PASS pass
ENV DB_NAME sample
ENV DB_USER mysql
ENV DB_PASS mysql
ENV DB_URI localhost:3306
RUN echo "=> Downloading MariaDB driver"
RUN curl https://downloads.mariadb.com/Connectors/java/connector-java-3.0.4/mariadb-java-client-3.0.4.jar > /opt/jboss/mariadb.driver.jar
ENV JBOSS_CLI /opt/jboss/wildfly/bin/jboss-cli.sh
ENV DEPLOYMENT_DIR /opt/jboss/wildfly/standalone/deployments/
# Expose http and admin ports and debug port
EXPOSE 8080 9990
RUN mkdir -p ${JBOSS_HOME}/customization/init.d
ADD docker-entrypoint.sh /opt/jboss/wildfly/customization/
CMD ["/opt/jboss/wildfly/customization/docker-entrypoint.sh"]

33
docker-compose.yml → docker/docker-compose.yml Normal file → Executable file
View file

@ -1,26 +1,28 @@
version: "3"
services:
wildfly:
app:
hostname: wildfly
container_name: wildfly
image: kaaass/wildfly-mysql
build:
context: .
network: host
environment:
- 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=mariadb:3306
depends_on:
- db
- DB_URI=db:3306
volumes:
- ${DEPLOYMENT_PATH}:/opt/jboss/wildfly/standalone/deployments/:rw
- ../build/libs/:/opt/jboss/wildfly/standalone/deployments/
ports:
- "8080:8080" # application
- "9990:9990" # admin console
- "8787:8787" # java debug
depends_on:
db:
condition: service_healthy
restart: unless-stopped
db:
hostname: mariadb
@ -32,6 +34,19 @@ services:
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
volumes:
- ${DATABASE_DATA_PATH}:/var/lib/mysql/ # data storage
- ./mariadb-volume/:/var/lib/mysql/ # data storage
ports:
- "3306:3306"
healthcheck:
test:
[
"CMD-SHELL",
'mysqladmin -p$$MYSQL_ROOT_PASSWORD -h localhost ping | grep "mysqld is alive" || exit 1',
]
interval: 2s
retries: 30
restart: unless-stopped
volumes:
mariadb-volume:
driver: local

70
docker/docker-entrypoint.sh Executable file
View file

@ -0,0 +1,70 @@
#!/bin/bash
set -e
if [[ ! -f $JBOSS_HOME/.setup ]]; then
# run init script
if (ls ${JBOSS_HOME}/customization/init.d/* 1>/dev/null 2>&1); then
for f in ${JBOSS_HOME}/customization/init.d/*; do
echo "=> Run custom init script '$f'"
bash "$f"
done
fi
# Set environment variables
DATASOURCE=java:/jdbc/datasources/${DB_NAME}DS
# Setup WildFly admin user
echo "=> Add WildFly administrator"
$JBOSS_HOME/bin/add-user.sh -u $WILDFLY_USER -p $WILDFLY_PASS --silent
# Configure datasource
echo "=> Create datasource: '${DATASOURCE}'"
$JBOSS_CLI <<EOF
# Start WildFly in standalone mode to install mariadb module
embed-server --server-config=standalone.xml
# Batch the following operations
batch
# Add MariaDB module
module add \
--name=org.mariadb \
--dependencies=javax.api,javax.transaction.api \
--resources=/opt/jboss/mariadb.driver.jar \
# Configure driver
/subsystem=datasources/jdbc-driver=mariadb:add(driver-name="mariadb", driver-module-name="org.mariadb", driver-class-name="org.mariadb.jdbc.Driver")
# Add new datasource
data-source add \
--name=${DB_NAME}Pool \
--jndi-name=${DATASOURCE} \
--driver-name=mariadb \
--connection-url=jdbc:mariadb://${DB_URI}/${DB_NAME} \
--user-name=${DB_USER} \
--password=${DB_PASS} \
--check-valid-connection-sql="/* ping */ SELECT 1" \
--min-pool-size=10 \
--enabled=true
# Execute the batch
run-batch
# Exit from standalone mode
stop-embedded-server
EOF
echo "=> Clean up"
rm -rf $JBOSS_HOME/standalone/configuration/standalone_xml_history/* \
$JBOSS_HOME/standalone/log/* \
/tmp/*.jar
unset WILDFLY_USER WILDFLY_PASS DB_NAME DB_USER DB_PASS DATASOURCE
touch $JBOSS_HOME/.setup
echo "=> Setup finished !!"
fi
echo "=> Start WildFly"
# Boot WildFly in standalone mode and bind it to all interfaces (enable admin console and debug)
$JBOSS_HOME/bin/standalone.sh -b 0.0.0.0 -bmanagement 0.0.0.0

View file

@ -0,0 +1,8 @@
package com.pixels;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@ApplicationPath("/api")
public class Backend extends Application {
}

View file

@ -8,8 +8,8 @@ import java.io.Serializable;
@Data
@Entity
@NamedQuery(name = "Group.list", query = "SELECT g FROM Group g")
public class Group implements Serializable {
@NamedQuery(name = "Groupe.list", query = "SELECT g FROM Groupe g")
public class Groupe implements Serializable {
@Id // clé primaire
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ -20,5 +20,4 @@ public class Group implements Serializable {
@OneToOne // le wallet commun à tous les membres du groupe
private Wallet wallet;
}

View file

@ -0,0 +1,51 @@
package com.pixels.services;
import java.util.List;
import javax.ejb.Singleton;
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import com.google.gson.Gson;
import com.pixels.beans.Pixel;
@Singleton
@Path("/pixel")
public class PixelService {
@PersistenceContext
private EntityManager em;
Gson gson = new Gson();
@GET
@Produces(MediaType.APPLICATION_JSON)
public String list() {
List<Pixel> query = em.createNamedQuery("Pixel.list", Pixel.class).getResultList();
return gson.toJson(query);
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public JsonObject add() {
JsonObjectBuilder response = Json.createObjectBuilder();
Pixel pixel = new Pixel();
em.persist(pixel);
response.add("status", "pixel created !");
return response.build();
}
}

View file

@ -7,13 +7,10 @@
<jta-data-source>java:/jdbc/datasources/pixelDS</jta-data-source>
<properties>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="false" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MariaDB103Dialect" />
<!-- Ligne suivante à décommenter pour remettre à zéro la db au déploiement -->
<!-- <property name="hibernate.hbm2ddl.auto" value="create-drop" /> -->
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
</persistence>