As the title says, when trying to deploy my project to AWS EB, collectstatic fails if used with S3. It creates a folder in the specified bucket, uploads 2 files and then suddenly returns Command 02_collectstatic failed
.
I use the following code:
myapp/settings.py
AWS_ACCESS_KEY_ID = '---key-ID---'
AWS_SECRET_ACCESS_KEY = '---key---'
AWS_STORAGE_BUCKET_NAME = '---bucket---'
DEFAULT_FILE_STORAGE = 'myapp.s3utils.MediaRootS3BotoStorage'
STATICFILES_STORAGE = 'myapp.s3utils.StaticRootS3BotoStorage'
S3_URL = 'http://s3.amazonaws.com/%s' % AWS_STORAGE_BUCKET_NAME
MEDIA_ROOT = '/media/'
MEDIA_URL = S3_URL + MEDIA_ROOT
STATIC_ROOT = '/static/'
STATIC_URL = S3_URL + STATIC_ROOT
myapp/s3utils.py
from storages.backends.s3boto import S3BotoStorage
StaticRootS3BotoStorage = lambda: S3BotoStorage(location='static')
MediaRootS3BotoStorage = lambda: S3BotoStorage(location='media')
.ebextensions/myapp.config
container_commands:
01_syncdb:
command: "django-admin.py syncdb --noinput"
leader_only: true
02_collectstatic:
command: "django-admin.py collectstatic --noinput"
option_settings:
- namespace: aws:elasticbeanstalk:container:python
option_name: WSGIPath
value: myapp/wsgi.py
- namespace: aws:elasticbeanstalk:container:python:staticfiles
option_name: /static/
value: myapp/static/
- option_name: DJANGO_SETTINGS_MODULE
value: myapp.settings
- option_name: AWS_SECRET_KEY
value: ---key---
- option_name: AWS_ACCESS_KEY_ID
value: ---key-ID---
The error log says
2013-12-04 17:29:42,887 [DEBUG] Running command 02_collectstatic
2013-12-04 17:29:42,888 [DEBUG] Generating defaults for command 02_collectstatic
<<<
2013-12-04 17:29:42,983 [DEBUG] No test for command 02_collectstatic
2013-12-04 17:30:38,186 [ERROR] Command 02_collectstatic (django-admin.py collectstatic --noinput) failed
2013-12-04 17:30:38,187 [DEBUG] Command 02_collectstatic output: error: [Errno 104] Connection reset by peer
Copying '/opt/python/ondeck/app/myapp/staticbase/js/skel.min.js'
Copying '/opt/python/ondeck/app/myapp/staticbase/js/config.js'
Copying '/opt/python/ondeck/app/myapp/staticbase/js/jquery.min.js'
2013-12-04 17:30:38,188 [ERROR] Error encountered during build of postbuild_0_myapp_git_23c2abc94089130640397058982b7612214c31f5_1386178136709__ebextensions_myapp_config: Command 02_collectstatic failed
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/cfnbootstrap/construction.py", line 511, in run_config
CloudFormationCarpenter(config, self._auth_config).build(worklog)
File "/usr/lib/python2.6/site-packages/cfnbootstrap/construction.py", line 247, in build
changes['commands'] = CommandTool().apply(self._config.commands)
File "/usr/lib/python2.6/site-packages/cfnbootstrap/command_tool.py", line 113, in apply
raise ToolError(u"Command %s failed" % name)
ToolError: Command 02_collectstatic failed
2013-12-04 17:30:38,189 [ERROR] Unhandled exception during build: Command 02_collectstatic failed
Traceback (most recent call last):
File "/opt/aws/bin/cfn-init", line 122, in <module>
worklog.build(detail.metadata, configSets)
File "/usr/lib/python2.6/site-packages/cfnbootstrap/construction.py", line 117, in build
Contractor(metadata).build(configSets, self)
File "/usr/lib/python2.6/site-packages/cfnbootstrap/construction.py", line 502, in build
self.run_config(config, worklog)
File "/usr/lib/python2.6/site-packages/cfnbootstrap/construction.py", line 511, in run_config
CloudFormationCarpenter(config, self._auth_config).build(worklog)
File "/usr/lib/python2.6/site-packages/cfnbootstrap/construction.py", line 247, in build
changes['commands'] = CommandTool().apply(self._config.commands)
File "/usr/lib/python2.6/site-packages/cfnbootstrap/command_tool.py", line 113, in apply
raise ToolError(u"Command %s failed" % name)
ToolError: Command 02_collectstatic failed
2013-12-04 17:33:00,210 [DEBUG] CloudFormation client initialized with endpoint https://cloudformation.us-west-2.amazonaws.com
2013-12-04 17:33:00,210 [DEBUG] Describing resource AWSEBAutoScalingGroup in stack arn:aws:cloudformation:us-west-2:298535049725:stack/awseb-e-m7uf3bwq2h-stack/1118d580-5cd0-11e3-8724-500150b35218
2013-12-04 17:33:00,405 [DEBUG] Not setting a reboot trigger as scheduling support is not available
2013-12-04 17:33:00,419 [INFO] Running configSets: InfoTask-TailLogs
2013-12-04 17:33:00,420 [INFO] Running configSet InfoTask-TailLogs
2013-12-04 17:33:00,421 [INFO] Running config InfoTask-TailLogs
2013-12-04 17:33:00,421 [DEBUG] No packages specified
2013-12-04 17:33:00,422 [DEBUG] No groups specified
2013-12-04 17:33:00,422 [DEBUG] No users specified
2013-12-04 17:33:00,422 [DEBUG] No sources specified
2013-12-04 17:33:00,422 [DEBUG] No files specified
2013-12-04 17:33:00,422 [DEBUG] Running command taillogs
2013-12-04 17:33:00,423 [DEBUG] No test for command taillogs
So, it seems that skel.min.js and config.js are copied and when trying to copy jquery.min.js the error occurs. Any idea what might cause this error?
@barrigaj, yes, I've found a solution. I simply had to change the order (MEDIA_ROOT and STATIC_ROOT need to be above DEFAULT_FILE_STORAGE and STATICFILES_STORAGE).
MEDIA_ROOT = '/media/'
STATIC_ROOT = '/static/'
DEFAULT_FILE_STORAGE = 'myapp.s3utils.MediaRootS3BotoStorage'
STATICFILES_STORAGE = 'myapp.s3utils.StaticRootS3BotoStorage'
S3_URL = 'http://s3.amazonaws.com/%s' % AWS_STORAGE_BUCKET_NAME
MEDIA_URL = S3_URL + MEDIA_ROOT
STATIC_URL = S3_URL + STATIC_ROOT
As the title says, when trying to deploy my project to AWS EB, collectstatic fails if used with S3. It creates a folder in the specified bucket, uploads 2 files and then suddenly returns Command 02_collectstatic failed
.
I use the following code:
myapp/settings.py
AWS_ACCESS_KEY_ID = '---key-ID---'
AWS_SECRET_ACCESS_KEY = '---key---'
AWS_STORAGE_BUCKET_NAME = '---bucket---'
DEFAULT_FILE_STORAGE = 'myapp.s3utils.MediaRootS3BotoStorage'
STATICFILES_STORAGE = 'myapp.s3utils.StaticRootS3BotoStorage'
S3_URL = 'http://s3.amazonaws.com/%s' % AWS_STORAGE_BUCKET_NAME
MEDIA_ROOT = '/media/'
MEDIA_URL = S3_URL + MEDIA_ROOT
STATIC_ROOT = '/static/'
STATIC_URL = S3_URL + STATIC_ROOT
myapp/s3utils.py
from storages.backends.s3boto import S3BotoStorage
StaticRootS3BotoStorage = lambda: S3BotoStorage(location='static')
MediaRootS3BotoStorage = lambda: S3BotoStorage(location='media')
.ebextensions/myapp.config
container_commands:
01_syncdb:
command: "django-admin.py syncdb --noinput"
leader_only: true
02_collectstatic:
command: "django-admin.py collectstatic --noinput"
option_settings:
- namespace: aws:elasticbeanstalk:container:python
option_name: WSGIPath
value: myapp/wsgi.py
- namespace: aws:elasticbeanstalk:container:python:staticfiles
option_name: /static/
value: myapp/static/
- option_name: DJANGO_SETTINGS_MODULE
value: myapp.settings
- option_name: AWS_SECRET_KEY
value: ---key---
- option_name: AWS_ACCESS_KEY_ID
value: ---key-ID---
The error log says
2013-12-04 17:29:42,887 [DEBUG] Running command 02_collectstatic
2013-12-04 17:29:42,888 [DEBUG] Generating defaults for command 02_collectstatic
<<<
2013-12-04 17:29:42,983 [DEBUG] No test for command 02_collectstatic
2013-12-04 17:30:38,186 [ERROR] Command 02_collectstatic (django-admin.py collectstatic --noinput) failed
2013-12-04 17:30:38,187 [DEBUG] Command 02_collectstatic output: error: [Errno 104] Connection reset by peer
Copying '/opt/python/ondeck/app/myapp/staticbase/js/skel.min.js'
Copying '/opt/python/ondeck/app/myapp/staticbase/js/config.js'
Copying '/opt/python/ondeck/app/myapp/staticbase/js/jquery.min.js'
2013-12-04 17:30:38,188 [ERROR] Error encountered during build of postbuild_0_myapp_git_23c2abc94089130640397058982b7612214c31f5_1386178136709__ebextensions_myapp_config: Command 02_collectstatic failed
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/cfnbootstrap/construction.py", line 511, in run_config
CloudFormationCarpenter(config, self._auth_config).build(worklog)
File "/usr/lib/python2.6/site-packages/cfnbootstrap/construction.py", line 247, in build
changes['commands'] = CommandTool().apply(self._config.commands)
File "/usr/lib/python2.6/site-packages/cfnbootstrap/command_tool.py", line 113, in apply
raise ToolError(u"Command %s failed" % name)
ToolError: Command 02_collectstatic failed
2013-12-04 17:30:38,189 [ERROR] Unhandled exception during build: Command 02_collectstatic failed
Traceback (most recent call last):
File "/opt/aws/bin/cfn-init", line 122, in <module>
worklog.build(detail.metadata, configSets)
File "/usr/lib/python2.6/site-packages/cfnbootstrap/construction.py", line 117, in build
Contractor(metadata).build(configSets, self)
File "/usr/lib/python2.6/site-packages/cfnbootstrap/construction.py", line 502, in build
self.run_config(config, worklog)
File "/usr/lib/python2.6/site-packages/cfnbootstrap/construction.py", line 511, in run_config
CloudFormationCarpenter(config, self._auth_config).build(worklog)
File "/usr/lib/python2.6/site-packages/cfnbootstrap/construction.py", line 247, in build
changes['commands'] = CommandTool().apply(self._config.commands)
File "/usr/lib/python2.6/site-packages/cfnbootstrap/command_tool.py", line 113, in apply
raise ToolError(u"Command %s failed" % name)
ToolError: Command 02_collectstatic failed
2013-12-04 17:33:00,210 [DEBUG] CloudFormation client initialized with endpoint https://cloudformation.us-west-2.amazonaws.com
2013-12-04 17:33:00,210 [DEBUG] Describing resource AWSEBAutoScalingGroup in stack arn:aws:cloudformation:us-west-2:298535049725:stack/awseb-e-m7uf3bwq2h-stack/1118d580-5cd0-11e3-8724-500150b35218
2013-12-04 17:33:00,405 [DEBUG] Not setting a reboot trigger as scheduling support is not available
2013-12-04 17:33:00,419 [INFO] Running configSets: InfoTask-TailLogs
2013-12-04 17:33:00,420 [INFO] Running configSet InfoTask-TailLogs
2013-12-04 17:33:00,421 [INFO] Running config InfoTask-TailLogs
2013-12-04 17:33:00,421 [DEBUG] No packages specified
2013-12-04 17:33:00,422 [DEBUG] No groups specified
2013-12-04 17:33:00,422 [DEBUG] No users specified
2013-12-04 17:33:00,422 [DEBUG] No sources specified
2013-12-04 17:33:00,422 [DEBUG] No files specified
2013-12-04 17:33:00,422 [DEBUG] Running command taillogs
2013-12-04 17:33:00,423 [DEBUG] No test for command taillogs
So, it seems that skel.min.js and config.js are copied and when trying to copy jquery.min.js the error occurs. Any idea what might cause this error?
@barrigaj, yes, I've found a solution. I simply had to change the order (MEDIA_ROOT and STATIC_ROOT need to be above DEFAULT_FILE_STORAGE and STATICFILES_STORAGE).
MEDIA_ROOT = '/media/'
STATIC_ROOT = '/static/'
DEFAULT_FILE_STORAGE = 'myapp.s3utils.MediaRootS3BotoStorage'
STATICFILES_STORAGE = 'myapp.s3utils.StaticRootS3BotoStorage'
S3_URL = 'http://s3.amazonaws.com/%s' % AWS_STORAGE_BUCKET_NAME
MEDIA_URL = S3_URL + MEDIA_ROOT
STATIC_URL = S3_URL + STATIC_ROOT
0 commentaires:
Enregistrer un commentaire