Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a prod Dockerfile #1672

Merged
merged 19 commits into from
Dec 26, 2024
Merged

Add a prod Dockerfile #1672

merged 19 commits into from
Dec 26, 2024

Conversation

PyRowMan
Copy link
Contributor

This PR adds a new Dockerfile that would be usefull to create production docker images.

The production docker image needs to have an adapted installing script & "php artisan optimize" command to work.

This commit introduces a `--yes` option to the `nntmux:install` command, allowing users to skip confirmation prompts for a streamlined installation process. It also improves messaging and error handling, particularly around locked installs, and removes unnecessary usage of `Str` helper methods. These changes enhance usability and code simplicity.
Created a reusable Blade component for the application logo. This addition provides a consistent and maintainable way to display the logo in views.
This commit introduces a Dockerized environment for the application, including a Dockerfile, docker-compose.yml, and a custom entrypoint script. The setup supports multiple services like MariaDB, Redis, and Elasticsearch, with health checks and environment configurations. It also automates dependency installation, environment setup, and Laravel-specific tasks like caching and installation processes.
@PyRowMan PyRowMan mentioned this pull request Dec 17, 2024
docker-compose.yml Outdated Show resolved Hide resolved
Removed unnecessary packages, environment variables, and Sail-specific configurations. Replaced "sail" with "nntmux" for images, networks, and volumes. Simplified the setup by removing unused tests and redundant configurations.
Dockerfile Outdated Show resolved Hide resolved
Copy link
Member

@DariusIII DariusIII left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check my comments and do the changes.

@PyRowMan
Copy link
Contributor Author

Check my comments and do the changes.

I have also removed some extra libs @CicerBro was asking for

PyRowMan added 2 commits December 18, 2024 12:01
Introduced a new `.env.dist` template to streamline environment variable management. Added Manticore service to the `docker-compose.yml` for enhanced database querying support. Updated `docker-entrypoint.sh` to use `envsubst` for environment substitution when generating `.env`.
Integrates Manticore search as a new service in the Docker Compose configuration. Configures ports, environment variables, resource limits, and volume mapping for Manticore. Ensures compatibility with the existing network and infrastructure.
@PyRowMan PyRowMan requested a review from DariusIII December 18, 2024 11:05
@PyRowMan
Copy link
Contributor Author

PyRowMan commented Dec 18, 2024

It works well on my machine with this params :

ELASTICSEARCH_LOGGING=true
ELASTICSEARCH_ENABLED=true
TEMP_UNRAR_PATH='/app/resources/tmp/unrar/'
TEMP_UNZIP_PATH='/app/resources/tmp/unzip/'

VIEW_COMPILED_PATH=/app/storage/framework/views

APP_TZ=Europe/Paris
APP_URL=localhost
SESSION_DOMAIN=null
MAIL_MAILER=smtp
MAIL_DRIVER=smtp
MAIL_HOST=mailpit
MAIL_PORT=1025

REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379
REDIS_CLIENT=phpredis

MANTICORESEARCH_HOST=manticore
ELASTICSEARCH_HOST=elasticsearch
DB_CONNECTION=mariadb
DB_HOST=mariadb
DB_URL=nnntmux
DB_PORT=3306
DB_USER=nntmuxMySQLusereee
DB_USERNAME=nntmuxMySQLuser
DB_DATABASE=nntmux
DB_PASSWORD=nntmuxMySQLpassword
DB_ROOTPASSWORD=nntmuxMySQLpassword
DB_NAME=nntmux

Oh and I've constated that the first characted of "DB_URL" is not interpreted, but it seems to be used instead of "DB_NAME"

In the future we could update the .env.dist to add some default values

Copy link
Member

@DariusIII DariusIII left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested all the changes and can confirm it works as it should?

vcorre added 2 commits December 19, 2024 12:36
Moved .env file creation logic to execute earlier in the script for better clarity and structure. Ensures .env is generated before running subsequent commands, improving maintainability.
Removed an unnecessary space in the schedule runner command. This change ensures consistency in formatting and avoids potential errors during script execution. No functional behavior is affected.
@DariusIII
Copy link
Member

When you are 95% sure that you fixed issues, i will merge this PR, unless i find something that breaks the main code. Just let me know.

This update ensures the Elasticsearch indexes are created and populated during container startup. It improves initial setup automation by running relevant Artisan commands to handle data indexing and predb population seamlessly.
@PyRowMan
Copy link
Contributor Author

Yes, the container is working well, i've already created the helm chart too :
image
image
image

@DariusIII
Copy link
Member

Ok, just add a comment here that PR can be merged and i will merge it.

@PyRowMan
Copy link
Contributor Author

Ok, just add a comment here that PR can be merged and i will merge it.

You can merge :)

docker-entrypoint.sh Outdated Show resolved Hide resolved
.dockerignore Show resolved Hide resolved
@PyRowMan PyRowMan marked this pull request as draft December 20, 2024 08:39
@PyRowMan
Copy link
Contributor Author

PyRowMan commented Dec 20, 2024

We've discovered yesterday that the nzb's where not added inside the folder /storage/nzb.

