From d8ca495471a5666527cbc949c29297a5887ff72e Mon Sep 17 00:00:00 2001 From: Samuel ORTION Date: Tue, 23 Aug 2022 13:25:10 +0200 Subject: [PATCH] docker: Working on mysql database and symfony dependencies --- .dockerignore | 17 +++---- .env.example | 2 +- docker-compose.yml | 35 +++++++++------ docker/php-fpm/Dockerfile | 2 +- docker/symfony/Dockerfile | 93 +++++++++++++++++++++++++++------------ www/composer.lock | 42 +++++++++--------- 6 files changed, 116 insertions(+), 75 deletions(-) diff --git a/.dockerignore b/.dockerignore index 61caea9..1494166 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,10 +1,7 @@ -var -.venv -.github -.ideas -media -daemon/systemd -analyzer -vendor -node_modules -build \ No newline at end of file +/var +/.venv +/.github +/.ideas +/media +/daemon/systemd +/analyzer diff --git a/.env.example b/.env.example index eb939b8..ed94dea 100644 --- a/.env.example +++ b/.env.example @@ -5,7 +5,7 @@ CUDA_VISIBLE_DEVICES="" DATABASE_USER="birdnet" DATABASE_PASSWORD="secret" # change this DATABASE_PORT="3306" -MYSQL_ROOT_PASSWORD="secret" # change this +DATABASE_ROOT_PASSWORD="secret" # change this RECORDS_DIR="/media/data/birdnet/records" CHARTS_DIR="/media/data/birdnet/charts" diff --git a/docker-compose.yml b/docker-compose.yml index 6000387..e5ade5f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,7 +27,7 @@ services: ports: - ${DATABASE_PORT:-3306}:3306 networks: - birdnet_network: + - birdnet_network environment: MYSQL_ROOT_PASSWORD: ${DATABASE_ROOT_PASSWORD:-secret}' MYSQL_USER: ${DATABASE_USER:-birdnet} @@ -38,11 +38,16 @@ services: php-fpm: container_name: birdnet_php-fpm - image: php:${PHP_VERSION:-8.1}-fpm + build: + context: . + dockerfile: ./docker/php-fpm/Dockerfile ports: - - '9000:9000' + - '${PHP_FPM_PORT:-9000}:9000' networks: - birdnet_network: + - birdnet_network + environment: + - APP_ENV=${APP_ENV:-prod} + - APP_DEBUG=${APP_DEBUG:-true} restart: unless-stopped volumes: - birdnet_app:${PROJECT_ROOT:-/opt/birdnet} @@ -50,21 +55,22 @@ services: symfony: container_name: birdnet_symfony networks: - birdnet_network: + - birdnet_network build: context: . dockerfile: ./docker/symfony/Dockerfile - environment: - - DATABASE_DEFAULT_URL=${DATABASE_DEFAULT_URL:-mysql://${DATABASE_USER:-birdnet}:${DATABASE_PASSWORD:-secret}@${DATABASE_HOST:-db}:3306/birdnet_default} - - DATABASE_OBSERVATION_URL=${DATABASE_OBSERVATION_URL:-mysql://${DATABASE_USER:-birdnet}:${DATABASE_PASSWORD:-secret}@${DATABASE_HOST:-db}:3306/birdnet_observation} - - RECORDS_DIR=/media/birdnet/records + args: + - DATABASE_DEFAULT_URL=mysql://${DATABASE_USER:-birdnet}:${DATABASE_PASSWORD:-secret}@${DATABASE_HOST:-birdnet_database}:${DATABASE_PORT:-3306}/birdnet_default + - DATABASE_OBSERVATIONS_URL=mysql://${DATABASE_USER:-birdnet}:${DATABASE_PASSWORD:-secret}@${DATABASE_HOST:-birdnet_database}:${DATABASE_PORT:-3306}/birdnet_observation + - RECORDS_DIR=/media/birdnet/records + - CHARTS_DIR=/media/birdnet/charts restart: on-failure volumes: - birdnet_app:${PROJECT_ROOT:-/opt/birdnet} - birdnet_records:${RECORDS_DIR:-/media/birdnet/records} depends_on: - db - + nginx: container_name: birdnet_nginx hostname: ${SERVER_NAME:-birdnet.local} @@ -76,11 +82,11 @@ services: - SYMFONY_PUBLIC=/opt/birdnet/www/public - CHARTS_DIR=/media/birdnet/charts - RECORDS_DIR=/media/birdnet/records - - PHP_FPM_HOST=php-fpm + - PHP_FPM_HOST=birdnet_php-fpm - PHP_FPM_PORT=9000 ports: - - '80:80' - - '443:443' + - '81:80' + - '444:443' volumes: - birdnet_app:/opt/birdnet - birdnet_records:/media/data/records @@ -96,6 +102,7 @@ services: networks: birdnet_network: + driver: bridge ipam: config: - subnet: ${IP_SUBNET:-172.25.0.0/24} @@ -107,4 +114,4 @@ volumes: driver_opts: type: none device: ${RECORDS_DIR:-/media/data/records} - o: bind \ No newline at end of file + o: bind diff --git a/docker/php-fpm/Dockerfile b/docker/php-fpm/Dockerfile index 388ef27..5876f81 100644 --- a/docker/php-fpm/Dockerfile +++ b/docker/php-fpm/Dockerfile @@ -3,6 +3,6 @@ ARG PHP_VERSION=${PHP_VERSION:-8.1} FROM php:${PHP_VERSION}-fpm RUN apt-get update && apt-get upgrade -y -RUN docker-php-ext-install pdo_mysql +RUN docker-php-ext-install pdo pdo_mysql EXPOSE 9000 \ No newline at end of file diff --git a/docker/symfony/Dockerfile b/docker/symfony/Dockerfile index 967362e..9b4a8df 100644 --- a/docker/symfony/Dockerfile +++ b/docker/symfony/Dockerfile @@ -2,39 +2,74 @@ ARG PHP_VERSION=${PHP_VERSION:-8.1} FROM php:${PHP_VERSION} -ARG PROJECT_ROOT=${PROJECT_ROOT:-/opt/birdnet} -ARG NODE_VERSION=${NODE_VERSION:-16.17.0} +ARG PROJECT_ROOT +ARG NODE_VERSION +ARG RECORDS_DIR +ARG CHARTS_DIR +ARG DATABASE_DEFAULT_URL +ARG DATABASE_OBSERVATIONS_URL -RUN apt-get update && apt-get upgrade -y \ - && apt-get install -y \ - curl \ - gzip \ - git \ - vim \ - && apt-get clean +ENV PHP_VERSION=${PHP_VERSION:-8.1} \ + NODE_VERSION=${NODE_VERSION:-16.17.0} \ + PROJECT_ROOT=${PROJECT_ROOT:-/opt/birdnet} \ + RECORDS_DIR=${RECORDS_DIR:-/media/data/birdnet/records} \ + CHARTS_DIR=${CHARTS_DIR:-/media/data/birdnet/charts} \ + DATABASE_DEFAULT_URL=${DATABASE_DEFAULT_URL:-mysql://birdnet:secret@birdnet_database/birdnet} \ + DATABASE_OBSERVATIONS_URL=${DATABASE_OBSERVATIONS_URL:-mysql://birdnet:secret@birdnet_database/birdnet_observations} -# Install composer -RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \ - && php composer-setup.php --install-dir=/usr/local/bin --filename=composer +ENV APP_ENV=${APP_ENV:-prod} +ENV APP_DEBUG=${APP_DEBUG:-0} -# Install nodejs and npm -ENV NVM_DIR="/usr/local/nvm" -RUN mkdir ${NVM_DIR} -RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash -RUN . "$NVM_DIR/nvm.sh" \ - && nvm install ${NODE_VERSION} \ - && nvm use ${NODE_VERSION} \ - && nvm alias default ${NODE_VERSION} \ - && npm install -g yarn -ENV PATH="$PATH:/usr/local/nvm/versions/node/v${NODE_VERSION}/bin" +# RUN apt-get update && apt-get upgrade -y \ +# && apt-get install -y \ +# curl \ +# zip \ +# unzip \ +# zlib1g-dev \ +# libzip-dev \ +# git \ +# vim \ +# && apt-get clean +# RUN docker-php-ext-install zip pdo_mysql + +# # Install composer +# RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \ +# && php composer-setup.php --install-dir=/usr/local/bin --filename=composer + +# # Install nodejs and npm +# ENV NVM_DIR="/usr/local/nvm" +# RUN mkdir ${NVM_DIR} +# RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash +# RUN . "$NVM_DIR/nvm.sh" \ +# && nvm install ${NODE_VERSION} \ +# && nvm use ${NODE_VERSION} \ +# && nvm alias default ${NODE_VERSION} \ +# && npm install -g yarn +# ENV PATH="$PATH:/usr/local/nvm/versions/node/v${NODE_VERSION}/bin" + +# Change permissions for the home folder of www-data (used for composer cache) +RUN chown -R www-data:www-data /var/www COPY . ${PROJECT_ROOT} -RUN chown -R www-data:www-data "${PROJECT_ROOT}" WORKDIR ${PROJECT_ROOT}/www -USER www-data -# Install composer packages -RUN composer install -# Install yarn dependencies -RUN . "$NVM_DIR/nvm.sh" && yarn install && yarn build +RUN rm -rf {vendor,node_modules} +RUN chown -R www-data:www-data . -CMD ["bash"] \ No newline at end of file +USER www-data +# Setup .env +RUN cp .env.local.example .env.local +RUN sed -i "s/^APP_ENV=.*/APP_ENV=prod/g" .env.local \ +&& sed -i "s/^APP_DEBUG=.*/APP_DEBUG=0/g" .env.local \ +&& sed -i "s/^APP_SECRET=.*/APP_SECRET=${APP_SECRET}/g" .env.local \ +&& sed -i "s|^DATABASE_DEFAULT_URL=.*|DATABASE_DEFAULT_URL=${DATABASE_DEFAULT_URL}|g" .env.local \ +&& sed -i "s|^DATABASE_OBSERVATIONS_URL=.*|DATABASE_OBSERVATIONS_URL=${DATABASE_OBSERVATIONS_URL}|g" .env.local \ +&& sed -i "s|^RECORDS_DIR=.*|RECORDS_DIR=${RECORDS_DIR}|g" .env.local \ +&& sed -i "s|^CHARTS_DIR=.*|CHARTS_DIR=${CHARTS_DIR}|g" .env.local + +# # # Install yarn dependencies +# RUN . "$NVM_DIR/nvm.sh" && yarn install && yarn build + +# # Install composer dependencies +# RUN composer install --no-interaction --prefer-dist --optimize-autoloader +# RUN composer dump-env prod +# RUN composer dump-autoload \ No newline at end of file diff --git a/www/composer.lock b/www/composer.lock index a9e8280..48d8a5b 100644 --- a/www/composer.lock +++ b/www/composer.lock @@ -174,26 +174,27 @@ }, { "name": "doctrine/collections", - "version": "1.6.8", + "version": "1.7.0", "source": { "type": "git", "url": "https://github.com/doctrine/collections.git", - "reference": "1958a744696c6bb3bb0d28db2611dc11610e78af" + "reference": "07d15c8a766e664ec271ae84e5dfc597aeeb03b1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/collections/zipball/1958a744696c6bb3bb0d28db2611dc11610e78af", - "reference": "1958a744696c6bb3bb0d28db2611dc11610e78af", + "url": "https://api.github.com/repos/doctrine/collections/zipball/07d15c8a766e664ec271ae84e5dfc597aeeb03b1", + "reference": "07d15c8a766e664ec271ae84e5dfc597aeeb03b1", "shasum": "" }, "require": { + "doctrine/deprecations": "^0.5.3 || ^1", "php": "^7.1.3 || ^8.0" }, "require-dev": { "doctrine/coding-standard": "^9.0", - "phpstan/phpstan": "^0.12", + "phpstan/phpstan": "^1.4.8", "phpunit/phpunit": "^7.5 || ^8.5 || ^9.1.5", - "vimeo/psalm": "^4.2.1" + "vimeo/psalm": "^4.22" }, "type": "library", "autoload": { @@ -237,22 +238,22 @@ ], "support": { "issues": "https://github.com/doctrine/collections/issues", - "source": "https://github.com/doctrine/collections/tree/1.6.8" + "source": "https://github.com/doctrine/collections/tree/1.7.0" }, - "time": "2021-08-10T18:51:53+00:00" + "time": "2022-08-18T05:44:45+00:00" }, { "name": "doctrine/common", - "version": "3.3.0", + "version": "3.3.1", "source": { "type": "git", "url": "https://github.com/doctrine/common.git", - "reference": "c824e95d4c83b7102d8bc60595445a6f7d540f96" + "reference": "6a76bd25b1030d35d6ba2bf2f69ca858a41fc580" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/common/zipball/c824e95d4c83b7102d8bc60595445a6f7d540f96", - "reference": "c824e95d4c83b7102d8bc60595445a6f7d540f96", + "url": "https://api.github.com/repos/doctrine/common/zipball/6a76bd25b1030d35d6ba2bf2f69ca858a41fc580", + "reference": "6a76bd25b1030d35d6ba2bf2f69ca858a41fc580", "shasum": "" }, "require": { @@ -261,6 +262,7 @@ }, "require-dev": { "doctrine/coding-standard": "^9.0", + "doctrine/collections": "^1", "phpstan/phpstan": "^1.4.1", "phpstan/phpstan-phpunit": "^1", "phpunit/phpunit": "^7.5.20 || ^8.5 || ^9.0", @@ -313,7 +315,7 @@ ], "support": { "issues": "https://github.com/doctrine/common/issues", - "source": "https://github.com/doctrine/common/tree/3.3.0" + "source": "https://github.com/doctrine/common/tree/3.3.1" }, "funding": [ { @@ -329,20 +331,20 @@ "type": "tidelift" } ], - "time": "2022-02-05T18:28:51+00:00" + "time": "2022-08-20T10:48:54+00:00" }, { "name": "doctrine/dbal", - "version": "3.4.0", + "version": "3.4.2", "source": { "type": "git", "url": "https://github.com/doctrine/dbal.git", - "reference": "118a360e9437e88d49024f36283c8bcbd76105f5" + "reference": "22de295f10edbe00df74f517612f1fbd711131e2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/dbal/zipball/118a360e9437e88d49024f36283c8bcbd76105f5", - "reference": "118a360e9437e88d49024f36283c8bcbd76105f5", + "url": "https://api.github.com/repos/doctrine/dbal/zipball/22de295f10edbe00df74f517612f1fbd711131e2", + "reference": "22de295f10edbe00df74f517612f1fbd711131e2", "shasum": "" }, "require": { @@ -424,7 +426,7 @@ ], "support": { "issues": "https://github.com/doctrine/dbal/issues", - "source": "https://github.com/doctrine/dbal/tree/3.4.0" + "source": "https://github.com/doctrine/dbal/tree/3.4.2" }, "funding": [ { @@ -440,7 +442,7 @@ "type": "tidelift" } ], - "time": "2022-08-06T20:35:57+00:00" + "time": "2022-08-21T14:21:06+00:00" }, { "name": "doctrine/deprecations",