Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
krls2020 committed Oct 25, 2024
0 parents commit ff671be
Show file tree
Hide file tree
Showing 227 changed files with 20,582 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2

[docker-compose.yml]
indent_size = 4
66 changes: 66 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_TIMEZONE=UTC
APP_URL=http://localhost

APP_LOCALE=en
APP_FALLBACK_LOCALE=en
APP_FAKER_LOCALE=en_US

APP_MAINTENANCE_DRIVER=file
# APP_MAINTENANCE_STORE=database

PHP_CLI_SERVER_WORKERS=4

BCRYPT_ROUNDS=12

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

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

SESSION_DRIVER=database
SESSION_LIFETIME=120
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=log
MAIL_HOST=127.0.0.1
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

VITE_APP_NAME="${APP_NAME}"
11 changes: 11 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
* text=auto eol=lf

*.blade.php diff=html
*.css diff=css
*.html diff=html
*.md diff=markdown
*.php diff=php

/.github export-ignore
CHANGELOG.md export-ignore
.styleci.yml export-ignore
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/.phpunit.cache
/node_modules
/public/build
/public/hot
/public/storage
/public/s3/glide_cache
/storage/*.key
/storage/pail
/vendor
.env
.env.backup
.env.production
.phpactor.json
.phpunit.result.cache
Homestead.json
Homestead.yaml
auth.json
npm-debug.log
yarn-error.log
/.fleet
/.idea
/.vscode
/.zed
83 changes: 83 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Zerops x Twill

This repository demonstrates how to set up and deploy Twill applications using Zerops for both development and
production environments.

[Twill](https://twill.io) is a CMS toolkit for Laravel that makes it quick and easy to create a custom, powerful admin
console. This recipe showcases how to run a Twill application on Zerops, including all advanced functionalities, with
sessions and cache stored in Redis and files stored in Object Storage, making it suitable for production of any size.

![TwillZerops](https://github.com/zeropsio/recipe-shared-assets/blob/main/covers/svg/cover-twill.svg)

<br/>

## Deploy on Zerops

You can either click the deploy button to deploy the development setup directly on Zerops or manually copy
the [import yaml](https://github.com/zeropsio/recipe-twill/blob/main/zerops-project-import.yml) to the import dialog in
the Zerops app.

[![Deploy on Zerops](https://github.com/zeropsio/recipe-shared-assets/blob/main/deploy-button/green/deploy-button.svg)](https://app.zerops.io/recipe/twill)

<br/>

## Recipe Features

- Twill running on a load-balanced **Zerops PHP + Nginx** service
- Zerops **MySQL** service as the database
- Zerops KeyDB (**Redis**) service for session and cache
- Zerops **Object Storage** (S3 compatible) service as the file system
- Proper setup for Laravel **cache**, **optimization**, and **database migrations**
- Logs set up to use **syslog** and accessible through Zerops GUI
- Utilization of Zerops built-in **environment variables** system
- Utilization of Zerops readiness check for proper **Zero downtime deployment**
- Utilization of Zerops health check for advanced **app monitoring**
- [Mailpit](https://github.com/axllent/mailpit) as **SMTP mock server**
- [Adminer](https://www.adminer.org) for **quick database management** tool
- [S3browser](https://github.com/zeropsio/s3browser) for quick **S3 storage browsing** and testing

<br/>

## Development vs. Production

### Development Setup

This setup includes tools and configurations for a rapid development cycle:

- Mailpit as the SMTP mock server
- Adminer for quick database management
- Fully commented-out configurations that you can easily switch to production settings

### Production Setup

For a production-ready environment, consider the following modifications:

- Use a highly available version of the MySQL database
- Use at least two containers for the Twill service to achieve high reliability and resilience by adding
`minContainers: 2` in the recipe YAML.
- Use a production-ready third-party SMTP server instead of Mailpit.
- Disable public access to Adminer or remove it altogether from the recipe YAML.

You can see a production example setup at [
`zerops-project-import-production.yml`](https://github.com/zeropsio/recipe-twill/blob/main/zerops-project-import-production.yml).

## Changes Made Over the Default Installation

To modify your existing Twill app to run efficiently on Zerops, follow these steps:

- Add [zerops.yml](https://github.com/zeropsio/recipe-twill/blob/main/zerops.yml) to your repository. The provided
example includes idempotent migrations, caching, and an optimized build process.
- Add [league/flysystem-aws-s3-v3](https://github.com/zeropsio/recipe-twill/blob/main/composer.json#L23) to your
composer.json to support the Object Storage file system.
- Setup health checks. Health checks are enabled out of the box in Laravel 11.
- Utilize Zerops [environment variables](https://github.com/zeropsio/recipe-twill/blob/main/zerops.yml#L22-L73)
and [secrets](https://github.com/zeropsio/recipe-twill/blob/main/zerops-project-import.yml#L13-L14) to setup S3 for
the file system, Redis for cache and sessions, and trusted proxies to work with a reverse proxy load balancer.
- Frontend and Backend:
- The setup includes a fully functional example of a frontend page and a backend seeded with data.
- Object Storage:
- Media are stored in Object Storage with local caching via Glide.

<br/>

Need help setting your project up? Join the [Zerops Discord community](https://discord.com/invite/WDvCZ54).
8 changes: 8 additions & 0 deletions app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace App\Http\Controllers;

abstract class Controller
{
//
}
39 changes: 39 additions & 0 deletions app/Http/Controllers/PageDisplayController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Http\Controllers;

use A17\Twill\Facades\TwillAppSettings;
use App\Repositories\PageRepository;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Storage;

class PageDisplayController extends Controller
{

public function home(): View
{
// Storage::disk('s3')->put('test.txt', 'Hello MinIO!');
if (TwillAppSettings::get('homepage.homepage.page')->isNotEmpty()) {
/** @var \App\Models\Page $frontPage */
$frontPage = TwillAppSettings::get('homepage.homepage.page')->first();

