diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 000000000..bbe1ccea4 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,94 @@ +# PHP CircleCI 2.0 configuration file +# +# Check https://circleci.com/docs/2.0/language-php/ for more details +# +version: 2 +jobs: + build: + environment: + DB: Mysql + # a host alias or IP address + MYSQL_SERVICE_HOST: 192.168.99.100 + MYSQL_SERVICE_PORT: 3306 + TEST_MYSQL_SERVICE_HOST: 192.168.99.100 + TEST_MYSQL_SERVICE_PORT: 3306 + DATABASE_NAME: phpcms + DATABASE_SERVICE_NAME: MYSQL + #(optional) + #WEBHOOK_URL: + # Persistent connection credentials + DATABASE_USER: root + # overrides docker-compose-alias.sh -p= + DATABASE_PASSWORD: pdocker + # Just add TEST_DATABASE_USER and TEST_DATABASE_PASSWORD + TEST_DATABASE_USER: ubuntu + # overrides docker-compose-alias.sh -t= + TEST_DATABASE_PASSWORD: ptest + # CakePHP generated + #CAKEPHP_SECRET_TOKEN: + #CAKEPHP_SECRET_SALT: + #CAKEPHP_SECURITY_CIPHER_SEED: + # Generated by ./configure.sh -h + GET_HASH_PASSWORD: ${GET_HASH_PASSWORD} + docker: + # Specify the version you desire here + - image: circleci/php:7.1-node-browsers + environment: + DOCKER_OS_NAME: linux + DOCKER_PHP_VERSION: 7.1 + + # Specify service dependencies here if necessary + # CircleCI maintains a library of pre-built images + # documented at https://circleci.com/docs/2.0/circleci-images/ + # Using the RAM variation mitigates I/O contention + # for database intensive operations. + # - image: circleci/mysql:5.7-ram + - image: circleci/mysql:5.7 + container_name: mysql + environment: + MYSQL_ALLOW_EMPTY_PASSWORD: yes + MYSQL_ROOT_PASSWORD: 'pdocker' + MYSQL_DATABASE: phpcms + + steps: + - checkout + - run: git submodule update --init --recursive + + - run: sudo apt update # PHP CircleCI 2.0 Configuration File# PHP CircleCI 2.0 Configuration File sudo apt install zlib1g-dev libsqlite3-dev + - run: sudo docker-php-ext-install zip + - run: sudo apt-get install mariadb-client + + # Download and cache dependencies + - restore_cache: + keys: + # "composer.lock" can be used if it is committed to the repo + - v1-dependencies-{{ checksum "composer.lock" }} + # fallback to using the latest cache if no exact match is found + - v1-dependencies- + + - run: composer install -n --prefer-dist + + - save_cache: + key: v1-dependencies-{{ checksum "composer.lock" }} + paths: + - ./app/Vendor/ + + - run: ./test-cake.sh -v --docker -p=$DATABASE_PASSWORD -t=$TEST_DATABASE_PASSWORD #| grep Test + # Installing and Using docker-compose + - run: + name: Install Docker Compose + command: | + curl -L https://github.com/docker/compose/releases/download/1.19.0/docker-compose-`uname -s`-`uname -m` > ~/docker-compose + chmod +x ~/docker-compose + sudo mv ~/docker-compose /usr/local/bin/docker-compose + - setup_remote_docker: # (2) + docker_layer_caching: true # (3) + + # use a primary image that already has Docker (recommended) + # build and push Docker image + # (4) + - run: | + TAG=0.1.$CIRCLE_BUILD_NUM + ./docker-compose-alias.sh -dns=b23prodtm.info -p=$DATABASE_PASSWORD -t=$TEST_DATABASE_PASSWORD up -d --build + docker login -u $DOCKER_USER -p $DOCKER_PASS + docker push b23dkr/myphpcms:$TAG diff --git a/.travis.yml b/.travis.yml index 8c1cae18f..e8a8ebc5d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,14 +15,13 @@ dist: xenial env: matrix: - - DB=Mysql _PHP=hhvm - - DB=Mysql _PHP=7.0 _PKG=php - - DB=Mysql _PHP=7.1 _PKG=php - - DB=Mysql _PHP=7.2 _PKG=php - - DB=Mysql _PHP=7.3 _PKG=php - - DB=Sqlite _PHP=7.0 _PKG=php - + - _PHP=latest _PKG=hhvm + - _PHP=7.1 _PKG=php + - _PHP=7.2 _PKG=php + - _PHP=7.3 _PKG=php global: + - _SSL=openssl + - DB=Mysql - PHPUNIT=4 - PHPCS=3 - COLLECT_COVERAGE=false @@ -33,30 +32,27 @@ env: matrix: fast_finish: true exclude: - - os: osx - env: DB=Mysql _PHP=7.0 _PKG=php - os: windows - os: linux include: - os: linux language: php - php: 7.0 - env: DB=Mysql _PHP=7.0 _PKG=php PHPENV_ROOT=~/.phpenv + php: 7.1 + env: _PHP=7.1 _PKG=php PHPENV_ROOT=~/.phpenv - os: linux language: php - php: hhvm - env: DB=Mysql _PHP=hhvm PHPENV_ROOT=~/.phpenv + php: 'hhvm' + env: _PHP=latest _PKG=hhvm PHPENV_ROOT=~/.phpenv - os: osx - os: windows - env: DB=Mysql _PHP=7.3 _PKG=php + env: _PHP=7.3 _PKG=php _SSL=openssl.light - os: windows - env: DB=Mysql _PHP=hhvm + env: _PHP=latest _PKG=hhvm _SSL=openssl.light allow_failures: - - php: hhvm + - php: 'hhvm' + - env: _PHP=latest _PKG=hhvm + - env: _PHP=7.3 _PKG=php - os: windows - - os: osx - - env: DB=Mysql _PHP=hhvm - - env: DB=Mysql _PHP=7.3 _PKG=php addons: coverity_scan: @@ -81,27 +77,29 @@ services: - memcached before_install: - - source .travis/TravisCI-OSX-PHP/build/phpenv_install.sh - - source .travis/TravisCI-OSX-PHP/build/prepare_${TRAVIS_OS_NAME}_env.sh #; source exports + - cd .travis/TravisCI-OSX-PHP + - source build/phpenv_install.sh + - source build/prepare_${TRAVIS_OS_NAME}_env.sh #; source exports - if [[ "${TRAVIS_OS_NAME}" == "linux" && "${_PHP}" == 7* ]]; then COLLECT_COVERAGE=true ; fi - if [[ "${TRAVIS_OS_NAME}" == "linux" && "${COLLECT_COVERAGE}" != "true" ]]; then phpenv config-rm xdebug.ini || true ; fi - - if [ ! -z "${ADDITIONAL_PHP_INI}" ]; then cd .travis/TravisCI-OSX-PHP; source build/custom_php_ini.sh; cd ../..; php --ini; fi + - if [ ! -z "${ADDITIONAL_PHP_INI}" ]; then source build/custom_php_ini.sh; fi - if [[ "${TRAVIS_OS_NAME}" == "linux" && "${COLLECT_COVERAGE}" != "true" ]]; then echo -n | openssl s_client -connect https://scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-; fi + - cd ../.. - source ./Scripts/configure_tmp.sh install: - - if [[ "${TRAVIS_OS_NAME}" == "windows" ]]; then .travis/TravisCI-OSX-PHP/build/handle_${TRAVIS_OS_NAME}_pkg.sh "openssl.light"; fi - - if [[ "${TRAVIS_OS_NAME}" != "linux" ]]; then .travis/TravisCI-OSX-PHP/build/handle_${TRAVIS_OS_NAME}_pkg.sh "${_PKG}" "${_PHP}" "--with-openssl"; fi - - if [[ "${TRAVIS_OS_NAME}" != "linux" ]]; then .travis/TravisCI-OSX-PHP/build/handle_${TRAVIS_OS_NAME}_pkg.sh "composer"; fi - - if [[ "${TRAVIS_OS_NAME}" != "linux" ]]; then bash -c 'composer install --dev --no-interaction'; fi + - cd .travis/TravisCI-OSX-PHP + - if [[ "${TRAVIS_OS_NAME}" != "linux" ]]; then build/handle_${TRAVIS_OS_NAME}_pkg.sh "${_SSL}"; /usr/local/opt/openssl/bin/c_rehash; fi + - if [[ "${TRAVIS_OS_NAME}" != "linux" ]]; then build/handle_${TRAVIS_OS_NAME}_pkg.sh "${_PKG}" "${_PHP}" "--with-openssl"; fi + - if [[ "${TRAVIS_OS_NAME}" != "linux" ]]; then build/handle_${TRAVIS_OS_NAME}_pkg.sh "composer"; bash -c 'composer install --dev --no-interaction'; fi + - cd ../.. - if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then curl -s http://getcomposer.org/installer | php && php composer.phar install --dev --no-interaction; fi before_script: - if [[ "${TRAVIS_OS_NAME}" == "linux" && "${_PHP}" == "hhvm" ]]; then curl -sSfL -o ~/.phpenv/versions/hhvm/bin/phpunit https://phar.phpunit.de/phpunit-5.7.phar; fi - mkdir -p build/logs -- if [ "${COVERITY_SCAN_BRANCH}" != 1 ]; then ./configure.sh "-c" "-h" "-p" "pass" "-s" "word" "--mig-database" "-y"; fi -- if [ "${COVERITY_SCAN_BRANCH}" != 1 ]; then .travis/configure.sh; fi + script: -- if [ "${COVERITY_SCAN_BRANCH}" != 1 ]; then ./test-cake.sh | grep Test; fi +- if [ "${COVERITY_SCAN_BRANCH}" != 1 ]; then ./test-cake.sh --travis | grep Test; fi after_script: - if [[ ("${COLLECT_COVERAGE}" == "true") && ("${COVERITY_SCAN_BRANCH}" != 1) ]]; then travis_retry php app/vendor/bin/php-coveralls -v -r ./app/; fi diff --git a/.travis/TravisCI-OSX-PHP b/.travis/TravisCI-OSX-PHP index 48fe835d5..94c5f2272 160000 --- a/.travis/TravisCI-OSX-PHP +++ b/.travis/TravisCI-OSX-PHP @@ -1 +1 @@ -Subproject commit 48fe835d53eabd67e420b34dd97207cf202c2e51 +Subproject commit 94c5f2272a56c81152c8a7c02d0ff18690eb16cb diff --git a/.travis/configure.sh b/.travis/configure.sh index d96d31d5c..28d73c93f 100755 --- a/.travis/configure.sh +++ b/.travis/configure.sh @@ -25,7 +25,6 @@ optional environment VARIABLES in .travis.yml ========================== "; [ ! -z $TEST_DATABASE_USER ] && [ ! -z $TEST_DATABASE_PASSWORD ] && [[ (! -z $TEST_MYSQL_SERVICE_HOST) || (! -z $TEST_PGSQL_SERVICE_HOST) ]] || echo "Missing VARIABLES. Please review your settings !" -php bin/composer.phar install --no-interaction if [ ! -z "${ADDITIONAL_PHP_INI}" ]; then /usr/bin/env bash .travis/TravisCI-OSX-PHP/build/custom_php_ini.sh; fi mkdir -p build/logs echo -e "Database Unit Tests... DB=${DB}" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..e159374e2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,42 @@ +FROM php:7.0-apache + +RUN apt-get update -yqq \ + && apt-get install -yqq --no-install-recommends \ + git \ + zip \ + unzip \ + && rm -rf /var/lib/apt/lists + +# Enable PHP extensions +RUN docker-php-ext-install pdo_mysql mysqli + +# Install composer +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer + +# Add cake and composer command to system path +ENV PATH="${PATH}:/var/www/html/lib/Cake/Console" +ENV PATH="${PATH}:/var/www/html/app/Vendor/bin" + +# COPY apache site.conf file +COPY docker/apache/site.conf /etc/apache2/sites-available/000-default.conf + +# Copy the source code into /var/www/html/ inside the image +COPY . /var/www/html/ + +# Set default working directory +WORKDIR /var/www/html/app + +# Create tmp directory and make it writable by the web server +RUN mkdir -p \ + tmp/cache/models \ + tmp/cache/persistent \ + && chown -R :www-data \ + tmp \ + && chmod -R 770 \ + tmp + +# Enable Apache modules and restart +RUN a2enmod rewrite \ + && service apache2 restart + +EXPOSE 80 diff --git a/INSTALL.md b/INSTALL.md new file mode 100644 index 000000000..91816be75 --- /dev/null +++ b/INSTALL.md @@ -0,0 +1,58 @@ +# INSTALLATION +Docker :whale: is able to use web server containers in local (VM/Vbox) or remote (Cloud) machine cluster (Kubernetes). +A typical install script could look like the following script, for instance edit a file : + + #!/usr/bin/env bash + + cd myphpcms + git pull + git submodule update --init --recursive + ./docker-compose-alias.sh -dns=domain.com -S -p=sqlrootpassword -t=testpassword -v $* + cd .. + +If you saved the file as _startup.sh_ In bash follows : ```startup.sh --build -d up``` You can add more docker-compose parameters as arguments. +Docker builds up a new container and pushes it in registry. +It will eventually run the container as the startup script succeeds. + +## Circle CI, Docker Local testing +The current project is a full php with mariadb container for the Docker Virtual Machine (VM) manager, or Docker-CE, or even a ```Dockerfile``` compatible container interface. We choose Circle CI because it's able to achieve full remote tests with docker :whale: before we deploy to a Cloud Provider, Kubernetes Cluster, OpenShift, etc. + +A local test may only run with a complete local Virtual Host (Vbox) configuration. See the requirements below. + +### Simple Docker compose tests +To use the built-in CakePHP 2 interface to test with Docker Compose YAML run the test script as follows : + + test-cake.sh --docker + +### Requirements +- Broadband Internet access to the Worldwide Web, to download the packages and container images dependencies from the remote Docker registries. +- The [VBoxmanager](https://www.virtualbox.org/wiki/Downloads) package. +- The Docker VM described with the Dockerfile. >:whale: [Get Started](https://docs.docker.com/machine/get-started/) application. +- The docker:docker user SSH remote access enabled (Ask the system administrator to enable Remote Session Accounts with Password authentification in /etc/ssh/sshd_config) +- The CircleCI Client installed in ```$PATH```. [CLI Configuration](https://circleci.com/docs/2.0/local-cli/#section=configuration) shell command line : + + curl -fLSs https://circle.ci/cli | bash + +Once everything is installed, please reboot your system. + +### Make local tests with CircleCI CLI +- Enable Docker VM on your system (a virtual Host is instancied) +- Shell command line : ```circleci local execute``` + +### Startup +Everyting is ready to launch a container in real cluster environment. The process is described further. [Kubespray with Ansible and Kubernetes cluster](https://github.com/b23prodtm/kubesrpay). + +### License + Copyright 2016 www.b23prodtm.info + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + * [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..06fe37208 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ +Apache License +Version 2.0, January 2004 +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, +and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by +the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all +other entities that control, are controlled by, or are under common +control with that entity. For the purposes of this definition, +"control" means (i) the power, direct or indirect, to cause the +direction or management of such entity, whether by contract or +otherwise, or (ii) ownership of fifty percent (50%) or more of the +outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity +exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, +including but not limited to software source code, documentation +source, and configuration files. + +"Object" form shall mean any form resulting from mechanical +transformation or translation of a Source form, including but +not limited to compiled object code, generated documentation, +and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or +Object form, made available under the License, as indicated by a +copyright notice that is included in or attached to the work +(an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object +form, that is based on (or derived from) the Work and for which the +editorial revisions, annotations, elaborations, or other modifications +represent, as a whole, an original work of authorship. For the purposes +of this License, Derivative Works shall not include works that remain +separable from, or merely link (or bind by name) to the interfaces of, +the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including +the original version of the Work and any modifications or additions +to that Work or Derivative Works thereof, that is intentionally +submitted to Licensor for inclusion in the Work by the copyright owner +or by an individual or Legal Entity authorized to submit on behalf of +the copyright owner. For the purposes of this definition, "submitted" +means any form of electronic, verbal, or written communication sent +to the Licensor or its representatives, including but not limited to +communication on electronic mailing lists, source code control systems, +and issue tracking systems that are managed by, or on behalf of, the +Licensor for the purpose of discussing and improving the Work, but +excluding communication that is conspicuously marked or otherwise +designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity +on behalf of whom a Contribution has been received by Licensor and +subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of +this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable +copyright license to reproduce, prepare Derivative Works of, +publicly display, publicly perform, sublicense, and distribute the +Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of +this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable +(except as stated in this section) patent license to make, have made, +use, offer to sell, sell, import, and otherwise transfer the Work, +where such license applies only to those patent claims licensable +by such Contributor that are necessarily infringed by their +Contribution(s) alone or by combination of their Contribution(s) +with the Work to which such Contribution(s) was submitted. If You +institute patent litigation against any entity (including a +cross-claim or counterclaim in a lawsuit) alleging that the Work +or a Contribution incorporated within the Work constitutes direct +or contributory patent infringement, then any patent licenses +granted to You under this License for that Work shall terminate +as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the +Work or Derivative Works thereof in any medium, with or without +modifications, and in Source or Object form, provided that You +meet the following conditions: + +(a) You must give any other recipients of the Work or +Derivative Works a copy of this License; and + +(b) You must cause any modified files to carry prominent notices +stating that You changed the files; and + +(c) You must retain, in the Source form of any Derivative Works +that You distribute, all copyright, patent, trademark, and +attribution notices from the Source form of the Work, +excluding those notices that do not pertain to any part of +the Derivative Works; and + +(d) If the Work includes a "NOTICE" text file as part of its +distribution, then any Derivative Works that You distribute must +include a readable copy of the attribution notices contained +within such NOTICE file, excluding those notices that do not +pertain to any part of the Derivative Works, in at least one +of the following places: within a NOTICE text file distributed +as part of the Derivative Works; within the Source form or +documentation, if provided along with the Derivative Works; or, +within a display generated by the Derivative Works, if and +wherever such third-party notices normally appear. The contents +of the NOTICE file are for informational purposes only and +do not modify the License. You may add Your own attribution +notices within Derivative Works that You distribute, alongside +or as an addendum to the NOTICE text from the Work, provided +that such additional attribution notices cannot be construed +as modifying the License. + +You may add Your own copyright statement to Your modifications and +may provide additional or different license terms and conditions +for use, reproduction, or distribution of Your modifications, or +for any such Derivative Works as a whole, provided Your use, +reproduction, and distribution of the Work otherwise complies with +the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, +any Contribution intentionally submitted for inclusion in the Work +by You to the Licensor shall be under the terms and conditions of +this License, without any additional terms or conditions. +Notwithstanding the above, nothing herein shall supersede or modify +the terms of any separate license agreement you may have executed +with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade +names, trademarks, service marks, or product names of the Licensor, +except as required for reasonable and customary use in describing the +origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or +agreed to in writing, Licensor provides the Work (and each +Contributor provides its Contributions) on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +implied, including, without limitation, any warranties or conditions +of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A +PARTICULAR PURPOSE. You are solely responsible for determining the +appropriateness of using or redistributing the Work and assume any +risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, +whether in tort (including negligence), contract, or otherwise, +unless required by applicable law (such as deliberate and grossly +negligent acts) or agreed to in writing, shall any Contributor be +liable to You for damages, including any direct, indirect, special, +incidental, or consequential damages of any character arising as a +result of this License or out of the use or inability to use the +Work (including but not limited to damages for loss of goodwill, +work stoppage, computer failure or malfunction, or any and all +other commercial damages or losses), even if such Contributor +has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing +the Work or Derivative Works thereof, You may choose to offer, +and charge a fee for, acceptance of support, warranty, indemnity, +or other liability obligations and/or rights consistent with this +License. However, in accepting such obligations, You may act only +on Your own behalf and on Your sole responsibility, not on behalf +of any other Contributor, and only if You agree to indemnify, +defend, and hold each Contributor harmless for any liability +incurred by, or claims asserted against, such Contributor by reason +of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + +To apply the Apache License to your work, attach the following +boilerplate notice, with the fields enclosed by brackets "{}" +replaced with your own identifying information. (Don't include +the brackets!) The text should be enclosed in the appropriate +comment syntax for the file format. We also recommend that a +file or class name and description of purpose be included on the +same "printed page" as the copyright notice for easier +identification within third-party archives. + +Copyright 2018 www.b23prodtm.info + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/README.md b/README.md index 3aba945df..65a6dcd46 100644 --- a/README.md +++ b/README.md @@ -28,13 +28,17 @@ It includes a link to [PHP-CMS Pohse](https://sourceforge.net/projects/pohse/) a You do not need to change anything in your existing PHP project's repository. However, if these files exist they will affect the behavior of the build process: +* **download from git** + + Use a git client to download the project. It will stay in the myphpcms/ folder : + ```git checkout https://github.com/b23prodtm/myphpcms.git``` + * **submodules**  The myphpcms folder includes modules that need to be pulled in order to install locally. After the first checkout browse to myphpcms folder and do ```git submodule update --init --recursive``` You'll see modules populating the subfolder app/webroot/... If something goes wrong, erase the myphpcms folder and start over. - > After a sucessful ```git checkout```each time, run once ```git submodule update --init --recursive``` to ensure submodules are downloaded from git. Otherwise your build may fail. * **composer.json** @@ -120,7 +124,7 @@ The following additional variables must be set up as server secrets environment, TEST_DATABASE_PASSWORD: # CakePHP generated CAKEPHP_SECRET_TOKEN: - CAKEPHP_SECRET_SQLT: + CAKEPHP_SECRET_SALT: CAKEPHP_SECURITY_CIPHER_SEED: # Generated by ./configure.sh -h GET_HASH_PASSWORD: @@ -271,7 +275,7 @@ The Mysql.php Datasource must define binary and mediumbinary storage types. Plea Add the *__mediumbinary__* storage, extending the original Datasource class: -`` +``` -`` +``` Ensure it is set as DATABASE_ENGINE in `app/Config/database.cms.php`,`./Scripts/bootargs.sh`, `.travis.yml` and update the database schema: ./migrate-database.sh -u 9. It looks like submodule folders have disappeared, why ? -A recent `git checkout` made the submodule disappear from disk, that can happen on master/development branch. Recall or add the shell configure script to your workflow: +A recent `git checkout ` made the submodule disappear from disk, that can happen on master/development branch. Recall or add the shell configure script to your workflow: ./configure.sh -m @@ -329,7 +333,7 @@ If you are working on a git remote tracked branch, it is recommended to remove f echo "/bin/composer.phar" >> .gitignore ### License - Copyright 2016 b23production GNU + Copyright 2016 www.b23prodtm.info Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/Scripts/bootargs.sh b/Scripts/bootargs.sh index c78546845..b0b17980c 100755 --- a/Scripts/bootargs.sh +++ b/Scripts/bootargs.sh @@ -7,6 +7,7 @@ red="\033[0;31m" green="\033[0;32m" orange="\033[0;33m" cyan="\033[0;36m" +echo -e "Loading ${orange}Test environment${nc} : $0..." #; To change Model/Datasource/Database [[ ("${DB}" == "Mysql") || -z $DB ]] && export DB="Mysql" && export DATABASE_ENGINE="MysqlCms" && export DATABASE_SERVICE_NAME="MYSQL" [ "${DB}" == "Pgsql" ] && export DATABASE_ENGINE="PostgresCms" && export DATABASE_SERVICE_NAME="PGSQL" @@ -35,7 +36,6 @@ export TEST_DATABASE_USER="test" export FTP_SERVICE_HOST="localhost" export FTP_SERVICE_USER="test" export FTP_SERVICE_PASSWORD="mypassword" -export PHP_CMS_DIR="./app/webroot/php_cms/" #; More about default environment app/Config/core.php #; Openshift Online secure keys (default_keys) export CAKEPHP_SECURITY_SALT="Word" diff --git a/Scripts/bootstrap.sh b/Scripts/bootstrap.sh index 93bda331c..55b2433e0 100755 --- a/Scripts/bootstrap.sh +++ b/Scripts/bootstrap.sh @@ -3,19 +3,16 @@ set -e source ./Scripts/lib/shell_prompt.sh source ./Scripts/lib/parsing.sh openshift=$(parse_arg_exists "-[oO]*|--openshift" $*) -if [ $openshift > /dev/null ]; then +if [ -z ${PHP_CMS_DIR} ]; then export PHP_CMS_DIR=app/webroot/php_cms; fi +if [ $openshift 2> /dev/null ]; then echo "Real environment bootargs..." + export CAKEPHP_DEBUG_LEVEL=1 else echo "Provided local/test bootargs..." + export CAKEPHP_DEBUG_LEVEL=2 source ./Scripts/bootargs.sh $* fi #; -#; -#; this development phase, don't use the same values for production (no setting means no debugger)! -#; -#; -export CAKEPHP_DEBUG_LEVEL=2 -#; #; check if file etc/constantes_local.properties exist (~ ./configure.sh was run once) #; if [ ! -f ${PHP_CMS_DIR}/e13/etc/constantes.properties ]; then @@ -30,17 +27,16 @@ if [[ ! $GET_HASH_PASSWORD ]]; then fi source $hash fi -echo -e "${nc}Password ${green}$GET_HASH_PASSWORD${nc}" +echo -e "${nc}Password ${green}${GET_HASH_PASSWORD}${nc}" #; Install PHPUnit, performs unit tests #; The website must pass health checks in order to be deployed -phpunit="./app/Vendor/bin/phpunit" -if [ ! -f $phpunit ]; then - if [ ! -f bin/composer.phar ]; then - source ./Scripts/composer.sh - fi - php bin/composer.phar update --prefer-dist --with-dependencies phpunit/phpunit cakephp/cakephp-codesniffer -else - echo -e "PHPUnit ${green}[OK]${nc}" +if [ $openshift 2> /dev/null ]; then + phpunit="./app/Vendor/bin/phpunit" + if [ ! -f $phpunit ]; then + source ./Scripts/composer.sh -o phpunit/phpunit cakephp/cakephp-codesniffer + else + echo -e "PHPUnit ${green}[OK]${nc}" + fi + echo `$phpunit --version` fi -echo `$phpunit --version` source ./Scripts/config_app_database.sh diff --git a/Scripts/composer.sh b/Scripts/composer.sh index 82a7b0ad8..2a9c0a410 100755 --- a/Scripts/composer.sh +++ b/Scripts/composer.sh @@ -5,21 +5,23 @@ #; #; #; colorful shell +source ./Scripts/lib/parsing.sh nc='\033[0m' red="\033[0;31m" green="\033[0;32m" orange="\033[0;33m" cyan="\033[0;36m" composer="bin/composer.phar" -if [ ! -f $composer ]; then +if [ $(which composer) 2> /dev/null ]; then + composer="composer" +else if [ ! -f $composer ]; then echo -e "Composer setup...\n" mkdir -p bin cd bin curl -sS https://getcomposer.org/installer | php cd .. -else - echo -e "Composer ${green}[OK]${nc}" -fi -bin/composer.phar --version -#; update plugins and dependencies -bin/composer.phar update --with-dependencies --apcu-autoloader $* +fi;fi +echo -e "Composer ${green}[OK]${nc}" +bash -c "${composer} --version" +#; update plugins and dependencies (composer install is good enough to check for updates) +bash -c "${composer} install $*" diff --git a/Scripts/config_app_database.sh b/Scripts/config_app_database.sh index 106b03be4..9d102f21c 100755 --- a/Scripts/config_app_database.sh +++ b/Scripts/config_app_database.sh @@ -1,6 +1,6 @@ #!/bin/bash sqlversion="5.7" -if [ ! $(which brew) > /dev/null ]; then echo "Missing homebrew... aborted mysql check."; else if [ ! $(which mysql) > /dev/null ]; then +if [ ! $(which brew) 2> /dev/null ]; then echo "Missing homebrew... aborted mysql check."; else if [ ! $(which mysql) 2> /dev/null ]; then echo -e "Missing MySQL ${sqlversion} database service." brew outdated mysql@${sqlversion} | brew upgrade echo -e "Installing with Homebrew..." diff --git a/Scripts/configure_tmp.sh b/Scripts/configure_tmp.sh index d2a400411..c2705906f 100755 --- a/Scripts/configure_tmp.sh +++ b/Scripts/configure_tmp.sh @@ -4,4 +4,4 @@ mkdir -p app/tmp/cache/models mkdir -p app/tmp/tests mkdir -p app/tmp/logs touch app/tmp/logs/error.log -chmod -Rv 755 app/tmp +chmod -Rv 770 app/tmp diff --git a/Scripts/docker_site_conf.sh b/Scripts/docker_site_conf.sh new file mode 100755 index 000000000..3b636454e --- /dev/null +++ b/Scripts/docker_site_conf.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +if [ $# -lt 1 ]; then echo "Usage: $0 "; fi +touch site.conf +echo -e " + + ServerName $1 + DocumentRoot /var/www/html/app/webroot/ + + + Options FollowSymLinks + AllowOverride All + Require all granted + +" >> site.conf +cat site.conf +mv site.conf docker/apache/. diff --git a/Scripts/install-docker-compose.sh b/Scripts/install-docker-compose.sh new file mode 100755 index 000000000..8e4cb6f43 --- /dev/null +++ b/Scripts/install-docker-compose.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +sudo apt-get remove docker-compose +sudo apt-get install python-pip +sudo pip install docker-compose diff --git a/Scripts/lib/parsing.sh b/Scripts/lib/parsing.sh index 6cf521da6..ae6b109d4 100755 --- a/Scripts/lib/parsing.sh +++ b/Scripts/lib/parsing.sh @@ -34,7 +34,7 @@ Please, enter the $4 value now: } #; export -f parse_arg_export parse_arg_exists() { - [ $# -eq 0 ] && echo "Usage: $0 arguments-list" + [ $# -lt 2 ] && echo "Usage: $0 list-or-\$*" arg1=$(echo $1 | cut -f 1 -d '|') arg2=$(echo $1 | cut -f 2 -d '|') shift @@ -45,3 +45,8 @@ parse_arg_exists() { esac; ((count++)); shift; done } #; export -f parse_arg_exists() +parse_dns_host() { + [ $# -lt 3 ] && echo "Usage: $0 " + parse_arg_export $1 "-dns*|-DNS*" $2 $3 +} +#; export -f parse_dns_host() diff --git a/composer.lock b/composer.lock index ce187a044..c135a9ea5 100644 --- a/composer.lock +++ b/composer.lock @@ -1,7 +1,7 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], "content-hash": "d4bdf8e6e5f64f050538e34d61eaa577", @@ -319,32 +319,32 @@ }, { "name": "doctrine/instantiator", - "version": "1.0.5", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" + "reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", - "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda", + "reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda", "shasum": "" }, "require": { - "php": ">=5.3,<8.0-DEV" + "php": "^7.1" }, "require-dev": { "athletic/athletic": "~0.1.8", "ext-pdo": "*", "ext-phar": "*", - "phpunit/phpunit": "~4.0", - "squizlabs/php_codesniffer": "~2.0" + "phpunit/phpunit": "^6.2.3", + "squizlabs/php_codesniffer": "^3.0.2" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "1.2.x-dev" } }, "autoload": { @@ -369,7 +369,7 @@ "constructor", "instantiate" ], - "time": "2015-06-14T21:17:01+00:00" + "time": "2017-07-22T11:58:36+00:00" }, { "name": "guzzlehttp/guzzle", @@ -693,29 +693,35 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "3.3.2", + "version": "4.3.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "bf329f6c1aadea3299f08ee804682b7c45b326a2" + "reference": "94fd0001232e47129dd3504189fa1c7225010d08" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/bf329f6c1aadea3299f08ee804682b7c45b326a2", - "reference": "bf329f6c1aadea3299f08ee804682b7c45b326a2", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/94fd0001232e47129dd3504189fa1c7225010d08", + "reference": "94fd0001232e47129dd3504189fa1c7225010d08", "shasum": "" }, "require": { - "php": "^5.6 || ^7.0", + "php": "^7.0", "phpdocumentor/reflection-common": "^1.0.0", "phpdocumentor/type-resolver": "^0.4.0", "webmozart/assert": "^1.0" }, "require-dev": { - "mockery/mockery": "^0.9.4", - "phpunit/phpunit": "^4.4" + "doctrine/instantiator": "~1.0.5", + "mockery/mockery": "^1.0", + "phpunit/phpunit": "^6.4" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.x-dev" + } + }, "autoload": { "psr-4": { "phpDocumentor\\Reflection\\": [ @@ -734,7 +740,7 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2017-11-10T14:09:06+00:00" + "time": "2017-11-30T07:14:17+00:00" }, { "name": "phpdocumentor/type-resolver", @@ -1875,32 +1881,31 @@ }, { "name": "symfony/config", - "version": "v3.4.21", + "version": "v4.2.3", "source": { "type": "git", "url": "https://github.com/symfony/config.git", - "reference": "17c5d8941eb75a03d19bc76a43757738632d87b3" + "reference": "25a2e7abe0d97e70282537292e3df45cf6da7b98" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/config/zipball/17c5d8941eb75a03d19bc76a43757738632d87b3", - "reference": "17c5d8941eb75a03d19bc76a43757738632d87b3", + "url": "https://api.github.com/repos/symfony/config/zipball/25a2e7abe0d97e70282537292e3df45cf6da7b98", + "reference": "25a2e7abe0d97e70282537292e3df45cf6da7b98", "shasum": "" }, "require": { - "php": "^5.5.9|>=7.0.8", - "symfony/filesystem": "~2.8|~3.0|~4.0", + "php": "^7.1.3", + "symfony/filesystem": "~3.4|~4.0", "symfony/polyfill-ctype": "~1.8" }, "conflict": { - "symfony/dependency-injection": "<3.3", - "symfony/finder": "<3.3" + "symfony/finder": "<3.4" }, "require-dev": { - "symfony/dependency-injection": "~3.3|~4.0", - "symfony/event-dispatcher": "~3.3|~4.0", - "symfony/finder": "~3.3|~4.0", - "symfony/yaml": "~3.0|~4.0" + "symfony/dependency-injection": "~3.4|~4.0", + "symfony/event-dispatcher": "~3.4|~4.0", + "symfony/finder": "~3.4|~4.0", + "symfony/yaml": "~3.4|~4.0" }, "suggest": { "symfony/yaml": "To use the yaml reference dumper" @@ -1908,7 +1913,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.4-dev" + "dev-master": "4.2-dev" } }, "autoload": { @@ -1935,7 +1940,7 @@ ], "description": "Symfony Config Component", "homepage": "https://symfony.com", - "time": "2019-01-01T13:45:19+00:00" + "time": "2019-01-30T11:44:30+00:00" }, { "name": "symfony/console", @@ -1998,6 +2003,74 @@ "homepage": "https://symfony.com", "time": "2018-11-20T15:55:20+00:00" }, + { + "name": "symfony/contracts", + "version": "v1.0.2", + "source": { + "type": "git", + "url": "https://github.com/symfony/contracts.git", + "reference": "1aa7ab2429c3d594dd70689604b5cf7421254cdf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/contracts/zipball/1aa7ab2429c3d594dd70689604b5cf7421254cdf", + "reference": "1aa7ab2429c3d594dd70689604b5cf7421254cdf", + "shasum": "" + }, + "require": { + "php": "^7.1.3" + }, + "require-dev": { + "psr/cache": "^1.0", + "psr/container": "^1.0" + }, + "suggest": { + "psr/cache": "When using the Cache contracts", + "psr/container": "When using the Service contracts", + "symfony/cache-contracts-implementation": "", + "symfony/service-contracts-implementation": "", + "symfony/translation-contracts-implementation": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Contracts\\": "" + }, + "exclude-from-classmap": [ + "**/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "A set of abstractions extracted out of the Symfony components", + "homepage": "https://symfony.com", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "time": "2018-12-05T08:06:11+00:00" + }, { "name": "symfony/debug", "version": "v3.0.9", @@ -2057,26 +2130,26 @@ }, { "name": "symfony/filesystem", - "version": "v3.4.21", + "version": "v4.2.3", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "c24ce3d18ccc9bb9d7e1d6ce9330fcc6061cafde" + "reference": "7c16ebc2629827d4ec915a52ac809768d060a4ee" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/c24ce3d18ccc9bb9d7e1d6ce9330fcc6061cafde", - "reference": "c24ce3d18ccc9bb9d7e1d6ce9330fcc6061cafde", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/7c16ebc2629827d4ec915a52ac809768d060a4ee", + "reference": "7c16ebc2629827d4ec915a52ac809768d060a4ee", "shasum": "" }, "require": { - "php": "^5.5.9|>=7.0.8", + "php": "^7.1.3", "symfony/polyfill-ctype": "~1.8" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.4-dev" + "dev-master": "4.2-dev" } }, "autoload": { @@ -2103,29 +2176,29 @@ ], "description": "Symfony Filesystem Component", "homepage": "https://symfony.com", - "time": "2019-01-01T13:45:19+00:00" + "time": "2019-01-16T20:35:37+00:00" }, { "name": "symfony/finder", - "version": "v3.4.21", + "version": "v4.2.3", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "3f2a2ab6315dd7682d4c16dcae1e7b95c8b8555e" + "reference": "ef71816cbb264988bb57fe6a73f610888b9aa70c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/3f2a2ab6315dd7682d4c16dcae1e7b95c8b8555e", - "reference": "3f2a2ab6315dd7682d4c16dcae1e7b95c8b8555e", + "url": "https://api.github.com/repos/symfony/finder/zipball/ef71816cbb264988bb57fe6a73f610888b9aa70c", + "reference": "ef71816cbb264988bb57fe6a73f610888b9aa70c", "shasum": "" }, "require": { - "php": "^5.5.9|>=7.0.8" + "php": "^7.1.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.4-dev" + "dev-master": "4.2-dev" } }, "autoload": { @@ -2152,7 +2225,7 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2019-01-01T13:45:19+00:00" + "time": "2019-01-16T20:35:37+00:00" }, { "name": "symfony/polyfill-ctype", @@ -2273,25 +2346,26 @@ }, { "name": "symfony/stopwatch", - "version": "v3.4.21", + "version": "v4.2.3", "source": { "type": "git", "url": "https://github.com/symfony/stopwatch.git", - "reference": "af55d31cb58c5452d2c160655fa1968b872a8084" + "reference": "b1a5f646d56a3290230dbc8edf2a0d62cda23f67" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/stopwatch/zipball/af55d31cb58c5452d2c160655fa1968b872a8084", - "reference": "af55d31cb58c5452d2c160655fa1968b872a8084", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/b1a5f646d56a3290230dbc8edf2a0d62cda23f67", + "reference": "b1a5f646d56a3290230dbc8edf2a0d62cda23f67", "shasum": "" }, "require": { - "php": "^5.5.9|>=7.0.8" + "php": "^7.1.3", + "symfony/contracts": "^1.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.4-dev" + "dev-master": "4.2-dev" } }, "autoload": { @@ -2318,7 +2392,7 @@ ], "description": "Symfony Stopwatch Component", "homepage": "https://symfony.com", - "time": "2019-01-01T13:45:19+00:00" + "time": "2019-01-16T20:31:39+00:00" }, { "name": "symfony/yaml", diff --git a/configure.sh b/configure.sh index ec109053a..48a58e49a 100755 --- a/configure.sh +++ b/configure.sh @@ -3,7 +3,7 @@ set -e source ./Scripts/lib/shell_prompt.sh source ./Scripts/lib/parsing.sh openshift=$(parse_arg_exists "-[oO]*|--openshift" $*) -if [ $openshift > /dev/null ]; then +if [ $openshift 2> /dev/null ]; then echo "Real environment bootargs..." else echo "Provided local/test bootargs..." @@ -26,7 +26,7 @@ while [[ "$#" > 0 ]]; do case $1 in #; [[-d|--mig-database] [-u]] argument fixes up : Error: Database connection "Mysql" is missing, or could not be created. args="" shift - if [ $openshift > /dev/null ]; then args="--openshift "; fi + if [ $openshift 2> /dev/null ]; then args="--openshift "; fi shell_prompt "./migrate-database.sh ${args}$*" "${cyan}Step 3. Migrate database\n${nc}" '-Y' break;; -[sS]*|-[pP]*|-[fF]*) @@ -54,6 +54,6 @@ while [[ "$#" > 0 ]]; do case $1 in *) echo "Unknown parameter passed: $0 $1"; exit 1;; esac; shift; done echo -e "${green}Fixing some file permissions...${nc}" -[ $openshift > /dev/null ] && echo "None." || source ./Scripts/configure_tmp.sh +[ $openshift 2> /dev/null ] && echo "None." || source ./Scripts/configure_tmp.sh #; update plugins and dependencies -source ./Scripts/composer.sh "-o" +source ./Scripts/composer.sh "--dev --no-interaction" diff --git a/docker-compose-alias.sh b/docker-compose-alias.sh new file mode 100755 index 000000000..01ce3f746 --- /dev/null +++ b/docker-compose-alias.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +source ./Scripts/lib/parsing.sh +bootargs="" +docker="" +saved=("$*") +usage="[-dns=] [-p|--sql-password=] [-t,--test-sql-password=] [other-args]" +[ $# -eq 0 ] && echo "Usage: $0 ${usage}" && exit 1 +while [[ "$#" > 0 ]]; do case $1 in + -[pP]*|--sql-password*) + parse_sql_password "$1" "DATABASE_PASSWORD" "user ${DATABASE_USER}";; + -[tT]*|--test-sql-password*) + parse_sql_password "$1" "TEST_DATABASE_PASSWORD" "test user ${TEST_DATABASE_USER}";; + -[vV]*|--verbose ) + echo "Passed params : $0 ${saved}";; + -[oO]*|--openshift ) + bootargs=$saved;; + -[S]*|-submodule ) + git submodule update --init --recursive;; + -dns*|-DNS*) + parse_dns_host "$1" "SERVER_NAME" "Domain Server Name";; + -[hH]*|--help ) + echo "Usage: $0 ${usage} + -dns= + Apache ServerName global directive + -p, --sql-password= + Exports DATABASE_PASSWORD + -t, --test-sql-password= + Exports TEST_DATABASE_PASSWORD + -S, --submodule + Update Git submodules + -o, --openshift + Use environment variables from real pod or current shell. Also calls composer update (heavy load task). + -v + Verbosity enabled + [other-args] + Passed to docker-compose + " + exit 0;; + *) docker="${docker} $1";; +esac; shift; done +export DB=Mysql +source Scripts/bootstrap.sh $bootargs +if [ ! $(which docker-compose) 2> /dev/null ]; then Scripts/install-docker-compose.sh; fi +if [ ! -z $SERVER_NAME ]; then + source Scripts/docker_site_conf.sh $SERVER_NAME +else + cp -v docker/apache/site-default.conf docker/apache/site.conf +fi +docker-compose $docker +sudo cp index-redirect-8000.php /var/www/html/index.php diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..b91eef6d6 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,53 @@ +version: "3" +services: + + app: + build: + context: . + dockerfile: Dockerfile + volumes: + - .:/var/www/html + ports: + - 8000:80 + depends_on: + - db + environment: + DOCKER_OS_NAME: linux + DOCKER_PHP_VERSION: ${_PHP} + DB: Mysql + # a host alias or IP address + MYSQL_SERVICE_HOST: db + MYSQL_SERVICE_PORT: 3306 + TEST_MYSQL_SERVICE_HOST: db + TEST_MYSQL_SERVICE_PORT: 3306 + DATABASE_NAME: phpcms + DATABASE_SERVICE_NAME: MYSQL + #(optional) + #WEBHOOK_URL: + # Persistent connection credentials + DATABASE_USER: root + # overrides docker-compose-alias.sh -p= + DATABASE_PASSWORD: ${DATABASE_PASSWORD} + # Just add TEST_DATABASE_USER and TEST_DATABASE_PASSWORD + TEST_DATABASE_USER: ubuntu + # overrides docker-compose-alias.sh -t= + #TEST_DATABASE_PASSWORD: + # CakePHP generated + #CAKEPHP_SECRET_TOKEN: + #CAKEPHP_SECRET_SALT: + #CAKEPHP_SECURITY_CIPHER_SEED: + # Generated by ./configure.sh -h + GET_HASH_PASSWORD: ${GET_HASH_PASSWORD} + db: + image: library/mariadb:10.4-bionic + volumes: + - db-data:/var/lib/mysql + environment: + MYSQL_DATABASE: ${DATABASE_NAME} + MYSQL_ROOT_PASSWORD: ${DATABASE_PASSWORD} + MYSQL_USER: ubuntu + MYSQL_PASSWORD: ${TEST_DATABASE_PASSWORD} + +volumes: + db-data: + external: false diff --git a/docker/apache/site-default.conf b/docker/apache/site-default.conf new file mode 100644 index 000000000..50051795c --- /dev/null +++ b/docker/apache/site-default.conf @@ -0,0 +1,9 @@ + + DocumentRoot /var/www/html/app/webroot/ + + + Options FollowSymLinks + AllowOverride All + Require all granted + + diff --git a/docker/apache/site.conf b/docker/apache/site.conf new file mode 100644 index 000000000..c58d2e914 --- /dev/null +++ b/docker/apache/site.conf @@ -0,0 +1,11 @@ + + + ServerName b23prodtm.info + DocumentRoot /var/www/html/app/webroot/ + + + Options FollowSymLinks + AllowOverride All + Require all granted + + diff --git a/docker/configure.sh b/docker/configure.sh new file mode 100644 index 000000000..4bf6c7807 --- /dev/null +++ b/docker/configure.sh @@ -0,0 +1,136 @@ +#!/usr/bin/env bash +export DB=Mysql +source Scripts/bootstrap.sh $* +cp -v docker/apache/site-default.conf docker/apache/site.conf +echo -e " +Set of default Test environment +========================== + Find exports for local test development phase only in './Scripts/bootargs.sh') + "; +echo -e " +Documented VARIABLES in docker-compose.yml + DOCKER_OS_NAME: os: ['osx','linux'] + DOCKER_PHP_VERSION : php: + DB=['Mysql', 'Pgsql', 'Sqlite'] + +Required VARIABLES in docker-compose.yml or Pod environment + DATABASE_USER: + DATABASE_PASSWORD: + TEST_DATABASE_USER: + TEST_DATABASE_PASSWORD: + if [ DB='Mysql' ]; then + TEST_MYSQL_SERVICE_HOST: + else if [ DB='Postgres' ]; then + TEST_POSTGRES_SERVICE_HOST: + fi +optional environment VARIABLES in docker-compose.yml + ADDITIONAL_PHP_INI='path to a php.ini settings file' +========================== +"; +[ ! -z $TEST_DATABASE_USER ] && [ ! -z $TEST_DATABASE_PASSWORD ] && [[ (! -z $TEST_MYSQL_SERVICE_HOST) || (! -z $TEST_PGSQL_SERVICE_HOST) ]] || echo "Missing VARIABLES. Please review your settings !" +if [ ! -z "${ADDITIONAL_PHP_INI}" ]; then /usr/bin/env bash .travis/TravisCI-OSX-PHP/build/custom_php_ini.sh; fi +mkdir -p build/logs +echo -e "Database Unit Tests... DB=${DB}" +if [[ "${DOCKER_OS_NAME}" == "linux" ]]; then + if [[ ${DOCKER_PHP_VERSION:0:3} == "7.2" ]]; then + pear config-set preferred_state snapshot && yes "" | pecl install mcrypt ; + fi; + sudo locale-gen de_DE + sudo locale-gen es_ES +fi; +if [[ ${DB} == 'Mysql' ]]; then mysql -v -e 'CREATE DATABASE IF NOT EXISTS cakephp_test;' -u ${DATABASE_USER} --password=${DATABASE_PASSWORD}; fi +if [[ ${DB} == 'Mysql' ]]; then mysql -v -e 'CREATE DATABASE IF NOT EXISTS cakephp_test2;' -u ${DATABASE_USER} --password=${DATABASE_PASSWORD}; fi +if [[ ${DB} == 'Mysql' ]]; then mysql -v -e 'CREATE DATABASE IF NOT EXISTS cakephp_test3;' -u ${DATABASE_USER} --password=${DATABASE_PASSWORD}; fi +if [[ ${DB} == 'Pgsql' ]]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi +if [[ ${DB} == 'Pgsql' ]]; then psql -c 'CREATE SCHEMA test2;' -U postgres -d cakephp_test; fi +if [[ ${DB} == 'Pgsql' ]]; then psql -c 'CREATE SCHEMA test3;' -U postgres -d cakephp_test; fi +chmod -R 777 ./app/tmp +if [[ "${DOCKER_OS_NAME}" == "linux" ]]; then + echo "extension = memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini + echo "yes" | pecl install apcu-5.1.3 || true + echo -e "extension = apcu.so\napc.enable_cli=1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini + phpenv rehash +fi +set +H +echo " array( + 'datasource' => 'Database/MysqlCms', + 'host' => '${TEST_MYSQL_SERVICE_HOST}', + 'login' => '${TEST_DATABASE_USER}', + 'password' => '${TEST_DATABASE_PASSWORD}' + ), + 'Pgsql' => array( + 'datasource' => 'Database/PostgresCms', + 'host' => '${TEST_PGSQL_SERVICE_HOST}', + 'login' => '${TEST_DATABASE_USER}', + 'database' => 'cakephp_test', + 'schema' => array( + 'default' => 'public', + 'test' => 'public', + 'test2' => 'test2', + 'test_database_three' => 'test3' + ) + ), + 'Sqlite' => array( + 'datasource' => 'Database/SqliteCms', + 'database' => array( + 'default' => ':memory:', + 'test' => ':memory:', + 'test2' => '/tmp/cakephp_test2.db', + 'test_database_three' => '/tmp/cakephp_test3.db' + ), + ) + ); + public \$default = array( + 'persistent' => false, + 'host' => '', + 'login' => '', + 'password' => '', + 'database' => 'cakephp_test', + 'prefix' => '' + ); + public \$test = array( + 'persistent' => false, + 'host' => '', + 'login' => '', + 'password' => '', + 'database' => 'cakephp_test', + 'prefix' => '' + ); + public \$test2 = array( + 'persistent' => false, + 'host' => '', + 'login' => '', + 'password' => '', + 'database' => 'cakephp_test2', + 'prefix' => '' + ); + public \$test_database_three = array( + 'persistent' => false, + 'host' => '', + 'login' => '', + 'password' => '', + 'database' => 'cakephp_test3', + 'prefix' => '' + ); + public function __construct() { + \$db = 'Mysql'; + if (!empty(\$_SERVER['DB'])) { + \$db = \$_SERVER['DB']; + } + foreach (array('default', 'test', 'test2', 'test_database_three') as \$source) { + \$config = array_merge(\$this->{\$source}, \$this->identities[\$db]); + if (is_array(\$config['database'])) { + \$config['database'] = \$config['database'][\$source]; + } + if (!empty(\$config['schema']) && is_array(\$config['schema'])) { + \$config['schema'] = \$config['schema'][\$source]; + } + \$this->{\$source} = \$config; + } + } + }" > app/Config/database.php + echo -e "${green}Unit Test was set up in app/Config/database.php${nc}" diff --git a/index-redirect-8000.php b/index-redirect-8000.php new file mode 100644 index 000000000..de563211b --- /dev/null +++ b/index-redirect-8000.php @@ -0,0 +1,22 @@ +'."\n", + ''."\n", + ''."\n", + ''."\n", + ''."\n", //Redirection HTML + 'Redirection'."\n", + ''."\n", + ''."\n", + "\n", + ''."\n", + '

