2017-09-21 9 views
1

私はDjango Storagesを使用してS3でファイルをホストするDjango v1.11.2セットアップに取り組んでいます。私が知る限り、記憶装置は正しく構成されています。問題なく「collectstatic」をうまく配置して実行できます。 S3でファイルが表示され、サイトは期待通りに機能します。Elasticbeanstalk Django S3ストレージとCollectstaticエラー

私はDjangoインポート/エクスポートモジュールも使用しており、MediaStorageオプションを使用してファイルを保存するように設定しています。インポートを実行すると、S3バケットに「静的」バケットと一緒に「メディア」フォルダが正常に作成されます。

ここで問題が発生します。 ebデプロイを実行し、あらゆる種類のアップデートをプッシュすると、このエラーが発生します。

[Instance: i-037825ca3bdf4a5c5] Command failed on instance. Return code: 1 Output: (TRUNCATED)...(path) File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/files/storage.py", line 111, in path raise NotImplementedError("This backend doesn't support absolute paths.") NotImplementedError: This backend doesn't support absolute paths. container_command 03_collectstatic in .ebextensions/02_python.config failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.

です。うーん。それは変だ。だから私は私のS3バケットに入る場合。 [メディア]フォルダのみを削除し、アプリケーションを再度展開すると、エラーが解決されます。

私のsettings.pyファイル内にある値は次のとおりです。

AWS_STORAGE_BUCKET_NAME = 'my-s3-bucket' 
AWS_S3_REGION_NAME = 'us-east-1' 
AWS_ACCESS_KEY_ID = 'xxxxxxxxxxxxx' 
AWS_SECRET_ACCESS_KEY = 'xxxxxxxxxxxxxxxxxxx' 
AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME 

STATICFILES_LOCATION = 'static' 
STATICFILES_STORAGE = 'custom_storages.StaticStorage' 

MEDIAFILES_LOCATION = 'media' 
DEFAULT_FILE_STORAGE = 'custom_storages.MediaStorage' 

STATIC_URL = '/static/' 
MEDIA_URL = '/media/' 

# custom_storages.py 
from django.conf import settings 
from storages.backends.s3boto3 import S3Boto3Storage 

class StaticStorage(S3Boto3Storage): 
    location = settings.STATICFILES_LOCATION 

class MediaStorage(S3Boto3Storage): 
    location = settings.MEDIAFILES_LOCATION 

これは、私は一日中、このいずれかで壁に頭を叩いてきたストレートEB

のうち、
[2017-09-21T02:41:17.534Z] INFO [15715] - [Application [email protected]/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_xxxxxxxx/Command 03_collectstatic] : Activity execution failed, because: base dir path /opt/python/bundle/4/app 
    Traceback (most recent call last): 
    File "./manage.py", line 22, in <module> 
    execute_from_command_line(sys.argv) 
    File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line 
    utility.execute() 
    File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 355, in execute 
    self.fetch_command(subcommand).run_from_argv(self.argv) 
    File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv 
    self.execute(*args, **cmd_options) 
    File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute 
    output = self.handle(*args, **options) 
    File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 199, in handle 
    collected = self.collect() 
    File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 124, in collect 
    handler(path, prefixed_path, storage) 
    File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 357, in copy_file 
    source_path = source_storage.path(path) 
    File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/files/storage.py", line 111, in path 
    raise NotImplementedError("This backend doesn't support absolute paths.") 
    NotImplementedError: This backend doesn't support absolute paths. 
    (ElasticBeanstalk::ExternalInvocationError) 

ログです。すべての提案が評価されます。ありがとうございました。

答えて

0

まあ、私はこの記事のおかげでこれを最終的に理解しました。私が変更したSTATICFILES_FINDERSの設定が原因でした。それは私の静的ファイルのメディアフォルダにチェックしていたため、総理にかなって

STATICFILES_FINDERS = (
     'django.contrib.staticfiles.finders.AppDirectoriesFinder', 
     'django.contrib.staticfiles.finders.FileSystemFinder', 
    ) 

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.AppDirectoriesFinder', 
    'django.contrib.staticfiles.finders.FileSystemFinder', 
    'django.contrib.staticfiles.finders.DefaultStorageFinder', 
) 

。私はこのプロジェクトを継承したので、彼らはこのように設定されていることに気づいていませんでした。

関連する問題