From 6da1b659154591a500d99e5f3a749939da450cca Mon Sep 17 00:00:00 2001 From: Flo Date: Fri, 31 Oct 2025 17:09:19 +0100 Subject: [PATCH] prod: new devenv --- .env.example | 6 ++-- bin/script/build | 3 -- bin/script/down | 3 -- bin/script/exec | 23 --------------- bin/script/firstRun | 40 ++++++++++++++++++++++++++ bin/script/init | 34 +++++++--------------- bin/script/stop | 3 -- bin/script/up | 3 -- bin/script/update | 39 +++++++++++++++++++++++++ composer.development.json | 4 +-- composer.json | 4 +-- config/autoload/api.global.php | 17 ----------- docker/docker-compose-mac.yml | 51 --------------------------------- docker/docker-compose.yml | 7 +++-- docker/mysql/scripts/initdb.sql | 4 +-- 15 files changed, 103 insertions(+), 138 deletions(-) delete mode 100755 bin/script/build delete mode 100755 bin/script/down delete mode 100755 bin/script/exec create mode 100755 bin/script/firstRun delete mode 100755 bin/script/stop delete mode 100755 bin/script/up create mode 100755 bin/script/update delete mode 100644 docker/docker-compose-mac.yml diff --git a/.env.example b/.env.example index bf42cae..885ae6c 100644 --- a/.env.example +++ b/.env.example @@ -1,10 +1,10 @@ # DB Configuration DB_DRIVER=pdo_mysql -DB_HOST=myTube-backend-mysql +DB_HOST=mytube-backend-mysql DB_PORT=3306 -DB_USER=myTube +DB_USER=mytube DB_PASSWORD=pass -DB_NAME=myTube +DB_NAME=mytube DB_NAME_LOG=log # MyTube Setup diff --git a/bin/script/build b/bin/script/build deleted file mode 100755 index 0cf812a..0000000 --- a/bin/script/build +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -$SCRIPT_DIR/exec build \ No newline at end of file diff --git a/bin/script/down b/bin/script/down deleted file mode 100755 index 7b6b977..0000000 --- a/bin/script/down +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -$SCRIPT_DIR/exec down \ No newline at end of file diff --git a/bin/script/exec b/bin/script/exec deleted file mode 100755 index 360cc39..0000000 --- a/bin/script/exec +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -COMMAND="$@" -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) - -#LOAD ENV VARIABLES FROM .ENV -export $(grep -v '^#' "${SCRIPT_DIR}/../../.env" | xargs) - -#MAC -if [[ "$OSTYPE" == "darwin"* ]]; then - docker compose -f "${SCRIPT_DIR}/../../docker/docker-compose-mac.yml" $COMMAND - -#LINUX -elif [[ "$OSTYPE" == "linux-gnu" ]]; then - docker compose -f "${SCRIPT_DIR}/../../docker/docker-compose.yml" $COMMAND - -else - echo "Dieses Skript wird auf deinem Gerät nicht unterstützt" - exit 1 -fi - -#UNSET ENV VARIABLES FROM .ENV -unset $(grep -v '^#' "${SCRIPT_DIR}/../../.env" | sed -E 's/(.*)=.*/\1/' | xargs) diff --git a/bin/script/firstRun b/bin/script/firstRun new file mode 100755 index 0000000..902f6b3 --- /dev/null +++ b/bin/script/firstRun @@ -0,0 +1,40 @@ +#!/bin/bash + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +PROJECT_DIR=$(realpath $SCRIPT_DIR/../../) +ENV_DIR=$(realpath $PROJECT_DIR/../../../) + +source $ENV_DIR/bin/messages +source $ENV_DIR/bin/drun + +# Create local config files +infomsg '[backend] Creating local config...' +cp "$PROJECT_DIR"/config/autoload/monolog.local.php.dist "$PROJECT_DIR"/config/autoload/monolog.local.php +cp "$PROJECT_DIR"/config/autoload/doctrine.local.php.dist "$PROJECT_DIR"/config/autoload/doctrine.local.php +cp "$PROJECT_DIR"/config/autoload/redis.local.php.dist "$PROJECT_DIR"/config/autoload/redis.local.php +successmsg '[backend] Local config done' + +# Install packages +infomsg '[backend] Composer install...' +drun backend composer install -o +successmsg '[backend] Composer install done' + +# Dump autoload +infomsg "[backend]: Dump autoload" +drun backend composer da +successmsg "[backend]: Dump autoload done" + +# Migrate Databases +infomsg '[backend] Running migrations...' +drun backend composer doctrine migrations:migrate --no-interaction +drun backend composer doctrine-log migrations:migrate --no-interaction +successmsg '[backend] Migrations done' + +# Seed DB +infomsg '[backend] Running seeder...' +drun backend composer console init:data +drun backend composer console rbac:update +successmsg '[backend] Seeding done' + +successmsg '[backend] Initialization script done' + diff --git a/bin/script/init b/bin/script/init index 5ba2fe5..0ddb959 100755 --- a/bin/script/init +++ b/bin/script/init @@ -2,31 +2,19 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) PROJECT_DIR=$(realpath $SCRIPT_DIR/../../) -ENV_DIR=$(realpath $PROJECT_DIR/../../) +ENV_DIR=$(realpath $PROJECT_DIR/../../../) +source $ENV_DIR/bin/messages # Check .env file -if [ ! -f "$PROJECT_DIR/.env" ] -then - echo "Create .env file from example..." +if [ ! -f "$PROJECT_DIR/.env" ] ; then + infomsg "[backend] Creating .env" cp "$PROJECT_DIR/.env.example" "$PROJECT_DIR/.env" - echo ".env file created, please change variables and call me again" - exit 1 + successmsg "[backend] Created .env" fi -# Build and start docker containers -$SCRIPT_DIR/exec build -$SCRIPT_DIR/exec up -d - -# Source drun -source $ENV_DIR/bin/script/drun - -# Install PHP packages -drun myTube-backend composer install - -# Migrate databases to current version -drun myTube-backend composer dmm -drun myTube-backend composer dmlm - -# Insert setup for project after this line -drun myTube-backend composer console rbac:update -drun myTube-backend composer console init:data \ No newline at end of file +# Check docker-compose.yml file +if [ ! -f "$PROJECT_DIR/docker/docker-compose.yml" ] ; then + infomsg "[backend] Creating docker-compose.yml" + cp "$PROJECT_DIR/docker/docker-compose.yml.dist" "$PROJECT_DIR/docker/docker-compose.yml" + successmsg "[backend] Creating docker-compose.yml" +fi diff --git a/bin/script/stop b/bin/script/stop deleted file mode 100755 index 64393e9..0000000 --- a/bin/script/stop +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -$SCRIPT_DIR/exec stop \ No newline at end of file diff --git a/bin/script/up b/bin/script/up deleted file mode 100755 index 7bd3164..0000000 --- a/bin/script/up +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -$SCRIPT_DIR/exec up -d \ No newline at end of file diff --git a/bin/script/update b/bin/script/update new file mode 100755 index 0000000..17cb3e1 --- /dev/null +++ b/bin/script/update @@ -0,0 +1,39 @@ +#!/bin/bash +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +PROJECT_DIR=$(realpath $SCRIPT_DIR/../../) +ENV_DIR=$(realpath $PROJECT_DIR/../../../) +SYSTEM_ENV_FILE="$PROJECT_DIR/.env" +CWD=$(pwd) + +source $ENV_DIR/bin/messages +source $ENV_DIR/bin/drun + +# Pull branch in project directory +infomsg "[backend]: Git pull" +cd "$PROJECT_DIR" +git pull +successmsg "[backend]: Git pull done" + +# Install packages +infomsg '[backend] Composer install...' +drun backend composer install -o +successmsg '[backend] Composer install done' + +# Dump autoload +infomsg "[backend]: Dump autoload" +drun backend composer da +successmsg "[backend]: Dump autoload done" + +# Migrate Databases +infomsg '[backend] Running migrations...' +drun backend composer doctrine migrations:migrate --no-interaction +drun backend composer doctrine-log migrations:migrate --no-interaction +successmsg '[backend] Migrations done' + +# Update permissions +infomsg "[backend]: Update roles and permissions" +drun backend composer console rbac:update +successmsg "[backend]: Update roles and permissions done" + +# Switch back to current working directory +cd "$CWD" \ No newline at end of file diff --git a/composer.development.json b/composer.development.json index 5f4aad0..b77abfd 100644 --- a/composer.development.json +++ b/composer.development.json @@ -81,8 +81,8 @@ "scripts": { "dmg": "php bin\/doctrine-migrations.php migrations:generate", "dmm": "php bin\/doctrine-migrations.php migrations:migrate --no-interaction", - "dmlg": "php bin\/doctrine-migrations-log.php migrations:generate", - "dmlm": "php bin\/doctrine-migrations-log.php migrations:migrate --no-interaction", + "doctrine": "php bin\/doctrine-migrations.php", + "doctrine-log": "php bin\/doctrine-migrations-log.php", "console": "php bin\/console.php", "createApi": "php bin\/createApi.php", "createPipeline": "php bin\/createPipeline.php", diff --git a/composer.json b/composer.json index 7fd2462..5796a3d 100644 --- a/composer.json +++ b/composer.json @@ -52,8 +52,8 @@ "scripts": { "dmg": "php bin/doctrine-migrations.php migrations:generate", "dmm": "php bin/doctrine-migrations.php migrations:migrate --no-interaction", - "dmlg": "php bin/doctrine-migrations-log.php migrations:generate", - "dmlm": "php bin/doctrine-migrations-log.php migrations:migrate --no-interaction", + "doctrine": "php bin/doctrine-migrations.php", + "doctrine-log": "php bin/doctrine-migrations-log.php", "console": "php bin/console.php", "createApi": "php bin/createApi.php", "createPipeline": "php bin/createPipeline.php", diff --git a/config/autoload/api.global.php b/config/autoload/api.global.php index bc0c3b9..ac889ef 100644 --- a/config/autoload/api.global.php +++ b/config/autoload/api.global.php @@ -3,26 +3,9 @@ return [ 'api' => [ 'keys' => [ - 'myTube' => $_ENV['HOMEPAGE_API_KEY'], - 'notification' => $_ENV['NOTIFICATION_API_KEY'], ], 'services' => [ - 'myTube' => [ - 'host' => 'myTube-backend-nginx', - 'apis' => [ - - ] - ], - 'notification' => [ - 'host' => 'notification-backend-nginx', - 'apis' => [ - 'send-mail' => [ - 'path' => '/api/mail/send', - 'method' => 'POST' - ], - ], - ], ], ], ]; diff --git a/docker/docker-compose-mac.yml b/docker/docker-compose-mac.yml deleted file mode 100644 index d2dc212..0000000 --- a/docker/docker-compose-mac.yml +++ /dev/null @@ -1,51 +0,0 @@ -version: '3' -networks: - myTube: - external: true - -services: - myTube-backend-mysql: - image: myTube-backend-mysql - networks: - - myTube - build: - context: ./../ - dockerfile: ./docker/mysql/dockerfile - volumes: - - /Users/flo/dev/backend/myTube/var/db:/var/lib/mysql:z - environment: - MYSQL_USER: ${DB_USER} - MYSQL_PASSWORD: ${DB_PASSWORD} - ports: - - 3306:3306 - healthcheck: - test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"] - timeout: 20s - retries: 10 - - myTube-backend-app: - image: myTube-backend-app - networks: - - myTube - build: - context: ./../ - dockerfile: ./docker/php/dockerfile - volumes: - - /Users/flo/dev/backend/myTube/:/var/www/html:z - ports: - - 9000:9000 - depends_on: - myTube-backend-mysql: - condition: service_healthy - - myTube-backend-nginx: - image: myTube-backend-nginx - networks: - - myTube - build: - context: ./../ - dockerfile: ./docker/nginx/dockerfile - ports: - - 8080:80 - depends_on: - - myTube-backend-app \ No newline at end of file diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index f5a39a0..e633bd9 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,4 +1,3 @@ -version: '3' networks: mytube: external: true @@ -45,7 +44,9 @@ services: build: context: ./../ dockerfile: ./docker/nginx/dockerfile - ports: - - 8080:80 + labels: + - "traefik.http.routers.backend.rule=(Host(`mytube.srv`) || Host(`192.168.152.60`)) && PathPrefix(`/api`)" + - "traefik.http.routers.backend.entrypoints=websecure" + - "traefik.http.routers.backend.tls.certresolver=le" depends_on: - mytube-backend-app \ No newline at end of file diff --git a/docker/mysql/scripts/initdb.sql b/docker/mysql/scripts/initdb.sql index ed527bc..c689830 100644 --- a/docker/mysql/scripts/initdb.sql +++ b/docker/mysql/scripts/initdb.sql @@ -1,4 +1,4 @@ CREATE DATABASE IF NOT EXISTS `log`; -CREATE DATABASE IF NOT EXISTS `myTube`; +CREATE DATABASE IF NOT EXISTS `mytube`; -GRANT ALL PRIVILEGES on *.* to 'myTube'@'%'; \ No newline at end of file +GRANT ALL PRIVILEGES on *.* to 'mytube'@'%'; \ No newline at end of file