enhance docker scripts

This commit is contained in:
2025-06-07 11:05:09 +02:00
parent f488f7e01d
commit c6a7d2d8df
4 changed files with 38 additions and 17 deletions

View File

@@ -1,20 +1,32 @@
all:
run
DOCKER_CONTAINER_NAME=awa-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
init_vendor:
cd laravel && composer i
init:
docker exec -i awa-laravel-1 /scripts/init_laravel.sh
exec_container:
docker exec -i awa-laravel-1 bash
# 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 exec -i awa-laravel-1 php artisan db:seed --class=$(CLASS)
$(DOCKER_CMD) php artisan db:seed --class=$(CLASS)
migrate:
$(DOCKER_CMD) php artisan migrate

View File

@@ -3,4 +3,5 @@ DB_HOST=mariadb
DB_PORT=3306
DB_DATABASE=laravel_db
DB_USERNAME=laravel_user
DB_PASSWORD=super_strong_password
DB_PASSWORD=super_strong_password
APP_KEY=""

View File

@@ -1,7 +1,8 @@
FROM bitnami/laravel
COPY init_laravel.sh /scripts/init_laravel.sh
COPY init_laravel.sh /init/init_laravel.sh
COPY .env /init/.env
RUN chmod +x /scripts/init_laravel.sh
RUN chmod +x /init/init_laravel.sh
CMD composer i && php artisan serve --host=0.0.0.0 --port=8000
CMD bash /init/init_laravel.sh

View File

@@ -1,4 +1,11 @@
#!/bin/sh
composer install
php artisan migrate --force
php artisan db:seed
# 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