From a21451cb25612d05290ede6ce6712dec63174bd2 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Fri, 22 Mar 2024 12:24:51 +0000 Subject: [PATCH 1/6] Readme update --- CONTRIBUTING.md | 1 + README.md | 234 ++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 198 insertions(+), 37 deletions(-) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..df0a627 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1 @@ +# Contributing to Cmfive diff --git a/README.md b/README.md index 46c1f7c..a8b76f6 100644 --- a/README.md +++ b/README.md @@ -1,54 +1,214 @@ -# cmfive-boilerplate +# Cmfive Boilerplate [![Docker Image](https://github.com/2pisoftware/cmfive-boilerplate/actions/workflows/docker-image.yml/badge.svg)](https://github.com/2pisoftware/cmfive-boilerplate/actions/workflows/docker-image.yml) [![CI](https://github.com/2pisoftware/cmfive-boilerplate/actions/workflows/ci.yml/badge.svg)](https://github.com/2pisoftware/cmfive-boilerplate/actions/workflows/ci.yml) [![CodeQL](https://github.com/2pisoftware/cmfive-boilerplate/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/2pisoftware/cmfive-boilerplate/actions/workflows/github-code-scanning/codeql) -A boilerplate project layout for Cmfive -Main documentation is at: -[cmfive.com](https://cmfive.com) +Welcome! Cmfive is a framework designed for fast ERP and CRM business software solutions. This project is a modular platform that consists of the boilerplate, a core and optionally additional modules. This is the boilerplate repository which contains everything you need to develop and run Cmfive. -## Installation -This guide assumes a working knowledge on how to set up nginx to serve a PHP application as well as having an empty MySQL database (with user and password) ready to go. +The full documentation is located at [cmfive.com](https://cmfive.com). -To install Cmfive, clone or download the Boilerplate repository and unpack (if necessary) into a directory of your choosing. +## Development -Copy the config.php.example file to config.php and update (at least) the database section to contain the credentials of your Cmfive database, e.g.: +### Quick Start -Config::set("database", [ - "hostname" => "localhost", - "username" => "cmfive", - "password" => "cmfive", - "database" => "cmfive", - "driver" => "mysql" -]); +Follow these steps to get up and running with Cmfive development. -Change any other configuration items as you see fit. +Cmfive development requires Docker and Docker Compose. If you don't have these installed you can download them or follow the instructions from the [Docker website](https://docs.docker.com/get-docker/). -## Detailed Setup -Boilerplate and core have many dependencies, including PHP, MYSQL and NodeJS. -For a manageable approach, containerisation is a good option. -To consciously customise a development or production deployment, become familiar with the resources and deployment strategies shown in: +First clone this repository and navigate to the directory: + +```sh +git clone https://github.com/2pisoftware/cmfive-boilerplate.git +cd cmfive-boilerplate +``` + +Next, pull the latest docker images for cmfive: + +```sh +docker compose pull +``` + +Then run the following command to start the development environment: + +```sh +docker compose up -d --wait +``` + +This will start the development environment and run it in the background. Once it's running, you can access the Cmfive installation at [http://localhost:3000](http://localhost:3000). + +The development username is `admin` and the password is `admin`. + +The files in the boilerplate repository will now be mounted to **/var/www/html** in the container. You can make changes to the files in the repository and they will be reflected in the container. + +To stop the development environment, run: + +```sh +# to stop the containers +docker compose down + +# or to stop and remove all volumes +docker compose down -v +``` + +### Contributing + +For further information on developing and contributing to cmfive please refer to [CONTRIBUTING.md](CONTRIBUTING.md). + +### Accessing the cmfive installation tools menu + +The installation tools menu contains maintenance, setup and testing tools for cmfive. You can access it with the following command: + +```sh +docker compose exec -it -u cmfive webapp php cmfive.php ``` -.codepipeline/README.md + +Here is some detail on the menu options provided: + +- **Install Core Libraries**: This will install any third party libraries Cmfive requires via Composer +- **Install Database Migrations**: This will install all Cmfive database migrations +- **Seed Admin User**: Sets up an administrator user which is needed to log in to a production Cmfive install +- **Generate Encryption Keys**: Generate new encryption keys used by Cmfive for secure Database fields +- **Tests**: Runs a chosen test in the Cmfive test suite + +### Development on the cmfive-core repository + +When the development environment has started the cmfive-core git repository is cloned on to the boilerplate. If you want to make changes to the core repository you can do so by navigating to the core directory: + +```sh +cd composer/vendor/2pisoftware/cmfive-core +``` + +For more information about developing on the core repository please refer to the [cmfive-core repository](https://github.com/2pisoftware/cmfive-core). + +### Theme development + +The theme is located in the core and you can find it in this directory: + +```sh +cd composer/vendor/2pisoftware/cmfive-core/system/templates/base +``` + +As part of the development environment there is a container which compiles the theme as you change it. To view the output of the theme development container run the following command: + +```sh +docker compose logs -f compiler +``` + +### Accessing the cmfive container shell + +You can access the cmfive container shell with the following command: + +```sh +# for cmfive user access +docker compose exec -it -u cmfive webapp sh +# or for root access +docker compose exec -it -u root webapp sh +``` + +### Running tests + +Ensure you have installed the dev tools first. You can do this by running the following command: + +```sh +./.codepipeline/docker/install_dev_tools.sh ``` -## Complete setup by running "php cmfive.php" -Running through commands will get you set up and ready to go. -Here is an explanation of each command: +#### Playwright + +To set up and test with playwright, follow the instructions in the [Playwright README](test/playwright/README.md). -## Install Core Libraries -Will install any third party libraries Cmfive requires via Composer (the composer executable is bundled with the Boilerplate repo) -## Install Database Migrations -Will install all Cmfive migrations -## Seed Admin User -Will set up an administrator user, needed to log in to a new Cmfive install -## Generate Encryption Keys -Will generate encryption keys used by Cmfive, for secure Database fields +#### PHPUnit -## Build core templates -With core installed, use npm to formalise available template components and styling: +To run the PHPUnit tests, you can run the following command: + +```sh +docker compose exec -u cmfive webapp php cmfive.php tests unit all ``` -cd system/templates/base -npm ci -npm run prod + +## Deploying + +### Docker + +A docker image for cmfive is available on [GitHub Container Registry](https://github.com/2pisoftware/cmfive-boilerplate/pkgs/container/cmfive). + +You will need to run a mysql or compatible container and link it to the cmfive container. See more information about the mysql container on the [Docker Hub page](https://hub.docker.com/_/mysql). + +The following options can be used with the Docker image. You may choose to use for example vanilla docker, docker-compose or Kubernetes. Please consult the documentation for these tools for more information on how to use the options below. + +#### Environment variables + +- **DB_HOST:** The hostname of the MySQL database server +- **DB_DATABASE:** The name of the database +- **DB_USERNAME:** The username to connect to the database +- **DB_PASSWORD:** The password to connect to the database +- **ENVIRONMENT:** (optional) The environment to run in (development, production). Defaults to production. +- **CMFIVE_CORE_BRANCH:** (optional) The branch of the cmfive-core repository to switch to while the container is starting. If not specified it will use the baked-in core. + +#### Build args + +The following build args can be used to customise the Docker image if you are building a custom one: + +- **CORE_BRANCH:** The branch of the cmfive-core repository to bake in at build-time. Defaults to `master`. +- **PHP_VERSION:** The version of PHP to use. See alpine linux packages for available versions. Defaults to the version in the Dockerfile (eg 81). + +#### Volumes + +**Data persistence**: + +Here are the directories of the container that should be mounted to volumes if you want to persist data: + +- **/var/www/html/storage**: Sessions and logs +- **/var/www/html/uploads**: Uploaded files +- **/var/www/html/backups**: Database backups + +**HTTPS**: + +A self-signed SSL/TLS certificate is included in the image. If you require a certificate for your domain you can mount your key and certificate files to the following paths: + +- **/etc/nginx/nginx.key** - The SSL/TLS key +- **/etc/nginx/nginx.crt** - The SSL/TLS certificate + +**Modules** + +If you have custom modules you can mount them to the following directory: + +- **/var/www/html/modules/name-of-module** + +#### Ports + +The following ports are exposed by the container, you can map them to different ports on the host: + +- **80** - HTTP +- **443** - HTTPS + +### Manual setup + +Here are the steps to set up cmfive without Docker. Please note that your environment may differ and you may need to adjust these steps accordingly. + +Install the following software + +- PHP +- MySQL +- Nginx +- NodeJS + +Clone the repository + +```sh +git clone http://github.com/2pisoftware/cmfive-boilerplate.git ``` + +Set up a cmfive database and user on MySQL. Consult the MySQL documentation for more information. + +Copy config.php.example to config.php and update the database details. + +Run `php cmfive.php` and: + +- Install Core Libraries +- Install Database Migrations +- Seed Admin User +- Generate Encryption Keys + +Navigate to the theme directory (composer/vendor/2pisoftware/cmfive-core/system/templates/base) and run `npm install`. + +After that, you can build the production theme with `npm run production`. From cf8369f9a19a548e94382d471c5f9d51712a9108 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Fri, 22 Mar 2024 13:45:20 +0000 Subject: [PATCH 2/6] Example usage --- README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/README.md b/README.md index a8b76f6..977b502 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,48 @@ A docker image for cmfive is available on [GitHub Container Registry](https://gi You will need to run a mysql or compatible container and link it to the cmfive container. See more information about the mysql container on the [Docker Hub page](https://hub.docker.com/_/mysql). +Here is an example of how to run a cmfive container with docker: + +```sh +# Define the configuration details +export DB_DATABASE=cmfive +export DB_USERNAME=cmfive +export DB_PASSWORD=cmfive +export DB_ROOT_PW=root +export CMFIVE_IMAGE=ghcr.io/2pisoftware/cmfive:latest + +# Create a network +docker network create cmfive + +# Run the mysql container +docker run --name mysql-8 -d -p 3306:3306 \ + -e MYSQL_ROOT_PASSWORD=$DB_ROOT_PW \ + -e MYSQL_DATABASE=$DB_DATABASE \ + -e MYSQL_USER=$DB_USERNAME \ + -e MYSQL_PASSWORD=$DB_PASSWORD \ + --network=cmfive \ + mysql:8 + +# Run the cmfive container +docker run --name cmfive -d -p 3000:80 \ + -v ./storage:/var/www/html/storage \ + -v ./uploads:/var/www/html/uploads \ + -v ./backups:/var/www/html/backups \ + -e DB_HOST=mysql-8 \ + -e DB_USERNAME=$DB_USERNAME \ + -e DB_PASSWORD=$DB_PASSWORD \ + -e DB_DATABASE=$DB_DATABASE \ + -e ENVIRONMENT=production \ + --network=cmfive \ + $CMFIVE_IMAGE +``` + +You can then proceed to set up an admin user with: + +```sh +docker exec -it -u cmfive cmfive php cmfive.php +``` + The following options can be used with the Docker image. You may choose to use for example vanilla docker, docker-compose or Kubernetes. Please consult the documentation for these tools for more information on how to use the options below. #### Environment variables From 190a94b63de1b6e2ff38f02f94cdb60a26753b22 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Thu, 28 Mar 2024 22:11:46 +1100 Subject: [PATCH 3/6] Contributing --- CONTRIBUTING.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index df0a627..828c677 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1 +1,43 @@ # Contributing to Cmfive + +We welcome contributions to Cmfive. This document outlines how you can contribute to Cmfive. + +Cmfive consists of two main repositories - the boilerplate and the core. The boilerplate is the environment for cmfive to run, plus stores things like uploads, backups, logs and docker definitions. The core contains the main functionality of cmfive, plus the theme and core modules. + +## Where to start + +Please see Quick Start in the [README.md](README.md) for instructions on setting up a development environment. + +The issue trackers are a good place to start. You can find the issue trackers here: + +- [Boilerplate](https://github.com/2pisoftware/cmfive-boilerplate/issues) +- [Core](https://github.com/2pisoftware/cmfive-core/issues) + +## Help that we're looking for + +We're looking for help with: + +- New features +- Bug fixes +- Bug reports +- Documentation + +## How to report bugs and request features + +Navigate to the Boilerplate or Core issue tracker and create a new issue. Please provide as much information as possible. + +## Pull request process + +1. Fork the repository +2. Create a new branch +3. Make your changes, ensuring that you follow coding standards +4. Run any relevant tests +5. Commit your changes +6. Push your changes to your fork +7. Create a pull request to develop + - For example you could merge your branch called `feature/my-new-feature` into the `develop` branch on the `2pisoftware/cmfive-core` repository +8. Your pull request will be reviewed by the maintainers +9. Your changes will be tested with CI +10. Your changes will be merged into the develop branch +11. Upon release, the develop branch will be merged into the main branch + From 4c773b40c3d7e8057b9b90af6c99cef354efb948 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Thu, 28 Mar 2024 22:11:58 +1100 Subject: [PATCH 4/6] VSCode Note --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 977b502..4f63d13 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,12 @@ When the development environment has started the cmfive-core git repository is c cd composer/vendor/2pisoftware/cmfive-core ``` +If you're using Visual Studio Code you can open a terminal then use this command to open the core in a new window: + +```sh +code composer/vendor/2pisoftware/cmfive-core +``` + For more information about developing on the core repository please refer to the [cmfive-core repository](https://github.com/2pisoftware/cmfive-core). ### Theme development From 46d5762f2fcfefae34cd6d2bce069d8daaf8a91f Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Tue, 2 Apr 2024 21:29:05 +1100 Subject: [PATCH 5/6] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 4f63d13..c48d82e 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,10 @@ Welcome! Cmfive is a framework designed for fast ERP and CRM business software s The full documentation is located at [cmfive.com](https://cmfive.com). +## Installing + +See [Deploying](#deploying). + ## Development ### Quick Start From 9aa047ebccb67b19637223eac82b01fd152f5114 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Tue, 2 Apr 2024 21:54:19 +1100 Subject: [PATCH 6/6] Update CONTRIBUTING.md --- CONTRIBUTING.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 828c677..2b12372 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,3 +41,4 @@ Navigate to the Boilerplate or Core issue tracker and create a new issue. Please 10. Your changes will be merged into the develop branch 11. Upon release, the develop branch will be merged into the main branch +Please keep issues that are related to your PR updated.