Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build fails if using external storage (such as S3) #41

Open
glitchwolfe opened this issue Mar 20, 2019 · 0 comments
Open

Build fails if using external storage (such as S3) #41

glitchwolfe opened this issue Mar 20, 2019 · 0 comments
Labels

Comments

@glitchwolfe
Copy link

glitchwolfe commented Mar 20, 2019

I am using Amazon S3 (via boto3) to store the media files for a wagtail/django project. When I try to build my site, I get a ResourceNotFound error showing that it's looking for my S3 bucket inside my local directory, rather than remotely:

fs.errors.ResourceNotFound: resource '/Users/me/Documents/Django-Project/bakery/https:/s3-region-name-here.amazonaws.com/django-project-media/media' not found

The build command does work if I copy all of my media to my local directory, but it would definitely be ideal if I did not have to do that, especially since I intend to automate the build process. I acknowledge my use case is pretty unusual, so I understand if this is more of an enhancement request than a bug.

Error log attached below (some info changed for privacy reasons).


Full Error Log

(app) xxxxxxxxxx:Django-Project $ ./manage.py build
Traceback (most recent call last):
  File "/Users/me/.virtualenvs/Django-Project/lib/python3.6/site-packages/fs/osfs.py", line 324, in makedir
    os.mkdir(sys_path, mode)
FileNotFoundError: [Errno 2] No such file or directory: b'/Users/me/Documents/Django-Project/bakery/https:/s3-region-name-here.amazonaws.com/django-project-media/media'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./manage.py", line 12, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/me/.virtualenvs/Django-Project/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "/Users/me/.virtualenvs/Django-Project/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/me/.virtualenvs/Django-Project/lib/python3.6/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/me/.virtualenvs/Django-Project/lib/python3.6/site-packages/django/core/management/base.py", line 335, in execute
    output = self.handle(*args, **options)
  File "/Users/me/.virtualenvs/Django-Project/lib/python3.6/site-packages/bakery/management/commands/build.py", line 109, in handle
    self.build_media()
  File "/Users/me/.virtualenvs/Django-Project/lib/python3.6/site-packages/bakery/management/commands/build.py", line 223, in build_media
    copy.copy_dir("osfs:///", smart_text(self.media_root), self.fs, smart_text(target_dir))
  File "/Users/me/.virtualenvs/Django-Project/lib/python3.6/site-packages/fs/copy.py", line 293, in copy_dir
    _dst_fs.makedir(_dst_path, recreate=True)
  File "/Users/me/.virtualenvs/Django-Project/lib/python3.6/site-packages/fs/osfs.py", line 327, in makedir
    raise errors.ResourceNotFound(path)
fs.errors.ResourceNotFound: resource '/Users/me/Documents/Django-Project/bakery/https:/s3-region-name-here.amazonaws.com/django-project-media/media' not found

Relevant Settings

# ----- settings.py -----

# Media Storage
MEDIAFILES_LOCATION = 'media'
MEDIA_URL = "https://s3-{}.amazonaws.com/{}/{}/".format(AWS_S3_REGION_NAME, AWS_STORAGE_BUCKET_NAME, MEDIAFILES_LOCATION)
DEFAULT_FILE_STORAGE = 'custom_storages.MediaStorage'

# Wagtail Bakery Settings
BUILD_DIR = os.path.join(BASE_DIR, 'bakery')
BAKERY_MULTISITE = True
BAKERY_VIEWS = (
    'wagtailbakery.views.AllPublishedPagesView',
)

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

class MediaStorage(S3Boto3Storage):
    location = settings.MEDIAFILES_LOCATION
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants