Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add features #18

Merged
merged 14 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: PHP Composer

on:
push:
branches: [ "main" ]

permissions:
contents: write

jobs:
generate-coverage-report:

runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci]')"
defaults:
run:
working-directory: ./source
steps:
- name: Setup PHP 8.3
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'

- name: Checkout code
uses: actions/checkout@v3

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run test suite with coverage
run: composer coverage

- name: Generate coverage badge
uses: timkrase/phpunit-coverage-badge@v1.2.1
with:
report: source/build/logs/clover.xml
report_type: clover
coverage_badge_path: source/build/logs/coverage.svg
push_badge: false

- name: Push coverage data to coverage branch
uses: peaceiris/actions-gh-pages@v3
with:
publish_dir: ./source/build/logs
publish_branch: coverage-data
github_token: ${{ secrets.GITHUB_TOKEN }}
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'
full_commit_message: Update coverage data
44 changes: 26 additions & 18 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,29 @@ jobs:
run:
working-directory: ./source
steps:
- uses: actions/checkout@v3

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-

- name: Install dependencies
run: composer install --prefer-dist --no-progress
- name: Run test suite
run: composer run-script test

- name: Setup PHP 8.3
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'

- name: Checkout code
uses: actions/checkout@v3

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run test suite
run: composer test
32 changes: 14 additions & 18 deletions configurations/production/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,44 @@ services:
build:
context: ./source
environment:
- BASE_URL=http://example.com/ # Don't forget to change this according to your project
- CI_ENVIRONMENT=production
- DB_DEFAULT_HOSTNAME=db-main
- DB_DEFAULT_HOSTNAME=database
- DB_DEFAULT_DATABASE=main
- DB_DEFAULT_USERNAME=root
- DB_DEFAULT_PASSWORD=root
- DB_DEFAULT_DBDRIVER=MySQLi
- DB_DEFAULT_PORT=3306
- DB_TESTS_HOSTNAME=db-test
- DB_TESTS_HOSTNAME=database
- DB_TESTS_DATABASE=test
- DB_TESTS_USERNAME=root
- DB_TESTS_PASSWORD=root
- DB_TESTS_DBDRIVER=MySQLi
- DB_TESTS_PORT=3306
volumes:
- source-code:/var/www
depends_on:
- database
nginx:
image: nginx:latest
container_name: nginx
volumes:
- ./configurations/production/nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro
- source-code:/var/www
ports:
- "8000:80"
db-main:
image: mysql
- "80:80"
depends_on:
- php-fpm
database:
image: mysql:8.3.0
container_name: mysql
volumes:
- main_mysql_data:/var/lib/mysql
- production_database:/var/lib/mysql
- ./configurations/production/mysql:/docker-entrypoint-initdb.d
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=main
ports:
- "3310:3306"
db-test:
image: mysql
volumes:
- test_mysql_data:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=test
ports:
- "3311:3306"
volumes:
main_mysql_data:
test_mysql_data:
production_database:
source-code:
4 changes: 4 additions & 0 deletions configurations/production/mysql/database-initialization.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE DATABASE IF NOT EXISTS `main`;
CREATE DATABASE IF NOT EXISTS `test`;

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
21 changes: 6 additions & 15 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
version: '3.7'

services:
db-main:
image: mysql
database:
image: mysql:8.3.0
container_name: mysql
volumes:
- main_mysql_data:/var/lib/mysql
- development_database:/var/lib/mysql
- ./configurations/production/mysql:/docker-entrypoint-initdb.d
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=main
ports:
- "3310:3306"
db-test:
image: mysql
volumes:
- test_mysql_data:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=test
ports:
- "3311:3306"
volumes:
main_mysql_data:
test_mysql_data:
development_database:
27 changes: 22 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Code Igniter 4 Starter Template
# CodeIgniter 4 Starter Template

