Compare commits

..

9 Commits

Author SHA1 Message Date
625f1d23d0
Bump version 0.2.0 2020-04-28 00:54:39 +02:00
62a872f168
Adapt again for mysql 2020-04-28 00:52:12 +02:00
1f435d24a7
Add first README 2020-04-28 00:38:10 +02:00
f6b7d69dcf
Add docker-compose env 2020-04-28 00:38:05 +02:00
5aeedf7adc
Use configs and mysql as default connector 2020-04-28 00:38:00 +02:00
fbbd2c2035
Add docker runner env 2020-04-28 00:37:55 +02:00
b55e96c8a5
Add docker builder env 2020-04-28 00:37:50 +02:00
c39efa9cb3
Fix sql script syntax 2020-04-28 00:37:44 +02:00
77ae0353b3
Magic with eclipse, convert to maven project 2020-04-28 00:37:37 +02:00
21 changed files with 262 additions and 36 deletions

View File

@ -8,12 +8,16 @@
<attribute name="owner.project.facets" value="jst.web"/> <attribute name="owner.project.facets" value="jst.web"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.8.0_172"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.8">
<attributes> <attributes>
<attribute name="owner.project.facets" value="java"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="lib" path="C:/Users/margh/Downloads/ojdbc6.jar"/> <!-- <classpathentry kind="lib" path="drivers/mysql-connector-java-5.1.39.jar"/> -->
<classpathentry kind="lib" path="C:/Users/margh/Downloads/mysql-connector-java-5.1.39.jar"/> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<classpathentry kind="output" path="build/classes"/> <attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath> </classpath>

2
.dockerignore Normal file
View File

@ -0,0 +1,2 @@
/Dockerfile
/docker-compose*

2
.gitignore vendored
View File

@ -1 +1,3 @@
/build/ /build/
/target/
/.m2/

View File

@ -20,8 +20,14 @@
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec> </buildSpec>
<natures> <natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature> <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature> <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature> <nature>org.eclipse.wst.common.project.facet.core.nature</nature>

View File

@ -1,7 +1,11 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8 org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.5

View File

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

20
Dockerfile Normal file
View File

@ -0,0 +1,20 @@
FROM maven:latest AS builder
COPY . /src
WORKDIR /src
RUN mvn clean install
FROM tomcat:8.5
ARG PROJECT_NAME=centralino_brigate
ARG PROJECT_VERS=0.2.0
RUN cd /usr/local/tomcat/webapps.dist/ \
&& for FILE in *; do \
echo "Symlinking: $FILE -> /usr/local/tomcat/webapps/$FILE"; \
ln -s $PWD/$FILE /usr/local/tomcat/webapps/$FILE; \
done
COPY docker/tomcat-users.xml /usr/local/tomcat/conf/
COPY docker/host-manager/context.xml /usr/local/tomcat/webapps.dist/host-manager/META-INF/context.xml
COPY docker/manager/context.xml /usr/local/tomcat/webapps.dist/manager/META-INF/context.xml
COPY --from=builder /src/target/${PROJECT_NAME}-${PROJECT_VERS}.war /usr/local/tomcat/webapps/

12
Dockerfile.build Normal file
View File

@ -0,0 +1,12 @@
FROM maven:latest
ARG uid=1000
ARG gid=1000
RUN groupadd -g ${gid} app \
&& useradd -m -d /src -u ${uid} -g ${gid} app
USER app
WORKDIR /src
ENTRYPOINT ["mvn"]
CMD ["clean", "install"]

45
README.md Normal file
View File

@ -0,0 +1,45 @@
## Centralino Brigate
App in jsp per sostegno all'attività delle brigate di solidarietà.
## How to
### Prerequisiti
- `docker`
- `docker-compose`
### Dev
Se si vuole tirar su un ambiente di sviluppo locale con tomcat e un db mysql
```
$ docker-compose up
```
Si troverà l'app a `http://localhost:8080/centralino_brigate-0.2.0/`. *ATTENZIONE*: NON è
production-safe!
Se si vuole buildare l'artifatto (output in `war` nella cartella `target/`),
per prima cosa creare l'immagine per il processo di build con maven (solo la prima volta):
```
$ docker build -t unit/mvn-builder:latest -f Dockerfile.build .
```
Dopo di che:
```
$ docker run --rm -v $PWD:/src -t unit/mvn-builder:latest
```
Se si vuole dettaglio sul processo di build
```
$ docker run --rm -v $PWD:/src -t unit/mvn-builder:latest -e -X clean install
```
### Prod
TODO

24
docker-compose.yml Normal file
View File

@ -0,0 +1,24 @@
---
version: "3.7"
services:
db:
image: mysql:5
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=brigate
- MYSQL_USER=brigate
- MYSQL_PASSWORD=password
volumes:
- /var/lib/mysql
- ./sql/mysql/:/docker-entrypoint-initdb.d/
ports:
- 3306:3306
brigate:
build:
dockerfile: ./Dockerfile
context: .
image: unit/centralino_brigate:0.2.0
ports:
- 8080:8080

View File

@ -0,0 +1,3 @@
<Context antiResourceLocking="false" privileged="true" >
<Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>

View File

