Skip to content

Commit

Permalink
Merge pull request #184 from 2pisoftware/develop
Browse files Browse the repository at this point in the history
- nginx config for dockerised deployments
  • Loading branch information
iceaxeliehne authored Oct 15, 2024
2 parents 531a327 + 0037e20 commit f3a2cbf
Show file tree
Hide file tree
Showing 20 changed files with 307 additions and 342 deletions.
2 changes: 1 addition & 1 deletion .codepipeline/docker/config.default.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//========== Database Configuration ==========================
Config::set("database", [
"hostname" => getenv('DB_HOST') ?: "mysqldb",
"port" => getenv('DB_PORT') ?: "",
"port" => getenv('DB_PORT') ?: "3306",
"username" => getenv('DB_USERNAME') ?: "cmfive",
"password" => getenv('DB_PASSWORD') ?: "cmfive",
"database" => getenv('DB_DATABASE') ?: "cmfive",
Expand Down
2 changes: 1 addition & 1 deletion .codepipeline/docker/configs/nginx/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ server {
# name: deny files extension rule
# precedence 4
# deny access to these file extensions
location ~ \.(json|lock|phar|example|xml|md|config|txt|help|html|ds|yml|yaml|sql)$ {
location ~ Dockerfile|\.(json|lock|phar|example|xml|md|config|txt|help|html|ds|yml|yaml|sql|dockerfile|cache|sh)$ {
deny all;
}

Expand Down
9 changes: 9 additions & 0 deletions .codepipeline/docker/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ if [ ! -f config.php ]; then
cp /bootstrap/config.default.php config.php
fi

# Add custom config
if [ -n "$CUSTOM_CONFIG" ]; then
echo "➕ Adding custom config"
# Remove existing custom config between markers
sed -i '/# BEGIN CUSTOM CONFIG/,/# END CUSTOM CONFIG/d' config.php
# Add new custom config
echo -e "\n# BEGIN CUSTOM CONFIG\n${CUSTOM_CONFIG}\n# END CUSTOM CONFIG" >> config.php
fi

#Ensure necessary directories have the correct permissions
echo "Setting permissions"
chmod ugo=rwX -R cache/ storage/ uploads/
Expand Down
95 changes: 9 additions & 86 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,12 @@ jobs:
done
# Pre-requisites Prepare Cmfive Environment
- name: Setup cmfive Test Environment
run: |
docker exec -t cmfive sh -c "chmod -R ugo=rwX /var/www/html*"

# Tests will assume playwright code is executable
# we should rely on deployment methods already to have provisioned:
# - name: Setup cmfive Test Environment
# run: |
# docker exec -t cmfive sh -c "chmod -R ugo=rwX /var/www/html*"

- name: Inject configs into cmfive Test Environment
run: |
Expand All @@ -143,88 +146,9 @@ jobs:
echo "⚠️ WARNING: could not find dev tools in boilerplate"
fi
- name: Prepare cmfive Test DB
run: |
docker exec -t cmfive sh -c "DB_HOST=mysql-8 DB_USERNAME=root DB_PASSWORD=root DB_DATABASE=$DB_DATABASE DB_PORT=3306 php cmfive.php testDB setup; exit \$?";
# Setup Node
- uses: actions/setup-node@v4
with:
node-version: 20

# Run Unit Tests
- name: "Run unit tests"
run: |
docker exec -u root cmfive chmod -R ugo=rwX /var/www/html/test/
docker exec -u cmfive cmfive sh -c "DB_HOST=mysql-8 DB_USERNAME=$DB_USERNAME DB_PASSWORD=$DB_PASSWORD DB_DATABASE=$DB_DATABASE DB_PORT=3306 php cmfive.php tests unit all; exit \$?"
if [ $? -gt 0 ]; then
echo "Admin module tests failed"
fi
# Setup playwright
- name: Setup Playwright
run: |
echo "Installing Playwright"
cd boilerplate/test/playwright
npm ci
npx playwright install --with-deps
- name: "Run admin module tests"
run: |
docker exec -u root cmfive sh -c "chmod ugo=rwX -R /var/www/html/system/modules/admin/install/migrations/"
cd boilerplate/test/playwright
npm run build
npm run test --module="admin" --reporter="github"
if [ $? -gt 0 ]; then
echo "Admin module tests failed"
fi
- name: "Run channel module tests"
- name: Run Unit and Playwright tests
run: |
cd boilerplate/test/playwright
npm run build
npm run test --module="channel" --reporter="github"
if [ $? -gt 0 ]; then
echo "Channel module tests failed"
fi
- name: "Run form module tests"
run: |
cd boilerplate/test/playwright
npm run build
npm run test --module="form" --reporter="github"
if [ $? -gt 0 ]; then
echo "Form module tests failed"
fi
- name: "Run report module tests"
run: |
cd boilerplate/test/playwright
npm run build
npm run test --module="report" --reporter="github"
if [ $? -gt 0 ]; then
echo "Report module tests failed"
fi
- name: "Run tag module tests"
run: |
cd boilerplate/test/playwright
npm run build
npm run test --module="tag" --reporter="github"
if [ $? -gt 0 ]; then
echo "Tag module tests failed"
fi
- name: "Run task module tests"
run: |
cd boilerplate/test/playwright
npm run build
npm run test --module="task" --reporter="github"
if [ $? -gt 0 ]; then
echo "Task module tests failed"
fi
- name: "Run timelog module tests"
run: |
cd boilerplate/test/playwright
npm run build
npm run test --module="timelog" --reporter="github"
if [ $? -gt 0 ]; then
echo "Timelog module tests failed"
fi
sh ./boilerplate/test/docker_run_tests.sh --cosine_container cmfive
- name: Get container logs
if: ${{ failure() }} || ${{ success() }}
Expand All @@ -245,9 +169,8 @@ jobs:
if: ${{ failure() }} || ${{ success() }}
uses: actions/upload-artifact@v4
with:
name: test-output-${{matrix.node_version}}
name: test-output
path: |
boilerplate/test/Codeception/tests/_output/
boilerplate/storage/log/
boilerplate/test/playwright/test-results/
boilerplate/test/playwright/playwright-report/
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ The following options can be used with the Docker image. You may choose to use f
- **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
- **CUSTOM_COFIG:** (optional) Custom configuration to add to the config.php file.
- **ENVIRONMENT:** (optional) The environment to run in (development, production). Defaults to production.
- **INSTALL_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 built-in core. Note: If this method is used, the theme will not be compiled automatically for the specified branch.

Expand Down
Binary file modified composer.phar
Binary file not shown.
25 changes: 14 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ services:
container_name: mysql-8
hostname: mysql-8
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_USER=cmfive
- MYSQL_PASSWORD=cmfive
- MYSQL_DATABASE=cmfive
- TZ=Australia/Sydney
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: cmfive
MYSQL_PASSWORD: cmfive
MYSQL_DATABASE: cmfive
TZ: Australia/Sydney
volumes:
- dbdata:/var/lib/mysql:delegated
networks:
Expand All @@ -28,12 +28,15 @@ services:
container_name: cmfive
hostname: nginx-php8.1
environment:
- TZ=Australia/Sydney
- DB_HOST=mysqldb
- DB_DATABASE=cmfive
- DB_USERNAME=cmfive
- DB_PASSWORD=cmfive
- ENVIRONMENT=development
TZ: Australia/Sydney
DB_HOST: mysqldb
DB_DATABASE: cmfive
DB_USERNAME: cmfive
DB_PASSWORD: cmfive
DB_PORT: 3306
ENVIRONMENT: development
CUSTOM_CONFIG: |
Config::set('tests', ['testrunner' => 'ENABLED']);
volumes:
- ./:/var/www/html:rw
ports:
Expand Down
100 changes: 0 additions & 100 deletions test/Guide.txt

This file was deleted.

1 change: 0 additions & 1 deletion test/Services/LaunchChromeSelenium.sh

This file was deleted.

5 changes: 0 additions & 5 deletions test/Services/Windows/LaunchChromeSelenium.bat

This file was deleted.

Binary file removed test/Services/Windows/chromedriver.exe
Binary file not shown.
1 change: 0 additions & 1 deletion test/Services/Windows/dockerised.bat

This file was deleted.

Binary file removed test/Services/Windows/geckodriver.exe
Binary file not shown.
Binary file not shown.
Binary file removed test/Services/selenium-server-standalone-3.14.0.jar
Binary file not shown.
85 changes: 37 additions & 48 deletions test/Setup.txt
Original file line number Diff line number Diff line change
@@ -1,51 +1,40 @@

1) Clone/pull/download: https://github.com/2pisoftware/cmfive-boilerplate
- Position it nicely for WebServer to find
- Match it to a CORE install (cmfive.php step[1] will clone main from scratch)
- Make symlinks etc as required
- Apply any other usual cmfive setup steps!
- Enable TestRunner in cmfive-boilerplate\config.php:
Config::set("tests", array(
"testrunner" => "ENABLED"
));
1) Setup Cosine environment, using end-to-end containers with default/dev/test MySQL container.
- docker-compose in boilerplate root folder will standup up a typical dev/test container deployment
- Manage install & symlinking for CORE and CUSTOM MODULES per the target module code for testing

2) Check-or-Add settings to your config.php:

//========== TestRunner Configuration ==========================
Config::set("system.environment", "development");
Config::set("core_template.foundation.reveal.animation", "none");
Config::set("core_template.foundation.reveal.animation_speed", 0);
Config::set('tests', ['testrunner' => 'ENABLED']);

//========== Database Configuration ==========================
Config::set("database", [
"hostname" => getenv('DB_HOST') ?: "mysqldb",
"port" => getenv('DB_PORT') ?: "3306",
"username" => getenv('DB_USERNAME') ?: "cmfive",
"password" => getenv('DB_PASSWORD') ?: "cmfive",
"database" => getenv('DB_DATABASE') ?: "cmfive",
"driver" => getenv('DB') ?: "mysql",
"backups" =>
[
'outputExt' => 'sql',
'commandPath' => [
'unix' => '/usr/bin/',
],
'backupCommand' => [
'unix' => 'mysqldump -u $username -h $hostname -P $port -p\'$password\' $dbname > $filename',
],
'restoreCommand' => [
'unix' => 'mysql -u $username -h $hostname -P $port -p\'$password\' $dbname < $filename',
],
]
]);

3) run "docker_run_tests.sh"
- check if you need to run chmod 755 docker_run_tests.sh for permission

