Created dockerfiles, makefile and docker-compose file

This commit is contained in:
Svetlana Mancic 2025-05-26 15:41:25 +02:00
parent 3a931080d4
commit fe44836741
7 changed files with 143 additions and 14 deletions

39
.dockerignore Normal file
View file

@ -0,0 +1,39 @@
# Include any files or directories that you don't want to be copied to your
# container here (e.g., local build artifacts, temporary files, etc.).
#
# For more help, visit the .dockerignore file reference guide at
# https://docs.docker.com/go/build-context-dockerignore/
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/.next
**/.cache
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/charts
**/docker-compose*
**/compose.y*ml
# **/target
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
**/vendor
LICENSE
README.md
**/gradle
gradlew
gradlew.bat
settings.gradle
Makefile

16
Dockerfile Normal file
View file

@ -0,0 +1,16 @@
FROM eclipse-temurin:24.0.1_9-jre-alpine-3.21@sha256:dbc9b392f33b2aca2c3d47de4534f3453e75d3b6dd27e08a555a47369be9b49c
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
WORKDIR /app
COPY --chown=appuser:appgroup ./target/*.jar app.jar
RUN chmod 500 app.jar
USER appuser
EXPOSE 8080
ENTRYPOINT [ "java", "-jar", "app.jar" ]

26
Dockerfile.multistage Normal file
View file

@ -0,0 +1,26 @@
FROM eclipse-temurin:24.0.1_9-jdk-alpine-3.21@sha256:d729416b123cd50d4a70122328ae17d38adced6fa767062d0c0f134e5843deab AS build
WORKDIR /app
COPY . .
RUN ./mvnw dependency:go-offline -B
RUN ./mvnw clean package -DskipTests
USER nobody
FROM eclipse-temurin:24.0.1_9-jre-alpine-3.21@sha256:dbc9b392f33b2aca2c3d47de4534f3453e75d3b6dd27e08a555a47369be9b49c as runtime
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
WORKDIR /app
COPY --from=build --chown=appuser:appgroup /app/target/*.jar app.jar
RUN chmod 500 app.jar
USER appuser
EXPOSE 8080
ENTRYPOINT [ "java", "-jar", "app.jar" ]

17
Makefile Normal file
View file

@ -0,0 +1,17 @@
.PHONY: up down logs restart ps
COMPOSE_FILE=docker-compose.yml
up:
docker compose -f $(COMPOSE_FILE) --env-file .env up -d --build $(service)
down:
docker compose -f $(COMPOSE_FILE) down $(service)
logs:
docker compose -f $(COMPOSE_FILE) logs --tail=100 -f $(service)
ps:
docker compose -f $(COMPOSE_FILE) ps
restart: down up

View file

@ -1,21 +1,46 @@
services:
mysql:
image: mysql:9.1
petclinic:
image: spring-petclinic-petclinic
build:
context: .
dockerfile: Dockerfile.multistage
container_name: petclinic
depends_on:
postgres:
condition: service_healthy
restart: always
ports:
- "3306:3306"
- "8080:8080"
environment:
- MYSQL_ROOT_PASSWORD=
- MYSQL_ALLOW_EMPTY_PASSWORD=true
- MYSQL_USER=petclinic
- MYSQL_PASSWORD=petclinic
- MYSQL_DATABASE=petclinic
volumes:
- "./conf.d:/etc/mysql/conf.d:ro"
SPRING_JPA_HIBERNATE_DDL_AUTO: update
SPRING_PROFILES_ACTIVE: postgres
POSTGRES_URL: ${DATABASE_URL}
POSTGRES_PASSWORD: ${DATABASE_PASS}
POSTGRES_USER: ${DATABASE_USER}
postgres:
image: postgres:17.0
container_name: postgres
restart: always
ports:
- "5432:5432"
environment:
- POSTGRES_PASSWORD=petclinic
- POSTGRES_USER=petclinic
- POSTGRES_DB=petclinic
POSTGRES_PASSWORD: ${DATABASE_PASS}
POSTGRES_USER: ${DATABASE_USER}
POSTGRES_DB: ${DATABASE}
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${DATABASE_USER} -d ${DATABASE}"]
interval: 10s
timeout: 10s
retries: 5
start_period: 10s
volumes:
postgres_data:

View file

@ -5,3 +5,7 @@ spring.datasource.username=${MYSQL_USER:petclinic}
spring.datasource.password=${MYSQL_PASS:petclinic}
# SQL is written to be idempotent so this is safe
spring.sql.init.mode=always
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# spring.jpa.show-sql=true

View file

@ -2,5 +2,7 @@ database=postgres
spring.datasource.url=${POSTGRES_URL:jdbc:postgresql://localhost/petclinic}
spring.datasource.username=${POSTGRES_USER:petclinic}
spring.datasource.password=${POSTGRES_PASS:petclinic}
# SQL is written to be idempotent so this is safe
# # SQL is written to be idempotent so this is safe
spring.sql.init.mode=always
spring.datasource.driver-class-name=org.postgresql.Driver