Redirection

'."\n", + ''."\n", + ''."\n"; diff --git a/migrate-database.sh b/migrate-database.sh index 0e88034d6..455a57538 100755 --- a/migrate-database.sh +++ b/migrate-database.sh @@ -3,7 +3,7 @@ set -e source ./Scripts/lib/shell_prompt.sh source ./Scripts/lib/parsing.sh openshift=$(parse_arg_exists "-[oO]*|--openshift" $*) -if [ $openshift > /dev/null ]; then +if [ $openshift 2> /dev/null ]; then echo "Real environment bootargs..." else echo "Provided local/test bootargs..." @@ -18,7 +18,10 @@ identities=app/Config/database.sql new_pass="" new_test_pass="" saved=("$*") +sql_source="" while [[ "$#" > 0 ]]; do case $1 in + --docker ) + sql_source="docker exec mysql ";; -[uU]* ) update_checked=1 ;; @@ -110,7 +113,7 @@ if [[ $import_identities -eq 1 ]]; then grant all on ${TEST_DATABASE_NAME}.* to '${TEST_DATABASE_USER}'@'${TEST_MYSQL_SERVICE_HOST}';\r create database if not exists ${TEST_DATABASE_NAME};\r " > $identities - echo "source ${identities}" | mysql -u $DATABASE_USER --password=$DATABASE_PASSWORD --connect-expired-password + ${sql_source} sh -c "echo \"source ${identities}\" | mysql -u $DATABASE_USER --password=$DATABASE_PASSWORD --connect-expired-password" export DATABASE_PASSWORD=$set_DATABASE_PASSWORD export TEST_DATABASE_PASSWORD=$set_TEST_DATABASE_PASSWORD fi diff --git a/test-cake.sh b/test-cake.sh index a4a94f16a..dea52df6e 100755 --- a/test-cake.sh +++ b/test-cake.sh @@ -2,6 +2,9 @@ source ./Scripts/lib/parsing.sh bootargs="" saved=("$*") +config_args="-c -h -p pass -s word --mig-database -y" +config_work_dir="" +notice="\n${cyan}Notice:${nc}The test script is about to modify the root and test users password into resp. ${orange}'proot'${nc} and ${cyan}'ptest'${nc}\n" while [[ "$#" > 0 ]]; do case $1 in --travis ) #; Test values @@ -10,12 +13,14 @@ while [[ "$#" > 0 ]]; do case $1 in export TRAVIS_OS_NAME="osx" export TRAVIS_PHP_VERSION=$(php -v | grep -E "[5-7]\.\\d+\.\\d+" | cut -d " " -f 2 | cut -c 1-3 ) - # remote servers CI don't need (-i) identities but the socket: use configure.sh --mig-database --openshift - notice="\n${cyan}Notice:${nc}The test script is about to modify the root and test users password into resp. ${orange}'proot'${nc} and ${cyan}'ptest'${nc}\n" - echo -e $notice - source ./configure.sh "--mig-database" "-p" "-t" "-i" "-p=proot" "-t=ptest" - echo -e $notice - source .travis/configure.sh;; + config_args="${config_args}" + config_work_dir=".travis";; + --docker ) + #; Test values + export DB="Mysql" + export COLLECT_COVERAGE="false" + config_args="${config_args}" + config_work_dir="docker";; --cov ) export COLLECT_COVERAGE=true;; -[hH]*|--help ) @@ -26,6 +31,8 @@ while [[ "$#" > 0 ]]; do case $1 in Exports TEST_DATABASE_PASSWORD --travis Travis CI Local Test Workflow + --docker + Docker Local Test Workflow --cov Coverage All Tests -o, --openshift @@ -37,12 +44,15 @@ while [[ "$#" > 0 ]]; do case $1 in -[tT]*|--test-sql-password*) parse_sql_password "$1" "TEST_DATABASE_PASSWORD" "test user ${TEST_DATABASE_USER}";; -[vV]*|--verbose ) - echo "Passed params : $0 ${saved}" - bootargs="${bootargs} $1";; + echo "Passed params : $0 ${saved}";; -[oO]*|--openshift ) - bootargs="${bootargs} $1";; + bootargs="${saved}";; *) echo "Unknown parameter passed: $0 $1"; exit 1;; esac; shift; done +echo -e $notice +source ./configure.sh "${config_args}" +echo -e $notice +[ ! -z $config_work_dir ] && source "${config_work_dir}/configure.sh" source ./Scripts/bootstrap.sh $bootargs show_password_status "$TEST_DATABASE_USER" "$TEST_DATABASE_PASSWORD" "is running tests" if [[ "$COLLECT_COVERAGE" == "true" ]]; then