Skip to content

Instantly share code, notes, and snippets.

@rodrigore
Forked from JacobBennett/Readme.MD
Last active April 28, 2019 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodrigore/94c1a89dfcd38c7350c3b24b5dc258fb to your computer and use it in GitHub Desktop.
Save rodrigore/94c1a89dfcd38c7350c3b24b5dc258fb to your computer and use it in GitHub Desktop.
Regarding Filesystems minio and s3
<?php
// Example of a filesystem using s3-swap
return [
's3' => [
'driver' => 's3-swap',
'key' => env('AWS_KEY'),
'secret' => env('AWS_SECRET'),
'region' => 'us-east-1',
'bucket' => 'horizon.wilbergroup.com',
// local use
'endpoint' => env('MINIO_ENDPOINT'),
'use_path_style_endpoint' => true,
]
];

Read article first

https://laravel-news.com/minio-s3-compliant-storage

Filesystem Decision Tree

Filesystem Driver

S3 BUCKET IN PRODUCTION

- How to use:
    - Use s3-swap driver and use minio for local development
    - Use Storage fake for tests

- when to use:
    - backups
    - uploaded files or documents storage (images, pdfs)
    - generated files or documents storage

MINIO IN PRODUCTION

- How to use:
    - Use s3 driver and use minio for local development
    - Use Storage fake for tests

- When to use:
    - Other internal, non-PHP processes need to be able to write to location
    - Convenient to access with Windows file explorer UI
    - Files will only be used internally

LOCAL IN PRODUCTION

- How to use:
    - use local driver
    - Use Storage fake for tests.

- When to use:
    - Files are present that we want in version control
    - Files that will change infrequently enough to justify being part of the repo
    - NON user uploaded files
    - Think "fixtures"

Filesystem Access Keys

Each application should have a single set of credentials per driver. The only exception to this would be if you were using multiple minio drives.

<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Storage;
class SwapDriverServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
Storage::extend('s3-swap', function ($app, $config) {
return Storage::createS3Driver($this->getConfig($app, $config));
});
}
public function getConfig($app, $config)
{
return !$app->environment('production') ?
$config :
array_except($config, [
'endpoint',
'use_path_style_endpoint',
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment