generated from Logisim-Evolution/Laravel-Docker
Initial commit
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
sqldata
|
||||
38
Makefile
Normal file
38
Makefile
Normal file
@@ -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
|
||||
59
README.md
Normal file
59
README.md
Normal file
@@ -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
|
||||
```
|
||||
29
docker-compose.yaml
Normal file
29
docker-compose.yaml
Normal file
@@ -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:
|
||||
7
images/.env
Normal file
7
images/.env
Normal file
@@ -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=""
|
||||
8
images/Laravel_Dockerfile
Normal file
8
images/Laravel_Dockerfile
Normal file
@@ -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
|
||||
19
images/SQL_Dockerfile
Normal file
19
images/SQL_Dockerfile
Normal file
@@ -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
|
||||
3
images/db_init.sql
Normal file
3
images/db_init.sql
Normal file
@@ -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;
|
||||
11
images/init_laravel.sh
Normal file
11
images/init_laravel.sh
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user