if ($frontPage->published) {
return view('site.page', ['item' => $frontPage]);
}
}


abort(404);
}

public function show(string $slug, PageRepository $pageRepository): View
{
$page = $pageRepository->forSlug($slug);

if (!$page) {
abort(404);
}

return view('site.page', ['item' => $page]);
}
}
49 changes: 49 additions & 0 deletions app/Http/Controllers/Twill/MenuLinkController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace App\Http\Controllers\Twill;

use A17\Twill\Models\Contracts\TwillModelContract;
use A17\Twill\Services\Forms\Fields\Browser;
use A17\Twill\Services\Listings\Columns\Text;
use A17\Twill\Services\Listings\TableColumns;
use A17\Twill\Services\Forms\Fields\Input;
use A17\Twill\Services\Forms\Form;
use A17\Twill\Http\Controllers\Admin\NestedModuleController as BaseModuleController;

class MenuLinkController extends BaseModuleController
{
protected $moduleName = 'menuLinks';
protected $showOnlyParentItemsInBrowsers = true;
protected $nestedItemsDepth = 1;
/**
* This method can be used to enable/disable defaults. See setUpController in the docs for available options.
*/
protected function setUpController(): void
{
$this->disablePermalink();
$this->enableReorder();
}

/**
* See the table builder docs for more information. If you remove this method you can use the blade files.
* When using twill:module:make you can specify --bladeForm to use a blade form instead.
*/
public function getForm(TwillModelContract $model): Form
{
$form = parent::getForm($model);

$form->add(Browser::make()->name('page')->modules([Page::class]));

return $form;
}

/**
* This is an example and can be removed if no modifications are needed to the table.
*/
protected function additionalIndexTableColumns(): TableColumns
{
$table = parent::additionalIndexTableColumns();

return $table;
}
}
62 changes: 62 additions & 0 deletions app/Http/Controllers/Twill/PageController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace App\Http\Controllers\Twill;

use A17\Twill\Models\Contracts\TwillModelContract;
use A17\Twill\Services\Forms\Fields\Medias;
use A17\Twill\Services\Forms\Fields\BlockEditor;
use A17\Twill\Services\Listings\Columns\Text;
use A17\Twill\Services\Listings\TableColumns;
use A17\Twill\Services\Forms\Fields\Input;
use A17\Twill\Services\Forms\Form;
use A17\Twill\Http\Controllers\Admin\ModuleController as BaseModuleController;

class PageController extends BaseModuleController
{
protected $moduleName = 'pages';
/**
* This method can be used to enable/disable defaults. See setUpController in the docs for available options.
*/
protected function setUpController(): void
{
$this->setPermalinkBase('');
$this->withoutLanguageInPermalink();
}

/**
* See the table builder docs for more information. If you remove this method you can use the blade files.
* When using twill:module:make you can specify --bladeForm to use a blade form instead.
*/
public function getForm(TwillModelContract $model): Form
{
$form = parent::getForm($model);

$form->add(
Input::make()->name('description')->label('Description')->translatable()
);

$form->add(
Medias::make()->name('cover')->label('Cover image')
);

$form->add(
BlockEditor::make()
);

return $form;
}

/**
* This is an example and can be removed if no modifications are needed to the table.
*/
protected function additionalIndexTableColumns(): TableColumns
{
$table = parent::additionalIndexTableColumns();

$table->add(
Text::make()->field('description')->title('Description')
);

return $table;
}
}
18 changes: 18 additions & 0 deletions app/Http/Requests/Twill/MenuLinkRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Http\Requests\Twill;

use A17\Twill\Http\Requests\Admin\Request;

class MenuLinkRequest extends Request
{
public function rulesForCreate()
{
return [];
}

public function rulesForUpdate()
{
return [];
}
}
Loading

0 comments on commit ff671be

Please sign in to comment.