diff --git a/.gitignore b/.gitignore index ee01dda..3f7e467 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ .idea/** +data/**/* + **/.DS_Store # Compiled class file @@ -138,4 +140,4 @@ gradle-app.setting # gradle/wrapper/gradle-wrapper.properties # IntelliJ -*.iml \ No newline at end of file +*.iml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 03683de..309580e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -63,4 +63,3 @@ code_quality: - build/reports/cpd/cpdCheck.xml #create a report on the quality of the code expose_as: 'Code Quality Report' - allow_failure: true diff --git a/Dockerfile b/Dockerfile index 7a6dc45..c931d3a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,9 @@ FROM openjdk:13-jdk-alpine -ENV DB_URL "" -ENV DB_USER "" -ENV DB_PASS "" + ARG JAR_FILE=build/libs/smarthut*.jar + COPY ${JAR_FILE} app.jar + +ENV SMARTHUT_THIS_VALUE_IS_PROD_IF_THIS_IS_A_CONTAINER_PIZZOCCHERI=prod EXPOSE 8080 ENTRYPOINT ["java","-jar","/app.jar"] diff --git a/HELP.md b/HELP.md deleted file mode 100644 index 6b12689..0000000 --- a/HELP.md +++ /dev/null @@ -1,13 +0,0 @@ -# Getting Started - -### Reference Documentation -For further reference, please consider the following sections: - -* [Official Gradle documentation](https://docs.gradle.org) -* [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/2.2.4.RELEASE/gradle-plugin/reference/html/) - -### Additional Links -These additional references should also help you: - -* [Gradle Build Scans – insights for your project's build](https://scans.gradle.com#gradle) - diff --git a/README.md b/README.md index d483ec4..f588721 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,53 @@ # backend +## Installation guide + +In order to install a SmartHut.sm, you can use *Docker* and *Docker Compose* +in order to create che corresponding containers. + +Use the following `docker-compose.yml` example file. Change the values +of `$PASSWORD` and `$SECRET` to respectively the chosen PostgreSQL password +and the JWT secret used to run the server. `$SECRET` must be at least 64 chars long. + +```yaml +version: '3' + +services: + smarthutdb: + restart: always + image: postgres:12-alpine + container_name: smarthutdb + volumes: + - ./data:/var/lib/postgresql/data + environment: + PGDATA: /var/lib/postgresql/data/data + POSTGRES_DB: smarthut + POSTGRES_USERNAME: postgres + POSTGRES_PASSWORD: $PASSWORD + + smarthutbackend: + restart: always + image: smarthutsm/smarthut-backend:M1 + ports: + - 8080:8080 + environment: + - POSTGRES_JDBC=jdbc:postgresql://smarthutdb:5432/smarthut + - POSTGRES_USER=postgres + - POSTGRES_PASS=$PASSWORD + - SECRET=$SECRET + - MAIL_HOST=smtp.gmail.com + - MAIL_PORT=587 + - MAIL_STARTTLS=true + - MAIL_USER=smarthut.sm@gmail.com + - MAIL_PASS=dcadvbagqfkwbfts + - BACKEND_URL=http://localhost:8080 + - FRONTEND_URL=http://localhost + + smarthut: + restart: always + image: smarthutsm/smarthut:M1 + ports: + - 80:80 + environment: + - BACKEND_URL=http://localhost:8080 +``` diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties new file mode 100644 index 0000000..2fb519c --- /dev/null +++ b/src/main/resources/application-dev.properties @@ -0,0 +1,33 @@ +spring.http.converters.preferred-json-mapper=gson +spring.datasource.url=jdbc:postgresql://localhost:5432/smarthut +spring.datasource.username=postgres +spring.datasource.password= + +# Hibernate properties +spring.jpa.database=POSTGRESQL +spring.jpa.show-sql=false +spring.jpa.hibernate.ddl-auto=update +spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl +spring.jpa.properties.hibernate.format_sql=true + +jwt.secret=thiskeymustbeverylongorthethingcomplainssoiamjustgoingtowritehereabunchofgarbageciaomamma + +spring.mail.test-connection=true +spring.mail.host=smtp.gmail.com +spring.mail.port=587 +spring.mail.properties.mail.smtp.starttls.enable=true +spring.mail.username=smarthut.sm@gmail.com +spring.mail.password=dcadvbagqfkwbfts +spring.mail.properties.mail.smtp.starttls.required=true +spring.mail.properties.mail.smtp.auth=true +spring.mail.properties.mail.smtp.connectiontimeout=5000 +spring.mail.properties.mail.smtp.timeout=5000 +spring.mail.properties.mail.smtp.writetimeout=5000 + +email.registrationSubject=Complete your SmartHut.sm registration +email.registration=To confirm your registration, please click here: +email.registrationPath=http://localhost:8080/register/confirm-account?token= + +email.resetpasswordSubject=SmartHut.sm password reset +email.resetpassword=To reset your password, please click here: +email.resetpasswordPath=http://localhost:3000/password-reset?token= \ No newline at end of file diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties new file mode 100644 index 0000000..7807d21 --- /dev/null +++ b/src/main/resources/application-prod.properties @@ -0,0 +1,39 @@ +spring.http.converters.preferred-json-mapper=gson + +# Database connection properties +spring.datasource.url=${POSTGRES_JDBC} +spring.datasource.username=${POSTGRES_USER} +spring.datasource.password=${POSTGRES_PASS} + +# Hibernate properties +spring.jpa.database=POSTGRESQL +spring.jpa.show-sql=false +spring.jpa.hibernate.ddl-auto=update +spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl +spring.jpa.properties.hibernate.format_sql=true + +# JWT secret +jwt.secret=${SECRET} + +# Mail connection properties +spring.mail.test-connection=true +spring.mail.host=${MAIL_HOST} +spring.mail.port=${MAIL_PORT} +spring.mail.properties.mail.smtp.starttls.enable=${MAIL_STARTTLS} +spring.mail.username=${MAIL_USER} +spring.mail.password=${MAIL_PASS} +spring.mail.properties.mail.smtp.starttls.required=${MAIL_STARTTLS} +spring.mail.properties.mail.smtp.auth=true +spring.mail.properties.mail.smtp.connectiontimeout=5000 +spring.mail.properties.mail.smtp.timeout=5000 +spring.mail.properties.mail.smtp.writetimeout=5000 + +# Registration email properties +email.registrationSubject=Complete your SmartHut.sm registration +email.registration=To confirm your registration, please click here: +email.registrationPath=${BACKEND_URL}/register/confirm-account?token= + +# Password reset email properties +email.resetpasswordSubject=SmartHut.sm password reset +email.resetpassword=To reset your password, please click here: +email.resetpasswordPath=${FRONTEND_URL}/password-reset?token= \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 2fb519c..2150e4d 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,33 +1 @@ -spring.http.converters.preferred-json-mapper=gson -spring.datasource.url=jdbc:postgresql://localhost:5432/smarthut -spring.datasource.username=postgres -spring.datasource.password= - -# Hibernate properties -spring.jpa.database=POSTGRESQL -spring.jpa.show-sql=false -spring.jpa.hibernate.ddl-auto=update -spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl -spring.jpa.properties.hibernate.format_sql=true - -jwt.secret=thiskeymustbeverylongorthethingcomplainssoiamjustgoingtowritehereabunchofgarbageciaomamma - -spring.mail.test-connection=true -spring.mail.host=smtp.gmail.com -spring.mail.port=587 -spring.mail.properties.mail.smtp.starttls.enable=true -spring.mail.username=smarthut.sm@gmail.com -spring.mail.password=dcadvbagqfkwbfts -spring.mail.properties.mail.smtp.starttls.required=true -spring.mail.properties.mail.smtp.auth=true -spring.mail.properties.mail.smtp.connectiontimeout=5000 -spring.mail.properties.mail.smtp.timeout=5000 -spring.mail.properties.mail.smtp.writetimeout=5000 - -email.registrationSubject=Complete your SmartHut.sm registration -email.registration=To confirm your registration, please click here: -email.registrationPath=http://localhost:8080/register/confirm-account?token= - -email.resetpasswordSubject=SmartHut.sm password reset -email.resetpassword=To reset your password, please click here: -email.resetpasswordPath=http://localhost:3000/password-reset?token= \ No newline at end of file +spring.profiles.active=${SMARTHUT_THIS_VALUE_IS_PROD_IF_THIS_IS_A_CONTAINER_PIZZOCCHERI:dev} \ No newline at end of file