Skip to content

Commit

Permalink
Merge pull request #21 from openfoodfoundation/feature/setup-s3
Browse files Browse the repository at this point in the history
Feature: Cloud storage system set up and working well
  • Loading branch information
ok200paul authored Aug 16, 2024
2 parents bb881a8 + d98d63b commit 7137b68
Show file tree
Hide file tree
Showing 8 changed files with 365 additions and 72 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ APP_KEY=
APP_DEBUG=true
APP_TIMEZONE=UTC
APP_URL=http://vine.test
APP_PRODUCTION_URL=http://vine.test

APP_LOCALE=en
APP_FALLBACK_LOCALE=en
Expand Down Expand Up @@ -63,6 +64,8 @@ AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false



VITE_APP_NAME="${APP_NAME}"

FLARE_KEY=
Expand Down
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,32 @@ LOG_STACK=sentry # or sentry,single etc for multiple

Todo - explain how pint works, and under what circumstances it'll run

## File Storage: Local vs. AWS S3
You are free to use whichever storage cloud you like - the default environment variable of `FILESYSTEM_DISK=local` means that the application will use the local server.

To configure the system to use AWS S3, first create a bucket in S3 and some access keys for your implementation. then update the following environment variables:

```dotenv
FILESYSTEM_DISK=s3
AWS_ACCESS_KEY_ID=[YourApplicationKey]
AWS_SECRET_ACCESS_KEY=[YourApplicationSecret]
AWS_DEFAULT_REGION=[S3 Bucket location eg ap-southeast-2]
AWS_BUCKET=[S3 Bucket Name]
AWS_USE_PATH_STYLE_ENDPOINT=false
```
The S3 bucket uses a configuration called `root`, which separates the base bucket into the environment that the application is running under. This is based on `APP_ENV`. If you are running `APP_ENV=local` and your bucket was called `AWS_BUCKET=ofn-vine-uk`, your bucket folder structure would look like this:

```
/ofn-vine-uk
/local 👈 // Objects would be placed here by default at the path you provide
/staging
/production
```

NOTE: No extra config is required for this behaviour on AWS S3. It is not the default for any other filesystem storage providers.


## API Middleware - Protecting The API

In /bootstrap.app.php we've configured middleware as follows:
Expand Down
12 changes: 1 addition & 11 deletions app/Console/Commands/TestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

namespace App\Console\Commands;

use App\Models\Team;
use App\Models\User;
use App\Models\Voucher;
use App\Models\VoucherSet;
use Illuminate\Console\Command;

class TestCommand extends Command
Expand All @@ -27,11 +23,5 @@ class TestCommand extends Command
/**
* Execute the console command.
*/
public function handle()
{
$users = User::factory(100)->createQuietly();
$teams = Team::factory(100)->createQuietly();
$vouchers = Voucher::factory(100)->createQuietly();
$voucherSets = VoucherSet::factory(100)->createQuietly();
}
public function handle() {}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"laravel/framework": "^11.9",
"laravel/sanctum": "^4.0",
"laravel/tinker": "^2.9",
"league/flysystem-aws-s3-v3": "^3.28",
"sentry/sentry-laravel": "^4.7",
"spatie/laravel-flare": "^1.0",
"tightenco/ziggy": "^2.0"
Expand Down
275 changes: 274 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion config/filesystems.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
'endpoint' => env('AWS_ENDPOINT'),
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
'throw' => false,
'root' => env('APP_ENV'),
],

],

/*
Expand Down
2 changes: 1 addition & 1 deletion config/scribe.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

// The base URL displayed in the docs. If this is empty, Scribe will use the value of config('app.url') at generation time.
// If you're using `laravel` type, you can set this to a dynamic string, like '{{ config("app.tenant_url") }}' to get a dynamic base URL.
'base_url' => env('APP_URL'),
'base_url' => env('APP_PRODUCTION_URL'),

'routes' => [
[
Expand Down
Loading

0 comments on commit 7137b68

Please sign in to comment.