From 8dbb8f8f69289ee8be3b2ef641bfaa7a428f6d18 Mon Sep 17 00:00:00 2001 From: jekkos Date: Sat, 23 Dec 2023 01:46:54 +0100 Subject: [PATCH] Enable docker config override (#3908) --- BUILD.md | 11 +++++++ Dockerfile | 1 - app/Config/Database.php | 27 +++++++--------- docker-compose.dev.yml | 40 +++-------------------- docker-compose.nginx.yml | 6 ++-- docker-compose.phpmyadmin.yml | 60 +++-------------------------------- docker-compose.test.yml | 18 +++-------- docker-compose.yml | 36 +++------------------ docker/build_assets.sh | 6 ---- 9 files changed, 43 insertions(+), 162 deletions(-) delete mode 100644 docker/build_assets.sh diff --git a/BUILD.md b/BUILD.md index 922398354..b8c8b07e6 100644 --- a/BUILD.md +++ b/BUILD.md @@ -45,6 +45,17 @@ I've added the following Powershell scripts to make my life a bit easier, which * `build.ps1` - Which runs the build but also restores the .env from a backup I make of it in a specifically placed folder. I place a copy of the configured .env file in a folder that has the following path from the working folder: `../env//.env` +### Containerized setup +Development using docker has the advantage that all the application's dependencies are contained within the docker environment. During development we want to have a live version of the code in the container when we edit it. This is accomplished by mounting the application folder within the /app of the docker container. + +The file permissions for the repository in the container should be the same as on the host. That's why we have to startthe PHP process in docker with the host current uid. + +``` +export UID=$(id -u) +export GID=$(id -g) +docker-compose -f docker-compose.dev.yml up +``` + ## The Result The build creates a developer version of a runnable instance of OSPOS. It contains a ton of developer stuff that **should not be deployed to a production environment**. diff --git a/Dockerfile b/Dockerfile index 1952f8cf0..f329dc3f4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,7 +21,6 @@ CMD ["/app/vendor/phpunit/phpunit/phpunit"] FROM ospos AS ospos_dev -RUN mkdir -p /app/bower_components && ln -s /app/bower_components /var/www/html/bower_components RUN yes | pecl install xdebug \ && echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \ && echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/xdebug.ini \ diff --git a/app/Config/Database.php b/app/Config/Database.php index 5f2e39bc8..f230b3280 100644 --- a/app/Config/Database.php +++ b/app/Config/Database.php @@ -76,6 +76,9 @@ class Database extends Config * * @var array */ + + + public $development = [ 'DSN' => '', 'hostname' => 'localhost', @@ -102,21 +105,6 @@ class Database extends Config { parent::__construct(); - if(!getenv('database.development.hostname')) - { - $this->development['hostname'] = getenv('database.development.hostname'); - } - - if(!getenv('database.development.hostname')) - { - $this->development['username'] = getenv('database.development.username'); - } - - if(!getenv('database.development.hostname')) - { - $this->development['password'] = getenv('database.development.password'); - } - // Ensure that we always set the database group to 'tests' if // we are currently running an automated test suite, so that // we don't overwrite live data on accident. @@ -129,5 +117,14 @@ class Database extends Config $this->defaultGroup = 'development'; break; } + + foreach ([&$this->development, &$this->tests, &$this->default] as &$config) { + $config['hostname'] = !getenv('MYSQL_HOST_NAME') ? $config['hostname'] : getenv('MYSQL_HOST_NAME'); + $config['username'] = !getenv('MYSQL_USERNAME') ? $config['username'] : getenv('MYSQL_USERNAME'); + $config['password'] = !getenv('MYSQL_PASSWORD') ? $config['password'] : getenv('MYSQL_PASSWORD'); + $config['database'] = !getenv('MYSQL_DB_NAME') ? $config['database'] : getenv('MYSQL_DB_NAME'); + + + } } } diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 006525444..367cf49a1 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -1,17 +1,7 @@ -version: '2' - -volumes: - uploads: - driver: local - logs: - driver: local - mysql: - driver: local - -networks: - app_net: - db_net: +version: '3.4' +include: + - docker/docker-mysql.yml services: ospos: build: @@ -26,33 +16,13 @@ services: - "80:80" networks: - app_net - - db_net volumes: - .:/app - - uploads:/app/public/uploads - - logs:/app/application/logs environment: - - PHP_TIMEZONE=UTC - CI_ENVIRONMENT=development - MYSQL_USERNAME=admin - MYSQL_PASSWORD=pointofsale - MYSQL_DB_NAME=ospos - MYSQL_HOST_NAME=mysql - - XDEBUG_CONFIG=remote_host=172.17.0.1 - - mysql: - image: mariadb:10.5 - container_name: mysql - restart: always - expose: - - "3306" - networks: - - db_net - volumes: - - ./app/Database:/docker-entrypoint-initdb.d - - mysql:/var/lib/mysql:rw - environment: - - MYSQL_ROOT_PASSWORD=pointofsale - - MYSQL_DATABASE=ospos - - MYSQL_USER=admin - - MYSQL_PASSWORD=pointofsale + - PHP_TIMEZONE=UTC + - XDEBUG_CONFIG=client_host=172.17.0.1 diff --git a/docker-compose.nginx.yml b/docker-compose.nginx.yml index 8d34b4e3e..f4c911e35 100644 --- a/docker-compose.nginx.yml +++ b/docker-compose.nginx.yml @@ -1,4 +1,4 @@ -version: '3.4' +version: '2.2' volumes: uploads: @@ -22,12 +22,11 @@ services: - "80" networks: - app_net - - db_net volumes: - uploads:/app/public/uploads - logs:/app/application/logs environment: - - CI_ENV=${OSPOS_CI_ENV} + - CI_ENVIRONMENT=${OSPOS_CI_ENV} - FORCE_HTTPS=true - PHP_TIMEZONE=UTC - MYSQL_USERNAME=${OSPOS_MYSQL_USERNAME} @@ -62,7 +61,6 @@ services: - "80" networks: - app_net - - db_net environment: - MYSQL_USERNAME=${OSPOS_MYSQL_USERNAME} - MYSQL_ROOT_PASSWORD=${OSPOS_MYSQL_ROOT_PASSWORD} diff --git a/docker-compose.phpmyadmin.yml b/docker-compose.phpmyadmin.yml index f6b5782ce..653555b09 100644 --- a/docker-compose.phpmyadmin.yml +++ b/docker-compose.phpmyadmin.yml @@ -1,60 +1,9 @@ -version: '3.4' +version: '2.2' -volumes: - uploads: - driver: local - logs: - driver: local - mysql: - driver: local - -networks: - app_net: - db_net: +include: + - docker-compose.dev.yml services: - ospos: - build: - context: . - target: ospos_dev - container_name: ospos_dev - restart: always - depends_on: - - mysql - ports: - - "80:80" - networks: - - app_net - - db_net - volumes: - - .:/app - - uploads:/app/public/uploads - - logs:/app/application/logs - environment: - - PHP_TIMEZONE=UTC - - MYSQL_USERNAME=admin - - MYSQL_PASSWORD=pointofsale - - MYSQL_DB_NAME=ospos - - MYSQL_HOST_NAME=mysql - - XDEBUG_CONFIG=remote_host=172.17.0.1 - - mysql: - image: mariadb:10.5 - container_name: mysql - restart: always - expose: - - "3306" - networks: - - db_net - volumes: - - ./database/database.sql:/docker-entrypoint-initdb.d/database.sql - - mysql:/var/lib/mysql:rw - environment: - - MYSQL_ROOT_PASSWORD=pointofsale - - MYSQL_DATABASE=ospos - - MYSQL_USER=admin - - MYSQL_PASSWORD=pointofsale - phpmyadmin: image: phpmyadmin/phpmyadmin container_name: phpmyadmin @@ -65,8 +14,7 @@ services: - "8000:80" networks: - app_net - - db_net environment: - MYSQL_USERNAME=admin - MYSQL_ROOT_PASSWORD=pointofsale - - PMA_HOST=mysql \ No newline at end of file + - PMA_HOST=mysql diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 6b86a04c6..743270d36 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -1,5 +1,8 @@ -version: '3.4' +version: '2.2' +include: + - docker/docker-mysql.yaml + services: test: build: @@ -9,7 +12,7 @@ services: - mysql container_name: ospos_test environment: - - CI_ENV=testing + - CI_ENVIRONMENT=testing - ENCRYPTION_KEY= - MYSQL_HOST_NAME=mysql - MYSQL_DATABASE=ospos @@ -19,14 +22,3 @@ services: ports: - "80:80" - mysql: - image: mariadb:10.5 - container_name: mysql - restart: always - volumes: - - ./database/database.sql:/docker-entrypoint-initdb.d/database.sql - environment: - - MYSQL_ROOT_PASSWORD=pointofsale - - MYSQL_DATABASE=ospos - - MYSQL_USER=admin - - MYSQL_PASSWORD=pointofsale diff --git a/docker-compose.yml b/docker-compose.yml index bda57b52a..b6b72e285 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,23 +1,14 @@ version: '2' -volumes: - uploads: - driver: local - logs: - driver: local - mysql: - driver: local - -networks: - app_net: - db_net: +include: + - docker/docker-mysql.yml services: sqlscript: - image: jekkos/opensourcepos:sql-ci4 + image: jekkos/opensourcepos:sql-ci4-branch command: /bin/sh -c 'exit 0' ospos: - image: jekkos/opensourcepos:ci4-upgrade + image: jekkos/opensourcepos:ci4-branch restart: always depends_on: - mysql @@ -25,7 +16,6 @@ services: - "127.0.0.1:80:80" networks: - app_net - - db_net volumes: - uploads:/app/public/uploads - logs:/app/application/logs @@ -38,21 +28,3 @@ services: - MYSQL_DB_NAME=ospos - MYSQL_HOST_NAME=mysql - mysql: - image: mariadb:10.5 - container_name: mysql - restart: always - expose: - - "3306" - networks: - - db_net - volumes_from: - - sqlscript - volumes: - - mysql:/var/lib/mysql:rw - environment: - - MYSQL_ROOT_PASSWORD=pointofsale - - MYSQL_DATABASE=ospos - - MYSQL_USER=admin - - MYSQL_PASSWORD=pointofsale - diff --git a/docker/build_assets.sh b/docker/build_assets.sh deleted file mode 100644 index 05bb62fa0..000000000 --- a/docker/build_assets.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -docker run --rm -v $(pwd):/app jekkos/composer composer install -docker run --rm -v $(pwd):/app jekkos/composer php bin/install.php translations develop -sed -i "s/'\(dev\)'/'$rev'/g" application/config/config.php -docker run --rm -it -v $(pwd):/app -w /app digitallyseamless/nodejs-bower-grunt sh -c "npm install && bower install && grunt package"