diff --git a/.env b/.env new file mode 100644 index 0000000..18edda9 --- /dev/null +++ b/.env @@ -0,0 +1,8 @@ +MYSQLDB_DATABASE=air_companies_management +MYSQLDB_USER=root +MYSQLDB_ROOT_PASSWORD=default +MYSQLDB_LOCAL_PORT=3308 +MYSQLDB_DOCKER_PORT=3306 +SPRING_LOCAL_PORT=8088 +SPRING_DOCKER_PORT=8080 +DEBUG_PORT=5005 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5c8ebe8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM openjdk:11 as builder +WORKDIR application +ARG JAR_FILE=target/*.jar +COPY ${JAR_FILE} application.jar +RUN java -Djarmode=layertools -jar application.jar extract + +FROM openjdk:11 +WORKDIR application +COPY --from=builder application/dependencies/ ./ +COPY --from=builder application/spring-boot-loader/ ./ +COPY --from=builder application/snapshot-dependencies/ ./ +COPY --from=builder application/application/ ./ +ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"] +EXPOSE 8080 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..b0bd32a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,37 @@ +version: "3.8" + +services: + mysqldb: + platform: linux/arm64 + image: mysql:latest + restart: unless-stopped + env_file: ./.env + environment: + - MYSQL_ROOT_PASSWORD=$MYSQLDB_ROOT_PASSWORD + - MYSQL_DATABASE=$MYSQLDB_DATABASE + ports: + - $MYSQLDB_LOCAL_PORT:$MYSQLDB_DOCKER_PORT + healthcheck: + test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ] + timeout: 30s + retries: 3 + app: + depends_on: + mysqldb: + condition: service_healthy + restart: on-failure + image: air_companies_management + build: . + env_file: ./.env + ports: + - $SPRING_LOCAL_PORT:$SPRING_DOCKER_PORT + - $DEBUG_PORT:$DEBUG_PORT + environment: + SPRING_APPLICATION_JSON: '{ + "spring.datasource.url" : "jdbc:mysql://mysqldb:$MYSQLDB_DOCKER_PORT/$MYSQLDB_DATABASE", + "spring.datasource.username" : "$MYSQLDB_USER", + "spring.datasource.password" : "$MYSQLDB_ROOT_PASSWORD", + "spring.datasource.driver-class-name" : "com.mysql.cj.jdbc.Driver", + "spring.jpa.hibernate.ddl-auto" : "create-drop" + }' + JAVA_TOOL_OPTIONS: "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005" diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 70683f6..bec7acd 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,13 +1,14 @@ spring.application.name=air-companies-manager server.servlet.context-path=/api spring.datasource.url=jdbc:mysql://localhost:3306/air_companies_management +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.username=root -spring.datasource.password=${DB_PASSWORD} +spring.datasource.password=default spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect spring.jpa.open-in-view=false spring.jpa.show-sql=true +spring.jpa.generate-ddl=true spring.jpa.hibernate.ddl-auto=create-drop -spring.jpa.defer-datasource-initialization=true spring.jackson.deserialization.fail-on-unknown-properties=true spring.datasource.initialization-mode=always spring.datasource.data=classpath:data/data.sql