-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Task 21 : Define Dockerfile and docker-compose.yml
- Loading branch information
1 parent
4894cde
commit 413b150
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Stage 1: Build stage | ||
FROM maven:3.9.7-amazoncorretto-21 AS build | ||
|
||
# Copy Maven files for dependency resolution | ||
COPY pom.xml ./ | ||
COPY .mvn .mvn | ||
|
||
# Copy application source code | ||
COPY src src | ||
|
||
# Build the project and create the executable JAR | ||
RUN mvn clean install -DskipTests | ||
|
||
# Stage 2: Run stage | ||
FROM amazoncorretto:21 | ||
|
||
# Set working directory | ||
WORKDIR rolepermissionexample | ||
|
||
# Copy the JAR file from the build stage | ||
COPY --from=build target/*.jar rolepermissionexample.jar | ||
|
||
# Expose port 1225 | ||
EXPOSE 1225 | ||
|
||
# Set the entrypoint command for running the application | ||
ENTRYPOINT ["java", "-jar", "rolepermissionexample.jar"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
version: "3.9" | ||
|
||
services: | ||
|
||
database: | ||
container_name: database | ||
image: mysql:8.0.33 | ||
restart: always | ||
env_file: | ||
- .env # Use the .env file for environment variables | ||
environment: | ||
MYSQL_DATABASE: springbootrolepermissionexample | ||
MYSQL_PASSWORD: ${DATABASE_PASSWORD} | ||
MYSQL_ROOT_PASSWORD: ${DATABASE_PASSWORD} | ||
MYSQL_ROOT_HOST: '%' | ||
MYSQL_PORT: 3307 | ||
volumes: | ||
- ./db:/var/lib/mysql | ||
ports: | ||
- "3307:3306" | ||
networks: | ||
- rolepermissionNetwork | ||
|
||
|
||
rolepermissionexample: | ||
image: 'rolepermissionexample:latest' | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
container_name: rolepermissionexample | ||
restart: on-failure | ||
env_file: | ||
- .env # Use the .env file for environment variables | ||
ports: | ||
- "1224:1224" | ||
environment: | ||
- server.port=1224 | ||
- spring.datasource.username=${DATABASE_USERNAME} | ||
- spring.datasource.password=${DATABASE_PASSWORD} | ||
- SECURITY_DB_IP=database | ||
- SECURITY_DB_PORT=3307 | ||
- spring.datasource.url=jdbc:mysql://host.docker.internal:3307/springbootrolepermissionexample | ||
depends_on: | ||
- database | ||
networks: | ||
- rolepermissionNetwork | ||
|
||
networks: | ||
rolepermissionNetwork: |