From 8b53899212f47702a8282f5fdba22508da16c552 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Tue, 23 Jan 2024 22:29:47 +0000 Subject: [PATCH 1/8] Https, readme updates --- .../local-dev/configs/nginx/default.conf | 3 ++ Dockerfile | 3 ++ README.md | 34 ++++++++++++------- docker-compose.yml | 1 + 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/.codepipeline/local-dev/configs/nginx/default.conf b/.codepipeline/local-dev/configs/nginx/default.conf index e7b361fd..b72f2d44 100644 --- a/.codepipeline/local-dev/configs/nginx/default.conf +++ b/.codepipeline/local-dev/configs/nginx/default.conf @@ -2,6 +2,9 @@ server { # listen on port listen 3000 default_server; listen [::]:3000 default_server; + listen 3443 ssl; + ssl_certificate /etc/nginx/nginx.crt; + ssl_certificate_key /etc/nginx/nginx.key; root /var/www/html; diff --git a/Dockerfile b/Dockerfile index b5c552f5..7e0c40f5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -67,4 +67,7 @@ HEALTHCHECK --interval=10s --timeout=10s --start-period=5s --retries=15 \ CMD curl -s -o /dev/null -w "%{http_code}" http://localhost:3000 | grep -q -E "^[1-3][0-9]{2}$" && \ test -f ~/.cmfive-installed +RUN cd /etc/nginx && \ + openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout nginx.key -out nginx.crt -subj "/C=AU/ST=NSW/L=Bega/O=2pi/CN=localhost" + CMD ["/bootstrap/start.sh"] \ No newline at end of file diff --git a/README.md b/README.md index 8a3c220e..8ca97d9c 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,16 @@ # cmfive-boilerplate ![Build Status](https://travis-ci.org/adam-buckley/cmfive-boilerplate.svg?branch=master) A boilerplate project layout for Cmfive -### Local hosting/deployment with docker-compose -Requirements: -- docker -- mkcert +## Deploying a development environment with docker-compose -Install the root CA on your machine so that the SSL certificate is trusted (you can skip this and opt to go through the warning pages that browsers will give you): -run from the boilerplate directory: +### Requirements -```bash -cd .build/certs -mkcert -install -``` +- docker +- docker-compose + +### Setting up -Once done you can start the containers. For development we recommend the Docker plugin by Microsoft for VS Code. Simply right click on the **docker-compose.yml** file and select **Compose Up**. +For development we recommend the Docker plugin by Microsoft for VS Code. Simply right click on the **docker-compose.yml** file and select **Compose Up**. Alternatively to run it on the CLI: @@ -32,8 +28,22 @@ docker ps NOTE: The compiler will always start after cmfive is running. +## Logging in + From there, navigate to: [http://localhost:3000](http://localhost:3000) and log in with your admin account. For development it is: - Username: admin - Password: admin - \ No newline at end of file + +## HTTPS + +If you need to test on HTTPS it's available on [https://localhost:3443](https://localhost:3443). It's configured with a self-signed certificate, ignore the browser warning. + +## Changing the cmfive-core branch + +When you work on the system directory you may need to change the branch. To do this you can run this command: + +```sh +# Replace develop with your desired branch +docker exec -it cmfive ./cmfive.php install core develop +``` \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index d6de9431..2a580a5a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -45,6 +45,7 @@ services: - ./test/Codeception/tests/_output:/var/www/html/test/Codeception/tests/_output ports: - "3000:3000" + - "3443:3443" networks: - default restart: unless-stopped From 8a0753b4bdbc76cba74abce7f70a86538d170847 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Tue, 23 Jan 2024 23:46:03 +0000 Subject: [PATCH 2/8] Dev mode --- config.php.example | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config.php.example b/config.php.example index 1aca13b0..06eb2504 100644 --- a/config.php.example +++ b/config.php.example @@ -117,3 +117,6 @@ Config::set('system.rest_api_key', "abcdefghijklmnopqrstuvwxyz1234567890"); Config::set('system.rest_include', [ // "Contact" ]); + +// Development mode +Config::set('system.environment', 'development'); From f3eb620ce03d75fdd121d5ea61bfefb6aa19f0ef Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Wed, 24 Jan 2024 12:00:39 +1100 Subject: [PATCH 3/8] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8ca97d9c..7516ba37 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,6 @@ If you need to test on HTTPS it's available on [https://localhost:3443](https:// When you work on the system directory you may need to change the branch. To do this you can run this command: ```sh -# Replace develop with your desired branch -docker exec -it cmfive ./cmfive.php install core develop -``` \ No newline at end of file +# Replace with your desired branch +docker exec -it cmfive ./cmfive.php install core +``` From a9a60fe6195b68c00909e418b557bef206f0c395 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Thu, 25 Jan 2024 00:47:02 +0000 Subject: [PATCH 4/8] Keep containers running across codespace stop/start --- docker-compose.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 2a580a5a..4a7d3e43 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,6 +21,7 @@ services: # 'delegated' may be faster on mac or win? networks: - default + restart: unless-stopped healthcheck: test: ["CMD", "mysqladmin", "ping", "-h", "localhost"] interval: 30s @@ -66,6 +67,7 @@ services: interval: 30s timeout: 5m retries: 5 + restart: unless-stopped depends_on: webapp: condition: service_healthy From 90e6eb39404fd1cc21f471834f4f6bd612be9b55 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Thu, 25 Jan 2024 00:47:44 +0000 Subject: [PATCH 5/8] Playwright docker container name --- test/playwright/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/playwright/package.json b/test/playwright/package.json index 5a72478b..46874c6c 100644 --- a/test/playwright/package.json +++ b/test/playwright/package.json @@ -5,8 +5,8 @@ "main": "index.js", "scripts": { "build": "node build.js", - "setup": "docker exec -i nginx-php8.1 bash -c \"php cmfive.php testDB setup\"", - "cleanup": "echo \"y\" | bash cleanupTestMigrations.sh && docker exec -i nginx-php8.1 bash -c \"php cmfive.php DB test\"", + "setup": "docker exec -i cmfive bash -c \"php cmfive.php testDB setup\"", + "cleanup": "echo \"y\" | bash cleanupTestMigrations.sh && docker exec -i cmfive bash -c \"php cmfive.php DB test\"", "test": "bash -c '${npm_config_clean:+npm run cleanup && }npx playwright test --reporter=\"${npm_config_reporter:-list}\" --project=\"${npm_config_platform:-chromium}\"${npm_config_module:+ --grep=\"$npm_config_module\"}'", "test:with-retries": "bash -c '${npm_config_clean:+npm run cleanup && }bash run-test-with-retries.sh \"${npm_config_module:-}\" \"${npm_config_platform:-chromium}\" \"${npm_config_reporter:-github}\" \"${npm_config_attempts:-3}\"'" }, From 0af78e32507e044a408e0a75af1e86baf24253f4 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Thu, 25 Jan 2024 03:10:00 +0000 Subject: [PATCH 6/8] Add override for cmfive auto setup @Dane-2pi --- .codepipeline/local-dev/setup.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.codepipeline/local-dev/setup.sh b/.codepipeline/local-dev/setup.sh index 12fd71d8..769a7757 100755 --- a/.codepipeline/local-dev/setup.sh +++ b/.codepipeline/local-dev/setup.sh @@ -1,6 +1,12 @@ #!/bin/bash set -e +#if SKIP_CMFIVE_AUTOSETUP is defined, exit +if [ "$SKIP_CMFIVE_AUTOSETUP" = true ]; then + echo "Skipping setup" + exit 0 +fi + #If ~/.cmfive-installed exists close the script if [ -f ~/.cmfive-installed ]; then echo "Cmfive already installed" From 1df80d441ae0808ca1dc036e0e7dc25279704fd5 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Thu, 25 Jan 2024 05:06:03 +0000 Subject: [PATCH 7/8] Fix health check when skipping autosetup --- .codepipeline/local-dev/setup.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.codepipeline/local-dev/setup.sh b/.codepipeline/local-dev/setup.sh index 769a7757..9ce2debb 100755 --- a/.codepipeline/local-dev/setup.sh +++ b/.codepipeline/local-dev/setup.sh @@ -4,6 +4,8 @@ set -e #if SKIP_CMFIVE_AUTOSETUP is defined, exit if [ "$SKIP_CMFIVE_AUTOSETUP" = true ]; then echo "Skipping setup" + #Let container know that everything is finished + touch ~/.cmfive-installed exit 0 fi From 9dd346d051822e0f328fe6c7ab419ac0ec8be30a Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Wed, 31 Jan 2024 11:06:09 +1100 Subject: [PATCH 8/8] Fix cookie issues. improve docker-compose setup --- .../local-dev/configs/nginx/nginx.conf | 1 + .codepipeline/local-dev/local-dev-config.php | 17 +++++++++-------- .codepipeline/local-dev/setup.sh | 17 ++++++----------- docker-compose.yml | 6 +++--- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/.codepipeline/local-dev/configs/nginx/nginx.conf b/.codepipeline/local-dev/configs/nginx/nginx.conf index 2adafb6e..eee6e595 100644 --- a/.codepipeline/local-dev/configs/nginx/nginx.conf +++ b/.codepipeline/local-dev/configs/nginx/nginx.conf @@ -1,6 +1,7 @@ user www-data; worker_processes 4; pid /run/nginx.pid; +error_log /dev/stderr info; events { worker_connections 768; diff --git a/.codepipeline/local-dev/local-dev-config.php b/.codepipeline/local-dev/local-dev-config.php index cfd9cee4..01185c0b 100644 --- a/.codepipeline/local-dev/local-dev-config.php +++ b/.codepipeline/local-dev/local-dev-config.php @@ -12,10 +12,11 @@ //========== Database Configuration ========================== Config::set("database", [ - "hostname" => "mysqldb", - "username" => "cmfive", - "password" => "cmfive", - "database" => "cmfive", + "hostname" => getenv('DB_HOST') ?: "mysqldb", + "port" => getenv('DB_PORT') ?: "", + "username" => getenv('DB_USERNAME') ?: "cmfive", + "password" => getenv('DB_PASSWORD') ?: "cmfive", + "database" => getenv('DB_DATABASE') ?: "cmfive", "driver" => getenv('DB') ?: "mysql", "backups" => [ @@ -36,10 +37,10 @@ ]); Config::set("report.database", [ - "hostname" => "mysqldb", - "username" => "cmfivero", - "password" => "cmfivero", - "database" => "cmfive", + "hostname" => getenv('DB_HOST') ?: "mysqldb", + "username" => getenv('DB_USERNAME') ?: "cmfive", + "password" => getenv('DB_PASSWORD') ?: "cmfive", + "database" => getenv('DB_DATABASE') ?: "cmfive", "driver" => getenv('DB') ?: "mysql", ]); diff --git a/.codepipeline/local-dev/setup.sh b/.codepipeline/local-dev/setup.sh index 9ce2debb..9c030a49 100755 --- a/.codepipeline/local-dev/setup.sh +++ b/.codepipeline/local-dev/setup.sh @@ -1,6 +1,11 @@ #!/bin/bash set -e +cd /var/www/html + +#Clear cache +rm -f cache/config.cache + #if SKIP_CMFIVE_AUTOSETUP is defined, exit if [ "$SKIP_CMFIVE_AUTOSETUP" = true ]; then echo "Skipping setup" @@ -9,22 +14,12 @@ if [ "$SKIP_CMFIVE_AUTOSETUP" = true ]; then exit 0 fi -#If ~/.cmfive-installed exists close the script -if [ -f ~/.cmfive-installed ]; then - echo "Cmfive already installed" - exit 0 -fi echo "Setting up cmfive" -cd /var/www/html - -#Wait 15 seconds for things to start -sleep 15 - #Copy the config template if config.php doens't exist if [ ! -f config.php ]; then echo "Installing config.php" - cp config.php.example config.php + cp .codepipeline/local-dev/local-dev-config.php config.php fi #Allow all permissions to the folders diff --git a/docker-compose.yml b/docker-compose.yml index 4a7d3e43..f6675956 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,9 +7,6 @@ services: image: mysql:8 container_name: mysql-8 hostname: mysql-8 - # command: --sql-mode="" - ports: - - "3306:3306" environment: - MYSQL_ROOT_PASSWORD=root - MYSQL_USER=cmfive @@ -54,6 +51,9 @@ services: links: - mysqldb - seleniumsrv + depends_on: + mysqldb: + condition: service_healthy compiler: image: node:18-alpine