-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Dockerfile & add docker-compose.prod.yml
- Loading branch information
1 parent
eacf877
commit e1cf1f0
Showing
5 changed files
with
96 additions
and
36 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 |
---|---|---|
@@ -1,35 +1,38 @@ | ||
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven | ||
|
||
# This workflow uses actions that are not certified by GitHub. | ||
# They are provided by a third-party and are governed by | ||
# separate terms of service, privacy policy, and support | ||
# documentation. | ||
|
||
name: Java CI with Maven | ||
# Définition du nom du workflow, qui sera affiché sur GitHub | ||
name: Java CI/CD with Maven | ||
|
||
# Définition des événements qui déclencheront l'exécution du workflow | ||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
push: # Lors d'un push | ||
branches: [ "main" ] # Sur la branche main | ||
pull_request: # Lors d'une pull request | ||
branches: [ "main" ] # Ciblant la branche main | ||
|
||
# Définition des jobs à exécuter | ||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up JDK 21 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '21' | ||
distribution: 'temurin' | ||
cache: maven | ||
- name: Build with Maven | ||
run: mvn -B package --file pom.xml | ||
|
||
# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive | ||
# - name: Update dependency graph | ||
# uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 | ||
build-and-test: # Nom du job | ||
runs-on: ubuntu-latest # Exécute le job sur la dernière version d'Ubuntu disponible | ||
|
||
steps: # Étapes du job | ||
- uses: actions/checkout@v4 # Étape pour cloner le code source du dépôt | ||
|
||
- name: Set up JDK 21 # Étape pour configurer JDK 21 | ||
uses: actions/setup-java@v3 # Utilise l'action setup-java pour configurer Java | ||
with: # Options pour l'action setup-java | ||
java-version: '21' # Spécifie la version de Java à utiliser | ||
distribution: 'temurin' # Spécifie la distribution de Java à utiliser | ||
cache: maven # Active le cache pour Maven | ||
|
||
- name: Build with Maven # Étape pour construire le projet avec Maven | ||
run: mvn -B package --file pom.xml # Exécute Maven pour compiler le projet et empaqueter | ||
|
||
- name: Run Checkstyle # Étape pour exécuter Checkstyle | ||
run: mvn checkstyle:checkstyle # Exécute Checkstyle pour vérifier la conformité du style de code | ||
|
||
- name: Run Tests # Étape pour exécuter les tests | ||
run: mvn test # Exécute les tests unitaires | ||
|
||
- name: Build Docker Image # Étape pour construire l'image Docker | ||
run: docker build -t spring-boot-student-management . # Construit l'image Docker à partir du Dockerfile | ||
|
||
# Ajoutez ici les étapes supplémentaires pour l'analyse de code et le déploiement |
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 |
---|---|---|
@@ -1,7 +1,33 @@ | ||
FROM openjdk:21 | ||
# Utilisation d'une image de base plus légère | ||
FROM maven:eclipse-temurin | ||
|
||
LABEL authors="nassim" | ||
|
||
ARG JAR_FILE=target/*.jar | ||
COPY ${JAR_FILE} app.jar | ||
# Création d'un répertoire pour l'application | ||
WORKDIR /app | ||
|
||
# Installation de dockerize | ||
ENV DOCKERIZE_VERSION v0.6.1 | ||
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \ | ||
&& tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \ | ||
&& rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz | ||
|
||
# Copie du fichier pom.xml et téléchargement des dépendances pour améliorer la mise en cache | ||
COPY pom.xml . | ||
RUN mvn dependency:go-offline | ||
|
||
# Copie du reste de l'application | ||
COPY src ./src | ||
|
||
# Construction de l'application | ||
RUN mvn clean install -DskipTests | ||
|
||
# Copie du jar dans le conteneur | ||
RUN mv target/*.jar app.jar | ||
|
||
# Spécification d'un utilisateur non root | ||
RUN useradd -m myuser | ||
USER myuser | ||
|
||
ENTRYPOINT ["java","-jar","/app.jar"] | ||
ENTRYPOINT ["dockerize", "-wait", "tcp://db:3306", "-timeout", "30s", "java","-jar","app.jar"] | ||
EXPOSE 8080 |
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,31 @@ | ||
services: | ||
db: | ||
image: mysql:8.0 | ||
command: --default-authentication-plugin=caching_sha2_password | ||
environment: | ||
MYSQL_ROOT_PASSWORD: password | ||
MYSQL_DATABASE: springbootdb | ||
volumes: | ||
- db_data:/var/lib/mysql | ||
networks: | ||
- app-network | ||
|
||
app: | ||
build: . | ||
ports: | ||
- "8080:8080" | ||
environment: | ||
SPRING_DATASOURCE_URL: jdbc:mysql://db:3306/springbootdb | ||
SPRING_DATASOURCE_USERNAME: root | ||
SPRING_DATASOURCE_PASSWORD: password | ||
depends_on: | ||
- db | ||
networks: | ||
- app-network | ||
|
||
volumes: | ||
db_data: | ||
|
||
networks: | ||
app-network: | ||
driver: bridge |
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