@ -0,0 +1,3 @@
<Context antiResourceLocking="false" privileged="true" >
<Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>

5
docker/tomcat-users.xml Normal file
View File

@ -0,0 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<role rolename="admin-gui"/>
<user username="unit" password="unit" roles="unit,admin-gui,manager-gui"/>
</tomcat-users>

44
pom.xml Normal file
View File

@ -0,0 +1,44 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>centralino_brigate</groupId>
<artifactId>centralino_brigate</artifactId>
<version>0.2.0</version>
<packaging>war</packaging>
<name>centralino_brigate</name>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.39</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
<!-- vim: set ft=xml et ts=2 sts=0: -->

View File

@ -1,21 +0,0 @@
use brigate;
CREATE TABLE CONTATTI
( NOME VARCHAR(255) NOT NULL,
COGNOME VARCHAR(255) NOT NULL ,
SERVIZIO_SOCIALE VARCHAR(255),
AREA VARCHAR(255),
INDIRIZZO VARCHAR(255) NOT NULL,
TELEFONO INTEGER PRIMARY KEY,
NUMERO INTEGER NOT NULL ,
COMPOSIZIONE_NUCLEO VARCHAR(255) NOT NULL ,
NOTE_SACCHETTO VARCHAR(255),
ULTIMA_CONSEGNA DATE,
EMAIL VARCHAR(256)
) ;
CREATE TABLE ORDINI
( TELEFONO INTEGER PRIMARY KEy REFERENCES CONTATTI(TELEFONO)
) ;

View File

@ -0,0 +1,25 @@
USE brigate;
CREATE TABLE contatti (
nome VARCHAR(255) NOT NULL,
cognome VARCHAR(255) NOT NULL,
servizio_sociale VARCHAR(255),
area VARCHAR(255),
indirizzo VARCHAR(255) NOT NULL,
telefono INT8 PRIMARY KEY,
numero INT8 NOT NULL,
composizione_nucleo VARCHAR(255) NOT NULL,
note_sacchetto VARCHAR(255),
ultima_consegna DATE,
email VARCHAR(256)
);
CREATE TABLE ordini (
telefono INT8 PRIMARY KEY REFERENCES contatti (telefono)
);
CREATE TABLE utenti (
nickname VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
ruolo VARCHAR(255)
);

View File

@ -12,7 +12,7 @@ import bean.Contatto;
public class ContattoDao implements ContattoDaoI { public class ContattoDao implements ContattoDaoI {
OracleConnection c = new OracleConnection(); MySqlConnection c = new MySqlConnection();
@Override @Override
public boolean create(String nome, String cognome, String servizio_sociale, String area, String indirizzo, public boolean create(String nome, String cognome, String servizio_sociale, String area, String indirizzo,

View File

@ -4,8 +4,11 @@ package dao;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.SQLException; import java.sql.SQLException;
import util.Config;
public class MySqlConnection { public class MySqlConnection {
Config cfg = new Config();
public static void main(String[] args) { public static void main(String[] args) {
MySqlConnection c = new MySqlConnection(); MySqlConnection c = new MySqlConnection();
@ -17,10 +20,10 @@ public class MySqlConnection {
public Connection open() { public Connection open() {
String nomeDriver = "com.mysql.driverDriver"; String nomeDriver = "com.mysql.jdbc.Driver";
String utente = "brigate"; //nome utente String utente = cfg.getDbUser(); //nome utente
String password = "password"; //password String password = cfg.getDbPass(); //password
String url = "jdbc:oracle:thin:@localhost:1521:orcl"; String url = "jdbc:mysql://" + cfg.getDbHost() + ":" + cfg.getDbPort() + "/brigate?autoReconnect=true&useSSL=false";
try { try {
Class.forName(nomeDriver); Class.forName(nomeDriver);
@ -42,4 +45,4 @@ public class MySqlConnection {
} }
} }
} }

View File

@ -9,7 +9,7 @@ import bean.Utente;
public class UtenteDao implements UtenteDaoI { public class UtenteDao implements UtenteDaoI {
OracleConnection c = new OracleConnection(); MySqlConnection c = new MySqlConnection();
@Override @Override
public boolean registrazione(String nickname, String password, String ruolo) { public boolean registrazione(String nickname, String password, String ruolo) {

41
src/util/Config.java Normal file
View File

@ -0,0 +1,41 @@
package util;
import java.io.FileNotFoundException;
import java.util.*;
import java.util.Properties;
public class Config {
Properties configFile;
public Config() {
configFile = new java.util.Properties();
try {
configFile.load(this.getClass().getClassLoader().getResourceAsStream("/etc/brigate/brigate.conf"));
} catch(FileNotFoundException ex) {
System.out.println("Missing config file");
}catch(Exception eta) {
eta.printStackTrace();
}
}
public String getDbUser() {
String user = this.configFile.getProperty("db_user", "brigate");
return user;
}
public String getDbPass() {
String pass = this.configFile.getProperty("db_password", "password");
return pass;
}
public String getDbHost() {
String host = this.configFile.getProperty("db_url", "db");
return host;
}
public String getDbPort() {
String port = this.configFile.getProperty("db_port", "3306");
return port;
}
}