Skip to content

Commit

Permalink
Fix installer and upgrade cakephp app skeleton (#6)
Browse files Browse the repository at this point in the history
- Generate a more secure salt and fix nginx permissions issue (#22)
- Use openssl to generate initial salt value
- Fix nginx permissions issue (on linux host os) causing webroot assets to not load.
- Adds checking webroot assets do not 404 to github actoin
- Fix installer and upgrade cakephp app skeleton to 4.4
  • Loading branch information
cnizzardini authored Jun 23, 2022
1 parent 5f80577 commit 0cf13a0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
23 changes: 14 additions & 9 deletions .assets/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
use Cake\Core\Configure;
use Cake\Core\Configure\Engine\PhpConfig;
use Cake\Datasource\ConnectionManager;
use Cake\Error\ConsoleErrorHandler;
use Cake\Error\ErrorHandler;
use Cake\Error\ErrorTrap;
use Cake\Error\ExceptionTrap;
use Cake\Http\ServerRequest;
use Cake\Log\Log;
use Cake\Mailer\Mailer;
Expand Down Expand Up @@ -89,6 +89,15 @@
Configure::load('app_local', 'default');
}

/**
* This try catch can be removed after install
*/
try {
Configure::load('swagger_bake', 'default', false);
} catch(\Exception $e) {
triggerWarning($e->getMessage() . '. Run `bin/cake mixerapi install` to clear this warning');
}

/*
* When debug = true the metadata cache should only last
* for a short time.
Expand Down Expand Up @@ -120,17 +129,13 @@
/*
* Register application error and exception handlers.
*/
$isCli = PHP_SAPI === 'cli';
if ($isCli) {
(new ConsoleErrorHandler(Configure::read('Error')))->register();
} else {
(new ErrorHandler(Configure::read('Error')))->register();
}
(new ErrorTrap(Configure::read('Error')))->register();
(new ExceptionTrap(Configure::read('Error')))->register();

/*
* Include the CLI bootstrap overrides.
*/
if ($isCli) {
if (PHP_SAPI === 'cli') {
require __DIR__ . '/bootstrap_cli.php';
}

Expand Down
7 changes: 4 additions & 3 deletions .docker/php/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ if [ "$1" = 'php-fpm' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/cakephp' ]; then
fi

COMPOSER_MEMORY_LIMIT=-1
composer create-project --prefer-dist --no-interaction cakephp/app:^4.2 .
composer create-project --prefer-dist --no-interaction cakephp/app:^4.4 .
rm -rf .github
cp config/.env.example config/.env
cp config/app_local.example.php config/app_local.php
cp ../.assets/bootstrap.php config/bootstrap.php

sed -i '/export APP_NAME/c\export APP_NAME="cakephp"' config/.env

salt=$(cat /dev/urandom | LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
salt=$(openssl rand -base64 32)
sed -i '/export SECURITY_SALT/c\export SECURITY_SALT="'$salt'"' config/.env

touch .gitkeep

composer require mixerapi/mixerapi
composer require mixerapi/mixerapi -W

# optional:
composer require mixerapi/crud
Expand All @@ -50,6 +50,7 @@ if [ "$1" = 'php-fpm' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/cakephp' ]; then

mkdir -p logs tmp

# Set ACLs for Linux users
echo "HOST OS: $HOST_OS"
if [[ $HOST_OS == *"Linux"* ]]; then
echo "Setting ACLs..."
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
- name: Start
run: docker-compose up -d
- name: Wait for services
run: sleep 5
- name: HTTP Check
run: curl -v -o /dev/null http://localhost:8080
run: sleep 10
- name: Check CakePHP Welcome Page
run: curl -f -v -o /dev/null http://localhost:8080
- name: Check NGINX Files
run: curl -f -v -o /dev/null http://localhost:8080/css/home.css
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ COPY .assets /srv/.assets

WORKDIR /srv/app

RUN addgroup -g 101 nginx
RUN adduser --disabled-password --gecos '' -u $UID cakephp;
RUN addgroup -g 101 nginx
RUN addgroup cakephp nginx
RUN addgroup cakephp www-data

COPY --from=composer /usr/bin/composer /usr/bin/composer

Expand Down

0 comments on commit 0cf13a0

Please sign in to comment.