Skip to content

Commit

Permalink
Merge pull request #39 from CodeURJC-DAW-2022-23/feat/docker-compose
Browse files Browse the repository at this point in the history
Feat: docker compose
  • Loading branch information
franchescoURJC authored Mar 28, 2023
2 parents c7548ff + cb36b68 commit 139e918
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 11 deletions.
5 changes: 5 additions & 0 deletions back/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Target
target/

# MySQL Database
mysql/
2 changes: 2 additions & 0 deletions back/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
.mysql
mysql

### STS ###
.apt_generated
Expand Down
15 changes: 11 additions & 4 deletions back/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
FROM openjdk:17

COPY target/alist-0.0.1.jar alist-0.0.1.jar
FROM maven:3-openjdk-17 as builder
WORKDIR /alist
COPY pom.xml /alist
COPY /src /alist/src
RUN mvn package -DskipTests=true

ENTRYPOINT ["java", "-jar", "/alist-0.0.1.jar"]
FROM openjdk:17
ENV JAVA_TOOL_OPTIONS="-Xss256K -XX:ReservedCodeCacheSize=64M -XX:MaxMetaspaceSize=100000K -Xmx64M"
WORKDIR /usr/alistapp
COPY --from=builder /alist/target/*.jar /usr/alistapp
EXPOSE 8443
ENTRYPOINT ["java", "-jar", "alist.jar"]
3 changes: 3 additions & 0 deletions back/docker/create_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
docker build .. -t $1
docker push $1
35 changes: 35 additions & 0 deletions back/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: '3.9'
services:
web:
image: franchescourjc/webapp1
ports:
- 8443:8443
environment:
- SPRING_DATASOURCE_URL=jdbc:mysql://db/alist
- SPRING_DATASOURCE_USERNAME=alist
- SPRING_DATASOURCE_PASSWORD=y0JlZhO3z8
- SPRING_JPA_HIBERNATE_DDL-AUTO=create-drop
depends_on:
- db
- mail
restart: on-failure
db:
platform: linux/x86_64
image: mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=y0JlZhO3z8
- MYSQL_DATABASE=alist
- MYSQL_USER=alist
- MYSQL_PASSWORD=y0JlZhO3z8
volumes:
- .mysql:/var/lib/mysql
restart: on-failure
mail:
image: maildev/maildev
ports:
- 1080:1080
- 1025:1025
volumes:
- ./maildev:/var/maildev
restart: on-failure

21 changes: 21 additions & 0 deletions back/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<java.version>17</java.version>
<springframework.version>6.0.2</springframework.version>
<springsecurity.version>6.0.2</springsecurity.version>
<start-class>net.daw.alist.AlistApplication</start-class>
</properties>

<dependencies>
Expand Down Expand Up @@ -122,10 +123,30 @@
</dependencies>

<build>
<finalName>alist</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
<configuration>
<arguments>
<argument>--server.ssl.enabled=false</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package net.daw.alist.services;

import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.support.DatabaseStartupValidator;

import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import java.util.stream.Stream;

@SpringBootConfiguration
public class DatabaseWaitConfigurator {

@Bean
public DatabaseStartupValidator databaseStartupValidator(DataSource dataSource) {
DatabaseStartupValidator dsv = new DatabaseStartupValidator();
dsv.setDataSource(dataSource);
dsv.setInterval(5);
dsv.setTimeout(120);
return dsv;
}

@Bean
public static BeanFactoryPostProcessor dependsOnPostProcessor() {
return bf -> {
String[] jpa = bf.getBeanNamesForType(EntityManagerFactory.class);
Stream.of(jpa).map(bf::getBeanDefinition).forEach(it -> it.setDependsOn("databaseStartupValidator"));
};
}

}
14 changes: 7 additions & 7 deletions back/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# mysql properties
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/alist
spring.datasource.username=alist
spring.datasource.password=y0JlZhO3z8
spring.datasource.url=jdbc:mysql://${MYSQLUSER:alist}:${MYSQLPASSWORD:y0JlZhO3z8}@${MYSQLHOST:localhost}:${MYSQLPORT:3306}/${MYSQLDATABASE:alist}
spring.datasource.username=${MYSQLUSER:alist}
spring.datasource.password=${MYSQLROOT:y0JlZhO3z8}
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=false
spring.jpa.database=mysql
Expand All @@ -17,22 +17,22 @@ logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE

spring.mustache.suffix=.html
logging.level.org.springframework.web=DEBUG
server.port=8443
server.port=${PORT:8443}
server.error.whitelabel.enabled=false

#mail properties
spring.mail.host=localhost
spring.mail.username=root
spring.mail.password=root
spring.mail.port=1025
spring.mail.port=${PORT:1025}

#keystore properties
server.ssl.key-store=classpath:keystore.jks
server.ssl.key-store-password=secret
server.ssl.key-password=secret

#Only accept HTTPS requests
server.ssl.enabled=true
# Not show database connection error
logging.level.com.zaxxer.hikari=OFF

#JWT config
jwt.header=Authorization
Expand Down

0 comments on commit 139e918

Please sign in to comment.