diff --git a/.gitignore b/.gitignore index 19cc0ba..15fbc09 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ /.idea /.vscode /downloaded +/src/commit /src/cache/* /src/vendor /src/views/custom/* diff --git a/README.md b/README.md index 96f1d6a..c9fa33b 100644 --- a/README.md +++ b/README.md @@ -188,19 +188,12 @@ GET https://iptv.axenov.dev//json ## Развёртывание проекта -### Aвтоматически +Локально достаточно выполнить `./iptv init && ./iptv open`. -Выполнить `./iptv init` +На сервере опционально можно настроить реверс-прокси до контейнера, например, чтобы настроить доступ по доменному +имени, изменить порт, подключить SSL-сертификаты или др. -### Вручную - -1. Выполнить `cp ./src/.env.example ./src/.env`, установить необходимые параметры в файле `./src/.env` -2. Выполнить `docker compose up -d --build` (или `./iptv up`) -3. Открыть `http://:8080` в браузере (или `./iptv open`) - -Если на сервере, на котором запускаются контейнеры, стоит apache2, то его можно использовать как реверс прокси: - -Для этого следует: +Если на сервере, на котором запускаются контейнеры, стоит apache2, то, чтобы использовать его как реверс-прокси, нужно: ``` $ sudo a2enmod proxy proxy_http proxy_balancer lbmethod_byrequests diff --git a/docker-compose.yml b/docker-compose.yml index 7c1dad5..24054ca 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -32,7 +32,7 @@ services: - ./log/nginx:/var/log/nginx:rw - ./src:/var/www:ro ports: - - 8080:80 + - '8080:80' links: - php depends_on: diff --git a/hooks/post-commit b/hooks/post-commit new file mode 100755 index 0000000..3820e9e --- /dev/null +++ b/hooks/post-commit @@ -0,0 +1,4 @@ +#!/bin/bash +# хук пробрасывает хэш свежего коммита в контейнер +# для его отображения в подвале страницы +git rev-parse HEAD > src/commit diff --git a/hooks/post-merge b/hooks/post-merge new file mode 100755 index 0000000..b54438e --- /dev/null +++ b/hooks/post-merge @@ -0,0 +1,7 @@ +#!/bin/bash +# хук пробрасывает хэш свежего коммита в контейнер +# для его отображения в подвале страницы и очищает +# кеш шаблонов twig после слияния веток +# главным образом необходимо при git pull +git rev-parse HEAD > src/commit +docker exec -ti iptv-php rm -rf cache/views diff --git a/iptv b/iptv index 9d59a10..c330d6a 100755 --- a/iptv +++ b/iptv @@ -15,15 +15,20 @@ open_browser() { } case "$1" in - '' | 'help' ) echo -e "Provide one of operations: \t init, start, stop, up, down, restart, rebuild, open"; + '' | 'help' ) echo -e "Provide one of operations: \t init, start, stop, up, down, restart, rebuild, open, hooks"; echo "Otherwise all args will passed to 'docker exec -ti $CONTAINER ...'" ;; - 'init' ) cp src/.env.example src/.env && nano src/.env && ./iptv up && ./iptv composer i && ./iptv open && echo -e "\nYou're welcome!\n\t$APP_URL";; + 'init' ) cp src/.env.example src/.env && \ + ./iptv hooks && \ + ./iptv up && \ + ./iptv composer i && \ + echo "Project started successfully! $APP_URL" ;; 'up' ) $CMD up -d --build && ./iptv open ;; # build and start containers 'down' ) $CMD down --remove-orphans ;; # stop and remove containers - 'start' ) $CMD start && ./iptv open ;; # start containers + 'start' ) $CMD start ;; # start containers 'stop' ) $CMD stop ;; # stop containers 'restart' ) $CMD stop && $CMD start ;; # restart containers 'rebuild' ) $CMD down --remove-orphans && $CMD up -d --build ;; # rebuild containers - 'open' ) open_browser $APP_URL ;; - * ) docker exec -ti $CONTAINER $@ # exec anything else in container + 'open' ) open_browser $APP_URL && echo -e "\nYou're welcome!\n\t$APP_URL" ;; + 'hooks' ) ./hooks/post-commit && cp hooks/* .git/hooks ;; + * ) docker exec -ti $CONTAINER $* ;; # exec anything else in container esac diff --git a/src/app/Extensions/TwigFunctions.php b/src/app/Extensions/TwigFunctions.php index 555cefc..a467b90 100644 --- a/src/app/Extensions/TwigFunctions.php +++ b/src/app/Extensions/TwigFunctions.php @@ -13,6 +13,7 @@ class TwigFunctions extends AbstractExtension { return [ new TwigFunction('config', [$this, 'config']), + new TwigFunction('commit', [$this, 'commit']), new TwigFunction('is_file', [$this, 'is_file']), new TwigFunction('base_url', [$this, 'base_url']), ]; @@ -23,6 +24,11 @@ class TwigFunctions extends AbstractExtension return config($key, $default); } + public function commit(): string + { + return file_get_contents(root_path('commit')); + } + public function base_url(string $path = ''): string { return base_url($path); diff --git a/src/views/layouts/default.twig b/src/views/layouts/default.twig index b1833d6..f9099d9 100644 --- a/src/views/layouts/default.twig +++ b/src/views/layouts/default.twig @@ -62,7 +62,12 @@ FAQ | GitHub | Gitea | axenov.dev + href="https://axenov.dev">axenov.dev
+ + commit {{ commit()[:8] }} + {% if is_file("custom/custom.twig") %}