mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-20 14:55:50 +00:00
Docker compose file for test enviroment
This commit is contained in:
parent
fc2a3d3992
commit
989924ce81
3 changed files with 9 additions and 144 deletions
|
@ -1,92 +0,0 @@
|
|||
# syntax=docker/dockerfile:1
|
||||
|
||||
# Comments are provided throughout this file to help you get started.
|
||||
# If you need more help, visit the Dockerfile-docker-init reference guide at
|
||||
# https://docs.docker.com/go/dockerfile-reference/
|
||||
|
||||
# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7
|
||||
|
||||
################################################################################
|
||||
|
||||
# Create a stage for resolving and downloading dependencies.
|
||||
FROM eclipse-temurin:17-jdk-jammy as deps
|
||||
|
||||
WORKDIR /build
|
||||
|
||||
# Copy the mvnw wrapper with executable permissions.
|
||||
COPY --chmod=0755 mvnw mvnw
|
||||
COPY .mvn/ .mvn/
|
||||
|
||||
# Download dependencies as a separate step to take advantage of Docker's caching.
|
||||
# Leverage a cache mount to /root/.m2 so that subsequent builds don't have to
|
||||
# re-download packages.
|
||||
RUN --mount=type=bind,source=pom.xml,target=pom.xml \
|
||||
--mount=type=cache,target=/root/.m2 ./mvnw dependency:go-offline -DskipTests
|
||||
|
||||
################################################################################
|
||||
|
||||
# Create a stage for building the application based on the stage with downloaded dependencies.
|
||||
# This Dockerfile-docker-init is optimized for Java applications that output an uber jar, which includes
|
||||
# all the dependencies needed to run your app inside a JVM. If your app doesn't output an uber
|
||||
# jar and instead relies on an application server like Apache Tomcat, you'll need to update this
|
||||
# stage with the correct filename of your package and update the base image of the "final" stage
|
||||
# use the relevant app server, e.g., using tomcat (https://hub.docker.com/_/tomcat/) as a base image.
|
||||
FROM deps as package
|
||||
|
||||
WORKDIR /build
|
||||
|
||||
COPY ./src src/
|
||||
RUN --mount=type=bind,source=pom.xml,target=pom.xml \
|
||||
--mount=type=cache,target=/root/.m2 \
|
||||
./mvnw package -DskipTests && \
|
||||
mv target/$(./mvnw help:evaluate -Dexpression=project.artifactId -q -DforceStdout)-$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout).jar target/app.jar
|
||||
|
||||
################################################################################
|
||||
|
||||
# Create a stage for extracting the application into separate layers.
|
||||
# Take advantage of Spring Boot's layer tools and Docker's caching by extracting
|
||||
# the packaged application into separate layers that can be copied into the final stage.
|
||||
# See Spring's docs for reference:
|
||||
# https://docs.spring.io/spring-boot/docs/current/reference/html/container-images.html
|
||||
FROM package as extract
|
||||
|
||||
WORKDIR /build
|
||||
|
||||
RUN java -Djarmode=layertools -jar target/app.jar extract --destination target/extracted
|
||||
|
||||
################################################################################
|
||||
|
||||
# Create a new stage for running the application that contains the minimal
|
||||
# runtime dependencies for the application. This often uses a different base
|
||||
# image from the install or build stage where the necessary files are copied
|
||||
# from the install stage.
|
||||
#
|
||||
# The example below uses eclipse-turmin's JRE image as the foundation for running the app.
|
||||
# By specifying the "17-jre-jammy" tag, it will also use whatever happens to be the
|
||||
# most recent version of that tag when you build your Dockerfile-docker-init.
|
||||
# If reproducability is important, consider using a specific digest SHA, like
|
||||
# eclipse-temurin@sha256:99cede493dfd88720b610eb8077c8688d3cca50003d76d1d539b0efc8cca72b4.
|
||||
FROM eclipse-temurin:17-jre-jammy AS final
|
||||
|
||||
# Create a non-privileged user that the app will run under.
|
||||
# See https://docs.docker.com/go/dockerfile-user-best-practices/
|
||||
ARG UID=10001
|
||||
RUN adduser \
|
||||
--disabled-password \
|
||||
--gecos "" \
|
||||
--home "/nonexistent" \
|
||||
--shell "/sbin/nologin" \
|
||||
--no-create-home \
|
||||
--uid "${UID}" \
|
||||
appuser
|
||||
USER appuser
|
||||
|
||||
# Copy the executable from the "package" stage.
|
||||
COPY --from=extract build/target/extracted/dependencies/ ./
|
||||
COPY --from=extract build/target/extracted/spring-boot-loader/ ./
|
||||
COPY --from=extract build/target/extracted/snapshot-dependencies/ ./
|
||||
COPY --from=extract build/target/extracted/application/ ./
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
ENTRYPOINT [ "java", "org.springframework.boot.loader.launch.JarLauncher" ]
|
34
compose.yaml
34
compose.yaml
|
@ -1,43 +1,27 @@
|
|||
# Comments are provided throughout this file to help you get started.
|
||||
# If you need more help, visit the Docker Compose reference guide at
|
||||
# https://docs.docker.com/go/compose-spec-reference/
|
||||
|
||||
# Here the instructions define your application as a service called "server".
|
||||
# This service is built from the Dockerfile-docker-init in the current directory.
|
||||
# You can add other services your application may depend on here, such as a
|
||||
# database or a cache. For examples, see the Awesome Compose repository:
|
||||
# https://github.com/docker/awesome-compose
|
||||
services:
|
||||
server:
|
||||
build:
|
||||
context: .
|
||||
ports:
|
||||
- 8080:8080
|
||||
|
||||
# The commented out section below is an example of how to define a PostgreSQL
|
||||
# database that your application can use. `depends_on` tells Docker Compose to
|
||||
# start the database before your application. The `db-data` volume persists the
|
||||
# database data between container restarts. The `db-password` secret is used
|
||||
# to set the database password. You must create `db/password.txt` and add
|
||||
# a password of your choosing to it before running `docker-compose up`.
|
||||
- 80:8080
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
- POSTGRES_URL=jdbc:postgresql://db:5432/petclinic
|
||||
- MYSQL_URL=jdbc:mysql://petclinic:petclinic@db:3306/petclinic
|
||||
db:
|
||||
image: postgres
|
||||
image: mysql
|
||||
restart: always
|
||||
volumes:
|
||||
- db-data:/var/lib/postgresql/data
|
||||
- db-data:/var/lib/mysql
|
||||
environment:
|
||||
- POSTGRES_DB=petclinic
|
||||
- POSTGRES_USER=petclinic
|
||||
- POSTGRES_PASSWORD=petclinic
|
||||
- MYSQL_DATABASE=petclinic
|
||||
- MYSQL_USER=petclinic
|
||||
- MYSQL_PASSWORD=petclinic
|
||||
ports:
|
||||
- 5432:5432
|
||||
- 3306:3306
|
||||
healthcheck:
|
||||
test: [ "CMD", "pg_isready", "-U", "petclinic" ]
|
||||
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
version: "2.2"
|
||||
|
||||
services:
|
||||
mysql:
|
||||
image: mysql:8.2
|
||||
ports:
|
||||
- "3306:3306"
|
||||
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"
|
||||
profiles:
|
||||
- mysql
|
||||
postgres:
|
||||
image: postgres:16.1
|
||||
ports:
|
||||
- "5432:5432"
|
||||
environment:
|
||||
- POSTGRES_PASSWORD=petclinic
|
||||
- POSTGRES_USER=petclinic
|
||||
- POSTGRES_DB=petclinic
|
||||
profiles:
|
||||
- postgres
|
Loading…
Reference in a new issue