Skip to content

Commit 0ac23cd

Browse files
Copilotjbtronics
andauthored
Add COMPOSER_EXTRA_PACKAGES env var for runtime package installation in Docker (#1138)
* Initial plan * Add COMPOSER_EXTRA_PACKAGES environment variable support for Docker containers Co-authored-by: jbtronics <[email protected]> * Add shellcheck disable comment for intentional word splitting Co-authored-by: jbtronics <[email protected]> * Add documentation for installing mailer packages in email.md Co-authored-by: jbtronics <[email protected]> * Add --no-dev flag to composer require to prevent dev packages installation Co-authored-by: jbtronics <[email protected]> * Use --no-install with require and run separate install command Co-authored-by: jbtronics <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: jbtronics <[email protected]>
1 parent 60ff727 commit 0ac23cd

File tree

4 files changed

+147
-2
lines changed

4 files changed

+147
-2
lines changed

.docker/frankenphp/docker-entrypoint.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,28 @@ if [ "$1" = 'frankenphp' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then
2626
composer install --prefer-dist --no-progress --no-interaction
2727
fi
2828

29+
# Install additional composer packages if COMPOSER_EXTRA_PACKAGES is set
30+
if [ -n "$COMPOSER_EXTRA_PACKAGES" ]; then
31+
echo "Installing additional composer packages: $COMPOSER_EXTRA_PACKAGES"
32+
# Note: COMPOSER_EXTRA_PACKAGES is intentionally not quoted to allow word splitting
33+
# This enables passing multiple package names separated by spaces
34+
# shellcheck disable=SC2086
35+
composer require $COMPOSER_EXTRA_PACKAGES --no-install --no-interaction --no-progress
36+
if [ $? -eq 0 ]; then
37+
echo "Running composer install to install packages without dev dependencies..."
38+
composer install --no-dev --no-interaction --no-progress --optimize-autoloader
39+
if [ $? -eq 0 ]; then
40+
echo "Successfully installed additional composer packages"
41+
else
42+
echo "Failed to install composer dependencies"
43+
exit 1
44+
fi
45+
else
46+
echo "Failed to add additional composer packages to composer.json"
47+
exit 1
48+
fi
49+
fi
50+
2951
if grep -q ^DATABASE_URL= .env; then
3052
echo "Waiting for database to be ready..."
3153
ATTEMPTS_LEFT_TO_REACH_DATABASE=60

.docker/partdb-entrypoint.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,28 @@ if [ -d /var/www/html/var/db ]; then
3939
fi
4040
fi
4141

42+
# Install additional composer packages if COMPOSER_EXTRA_PACKAGES is set
43+
if [ -n "$COMPOSER_EXTRA_PACKAGES" ]; then
44+
echo "Installing additional composer packages: $COMPOSER_EXTRA_PACKAGES"
45+
# Note: COMPOSER_EXTRA_PACKAGES is intentionally not quoted to allow word splitting
46+
# This enables passing multiple package names separated by spaces
47+
# shellcheck disable=SC2086
48+
sudo -E -u www-data composer require $COMPOSER_EXTRA_PACKAGES --no-install --no-interaction --no-progress
49+
if [ $? -eq 0 ]; then
50+
echo "Running composer install to install packages without dev dependencies..."
51+
sudo -E -u www-data composer install --no-dev --no-interaction --no-progress --optimize-autoloader
52+
if [ $? -eq 0 ]; then
53+
echo "Successfully installed additional composer packages"
54+
else
55+
echo "Failed to install composer dependencies"
56+
exit 1
57+
fi
58+
else
59+
echo "Failed to add additional composer packages to composer.json"
60+
exit 1
61+
fi
62+
fi
63+
4264
# Start PHP-FPM (the PHP_VERSION is replaced by the configured version in the Dockerfile)
4365
php-fpmPHP_VERSION -F &
4466

docs/installation/email.md

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,75 @@ To make emails work you have to properly configure a mail provider in Part-DB.
1515
## Configuration
1616

1717
Part-DB uses [Symfony Mailer](https://symfony.com/doc/current/mailer.html) to send emails, which supports multiple
18-
automatic mail providers (like MailChimp or SendGrid). If you want to use one of these providers, check the Symfony
18+
mail providers (like Mailgun, SendGrid, or Brevo). If you want to use one of these providers, check the Symfony
1919
Mailer documentation for more information.
2020

2121
We will only cover the configuration of an SMTP provider here, which is sufficient for most use-cases.
2222
You will need an email account, which you can use to send emails from via password-based SMTP authentication, this account
2323
should be dedicated to Part-DB.
2424

25+
### Using specialized mail providers (Mailgun, SendGrid, etc.)
26+
27+
If you want to use a specialized mail provider like Mailgun, SendGrid, Brevo (formerly Sendinblue), Amazon SES, or
28+
Postmark instead of SMTP, you need to install the corresponding Symfony mailer package first.
29+
30+
#### Docker installation
31+
32+
If you are using Part-DB in Docker, you can install additional mailer packages by setting the `COMPOSER_EXTRA_PACKAGES`
33+
environment variable in your `docker-compose.yaml`:
34+
35+
```yaml
36+
environment:
37+
- COMPOSER_EXTRA_PACKAGES=symfony/mailgun-mailer
38+
- MAILER_DSN=mailgun+api://API_KEY:DOMAIN@default
39+
40+
- EMAIL_SENDER_NAME=Part-DB
41+
- ALLOW_EMAIL_PW_RESET=1
42+
```
43+
44+
You can install multiple packages by separating them with spaces:
45+
46+
```yaml
47+
environment:
48+
- COMPOSER_EXTRA_PACKAGES=symfony/mailgun-mailer symfony/sendgrid-mailer
49+
```
50+
51+
The packages will be installed automatically when the container starts.
52+
53+
Common mailer packages:
54+
- `symfony/mailgun-mailer` - For [Mailgun](https://www.mailgun.com/)
55+
- `symfony/sendgrid-mailer` - For [SendGrid](https://sendgrid.com/)
56+
- `symfony/brevo-mailer` - For [Brevo](https://www.brevo.com/) (formerly Sendinblue)
57+
- `symfony/amazon-mailer` - For [Amazon SES](https://aws.amazon.com/ses/)
58+
- `symfony/postmark-mailer` - For [Postmark](https://postmarkapp.com/)
59+
60+
#### Direct installation (non-Docker)
61+
62+
If you have installed Part-DB directly on your server (not in Docker), you need to manually install the required
63+
mailer package using composer.
64+
65+
Navigate to your Part-DB installation directory and run:
66+
67+
```bash
68+
# Install the package as the web server user
69+
sudo -u www-data composer require symfony/mailgun-mailer
70+
71+
# Clear the cache
72+
sudo -u www-data php bin/console cache:clear
73+
```
74+
75+
Replace `symfony/mailgun-mailer` with the package you need. You can install multiple packages at once:
76+
77+
```bash
78+
sudo -u www-data composer require symfony/mailgun-mailer symfony/sendgrid-mailer
79+
```
80+
81+
After installing the package, configure the `MAILER_DSN` in your `.env.local` file according to the provider's
82+
documentation (see [Symfony Mailer documentation](https://symfony.com/doc/current/mailer.html) for DSN format for
83+
each provider).
84+
85+
## SMTP Configuration
86+
2587
To configure the SMTP provider, you have to set the following environment variables:
2688

2789
`MAILER_DSN`: You have to provide the SMTP server address and the credentials for the email account here. The format is

docs/installation/installation_docker.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ services:
8080
#- BANNER=This is a test banner<br>with a line break
8181

8282
# If you use a reverse proxy in front of Part-DB, you must configure the trusted proxies IP addresses here (see reverse proxy documentation for more information):
83-
# - TRUSTED_PROXIES=127.0.0.0/8,::1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
83+
# - TRUSTED_PROXIES=127.0.0.0/8,::1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
84+
85+
# If you need to install additional composer packages (e.g., for specific mailer transports), you can specify them here:
86+
# The packages will be installed automatically when the container starts
87+
# - COMPOSER_EXTRA_PACKAGES=symfony/mailgun-mailer symfony/sendgrid-mailer
8488
```
8589

8690
4. Customize the settings by changing the environment variables (or adding new ones). See [Configuration]({% link
@@ -149,6 +153,9 @@ services:
149153
# Override value if you want to show a given text on homepage.
150154
# When this is commented out the webUI can be used to configure the banner
151155
#- BANNER=This is a test banner<br>with a line break
156+
157+
# If you need to install additional composer packages (e.g., for specific mailer transports), you can specify them here:
158+
# - COMPOSER_EXTRA_PACKAGES=symfony/mailgun-mailer symfony/sendgrid-mailer
152159

153160
database:
154161
container_name: partdb_database
@@ -169,6 +176,38 @@ services:
169176

170177
```
171178

179+
### Installing additional composer packages
180+
181+
If you need to use specific mailer transports or other functionality that requires additional composer packages, you can
182+
install them automatically at container startup using the `COMPOSER_EXTRA_PACKAGES` environment variable.
183+
184+
For example, if you want to use Mailgun as your email provider, you need to install the `symfony/mailgun-mailer` package.
185+
Add the following to your docker-compose.yaml environment section:
186+
187+
```yaml
188+
environment:
189+
- COMPOSER_EXTRA_PACKAGES=symfony/mailgun-mailer
190+
- MAILER_DSN=mailgun+api://API_KEY:DOMAIN@default
191+
```
192+
193+
You can specify multiple packages by separating them with spaces:
194+
195+
```yaml
196+
environment:
197+
- COMPOSER_EXTRA_PACKAGES=symfony/mailgun-mailer symfony/sendgrid-mailer
198+
```
199+
200+
{: .info }
201+
> The packages will be installed when the container starts. This may increase the container startup time on the first run.
202+
> The installed packages will persist in the container until it is recreated.
203+
204+
Common mailer packages you might need:
205+
- `symfony/mailgun-mailer` - For Mailgun email service
206+
- `symfony/sendgrid-mailer` - For SendGrid email service
207+
- `symfony/brevo-mailer` - For Brevo (formerly Sendinblue) email service
208+
- `symfony/amazon-mailer` - For Amazon SES email service
209+
- `symfony/postmark-mailer` - For Postmark email service
210+
172211
### Update Part-DB
173212

174213
You can update Part-DB by pulling the latest image and restarting the container.

0 commit comments

Comments
 (0)