At first I though it was because the folder didn't exist since i'm mounting a volume inside it, but creating it doesn't seem to resolve the issue.

I need a bit of time to investigate the issue, but if some of you know from where is could be coming, i'm all ears.

PS :

It could be related to theses errors :

[2024-12-20 00:41:05] NNTmux.ERROR: Allowed memory size of 134217728 bytes exhausted (tried to allocate 1687552 bytes) {"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\FatalError(code: 0): Allowed memory size of 134217728 bytes exhausted (tried to allocate 1687552 bytes) at /app/vendor/laravel/framework/src/Illuminate/Database/MySqlConnection.php:47)
[stacktrace]
#0 {main}
"}
[2024-12-20 00:42:00] NNTmux.ERROR: Allowed memory size of 134217728 bytes exhausted (tried to allocate 1568768 bytes) {"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\FatalError(code: 0): Allowed memory size of 134217728 bytes exhausted (tried to allocate 1568768 bytes) at /app/vendor/laravel/framework/src/Illuminate/Database/MySqlConnection.php:47)
[stacktrace]
#0 {main}
"}
[2024-12-20 00:47:08] NNTmux.ERROR: Allowed memory size of 134217728 bytes exhausted (tried to allocate 1474560 bytes) {"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\FatalError(code: 0): Allowed memory size of 134217728 bytes exhausted (tried to allocate 1474560 bytes) at /app/Blacklight/Binaries.php:867)
[stacktrace]
#0 {main}
"}

or this one :


[2024-12-20 07:47:55] NNTmux.ERROR: App\Models\Predb::getAll(): Argument #1 ($search) must be of type string, null given, called in /app/app/Http/Controllers/Admin/AdminPredbController.php on line 20 {"userId":3,"exception":"[object] (TypeError(code: 0): App\\Models\\Predb::getAll(): Argument #1 ($search) must be of type string, null given, called in /app/app/Http/Controllers/Admin/AdminPredbController.php on line 20 at /app/app/Models/Predb.php:191)
[stacktrace]
#0 /app/app/Http/Controllers/Admin/AdminPredbController.php(20): App\\Models\\Predb::getAll()
#1 /app/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): App\\Http\\Controllers\\Admin\\AdminPredbController->index()
#2 /app/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(44): Illuminate\\Routing\\Controller->callAction()
#3 /app/vendor/laravel/framework/src/Illuminate/Routing/Route.php(266): Illuminate\\Routing\\ControllerDispatcher->dispatch()
#4 /app/vendor/laravel/framework/src/Illuminate/Routing/Route.php(212): Illuminate\\Routing\\Route->runController()
#5 /app/vendor/laravel/framework/src/Illuminate/Routing/Router.php(808): Illuminate\\Routing\\Route->run()
#6 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(144): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}()
#7 /app/app/Http/Middleware/Google2FAMiddleware.php(20): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#8 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): App\\Http\\Middleware\\Google2FAMiddleware->handle()
#9 /app/vendor/spatie/laravel-permission/src/Middleware/RoleMiddleware.php(39): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#10 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Spatie\\Permission\\Middleware\\RoleMiddleware->handle()
#11 /app/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(51): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#12 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle()
#13 /app/vendor/laravel/framework/src/Illuminate/Session/Middleware/AuthenticateSession.php(67): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#14 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Session\\Middleware\\AuthenticateSession->handle()
#15 /app/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php(64): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#16 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Auth\\Middleware\\Authenticate->handle()
#17 /app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(88): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#18 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->handle()
#19 /app/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#20 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\View\\Middleware\\ShareErrorsFromSession->handle()
#21 /app/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(121): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#22 /app/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\\Session\\Middleware\\StartSession->handleStatefulRequest()
#23 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Session\\Middleware\\StartSession->handle()
#24 /app/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#25 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse->handle()
#26 /app/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(75): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#27 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Cookie\\Middleware\\EncryptCookies->handle()
#28 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(119): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#29 /app/vendor/laravel/framework/src/Illuminate/Routing/Router.php(807): Illuminate\\Pipeline\\Pipeline->then()
#30 /app/vendor/laravel/framework/src/Illuminate/Routing/Router.php(786): Illuminate\\Routing\\Router->runRouteWithinStack()
#31 /app/vendor/laravel/framework/src/Illuminate/Routing/Router.php(750): Illuminate\\Routing\\Router->runRoute()
#32 /app/vendor/laravel/framework/src/Illuminate/Routing/Router.php(739): Illuminate\\Routing\\Router->dispatchToRoute()
#33 /app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(201): Illuminate\\Routing\\Router->dispatch()
#34 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(144): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}()
#35 /app/vendor/livewire/livewire/src/Features/SupportDisablingBackButtonCache/DisableBackButtonCacheMiddleware.php(19): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#36 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Livewire\\Features\\SupportDisablingBackButtonCache\\DisableBackButtonCacheMiddleware->handle()
#37 /app/app/Http/Middleware/ForceJsonOnAPI.php(24): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#38 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): App\\Http\\Middleware\\ForceJsonOnAPI->handle()
#39 /app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(110): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#40 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance->handle()
#41 /app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#42 /app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle()
#43 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull->handle()
#44 /app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#45 /app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(51): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle()
#46 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\TrimStrings->handle()
#47 /app/vendor/laravel/framework/src/Illuminate/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#48 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Http\\Middleware\\ValidatePostSize->handle()
#49 /app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(110): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#50 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance->handle()
#51 /app/vendor/laravel/framework/src/Illuminate/Http/Middleware/HandleCors.php(49): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#52 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Http\\Middleware\\HandleCors->handle()
#53 /app/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php(58): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#54 /app/vendor/monicahq/laravel-cloudflare/src/Http/Middleware/TrustProxies.php(25): Illuminate\\Http\\Middleware\\TrustProxies->handle()
#55 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Monicahq\\Cloudflare\\Http\\Middleware\\TrustProxies->handle()
#56 /app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/InvokeDeferredCallbacks.php(22): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#57 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\InvokeDeferredCallbacks->handle()
#58 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(119): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#59 /app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(176): Illuminate\\Pipeline\\Pipeline->then()
#60 /app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(145): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter()
#61 /app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1190): Illuminate\\Foundation\\Http\\Kernel->handle()
#62 /app/public/index.php(17): Illuminate\\Foundation\\Application->handleRequest()
#63 {main}
"}

PyRowMan added 5 commits December 20, 2024 11:54
Introduced a conditional check in the entrypoint script to only clear caches if the install lock is missing and added logic to create necessary folder structures. Updated Laravel-specific post-installation steps to include extended permission settings. Enhanced the Dockerfile by including the Imagick PHP extension and updated `.dockerignore` to exclude additional storage directories.
Added .php-cs-fixer.cache to ignore list for better tooling support.
@PyRowMan PyRowMan marked this pull request as ready for review December 20, 2024 14:36
@PyRowMan
Copy link
Contributor Author

PyRowMan commented Dec 20, 2024

I wanted to push the logs in the stdout but i'll do that in another PR if it's ok.

@DariusIII
Copy link
Member

I wanted to push the logs in the stdout but i'll do that in another PR if it's ok.

That's fine.

@PyRowMan
Copy link
Contributor Author

I wanted to push the logs in the stdout but i'll do that in another PR if it's ok.

That's fine.

Then the PR is ready, i'm testing it along side with a helm chart on my local server and it runs smoothly :D

@DariusIII
Copy link
Member

Resolve these conflicts after merging your previous PR and i will merge this one.

@DariusIII DariusIII merged commit 2c5ae82 into NNTmux:master Dec 26, 2024
1 check passed
@DariusIII
Copy link
Member

I have an issue with permissions and web-app container does not start.

2024-12-26 22:05:55 {"level":"info","ts":1735247155.8758616,"msg":"FrankenPHP started 🐘","php_version":"8.3.14","num_threads":16}
2024-12-26 22:05:55 {"level":"info","ts":1735247155.8764682,"msg":"autosaved config (load with --resume flag)","file":"/config/caddy/autosave.json"}
2024-12-26 22:05:55 {"level":"info","ts":1735247155.8764944,"msg":"serving initial configuration"}
2024-12-26 22:06:04 {"level":"error","ts":1735247164.5367372,"msg":"write error","error":"write tcp 127.0.0.1:80->127.0.0.1:58234: write: connection reset by peer"}
2024-12-26 22:06:17 {"level":"error","ts":1735247177.4906685,"msg":"write error","error":"write tcp 127.0.0.1:80->127.0.0.1:38334: write: broken pipe"}

dependency failed to start: container newznab-tmux-webapp-1 is unhealthy

@PyRowMan
Copy link
Contributor Author

I have an issue with permissions and web-app container does not start.

2024-12-26 22:05:55 {"level":"info","ts":1735247155.8758616,"msg":"FrankenPHP started 🐘","php_version":"8.3.14","num_threads":16}
2024-12-26 22:05:55 {"level":"info","ts":1735247155.8764682,"msg":"autosaved config (load with --resume flag)","file":"/config/caddy/autosave.json"}
2024-12-26 22:05:55 {"level":"info","ts":1735247155.8764944,"msg":"serving initial configuration"}
2024-12-26 22:06:04 {"level":"error","ts":1735247164.5367372,"msg":"write error","error":"write tcp 127.0.0.1:80->127.0.0.1:58234: write: connection reset by peer"}
2024-12-26 22:06:17 {"level":"error","ts":1735247177.4906685,"msg":"write error","error":"write tcp 127.0.0.1:80->127.0.0.1:38334: write: broken pipe"}

dependency failed to start: container newznab-tmux-webapp-1 is unhealthy

It seems to be more about a 80 port that is already used, try to use another port in APP_PORT

@DariusIII
Copy link
Member

Changed it to 8000 but container still tries to use 80.

@DariusIII
Copy link
Member

Actually its healthcheck that is failing.

@PyRowMan
Copy link
Contributor Author

Actually its healthcheck that is failing.

I'll do anotther MR, I've resolved it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants