Skip to content

Commit 0cf13a0

Browse files
authored
Fix installer and upgrade cakephp app skeleton (#6)
- 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
1 parent 5f80577 commit 0cf13a0

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

.assets/bootstrap.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
use Cake\Core\Configure;
3636
use Cake\Core\Configure\Engine\PhpConfig;
3737
use Cake\Datasource\ConnectionManager;
38-
use Cake\Error\ConsoleErrorHandler;
39-
use Cake\Error\ErrorHandler;
38+
use Cake\Error\ErrorTrap;
39+
use Cake\Error\ExceptionTrap;
4040
use Cake\Http\ServerRequest;
4141
use Cake\Log\Log;
4242
use Cake\Mailer\Mailer;
@@ -89,6 +89,15 @@
8989
Configure::load('app_local', 'default');
9090
}
9191

92+
/**
93+
* This try catch can be removed after install
94+
*/
95+
try {
96+
Configure::load('swagger_bake', 'default', false);
97+
} catch(\Exception $e) {
98+
triggerWarning($e->getMessage() . '. Run `bin/cake mixerapi install` to clear this warning');
99+
}
100+
92101
/*
93102
* When debug = true the metadata cache should only last
94103
* for a short time.
@@ -120,17 +129,13 @@
120129
/*
121130
* Register application error and exception handlers.
122131
*/
123-
$isCli = PHP_SAPI === 'cli';
124-
if ($isCli) {
125-
(new ConsoleErrorHandler(Configure::read('Error')))->register();
126-
} else {
127-
(new ErrorHandler(Configure::read('Error')))->register();
128-
}
132+
(new ErrorTrap(Configure::read('Error')))->register();
133+
(new ExceptionTrap(Configure::read('Error')))->register();
129134

130135
/*
131136
* Include the CLI bootstrap overrides.
132137
*/
133-
if ($isCli) {
138+
if (PHP_SAPI === 'cli') {
134139
require __DIR__ . '/bootstrap_cli.php';
135140
}
136141

.docker/php/docker-entrypoint.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ if [ "$1" = 'php-fpm' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/cakephp' ]; then
1616
fi
1717

1818
COMPOSER_MEMORY_LIMIT=-1
19-
composer create-project --prefer-dist --no-interaction cakephp/app:^4.2 .
19+
composer create-project --prefer-dist --no-interaction cakephp/app:^4.4 .
2020
rm -rf .github
2121
cp config/.env.example config/.env
2222
cp config/app_local.example.php config/app_local.php
2323
cp ../.assets/bootstrap.php config/bootstrap.php
2424

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

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

3030
touch .gitkeep
3131

32-
composer require mixerapi/mixerapi
32+
composer require mixerapi/mixerapi -W
3333

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

5151
mkdir -p logs tmp
5252

53+
# Set ACLs for Linux users
5354
echo "HOST OS: $HOST_OS"
5455
if [[ $HOST_OS == *"Linux"* ]]; then
5556
echo "Setting ACLs..."

.github/workflows/build.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ jobs:
2020
- name: Start
2121
run: docker-compose up -d
2222
- name: Wait for services
23-
run: sleep 5
24-
- name: HTTP Check
25-
run: curl -v -o /dev/null http://localhost:8080
23+
run: sleep 10
24+
- name: Check CakePHP Welcome Page
25+
run: curl -f -v -o /dev/null http://localhost:8080
26+
- name: Check NGINX Files
27+
run: curl -f -v -o /dev/null http://localhost:8080/css/home.css

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ COPY .assets /srv/.assets
3535

3636
WORKDIR /srv/app
3737

38-
RUN addgroup -g 101 nginx
3938
RUN adduser --disabled-password --gecos '' -u $UID cakephp;
39+
RUN addgroup -g 101 nginx
40+
RUN addgroup cakephp nginx
41+
RUN addgroup cakephp www-data
4042

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

0 commit comments

Comments
 (0)