Skip to content

Commit

Permalink
feat: add minio storage
Browse files Browse the repository at this point in the history
  • Loading branch information
arthaud-proust committed Mar 18, 2024
1 parent c21d9ca commit 472b7b5
Show file tree
Hide file tree
Showing 18 changed files with 368 additions and 167 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ APP_SECRET=29c5d90ac6f09ea2c70dd8eadd6fd606
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
# DATABASE_URL="mysql://app:[email protected]:3306/app?serverVersion=8.0.32&charset=utf8mb4"
# DATABASE_URL="mysql://app:[email protected]:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8"
DATABASE_URL="postgresql://app:!ChangeMe!@database:5432/app?serverVersion=16&charset=utf8"
###< doctrine/doctrine-bundle ###

MINIO_REGION="eu-east-1"
MINIO_ENDPOINT="127.0.0.1:9000"
MINIO_ENDPOINT="http://minio:9000"
MINIO_ROOT_USER="minio"
MINIO_ROOT_PASSWORD="password"
MINIO_BUCKET="bild"
17 changes: 11 additions & 6 deletions compose.override.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ services:
# Ensure that host.docker.internal is correctly defined on Linux
- host.docker.internal:host-gateway
tty: true

###> symfony/mercure-bundle ###
###< symfony/mercure-bundle ###

###> doctrine/doctrine-bundle ###
###> symfony/mercure-bundle ###
###< symfony/mercure-bundle ###
###> doctrine/doctrine-bundle ###
database:
ports:
- "5432:5432"
###< doctrine/doctrine-bundle ###
###< doctrine/doctrine-bundle ###

minio:
ports:
- "9000:9000"
- "9001:9001"
13 changes: 10 additions & 3 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ services:
target: 443
published: ${HTTP3_PORT:-443}
protocol: udp
networks:
- minio
- database

# Mercure is installed as a Caddy module, prevent the Flex recipe from installing another service
###> symfony/mercure-bundle ###
Expand All @@ -53,6 +56,8 @@ services:
- database_data:/var/lib/postgresql/data:rw
# You may use a bind-mounted host directory instead, so that it is harder to accidentally remove the volume and lose all your data!
# - ./docker/db/data:/var/lib/postgresql/data:rw
networks:
- database
###< doctrine/doctrine-bundle ###

minio:
Expand All @@ -63,9 +68,8 @@ services:
volumes:
- minio_data:/data
command: server /data --console-address ":9001"
ports:
- 9000:9000
- 9001:9001
networks:
- minio

volumes:
caddy_data:
Expand All @@ -79,3 +83,6 @@ volumes:

minio_data:

networks:
database:
minio:
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"jms/serializer-bundle": "^5.4",
"league/flysystem-aws-s3-v3": "^3.25",
"league/flysystem-bundle": "^3.3",
"league/flysystem-memory": "^3.25",
"nelmio/api-doc-bundle": "^4.24",
"runtime/frankenphp-symfony": "^0.2.0",
"sensio/framework-extra-bundle": "*",
Expand Down
60 changes: 59 additions & 1 deletion composer.lock

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

5 changes: 0 additions & 5 deletions config/packages/flysystem.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,3 @@ flysystem:
options:
client: Aws\S3\S3Client
bucket: '%env(resolve:MINIO_BUCKET)%'

local.storage:
adapter: 'local'
options:
directory: '%kernel.project_dir%/var/storage/default'
9 changes: 9 additions & 0 deletions config/packages/test/flysystem.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Read the documentation at https://github.com/thephpleague/flysystem-bundle/blob/master/docs/1-getting-started.md
flysystem:
storages:
default.storage:
adapter: 'aws'
options:
client: Aws\S3\S3Client
bucket: '%env(resolve:MINIO_BUCKET)%'

5 changes: 5 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ services:
version: 'latest'
region: '%env(resolve:MINIO_REGION)%'
endpoint: '%env(resolve:MINIO_ENDPOINT)%'
use_path_style_endpoint: true
credentials:
key: '%env(resolve:MINIO_ROOT_USER)%'
secret: '%env(resolve:MINIO_ROOT_PASSWORD)%'

App\Facade\FileSystemFacade:
autowire: true
public: true
32 changes: 32 additions & 0 deletions migrations/Version20240317212837.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240317212837 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE content ADD image_url VARCHAR(255) NOT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE SCHEMA public');
$this->addSql('ALTER TABLE content DROP image_url');
}
}
15 changes: 15 additions & 0 deletions src/Entity/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class Content
#[ORM\ManyToOne]
private ?Profile $profile = null;

#[ORM\Column(length: 255)]
private ?string $imageUrl = null;

public function getId(): ?string
{
return $this->id;
Expand Down Expand Up @@ -69,4 +72,16 @@ public function setProfile(?Profile $profile): static

return $this;
}

public function getImageUrl(): ?string
{
return $this->imageUrl;
}

public function setImageUrl(string $imageUrl): static
{
$this->imageUrl = $imageUrl;

return $this;
}
}
16 changes: 16 additions & 0 deletions src/Facade/FileSystemFacade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Facade;

use League\Flysystem\FilesystemOperator;

readonly final class FileSystemFacade
{
public FilesystemOperator $storage;

public function __construct(
FilesystemOperator $defaultStorage
) {
$this->storage = $defaultStorage;
}
}
11 changes: 9 additions & 2 deletions src/Factory/ContentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
namespace App\Factory;

use App\Entity\Content;
use App\Facade\FileSystemFacade;
use App\Repository\ContentRepository;
use Zenstruck\Foundry\ModelFactory;
use Zenstruck\Foundry\Proxy;
use Zenstruck\Foundry\RepositoryProxy;
use function file_get_contents;

/**
* @extends ModelFactory<Content>
Expand Down Expand Up @@ -50,8 +52,9 @@ final class ContentFactory extends ModelFactory
*
* @todo inject services if required
*/
public function __construct()
{
public function __construct(
protected FileSystemFacade $fileSystemFacade
) {
parent::__construct();
}

Expand All @@ -62,8 +65,12 @@ public function __construct()
*/
protected function getDefaults(): array
{
$imageFsUrl = 'stub/placeholder.png';
$this->fileSystemFacade->storage->write($imageFsUrl, file_get_contents(__DIR__ . '/../../tests/Stub/placeholder.jpg'));

return [
'name' => self::faker()->sentence(),
'image_url' => $imageFsUrl,
];
}

Expand Down
Loading

0 comments on commit 472b7b5

Please sign in to comment.