chore: configure Docker to deploy project using environment-based properties
This commit is contained in:
parent
8b2795d518
commit
2959c68bf3
9
.env.example
Normal file
9
.env.example
Normal file
@ -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
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,5 +2,5 @@
|
|||||||
*.toml
|
*.toml
|
||||||
*.db
|
*.db
|
||||||
target
|
target
|
||||||
|
.env
|
||||||
Icon?
|
Icon?
|
16
Dockerfile
Normal file
16
Dockerfile
Normal file
@ -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"]
|
@ -1,6 +1,9 @@
|
|||||||
info:
|
info:
|
||||||
app:
|
app:
|
||||||
version: @project.version@
|
version: @project.version@
|
||||||
|
app:
|
||||||
|
cors:
|
||||||
|
allowed-origins: ${APP_ALLOWED_ORIGINS:http://localhost:8080}
|
||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
name: portfolio-api
|
name: portfolio-api
|
||||||
@ -8,13 +11,26 @@ spring:
|
|||||||
resources:
|
resources:
|
||||||
add-mappings: false
|
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:
|
jpa:
|
||||||
hibernate:
|
hibernate:
|
||||||
ddl-auto: update
|
ddl-auto: validate
|
||||||
properties:
|
properties:
|
||||||
hibernate.transaction.jta.platform: org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform
|
hibernate.transaction.jta.platform: org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform
|
||||||
hibernate:
|
hibernate:
|
||||||
format_sql: true
|
format_sql: true
|
||||||
|
dialect: org.hibernate.dialect.PostgreSQLDialect
|
||||||
show-sql: true
|
show-sql: true
|
||||||
|
|
||||||
jackson:
|
jackson:
|
||||||
@ -32,46 +48,7 @@ server:
|
|||||||
servlet:
|
servlet:
|
||||||
context-path: /api
|
context-path: /api
|
||||||
forward-headers-strategy: framework
|
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
|
|
35
docker-compose.yml
Normal file
35
docker-compose.yml
Normal file
@ -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:
|
Loading…
x
Reference in New Issue
Block a user