contextualcode / ezplatform-aws-s3-adapter
eZ Platform 的 AWS S3 文件适配器
5.2
2024-08-19 12:00 UTC
Requires
- ibexa/core: ^4.6
- league/flysystem-aws-s3-v3: ^2.0.0
README
此扩展提供 AWS S3 文件适配器,主要特点包括
- 易于安装和配置。
- 每个环境都在同一个 AWS S3 存储桶内使用自己的存储。该扩展提供同步不同环境之间存储的脚本。
- 对于生成的图像别名使用直接 AWS S3 链接。
- 它还提供了一个生成特定内容项特定图像别名的脚本。在某些情况下,这可能用于性能优化。
- 二进制文件以私有 ACL 上传。因此,无法绕过 Ibexa DXP 安全规则访问它们。
安装
使用 AWS S3 创建一个新的公开存储桶。
使用 AWS IAM 创建一个具有对先前创建的 S3 存储桶读写访问权限的新“程序访问”用户。
设置 AWS 凭据为环境变量。如果项目运行在 Ibexa Cloud 或 Platform.sh
platform variable:create --level=project --name=AWS_ACCESS_KEY_ID \ --value=<YOUR_KEY_ID> --json=false --sensitive=false --prefix=env \ --visible-build=false --visible-runtime=true --enabled=true --inheritable=true platform variable:create --level=project --name=AWS_SECRET_ACCESS_KEY \ --value=<YOUR_ACCESS_KEY> --json=false --sensitive=true --prefix=env \ --visible-build=false --visible-runtime=true --enabled=true --inheritable=true
将变量添加到
.env
文件... ###> contextualcode/ezplatform-aws-s3-adapter ### AWS_FILE_ADAPTER_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} AWS_FILE_ADAPTER_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} AWS_FILE_ADAPTER_REGION=us-east-1 AWS_FILE_ADAPTER_BUCKET=<S3_BUCKET_NAME> AWS_FILE_ADAPTER_PREFIX=${PLATFORM_BRANCH} ###< contextualcode/ezplatform-aws-s3-adapter ###
使用 composer require
contextualcode/ezplatform-aws-s3-adapter
composer require contextualcode/ezplatform-aws-s3-adapter
更新
config/packages/oneup_flysystem.yaml
oneup_flysystem: adapters: aws_s3_adapter: awss3v3: client: 'amazon.client.aws_s3_adapter' bucket: '%env(AWS_FILE_ADAPTER_BUCKET)%' prefix: '%env(AWS_FILE_ADAPTER_PREFIX)%' ez_io: binarydata_handlers: aws_s3: flysystem: adapter: aws_s3_adapter metadata_handlers: dfs: legacy_dfs_cluster: connection: doctrine.dbal.default_connection ezplatform: system: default: io: binarydata_handler: aws_s3 metadata_handler: dfs
如果您在现有项目中启用 AWS S3 文件适配器,请迁移现有文件
php -d memory_limit=-1 bin/console ezplatform:io:migrate-files --from=default,default --to=dfs,aws_s3 --no-interaction
部署更改
git add composer.json composer.lock symfony.lock .env config/bundles.php config/packages/oneup_flysystem.yaml git commit -m "Installed AWS S3 file adapter" git push
同步不同环境之间的存储
此扩展提供同步不同环境之间存储的脚本。此脚本依赖于 AWS CLI。请确保已安装并设置。使用方法
bin/sync-environment-storage <AWS_S3_BUCKET_NAME> <DESTINATION_ENVIRONMENT> <SOURCE_ENVIRONMENT>
因此,如果您想将 master
环境的存储同步到使用 my-project-storage
AWS S3 存储桶的 staging
环境中,您应该运行
bin/sync-environment-storage my-project-storage staging master
生成图像别名
此外,此扩展还提供 bin/regenerate-image-aliases
脚本。该脚本允许为特定内容重新生成图像别名。使用方法
bin/regenerate-image-aliases <CLEAR_BEFORE> <LOCATION_IDS> <CONTENT_TYPES> <ALIASES>
为了重新生成在过去的 24 小时内创建的“medium”和“large”别名,请对所有位于根位置(位置 ID:1)的文件夹和文章运行
bin/regenerate-image-aliases '24 hours ago' '1' 'folder,article' 'medium,large'
根据项目需求,可能将类似的脚本添加到 cron 作业中。因此,当页面渲染时,其图像别名已生成,且不使用 CPU 资源生成图像别名。