diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..219c273 --- /dev/null +++ b/.env.example @@ -0,0 +1,9 @@ +SPRING_PROFILES_ACTIVE=dev + +APP_ALLOWED_ORIGINS='http://127.0.0.1:3000, http://localhost:3000' + +DB_NAME=EXAMPLE_DB +DB_USER=EXAMPLE +DB_PASSWORD=SECRET +DB_HOST=127.0.0.1 +DB_PORT=5432 \ No newline at end of file diff --git a/.gitignore b/.gitignore index f1fe883..2f7dbd9 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,5 @@ *.toml *.db target - +.env Icon? \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a7e385d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +# Stage 1: Build +FROM maven:3.9-eclipse-temurin-21-alpine AS build +WORKDIR /app + +# Copiamos todo el proyecto +COPY . . + +# Compilamos todo el proyecto (todos los módulos) +RUN mvn clean package -DskipTests + +# Stage 2: Run +FROM openjdk:21-jdk +WORKDIR /app +COPY --from=build /app/bootstrap/target/*.jar app.jar +EXPOSE 8080 +ENTRYPOINT ["java", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005", "-Xmx512m", "-Xms256m", "-jar", "app.jar","--spring.profiles.active=prod"] \ No newline at end of file diff --git a/bootstrap/src/main/resources/application.yml b/bootstrap/src/main/resources/application.yml index f78a79e..c4e5bd1 100644 --- a/bootstrap/src/main/resources/application.yml +++ b/bootstrap/src/main/resources/application.yml @@ -1,6 +1,9 @@ info: app: version: @project.version@ +app: + cors: + allowed-origins: ${APP_ALLOWED_ORIGINS:http://localhost:8080} spring: application: name: portfolio-api @@ -8,13 +11,26 @@ spring: resources: add-mappings: false + datasource: + url: jdbc:postgresql://${DB_HOST:localhost}:${DB_PORT:5432}/${DB_NAME:portfolio} + username: ${DB_USER:postgres} + password: ${DB_PASSWORD:postgres} + driver-class-name: org.postgresql.Driver + hikari: + maximum-pool-size: 3 + minimum-idle: 1 + idle-timeout: 30000 + connection-timeout: 10000 + leak-detection-threshold: 10000 + jpa: hibernate: - ddl-auto: update + ddl-auto: validate properties: hibernate.transaction.jta.platform: org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform hibernate: format_sql: true + dialect: org.hibernate.dialect.PostgreSQLDialect show-sql: true jackson: @@ -32,46 +48,7 @@ server: servlet: context-path: /api forward-headers-strategy: framework ---- -spring: - config: - activate: - on-profile: default - datasource: - url: jdbc:h2:file:./portfolio-db - driver-class-name: org.h2.Driver - username: sa - password: - jpa: - properties: - hibernate: - dialect: org.hibernate.dialect.H2Dialect - h2: - console: - enabled: true - path: /h2-console ---- -spring: - config: - activate: - on-profile: prod - - datasource: - url: jdbc:postgresql://${DB_HOST:localhost}:${DB_PORT:5432}/${DB_NAME:portfolio} - username: ${DB_USER:postgres} - password: ${DB_PASSWORD:postgres} - driver-class-name: org.postgresql.Driver - hikari: - maximum-pool-size: 3 - minimum-idle: 1 - idle-timeout: 30000 - connection-timeout: 10000 - leak-detection-threshold: 10000 - - jpa: - hibernate: - ddl-auto: update \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..8a8ad5b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,35 @@ +services: + db: + image: postgres:15-alpine + restart: unless-stopped + environment: + POSTGRES_DB: ${DB_NAME} + POSTGRES_USER: ${DB_USER} + POSTGRES_PASSWORD: ${DB_PASSWORD} + ports: + - "5432:5432" + networks: + common_network: + ipv4_address: 10.1.0.121 + volumes: + - db_data:/var/lib/postgresql/data + + api: + build: . + restart: unless-stopped + ports: + - "8095:8080" + networks: + common_network: + ipv4_address: 10.1.0.121 + environment: + DB_NAME: ${DB_NAME} + DB_HOST: ${DB_HOST} + DB_PORT: ${DB_PORT} + DB_USER: ${DB_USER} + DB_PASSWORD: ${DB_PASSWORD} + depends_on: + - db + +volumes: + db_data: \ No newline at end of file