Skip to content

Commit

Permalink
Merge pull request #81 from 2pisoftware/feat/streamline-setup
Browse files Browse the repository at this point in the history
fix/Https, Readme, Dev mode, Add override, Playwright fix
  • Loading branch information
mattbell87 authored Jan 31, 2024
2 parents 925502c + 9dd346d commit e43a202
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 34 deletions.
3 changes: 3 additions & 0 deletions .codepipeline/local-dev/configs/nginx/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions .codepipeline/local-dev/configs/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
user www-data;
worker_processes 4;
pid /run/nginx.pid;
error_log /dev/stderr info;

events {
worker_connections 768;
Expand Down
17 changes: 9 additions & 8 deletions .codepipeline/local-dev/local-dev-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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" =>
[
Expand All @@ -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",
]);

Expand Down
21 changes: 12 additions & 9 deletions .codepipeline/local-dev/setup.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
#!/bin/bash
set -e

#If ~/.cmfive-installed exists close the script
if [ -f ~/.cmfive-installed ]; then
echo "Cmfive already installed"
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"
#Let container know that everything is finished
touch ~/.cmfive-installed
exit 0
fi
echo "Setting up cmfive"

cd /var/www/html

#Wait 15 seconds for things to start
sleep 15
echo "Setting up cmfive"

#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
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
34 changes: 22 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:

Expand All @@ -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


## 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 <BRANCH NAME> with your desired branch
docker exec -it cmfive ./cmfive.php install core <BRANCH NAME>
```
3 changes: 3 additions & 0 deletions config.php.example
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,6 @@ Config::set('system.rest_api_key', "abcdefghijklmnopqrstuvwxyz1234567890");
Config::set('system.rest_include', [
// "Contact"
]);

// Development mode
Config::set('system.environment', 'development');
9 changes: 6 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,6 +18,7 @@ services:
# 'delegated' may be faster on mac or win?
networks:
- default
restart: unless-stopped
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 30s
Expand All @@ -45,13 +43,17 @@ services:
- ./test/Codeception/tests/_output:/var/www/html/test/Codeception/tests/_output
ports:
- "3000:3000"
- "3443:3443"
networks:
- default
restart: unless-stopped
working_dir: /var/www/html
links:
- mysqldb
- seleniumsrv
depends_on:
mysqldb:
condition: service_healthy

compiler:
image: node:18-alpine
Expand All @@ -65,6 +67,7 @@ services:
interval: 30s
timeout: 5m
retries: 5
restart: unless-stopped
depends_on:
webapp:
condition: service_healthy
Expand Down
4 changes: 2 additions & 2 deletions test/playwright/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}\"'"
},
Expand Down

0 comments on commit e43a202

Please sign in to comment.