chore: настройка GitHub Actions для сборки Docker-образа и оптимизация Dockerfile#186
chore: настройка GitHub Actions для сборки Docker-образа и оптимизация Dockerfile#186GaMeRaM wants to merge 7 commits into
Conversation
Move the static frontend build into the Docker image instead of relying on a checked-in public snapshot. Why: - the committed public output had drifted from frontend source and referenced missing _nuxt assets - the image should produce a consistent public directory from source at build time - this removes a class of stale artifact bugs where HTML, payloads and hashed assets no longer match What changed: - add a Bun-based frontend builder stage that runs Nuxt generate - copy the generated public output from the builder stage into the runtime image - keep geoip and PHP dependency setup as separate build concerns - add frontend bun.lock for reproducible frontend dependency installs - tighten .dockerignore so local frontend build artifacts are not sent into Docker context Result: - Docker builds no longer depend on the repository shipping a prebuilt public tree - image builds are reproducible from frontend source - Docker context size is drastically smaller after excluding frontend/node_modules and Nuxt artifacts - the generated public output is now aligned with the actual frontend build
Treat the root public directory as generated frontend output instead of repository source. Why: - frontend source now lives under frontend/ and the Docker image builds the static site during image build - keeping generated public artifacts in git creates drift between source and built output - compose mounts and nginx host-file assumptions were overriding or bypassing the image-built frontend What changed: - ignore the generated root public directory in git - remove tracked public artifacts from the repository index while keeping them local for development - stop bind-mounting host public into app and nginx containers in compose files - let nginx fall back to the app for static asset misses instead of hard failing on missing host files Result: - frontend source of truth is consolidated under frontend/ - Docker and compose use the image-built frontend output consistently - generated Nuxt assets no longer churn in git history
Address two follow-up issues discovered during review of the Docker and CI changes. Why: - workflow_dispatch could trigger a publish without providing a predictable tag, which made manual test publishes unsuitable for branch and PR validation - the custom PHP JIT ini file was loading OPcache explicitly even though the base php:8.2-cli image already enables it, causing repeated "Cannot load Zend OPcache - it was already loaded" warnings during image build and runtime PHP commands What changed: - add a required workflow_dispatch input named image_tag for manual image publishing - split Docker metadata generation so manual runs always publish with the explicit tag provided by image_tag - keep the existing default-branch and git-tag publish behavior unchanged for normal push-based automation - remove the redundant zend_extension=opcache.so line from the custom JIT ini file Result: - manual GHCR publishes are now deterministic and usable for testing images from non-default branches - PHP no longer emits duplicate OPcache load warnings in the Docker image - JIT remains enabled and the existing image behavior is preserved aside from the warning removal
The Dockerfile refactor switched to a combined COPY for src, config and storage, but that form flattened directory contents into /app instead of creating /app/src, /app/config and /app/storage. Why this matters: - Composer autoload expects /app/src/functions.php based on composer.json autoload configuration - the plain image could fail at startup because the application files no longer matched the expected runtime layout - this also made runtime verification misleading because bind mounts in compose could mask the broken image structure What changed: - replace the combined COPY with explicit directory copies for src, config and storage Result: - the built image now preserves the expected application layout - the plain Docker image can be started without relying on host bind mounts to restore missing paths
| location / { | ||
| location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf|woff|woff2|eot|txt)$ { | ||
| try_files $uri $uri/ =404; | ||
| try_files $uri $uri/ @fallback; |
There was a problem hiding this comment.
for DDoS protection this thing may cause problems
nginx static cache not work for 404 but will make request to api
| frontend/.output | ||
| tmp | ||
| package-lock.json No newline at end of file | ||
| package-lock.json |
There was a problem hiding this comment.
предлагаю за одно удалить все лишние игноры из папки frontend, там копипаста (и gitignore тоже)
Ну и если тут проект ориентирован на bun, package-lock/yarn.lock наверное можно удалить из игноров так как их тут быть не должно.
There was a problem hiding this comment.
Из гита удалить стоит, а из игноров наоборот. Надо ведь оставить возможность собирать тем чем хочется локально без docker для тех кто хочет запустить без docker-а.
There was a problem hiding this comment.
Из гита удалить стоит, а из игноров наоборот. Надо ведь оставить возможность собирать тем чем хочется локально без docker для тех кто хочет запустить без docker-а.
Тогда надо лок файлы собрать и под гит их сохранить, так как я собрал на nodejs и словил пару ошибок сначала при резолве пакетов, потом при билде (ворнинги + ошибки резолва путей)
| # geoip | ||
| RUN git clone https://github.com/v2fly/geoip.git /app/geoip/ \ | ||
| && cd /app/geoip/ && go build . | ||
| COPY ./frontend /app/frontend |
There was a problem hiding this comment.
а не легче было бы просто всё скопировать, потом заинсталлить всё что нужно, а public/* собственно скопировать как это сделано дальше?
There was a problem hiding this comment.
Суть в том чтобы не переустанавливать зависимости каждый раз когда меняется код
There was a problem hiding this comment.
Я понимаю суть этого докерфайла, я говорю о том, что нет смысла копировать что-то дважды, скопировать сразу все просто логичней
|
|
||
| WORKDIR /app | ||
|
|
||
| COPY ./composer.json /app/ |
There was a problem hiding this comment.
я бы предложил под гит закинуть composer.lock чтобы зафиксировать дерево версий и тут его просто копировать, чтобы лишнего не закачивать в образ
| @@ -1,50 +1,64 @@ | |||
| FROM php:8.2-cli | |||
| FROM golang:1.24-bookworm AS geoip-builder | |||
There was a problem hiding this comment.
по хорошему бы доку дописать, чтобы запускали docker compose up -d --build, чтобы перебилд делали, раз вся загрузка ассетов и прочего находится тут, чтобы контейнер перебилдился
There was a problem hiding this comment.
Для разработки согласен. Для обычного деплоя достаточно образа из реестра
There was a problem hiding this comment.
Дока существует как раз для того, чтобы можно было делать пулл реквесты и раз тут переделывается способ разработки, то и доку дополнять было бы хорошо
|
@copilot resolve the merge conflicts in this pull request - you can leave the files in the /public/ folder, those that are newer, do not apply these from pull request |
Что сделано
Что изменено в Dockerfile
Что изменено в окружении запуска
Что изменено в структуре фронтенда
Результат