Skip to content

Commit

Permalink
Upgrade MFA to Laravel 11 (#10)
Browse files Browse the repository at this point in the history
* Update to Laravel 11

* Fix release.yml workflow

* Fix typo in pint.yml workflow
  • Loading branch information
JanOppolzer authored Jul 18, 2024
1 parent 30cb8c2 commit e9c9bc4
Show file tree
Hide file tree
Showing 76 changed files with 3,536 additions and 3,660 deletions.
67 changes: 36 additions & 31 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,37 +1,54 @@
APP_NAME=Laravel
APP_ENV=local
APP_NAME=MFA
APP_ENV=production
APP_KEY=
APP_DEBUG=true
APP_DEBUG=false
APP_TIMEZONE=Europe/Prague
APP_URL=http://localhost

APP_LOCALE=en
APP_FALLBACK_LOCALE=en
APP_FAKER_LOCALE=en_US

APP_MAINTENANCE_DRIVER=file
# APP_MAINTENANCE_STORE=database

BCRYPT_ROUNDS=12

LOG_CHANNEL=stack
LOG_STACK=single
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=mfa_laravel
DB_USERNAME=root
DB_PASSWORD=
DB_CONNECTION=sqlite
# DB_HOST=127.0.0.1
# DB_PORT=3306
# DB_DATABASE=laravel
# DB_USERNAME=root
# DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_DRIVER=database
SESSION_LIFETIME=120
SESSION_SECURE_COOKIE=true
SESSION_ENCRYPT=false
SESSION_PATH=/
SESSION_DOMAIN=null

BROADCAST_CONNECTION=log
FILESYSTEM_DISK=local
QUEUE_CONNECTION=database

CACHE_STORE=database
CACHE_PREFIX=

MEMCACHED_HOST=127.0.0.1

REDIS_CLIENT=phpredis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=mailpit
MAIL_PORT=1025
MAIL_MAILER=log
MAIL_HOST=127.0.0.1
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
Expand All @@ -44,16 +61,4 @@ AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_HOST=
PUSHER_PORT=443
PUSHER_SCHEME=https
PUSHER_APP_CLUSTER=mt1

VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
VITE_APP_NAME="${APP_NAME}"
30 changes: 30 additions & 0 deletions .github/workflows/pint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Pint

on:
push:
branches:
- "*"
paths-ignore:
- README.md
- .github/workflows/release.yml

jobs:
pint:
runs-on: ubuntu-24.04

name: Test code quality

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

- name: Checkout repository
uses: actions/checkout@v4

- name: Install Composer dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress

- name: Test code style
run: vendor/bin/pint
56 changes: 56 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Release

on:
push:
tags:
- "*"

permissions:
contents: write

jobs:
build-and-release:
runs-on: ubuntu-24.04

name: Build and release

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

- name: Checkout repository
uses: actions/checkout@v4

- name: Install NPM dependencies
run: npm install

- name: Build assets
run: npm run build

- name: Clean release
run: |
rm -rf .git* node_modules
- name: Define release version
run: |
TAG=${{ github.ref_name }}
{
echo "TAG=$TAG"
echo "VERSION=${TAG#v}"
} >> "$GITHUB_ENV"
- name: Build release
run: |
DIRECTORY="mfa-$VERSION"
TARGET="/tmp/mfa-$VERSION.tar.gz"
cd ..
cp -R mfa "$DIRECTORY"
tar --owner 0 --group 0 -czf "$TARGET" "$DIRECTORY"
rm -rf "$DIRECTORY"
- name: Create release
uses: softprops/action-gh-release@v2
with:
files: /tmp/mfa-*.tar.gz
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
/.phpunit.cache
/node_modules
/public/build
/public/hot
/public/storage
/storage/*.key
/vendor
.env
.env.backup
.env.production
.phpactor.json
.phpunit.result.cache
Homestead.json
Homestead.yaml
auth.json
envoy
npm-debug.log
yarn-error.log
/.fleet
/.idea
/.vscode
envoy
113 changes: 61 additions & 52 deletions Envoy.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__, 'envoy');

try {
$dotenv->load();
$dotenv->required([
'TARGET_SERVER', 'TARGET_USER', 'TARGET_DIR',
'REPOSITORY',
'APP_NAME', 'APP_ENV', 'APP_DEBUG', 'APP_URL',
])->notEmpty();
$dotenv->load();
$dotenv->required([
'TARGET_SERVER', 'TARGET_USER', 'TARGET_DIR',
'REPOSITORY',
'APP_NAME', 'APP_ENV', 'APP_DEBUG', 'APP_URL',
])->notEmpty();
} catch(Exception $e) {
echo "Something went wrong:\n\n";
echo "{$e->getMessage()} \n\n";
exit;
echo "Something went wrong:\n\n";
echo "{$e->getMessage()} \n\n";
exit;
}

$server = $_ENV['TARGET_SERVER'];
Expand All @@ -38,84 +38,93 @@
echo "=> Install {{ $app_name }} into ~/{{ $dir }}/ at {{ $user }}"@"{{ $server }}..."

echo "Check ~/{{ $dir }}/"
if [ ! -d {{ $dir }} ]; then
mkdir -p {{ $dir }}
fi
if [ ! -d {{ $dir }} ]; then
mkdir -p {{ $dir }}
fi

cd {{ $dir }}

echo "Clone '{{ $branch }}' branch of {{ $repository }} into ~/{{ $dir }}/{{ $destination }}/"
git clone {{ $repository }} --branch={{ $branch }} --depth=1 -q ~/{{ $dir }}/{{ $destination }}
echo "Define variables"
export URL=`wget -qO- https://api.github.com/repos/CESNET/mfa/releases/latest | grep browser_download_url |
cut -d'"' -f4`
export FILE=`basename $URL`
export DIR=${FILE%.tar.gz}

echo "Download source code"
wget -q $URL

echo "Extract source code"
tar -xzf $FILE

echo "Backup existing ~/{{ $dir }}/.env"
if [ -f .env ]; then
mv .env .env-{{ $destination }}.bak
fi
if [ -f .env ]; then
mv .env .env-$DIR.bak
fi

echo "Prepare new ~/{{ $dir }}/.env"
if [ ! -f .env ]; then
cp {{ $destination }}/.env.example .env
fi
if [ ! -f .env ]; then
cp $DIR/.env.example .env
fi

echo "Update ~/{{ $dir }}/.env"
sed -i "s%APP_NAME=.*%APP_NAME={{ $app_name }}%; \
s%APP_ENV=.*%APP_ENV={{ $app_env }}%; \
s%APP_DEBUG=.*%APP_DEBUG={{ $app_debug }}%; \
s%APP_URL=.*%APP_URL={{ $app_url }}%" .env
sed -i "s%APP_NAME=.*%APP_NAME={{ $app_name }}%; \
s%APP_ENV=.*%APP_ENV={{ $app_env }}%; \
s%APP_DEBUG=.*%APP_DEBUG={{ $app_debug }}%; \
s%APP_URL=.*%APP_URL={{ $app_url }}%" .env

echo "Symlink ~/{{ $dir }}/.env"
ln -s ../.env ~/{{ $dir }}/{{ $destination }}/.env
ln -s ../.env ~/{{ $dir }}/$DIR/.env

echo "Check ~/{{ $dir }}/storage/ and fix permissions if necessary"
if [ ! -d storage ]; then
mv {{ $destination }}/storage .
setfacl -Rm g:www-data:rwx,d:g:www-data:rwx storage
else
rm -rf {{ $destination }}/storage
fi
if [ ! -d storage ]; then
mv $DIR/storage .
setfacl -Rm g:www-data:rwx,d:g:www-data:rwx storage
else
rm -rf $DIR/storage
fi

echo "Fix permissions to ~/{{ $dir }}/bootstrap/cache"
setfacl -Rm g:www-data:rwx,d:g:www-data:rwx ~/{{ $dir }}/{{ $destination }}/bootstrap/cache
setfacl -Rm g:www-data:rwx,d:g:www-data:rwx ~/{{ $dir }}/$DIR/bootstrap/cache

echo "Symlink ~/{{ $dir }}/storage/"
ln -s ../storage {{ $destination }}/storage
ln -s ../storage $DIR/storage

echo "Unlink ~/{{ $dir }}/{{ $symlink }}"
if [ -h {{ $symlink }} ]; then
rm {{ $symlink }}
fi
if [ -h {{ $symlink }} ]; then
rm {{ $symlink }}
fi

echo "Symlink ~/{{ $dir }}/{{ $destination }} to ~/{{ $dir }}/{{ $symlink }}"
ln -s {{ $destination }} {{ $symlink }}
echo "Symlink ~/{{ $dir }}/$DIR to ~/{{ $dir }}/{{ $symlink }}"
ln -s $DIR {{ $symlink }}

echo "Install composer dependencies"
cd current
composer install -q --no-dev --optimize-autoloader --no-ansi --no-interaction --no-progress --prefer-dist
cd ..
cd current
composer install -q --no-dev --optimize-autoloader --no-ansi --no-interaction --no-progress --prefer-dist
cd ..

echo "Generate key"
if [ `grep '^APP_KEY=' .env | grep 'base64:' | wc -l` -eq 0 ]; then
cd current
php artisan key:generate -q --no-ansi --no-interaction
cd ..
fi
if [ `grep '^APP_KEY=' .env | grep 'base64:' | wc -l` -eq 0 ]; then
cd current
php artisan key:generate -q --no-ansi --no-interaction
cd ..
fi

cd {{ $destination }}
cd $DIR

echo "Optimize"
php artisan optimize:clear -q --no-ansi --no-interaction
php artisan optimize:clear -q --no-ansi --no-interaction

echo "Cache config"
php artisan config:cache -q --no-ansi --no-interaction
php artisan config:cache -q --no-ansi --no-interaction

echo "Cache routes"
php artisan route:cache -q --no-ansi --no-interaction
php artisan route:cache -q --no-ansi --no-interaction

echo "Cache views"
php artisan view:cache -q --no-ansi --no-interaction
php artisan view:cache -q --no-ansi --no-interaction

echo "Reload PHP-FPM"
sudo systemctl reload php8.1-fpm
sudo systemctl reload php8.3-fpm
@endtask

@task('cleanup')
Expand Down
Loading

0 comments on commit e9c9bc4

Please sign in to comment.