FOR TEST ENVIRONMENT --> BEST TO PROCEED FROM HERE WITH DOCKER-"UP" FROM BOILERPLATE COMPOSE YML

2) cm5 --> Install
- TestRunner will need a 'volatile' database to work into.
- Use "cmfive.php" to manage chosen cm5 database

- Create/Check cmfive-boilerplate config.php for all database settings
- use example to correctly configure DB executable commands and paths
- leave parameters as-is; these will be auto-filled
- these settings do not override any settings elsewhere (eg: in Admin module config)

- CHECK THE CONFIG WORKS -> test for backup and restore, examine files in cmfive-boilerplate\backups
- BE SURE YOU CAN ACCESS A BACKUP

- Run : "Setup empty TestRunner DB and Administrator"
- once only
- backs up standing DB -> BUT ONLY IF backup config.php is correct!
- deletes all data -> CAN ONLY BE RECOVERED if your backup is good!
- runs all migrations & seeds test Admin user
- grabs snapshot of new 'empty' database to use for tests

3) Codeception --> Install
- Use "test\.install\install.sh"
- it will get a fresh "composer.phar" & pull Codeception source + modules,
then "BOOTSTRAPS" codeception project environment
- if you cannot use bash, follow all steps in the script per your own OS tools

4) Selenium support
- provisioned by Docker, copy settings from config.example on config.php
- customise if not using Docker

5) Check cmfive-boilerplate\test\Codeception\tests\acceptance.suite.dist.yml:
--> needs to match your cmfive WebServer & Browser & WebDriver
- provisioned from config.php
- copy settings from config.example on config.php
- set specifics for your DB (&Selenium if not using from Docker)

6) Execute in --> cmfive-boilerplate:
--> Use "cmfive.php" for TestRunner functions & as wrapper for command line tools

Loading

0 comments on commit f3a2cbf

Please sign in to comment.