From 201883d9874b582216a07f2e993e032dfd1f1e53 Mon Sep 17 00:00:00 2001 From: pushrbx Date: Tue, 24 Oct 2023 00:41:28 +0100 Subject: [PATCH] wip fixed issues with container start ups --- Dockerfile | 7 +++---- container-setup.sh | 6 ++++-- docker-compose.yml | 16 ++++++++++------ docker-entrypoint.php | 5 +++-- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 45f2a13..8e07b4c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,12 @@ FROM docker.io/spiralscout/roadrunner:2.12.2 as roadrunner FROM docker.io/composer:2.5.1 as composer -FROM docker.io/mlocati/php-extension-installer:1.5.52 as php-ext-installer +FROM docker.io/mlocati/php-extension-installer:2.1.58 as php-ext-installer FROM php:8.1.16-bullseye COPY --from=composer /usr/bin/composer /usr/bin/composer COPY --from=php-ext-installer /usr/bin/install-php-extensions /usr/local/bin/ ENV COMPOSER_HOME="/tmp/composer" RUN set -x \ - && install-php-extensions intl bz2 gettext mongodb-stable redis opcache sockets pcntl \ + && install-php-extensions intl mbstring mongodb-stable redis opcache sockets pcntl \ # install xdebug (for testing with code coverage), but do not enable it && IPE_DONT_ENABLE=1 install-php-extensions xdebug-3.2.0 @@ -17,9 +17,8 @@ RUN set -ex \ && apt-get update && apt-get install -y --no-install-recommends \ openssl \ git \ - dos2unix \ + wget \ unzip \ - wget \ # install supercronic (for laravel task scheduling), project page: && wget -q "https://github.com/aptible/supercronic/releases/download/v0.1.12/supercronic-linux-$(dpkg --print-architecture)" \ -O /usr/bin/supercronic \ diff --git a/container-setup.sh b/container-setup.sh index 03f52ca..3814038 100755 --- a/container-setup.sh +++ b/container-setup.sh @@ -21,6 +21,7 @@ display_help() { echo "help Print CLI help" echo "build-image Build Image Locally" echo "start Start Jikan API (mongodb, typesense, redis, jikan-api workers)" + echo "stop Stop Jikan API" echo "validate-prereqs Validate pre-reqs installed (docker, docker-compose)" echo "execute-indexers Execute the indexers, which will scrape and index data from MAL. (Notice: This can take days)" echo "" @@ -69,6 +70,7 @@ validate_prereqs() { build_image() { validate_prereqs + $DOCKER_CMD inspect jikanme/jikan-rest:"$_JIKAN_API_VERSION" &> /dev/null && $DOCKER_CMD rmi jikanme/jikan-rest:"$_JIKAN_API_VERSION" $DOCKER_CMD build --rm --compress -t jikanme/jikan-rest:"$_JIKAN_API_VERSION" . $DOCKER_CMD tag jikanme/jikan-rest:"$_JIKAN_API_VERSION" jikanme/jikan-rest:latest } @@ -116,11 +118,11 @@ case "$1" in "start") start ;; - "stop") + "stop") validate_prereqs $DOCKER_COMPOSE_CMD -p "$DOCKER_COMPOSE_PROJECT_NAME" down ;; - "execute-indexers") + "execute-indexers") echo "Indexing anime..." $DOCKER_COMPOSE_CMD -p "$DOCKER_COMPOSE_PROJECT_NAME" exec jikan_rest php /app/artisan indexer:anime echo "Indexing manga..." diff --git a/docker-compose.yml b/docker-compose.yml index 96a2b9a..0eaa717 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -39,6 +39,10 @@ services: test: [ 'CMD-SHELL', 'wget --spider -q "http://127.0.0.1:2114/health?plugin=http"' ] interval: 2s timeout: 2s + links: + - mongodb + - redis + - typesense depends_on: mongodb: { condition: service_healthy } redis: { condition: service_healthy } @@ -51,7 +55,7 @@ services: - mongo-data:/data/db ports: - '27017/tcp' - command: "--wiredTigerCacheSizeGB ${MONGO_CACHE_SIZE_GB:1}" + command: "--wiredTigerCacheSizeGB ${MONGO_CACHE_SIZE_GB:-1.0}" networks: - jikan_network secrets: @@ -61,18 +65,16 @@ services: MONGO_INITDB_ROOT_USERNAME_FILE: /run/secrets/db_username MONGO_INITDB_ROOT_PASSWORD_FILE: /run/secrets/db_password healthcheck: - test: echo 'db.runCommand("ping").ok' | mongo mongodb://localhost:27017 --quiet + test: echo 'db.runCommand("ping").ok' | mongosh mongodb://localhost:27017 --quiet interval: 30s timeout: 10s retries: 5 redis: - image: docker.io/redis:7-alpine + image: docker.io/redis:6-alpine hostname: redis secrets: - redis_password - environment: - REDIS_PASSWORD: "${REDIS_PASSWORD:-null}" networks: - jikan_network command: @@ -99,7 +101,9 @@ services: command: - -c - TYPESENSE_API_KEY="$$(cat /run/secrets/typesense_api_key)" /opt/typesense-server --data-dir /data - restart: no + deploy: + restart_policy: + condition: none volumes: - typesense-data:/data ports: diff --git a/docker-entrypoint.php b/docker-entrypoint.php index c80a0bf..6d69d07 100644 --- a/docker-entrypoint.php +++ b/docker-entrypoint.php @@ -37,7 +37,6 @@ if (!file_exists(".env")) { $envWriter = new \MirazMac\DotEnv\Writer(__DIR__ . '/' . '.env'); $itemsWritten = 0; foreach (array_keys($current_env) as $env_key) { - echo $env_key; if (!str_contains($env_key, "__FILE")) { continue; } @@ -52,12 +51,14 @@ foreach (array_keys($current_env) as $env_key) { if ($itemsWritten > 0) { $envWriter->write(); - echo "Secrets loaded successfully."; + echo "Secrets loaded successfully.\n"; } $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."; exit(1);