diff --git a/.dockerignore b/.dockerignore index 7987a48..b3c3f71 100644 --- a/.dockerignore +++ b/.dockerignore @@ -5,3 +5,4 @@ !/apache.conf !/php.ini !/koel-entrypoint +!/koel-init diff --git a/Dockerfile b/Dockerfile index 089620a..0e537d8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -124,6 +124,7 @@ ENV FFMPEG_PATH=/usr/bin/ffmpeg \ # Setup bootstrap script. COPY koel-entrypoint /usr/local/bin/ +COPY koel-init /usr/local/bin/ ENTRYPOINT ["koel-entrypoint"] CMD ["apache2-foreground"] diff --git a/README.md b/README.md index 8c5a5a0..fb03194 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,8 @@ docker-compose -f ./docker-compose.postgres.yml up -d ## The `koel:init` command +This command is automatically ran when the container starts, but can be disabled if you want to do some manual adjustments first. As such it is often sufficient to provide the needed env variables to the container to setup koel. + For the first installation and every subsequent upgrade, you will need to run the `koel:init` command, which handles migrations and other setup tasks. For instance, during the first run, this command will generate the `APP_KEY`, create the default admin user, and initialize the database. For subsequent runs, it will apply any new migrations and update the database schema as needed. @@ -189,6 +191,7 @@ For all new songs, the search index will be automatically populated by `php arti > [!IMPORTANT] > This list is not exhaustive and may not be up-to-date. See [`.env.example`][koel-env-example] for a complete reference. +- `SKIP_INIT`: Prevents the container from automatically running the init script on startup. - `DB_CONNECTION`: `mysql` OR `pgsql` OR `sqlsrv` OR `sqlite-persistent`. Corresponds to the type of database being used with Koel. - `DB_HOST`: `database`. The name of the Docker container hosting the database. Koel needs to be on the same Docker network to find the database by its name. - `DB_USERNAME`: `koel`. If you change it, also change it in the database container. @@ -199,6 +202,7 @@ For all new songs, the search index will be automatically populated by `php arti - `MEMORY_LIMIT`: The amount of memory in MB for the scanning process. Increase this value if `php artisan koel:scan` runs out of memory. - `LASTFM_API_KEY` and `LASTFM_API_SECRET`: Enables Last.fm integration. See https://docs.koel.dev/3rd-party.html#last-fm - `SPOTIFY_CLIENT_ID` and `SPOTIFY_CLIENT_SECRET`: Enables Spotify integration. See https://docs.koel.dev/3rd-party.html#spotify +- `OPTIMIZE_CONFIG` Preloads and optimizes koel's configuration. This disables config modifications while the container is running. If you enable this, every change to the configuration will require a container restart to be applied. ## Volumes diff --git a/koel-entrypoint b/koel-entrypoint index cf21cd4..de2e25f 100755 --- a/koel-entrypoint +++ b/koel-entrypoint @@ -1,10 +1,13 @@ -#!/bin/bash +#!/bin/sh set -e # Change to program root directory. cd /var/www/html +# Run the koel-init script to (optionally) optimize configs and (optionally) run initialize/update koel +su -s '/bin/sh' -c "/usr/local/bin/koel-init" www-data + # Run the next entrypoint in the chain. echo "running docker-php-entrypoint with arguments $@" docker-php-entrypoint $@ diff --git a/koel-init b/koel-init new file mode 100755 index 0000000..27aa1f6 --- /dev/null +++ b/koel-init @@ -0,0 +1,27 @@ +#!/bin/bash + +if [[ ! -f /var/www/html/.env ]]; then + echo "No .env file found in /var/www/html. Make sure to mount a .env file to store the configuration. You can use the koel:init command (see https://github.com/koel/docker#the-koelinit-command) for a guided setup." + echo "" + echo "See https://github.com/koel/koel/blob/master/.env.example for an example .env file." + exit 0 +fi + +if [[ -z "${SKIP_INIT}" ]]; then + + if [[ -z "${OPTIMIZE_CONFIG}" ]]; then + echo "Config not optimized. You can optimize the config with `OPTIMIZE_CONFIG`. Note that this will prevent config modifications from being applied until the container is restarted." + else + echo "Optimizing config..." + # clear before caching, in case this is a container reboot and it was already cached from before + php artisan config:clear + php artisan config:cache + fi + + # Invoke the init script so database migrations run and the config is at least partially validated + echo "Running installer..." + php artisan koel:init --no-assets --no-interaction + php artisan koel:doctor +else + echo "Initialization skipped. koel might not work properly if it is misconfigured or if the database is out of date. This should not be used outside of debugging or manual initial setups!" +fi