![Status Badge](https://github.com/trubusoft/codeigniter4-starter/actions/workflows/php.yml/badge.svg?branch-main)
![Coverage Badge](https://github.com/trubusoft/codeigniter4-starter/blob/coverage-data/coverage.svg)

Starter template for CodeIgniter 4.4.5 with docker development & production configuration.
Starter template for CodeIgniter 4.4.5+ with:
- Docker configuration for both development & production.
- Test & Coverage workflow template with GitHub runner

Tested for development & production on Ubuntu 20.04 LTS.

Expand Down Expand Up @@ -32,13 +35,15 @@ php -v
- `intl`: for CI4
- `dom`: for PHPUnit
- `mbstring`: for PHPUnit
- `xdebug`: code coverage driver for PHPUnit

```
sudo apt install php8.3-mysql
sudo apt install php8.3-curl
sudo apt install php8.3-intl
sudo apt install php8.3-dom
sudo apt install php8.3-mbstring
sudo apt install php8.3-xdebug
```

Check that above modules exist by running `php -m`.
Expand Down Expand Up @@ -71,7 +76,7 @@ Try running the bare minimum settings now with:

```
cd source
./spark serve
php spark serve
```

A page should now be served at `http://localhost:8080/`.
Expand Down Expand Up @@ -99,19 +104,31 @@ docker compose up -d
You can start the development session with the built-in `spark`:
```
cd source
./spark serve
php spark serve
```

The [bitnami/codeigniter](https://hub.docker.com/r/bitnami/codeigniter) image can also be used instead
as an alternative to the `spark`.
For this, please refer to [development_with_bitnami_image.md](configurations/development/bitnami/development_with_bitnami_image.md).

### Testing

Run the tests with:

```
cd source
composer test
```

or generate coverage report with:

```
cd source
composer run-script test
composer coverage
```

Coverage report will be created at `/source/build/logs`.

### Debugging
- Use the provided [Debug Toolbar](https://codeigniter4.github.io/userguide/tutorial/index.html#debug-toolbar)
- Error logs will be printed on `writable/logs`
Expand Down
12 changes: 12 additions & 0 deletions source/app/Config/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@

class App extends BaseConfig
{
public function __construct()
{
parent::__construct();

/**
* In Production, use HOST_NAME if provided instead of the default localhost:8080
*/
if (getenv('BASE_URL')) {
$this->baseURL = getenv('BASE_URL');
}
}

/**
* --------------------------------------------------------------------------
* Base Site URL
Expand Down
3 changes: 2 additions & 1 deletion source/app/Config/Routes.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

use App\Controllers\HomeController;
use CodeIgniter\Router\RouteCollection;

/**
* @var RouteCollection $routes
*/
$routes->get('/', 'Home::index');
$routes->get('/', [HomeController::class, 'index'], ['as' => 'index']);
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Controllers;

class Home extends BaseController
class HomeController extends BaseController
{
public function index(): string
{
Expand Down
33 changes: 25 additions & 8 deletions source/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@
"description": "CodeIgniter4 starter app",
"license": "MIT",
"type": "project",
"homepage": "https://codeigniter.com",
"homepage": "https://github.com/trubusoft/eprocurement",
"authors": [
{
"name": "Rahmat Nazali Salimi",
"email": "rahmatnazali95@gmail.com",
"homepage": "https://rahmatnazali.github.io",
"role": "Developer, Maintainer"
}
],
"support": {
"forum": "https://forum.codeigniter.com/",
"source": "https://github.com/codeigniter4/CodeIgniter4",
"slack": "https://codeigniterchat.slack.com"
"email": "rahmatnazali95@gmail.com"
},
"require": {
"php": "^7.4 || ^8.0",
"codeigniter4/framework": "^4.0"
"php": "^8.3",
"codeigniter4/framework": "^4.4.5"
},
"require-dev": {
"fakerphp/faker": "^1.9",
Expand All @@ -34,6 +40,17 @@
"sort-packages": true
},
"scripts": {
"test": "phpunit"
"test": [
"@putenv XDEBUG_MODE=off",
"phpunit --color=always"
],
"test-debug": [
"@putenv XDEBUG_MODE=off",
"phpunit --color=always --debug"
],
"coverage": [
"@putenv XDEBUG_MODE=coverage",
"phpunit --color=always"
]
}
}
}
Loading
Loading