commit 9829dfc6b500da2eec8e5d9d58649482a132ced3 Author: Logisim-Evolution <> Date: Sat Jun 7 11:10:44 2025 +0000 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a0b502d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +sqldata diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..daf821c --- /dev/null +++ b/Makefile @@ -0,0 +1,38 @@ +CURRENT_DIR=$(shell basename $(PWD)) +CURRENT_DIR_LC=$(shell echo $(CURRENT_DIR) | tr A-Z a-z) +DOCKER_CONTAINER_NAME=$(CURRENT_DIR_LC)-laravel-1 +DOCKER_CMD=docker exec -it $(DOCKER_CONTAINER_NAME) + +# Launch the container detached +all: + docker compose up -d + +# Launch the container +run: + docker compose up + +# Stop the container +stop: + docker compose down + +# Stop the container and wipe the database +down: + docker compose down -v + + + + +# These tasks need the docker container to be running + +exec_container: + $(DOCKER_CMD) bash + +seed: + $(DOCKER_CMD) php artisan db:seed --class=$(CLASS) + +migrate: + $(DOCKER_CMD) php artisan migrate + +init_breeze: + $(DOCKER_CMD) composer require laravel/breeze --dev + $(DOCKER_CMD) php artisan breeze:install --dark blade \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..890876e --- /dev/null +++ b/README.md @@ -0,0 +1,59 @@ +# Laravel Docker + +## Commandes + +Pour lancer les conteneurs : + +```sh +make run +``` + +Arrêter les conteneurs : + +```sh +make stop +``` + +Effectuer les migrations : + +```sh +make migrate +``` + +Exécuter un seeder : + +```sh +make CLASS="VOTRESEEDER" seed +``` + +Installer Breeze (Attention ! Vos routes seront écrasées !): + +```sh +make init_breeze +``` + +Ouvrir un terminal dans le conteneur laravel : + +```sh +make exec_container +``` + +## Instructions + +Les données de la base de données persistent dans le volume docker `laravel_db_volume` + +Les fichiers Laravel sont ensuite disponibles dans le dossier `laravel`. + +Si vous venez de créer le dossier laravel, supprimer le fichier .env et relancer les contenaurs. + +Le site est ensuite accessible à l'adresse suivante : `http://localhost:8080` + +# Git + +Après avoir cloné ce repo, pour pouvoir pousser sur le vôtre : + +``` +git remote remove origin +git remote add origin [Votre URL git] +git push -u origin main +``` \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..c1b7947 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,29 @@ +services: + mariadb: + build: + context: images + dockerfile: SQL_Dockerfile + environment: + MARIADB_ROOT_PASSWORD: super_strong_password_of_root + MARIADB_DATABASE: laravel_db + ports: + - "3306:3306" # Attention: faille de sécurité ! + volumes: + - laravel_db_volume:/var/lib/mysql + + laravel: + build: + context: images + dockerfile: Laravel_Dockerfile + ports: + - "8080:8000" + environment: + LARAVEL_DATABASE_USER: laravel_user + LARAVEL_DATABASE_PASSWORD: super_strong_password + LARAVEL_DATABASE_NAME: laravel_db + LARAVEL_DATABSE_HOST: mariadb + volumes: + - ./laravel:/app + +volumes: + laravel_db_volume: \ No newline at end of file diff --git a/images/.env b/images/.env new file mode 100644 index 0000000..2922e33 --- /dev/null +++ b/images/.env @@ -0,0 +1,7 @@ +DB_CONNECTION=mariadb +DB_HOST=mariadb +DB_PORT=3306 +DB_DATABASE=laravel_db +DB_USERNAME=laravel_user +DB_PASSWORD=super_strong_password +APP_KEY="" \ No newline at end of file diff --git a/images/Laravel_Dockerfile b/images/Laravel_Dockerfile new file mode 100644 index 0000000..339e443 --- /dev/null +++ b/images/Laravel_Dockerfile @@ -0,0 +1,8 @@ +FROM bitnami/laravel + +COPY init_laravel.sh /init/init_laravel.sh +COPY .env /init/.env + +RUN chmod +x /init/init_laravel.sh + +CMD bash /init/init_laravel.sh \ No newline at end of file diff --git a/images/SQL_Dockerfile b/images/SQL_Dockerfile new file mode 100644 index 0000000..1d6f20a --- /dev/null +++ b/images/SQL_Dockerfile @@ -0,0 +1,19 @@ +FROM mariadb:latest as builder + +COPY db_init.sql /docker-entrypoint-initdb.d/ + +# That file does the DB initialization but also runs mysql daemon, by removing the last line it will only init +RUN ["sed", "-i", "s/exec \"$@\"/echo \"not running $@\"/", "/usr/local/bin/docker-entrypoint.sh"] + +ENV MARIADB_USER=root +ENV MARIADB_ROOT_PASSWORD=super_strong_password + +# Need to change the datadir to something else that /var/lib/mysql because the parent docker file defines it as a volume. +# https://docs.docker.com/engine/reference/builder/#volume : +# Changing the volume from within the Dockerfile: If any build steps change the data within the volume after +# it has been declared, those changes will be discarded. +RUN ["/usr/local/bin/docker-entrypoint.sh", "mariadbd", "--datadir", "/initialized-db", "--aria-log-dir-path", "/initialized-db"] + +FROM mariadb:latest + +COPY --from=builder /initialized-db /var/lib/mysql \ No newline at end of file diff --git a/images/db_init.sql b/images/db_init.sql new file mode 100644 index 0000000..7126bb4 --- /dev/null +++ b/images/db_init.sql @@ -0,0 +1,3 @@ +CREATE USER laravel_user IDENTIFIED BY 'super_strong_password'; + +GRANT CREATE, ALTER, DROP, SELECT, INSERT, UPDATE, DELETE ON laravel_db.* TO laravel_user; \ No newline at end of file diff --git a/images/init_laravel.sh b/images/init_laravel.sh new file mode 100644 index 0000000..398a543 --- /dev/null +++ b/images/init_laravel.sh @@ -0,0 +1,11 @@ +#!/bin/sh +composer install + +# Create .env if it does not exist +if ! [ -e ".env" ] ; then + cp /init/.env . + php artisan key:generate +fi + +php artisan migrate --force +php artisan serve --host=0.0.0.0 --port=8000 \ No newline at end of file