From 708b0cf3866400c32a45c25563b2ab8c7352196f Mon Sep 17 00:00:00 2001 From: Philipp Lang Date: Mon, 15 May 2023 19:48:37 +0200 Subject: [PATCH] Mod docker compose --- .app.env.example | 15 ++++ .docker/nginx.Dockerfile | 18 +++++ Dockerfile => .docker/php.Dockerfile | 6 +- .env.example | 50 ------------ .gitignore | 2 + README.md | 56 +++++++++++++ config/broadcasting.php | 6 +- config/session.php | 4 +- database/seeders/UserSeeder.php | 3 +- docker-compose.yml | 116 ++++++++++++++++----------- 10 files changed, 168 insertions(+), 108 deletions(-) create mode 100644 .app.env.example create mode 100644 .docker/nginx.Dockerfile rename Dockerfile => .docker/php.Dockerfile (63%) delete mode 100644 .env.example diff --git a/.app.env.example b/.app.env.example new file mode 100644 index 00000000..24789f31 --- /dev/null +++ b/.app.env.example @@ -0,0 +1,15 @@ +APP_NAME="Adrema" +APP_ENV=local +APP_KEY=YOUR_APP_KEY +APP_DEBUG=true +APP_URL=http://localhost:8000 +APP_MODE=stamm + +MAIL_MAILER=smtp +MAIL_HOST=smtp.mailtrap.io +MAIL_PORT=2525 +MAIL_USERNAME=null +MAIL_PASSWORD=null +MAIL_ENCRYPTION=null +MAIL_FROM_ADDRESS=null +MAIL_FROM_NAME=me diff --git a/.docker/nginx.Dockerfile b/.docker/nginx.Dockerfile new file mode 100644 index 00000000..17113d7f --- /dev/null +++ b/.docker/nginx.Dockerfile @@ -0,0 +1,18 @@ +FROM composer:2.2.7 as composer +WORKDIR /app +COPY . /app +RUN composer install --ignore-platform-reqs --no-dev + +FROM node:17.9.0-slim as node +WORKDIR /app +COPY . /app +RUN npm install && npm run prod && npm run img && rm -R node_modules + +FROM nginx:1.21.6-alpine as nginx +WORKDIR /app +COPY --chown=www-data:www-data . /app +COPY --chown=www-data:www-data --from=node /app/public /app/public +COPY --chown=www-data:www-data --from=composer /app/vendor /app/vendor +EXPOSE 80 + +CMD ["nginx", "-g", "daemon off;"] diff --git a/Dockerfile b/.docker/php.Dockerfile similarity index 63% rename from Dockerfile rename to .docker/php.Dockerfile index 90d2169f..bf80154d 100644 --- a/Dockerfile +++ b/.docker/php.Dockerfile @@ -9,8 +9,10 @@ COPY . /app RUN npm install && npm run prod && rm -R node_modules FROM php:8.1.6-fpm as php -RUN apt-get update && apt-get install -y libcurl3-dev apt-utils zlib1g-dev libpng-dev libicu-dev libonig-dev texlive -RUN docker-php-ext-install pdo_mysql curl gd intl mbstring +WORKDIR /app +RUN apt-get update && apt-get install -y rsync libcurl3-dev apt-utils zlib1g-dev libpng-dev libicu-dev libonig-dev texlive texlive-fonts-extra +RUN docker-php-ext-install pdo_mysql curl gd intl mbstring pcntl +RUN pecl install redis && docker-php-ext-enable redis COPY --chown=www-data:www-data . /app COPY --chown=www-data:www-data --from=node /app/public /app/public COPY --chown=www-data:www-data --from=composer /app/vendor /app/vendor diff --git a/.env.example b/.env.example deleted file mode 100644 index e0a9c4c5..00000000 --- a/.env.example +++ /dev/null @@ -1,50 +0,0 @@ -APP_NAME=Laravel -APP_ENV=local -APP_KEY= -APP_DEBUG=true -APP_URL=http://localhost -APP_MODE= - -LOG_CHANNEL=stack - -DB_CONNECTION=mysql -DB_HOST=127.0.0.1 -DB_PORT=3306 -DB_DATABASE=laravel -DB_USERNAME=root -DB_PASSWORD= - -BROADCAST_DRIVER=log -CACHE_DRIVER=file -QUEUE_CONNECTION=sync -SESSION_DRIVER=file -SESSION_LIFETIME=120 - -REDIS_HOST=127.0.0.1 -REDIS_PASSWORD=null -REDIS_PORT=6379 - -MAIL_MAILER=smtp -MAIL_HOST=smtp.mailtrap.io -MAIL_PORT=2525 -MAIL_USERNAME=null -MAIL_PASSWORD=null -MAIL_ENCRYPTION=null -MAIL_FROM_ADDRESS=null -MAIL_FROM_NAME="${APP_NAME}" - -AWS_ACCESS_KEY_ID= -AWS_SECRET_ACCESS_KEY= -AWS_DEFAULT_REGION=us-east-1 -AWS_BUCKET= - -XELATEX_BIN= -PDFLATEX_BIN= - -PUSHER_APP_ID= -PUSHER_APP_KEY= -PUSHER_APP_SECRET= -PUSHER_APP_CLUSTER=mt1 - -MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" -MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" diff --git a/.gitignore b/.gitignore index b9741ff1..6a19d7a0 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ tags /public/mix-manifest.json resources/img/sprite.svg /.php-cs-fixer.cache +/data +.app.env diff --git a/README.md b/README.md index e03b1d31..557c8cc8 100644 --- a/README.md +++ b/README.md @@ -31,3 +31,59 @@ Ziel dieses Projektes ist es, viele Dinge, die man normalerweise manuell zu tun Außerdem ist AdReMa auch problemlos auf Handys und Tablets bedienbar ("mobiles Design") ![Mobile Ansicht](https://git.zoomyboy.de/silva/adrema/raw/branch/master/doc/assets/member-mobile.jpg) +# Installation + +Submodules updaten: + +``` +git submodule update --init +``` + +Example env erstellen: + +``` +cp .app.env.example .app.env +``` + +Container bauen + +``` +docker-compose build +``` + +Key generieren + +``` +docker-compose run php php artisan key:generate --show +``` + +Ersetze nun "YOUR_APP_KEY" in .app.env mit dem generierten Key (base64:qzX....). + +Führe nun den DB Container aus, um eine erste Version der Datenbank zu erstellen. + +``` +docker-compose up db -d +``` + +Migrations ausführen + +``` +docker-compose run php php artisan migrate --seed +``` + +Alles stoppen, dann alles neu starten + +``` +docker-compose stop +docker-compose up -d +``` + +Nun kannst du auf localhost:8000 die App öffnen, einen LB verwenden, den Port mit CLI Optionen ändern, etc. + +## Standard Login + +Wenn du die Seeder ausführst ("--seed", siehe oben), wird ein Benutzer mit folgenden Zugangsdaten erstellt: + +* E-Mail-Adresse: admin@example.com +* Passwort: admin + diff --git a/config/broadcasting.php b/config/broadcasting.php index 3bba1103..c03717e4 100644 --- a/config/broadcasting.php +++ b/config/broadcasting.php @@ -1,7 +1,6 @@ env('BROADCAST_DRIVER', 'null'), + 'default' => env('BROADCAST_DRIVER', 'log'), /* |-------------------------------------------------------------------------- @@ -29,7 +28,6 @@ return [ */ 'connections' => [ - 'pusher' => [ 'driver' => 'pusher', 'key' => env('PUSHER_APP_KEY'), @@ -53,7 +51,5 @@ return [ 'null' => [ 'driver' => 'null', ], - ], - ]; diff --git a/config/session.php b/config/session.php index 1afe371b..37fb533e 100644 --- a/config/session.php +++ b/config/session.php @@ -3,7 +3,6 @@ use Illuminate\Support\Str; return [ - /* |-------------------------------------------------------------------------- | Default Session Driver @@ -31,7 +30,7 @@ return [ | */ - 'lifetime' => env('SESSION_LIFETIME', 120000), + 'lifetime' => env('SESSION_LIFETIME', 10080), // one week 'expire_on_close' => false, @@ -195,5 +194,4 @@ return [ */ 'same_site' => 'lax', - ]; diff --git a/database/seeders/UserSeeder.php b/database/seeders/UserSeeder.php index 5b06e805..23c8fe6a 100644 --- a/database/seeders/UserSeeder.php +++ b/database/seeders/UserSeeder.php @@ -15,10 +15,11 @@ class UserSeeder extends Seeder */ public function run() { - User::factory()->create([ + User::create([ 'email' => 'admin@example.com', 'email_verified_at' => now(), 'password' => Hash::make('admin'), + 'name' => 'Adrema Benutzer', ]); } } diff --git a/docker-compose.yml b/docker-compose.yml index 43f14bab..39b3205c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,48 +1,70 @@ -version: '1' +version: '3' services: - webservice: - image: nginx:1.21.6-alpine - container_name: nginx - depends_on: - - php - ports: - - "8000:80" - volumes: - - ./:/app - - ./storage:/app/storage - - ./.docker/nginx/nginx.conf:/etc/nginx/nginx.conf - php: - build: - context: . - dockerfile: ./.docker/php.Dockerfile - container_name: php - depends_on: - - db - - dbtest - command: php-fpm -F -R - volumes: - - ./:/app - - ./storage:/app/storage - - ./.docker/nginx/nginx.conf:/etc/nginx/nginx.conf - db: - image: mariadb:10.6.5 - container_name: db - environment: - MARIADB_ROOT_PASSWORD: local - MYSQL_PASSWORD: local - MYSQL_DATABASE: db - MYSQL_USER: db - volumes: - - /opt/mysql-docker/scoutrobot-db:/var/lib/mysql - ports: - - "3309:3306" - dbtest: - image: mariadb:10.6.5 - container_name: dbtest - environment: - MARIADB_ROOT_PASSWORD: local - MYSQL_PASSWORD: local - MYSQL_DATABASE: db - MYSQL_USER: db - volumes: - - /opt/mysql-docker/scoutrobot-dbtest:/var/lib/mysql + webservice: + build: + context: . + dockerfile: ./.docker/nginx.Dockerfile + image: nginx:1.21.6-alpine + container_name: nginx + depends_on: + - php + ports: + - '8000:80' + volumes: + - ./.docker/nginx/nginx.conf:/etc/nginx/nginx.conf + + php: + build: + context: . + dockerfile: ./.docker/php.Dockerfile + container_name: php + depends_on: + - db + command: php-fpm -F -R + env_file: + - .app.env + environment: + DB_HOST: db + DB_DATABASE: db + DB_USERNAME: db + DB_PASSWORD: secret + QUEUE_CONNECTION: redis + XELATEX_BIN: /usr/bin/xelatex + PDFLATEX_BIN: /usr/bin/pdflatex + REDIS_HOST: redis + + horizon: + build: + context: . + dockerfile: ./.docker/php.Dockerfile + container_name: horizon + depends_on: + - db + - php + command: php artisan horizon + env_file: + - .app.env + environment: + DB_HOST: db + DB_DATABASE: db + DB_USERNAME: db + DB_PASSWORD: secret + QUEUE_CONNECTION: redis + XELATEX_BIN: /usr/bin/xelatex + PDFLATEX_BIN: /usr/bin/pdflatex + REDIS_HOST: redis + + db: + image: mariadb:10.6.5 + container_name: db + environment: + MARIADB_ROOT_PASSWORD: secret_root_password + MYSQL_PASSWORD: secret + MYSQL_DATABASE: db + MYSQL_USER: db + volumes: + - ./data/db:/var/lib/mysql + + redis: + image: redis:alpine3.18 + container_name: redis