fixed minor issues and added indexer scheduling to container image

This commit is contained in:
pushrbx 2022-09-10 16:58:13 +01:00
parent d49a159dae
commit 406d77bbeb
4 changed files with 25 additions and 15 deletions

View File

@ -1,4 +1,5 @@
.dockerignore
docker/*
Makefile
docker*.yml
Dockerfile

View File

@ -1,5 +1,5 @@
FROM jikanme/jikan-rest-php:8.1
ARG GITHUB_PERSONAL_TOKEN
RUN set -ex \
&& apt-get update && apt-get install -y --no-install-recommends \
openssl \
@ -22,7 +22,7 @@ RUN set -ex \
# create unpriviliged user
&& adduser --disabled-password --shell "/sbin/nologin" --home "/nonexistent" --no-create-home --uid "10001" --gecos "" "jikanapi" \
&& mkdir /app /var/run/rr \
&& chown -R jikanapi:jikanapi /app /var/run/rr \
&& chown -R jikanapi:jikanapi /app /var/run/rr /etc/supercronic/laravel \
&& chmod -R 777 /var/run/rr
USER jikanapi:jikanapi
@ -34,8 +34,8 @@ COPY --chown=jikanapi:jikanapi ./composer.* /app/
# check if GITHUB_PERSONAL_TOKEN is set and configure it for composer
# it is recommended to set this for the build, otherwise the build might fail because of github's rate limits
RUN if [ -z ${GITHUB_PERSONAL_TOKEN+x} ]; then echo "** GITHUB_PERSONAL_TOKEN is not set. This build may fail due to github rate limits."; \
else composer config github-oath.github.com "$GITHUB_PERSONAL_TOKEN"; fi
RUN if [ -z "$GITHUB_PERSONAL_TOKEN" ]; then echo "** GITHUB_PERSONAL_TOKEN is not set. This build may fail due to github rate limits."; \
else composer config github-oauth.github.com "$GITHUB_PERSONAL_TOKEN"; fi
# install composer dependencies (autoloader MUST be generated later!)
RUN composer install -n --no-dev --no-cache --no-ansi --no-autoloader --no-scripts --prefer-dist

View File

@ -48,11 +48,12 @@ VAR2=value2
```
There are additional configuration options:
| Name | Description |
|--------------------------------|---------------------------------------------------------------------------------------------------------------------------|
| RR_MAX_WORKER_MEMORY | (Number) Configures the available memory in megabytes for the php scripts |
| RR_MAX_REQUEST_SIZE_MB | (Number) Configures the max allowed request body size in megabytes |
| JIKAN_QUEUE_WORKER_PROCESS_NUM | (Number) Configures the number of running queue worker processes. (You want to increase this if you experience huge load) |
| Name | Description |
|--------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| RR_MAX_WORKER_MEMORY | (Number) Configures the available memory in megabytes for the php scripts |
| RR_MAX_REQUEST_SIZE_MB | (Number) Configures the max allowed request body size in megabytes |
| JIKAN_QUEUE_WORKER_PROCESS_NUM | (Number) Configures the number of running queue worker processes. (You want to increase this if you experience huge load) |
| JIKAN_ENABLE_PERIODICAL_FULL_INDEXER | (Bool) Configures whether to run the anime/manga indexer every week, which would crawl all anime/manga at first then it would just grab the latest anime/manga entries from MAL. Defaults to false. |
You can read more about additional configuration options on the [Configuration Wiki page](https://github.com/jikan-me/jikan-rest/wiki/Configuration).

View File

@ -2,7 +2,6 @@
<?php
use Dotenv\Dotenv;
use Illuminate\Support\Env;
require_once __DIR__.'/vendor/autoload.php';
@ -30,11 +29,10 @@ if (!file_exists(".env")) {
$writer->write();
}
$dotenv = Dotenv::create(
Env::getRepository(),
__DIR__
);
$current_env = $dotenv->load();
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
$current_env = $_ENV;
if ($current_env["SCOUT_DRIVER"] === "typesense" && empty($current_env["TYPESENSE_API_KEY"])) {
echo "Please set the TYPESENSE_API_KEY environment variable when setting SCOUT_DRIVER to typesense.";
@ -45,4 +43,14 @@ $rrConfig = \Symfony\Component\Yaml\Yaml::parse(file_get_contents(".rr.yaml"));
$rrConfig["http"]["pool"]["supervisor"]["max_worker_memory"] = (int) env("RR_MAX_WORKER_MEMORY", 128);
$rrConfig["http"]["max_request_size"] = (int) env("RR_MAX_REQUEST_SIZE_MB", 256);
$rrConfig["service"]["laravel_queue_worker_1"]["process_num"] = (int) env("JIKAN_QUEUE_WORKER_PROCESS_NUM", 1);
$periodical_full_indexer_key = "JIKAN_ENABLE_PERIODICAL_FULL_INDEXER";
if (array_key_exists($periodical_full_indexer_key, $current_env) && in_array($current_env[$periodical_full_indexer_key], [1, '1', 'true', 'True', 'TRUE'])) {
$supercronic_schedule = file_get_contents("/etc/supercronic/laravel");
$supercronic_schedule .= PHP_EOL;
$supercronic_schedule .= "0 1 * * 1 php /app/artisan indexer:anime --fail && php /app/artisan indexer:anime --resume && php /app/artisan indexer:manga --fail && php /app/artisan indexer:manga --resume";
$supercronic_schedule .= PHP_EOL;
file_put_contents("/etc/supercronic/laravel", $supercronic_schedule);
$current_time = time();
echo json_encode(["level" => "info", "ts" => "$current_time.0", "logger" => "container_entrypoint", "msg" => "Full anime/manga indexer is enabled. They will run every Monday at 1am."]) . PHP_EOL;
}
file_put_contents(".rr.yaml", \Symfony\Component\Yaml\Yaml::dump($rrConfig, 8));