瀏覽代碼

add support for Google Cloud Storage (#256)

Tobias McNulty 5 年之前
父節點
當前提交
02737b411b
共有 2 個文件被更改,包括 12 次插入2 次删除
  1. 9 0
      bakerydemo/settings/production.py
  2. 3 2
      requirements/production.txt

+ 9 - 0
bakerydemo/settings/production.py

@@ -100,6 +100,15 @@ if 'AWS_STORAGE_BUCKET_NAME' in os.environ:
     MEDIA_URL = "https://%s/" % AWS_S3_CUSTOM_DOMAIN
     DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3Boto3Storage'
 
+if 'GS_BUCKET_NAME' in os.environ:
+    GS_BUCKET_NAME = os.getenv('GS_BUCKET_NAME')
+    GS_PROJECT_ID = os.getenv('GS_PROJECT_ID')
+    GS_DEFAULT_ACL = 'publicRead'
+    GS_AUTO_CREATE_BUCKET = True
+
+    INSTALLED_APPS.append('storages')
+    DEFAULT_FILE_STORAGE = 'storages.backends.gcloud.GoogleCloudStorage'
+
 LOGGING = {
     'version': 1,
     'disable_existing_loggers': False,

+ 3 - 2
requirements/production.txt

@@ -2,13 +2,14 @@
 # elasticsearch==2.x.x chosen for compatibility with t2.micro.elasticsearch and t2.small.elasticsearch
 # instance types on AWS (Elasticsearch 2.3). Adjust for your deployment as needed.
 elasticsearch==2.4.1
-# Additional dependencies for Heroku deployment
+# Additional dependencies for Heroku, AWS, and Google Cloud deployment
 dj-database-url==0.4.1
 uwsgi>=2.0.17,<2.1
 psycopg2>=2.7,<3.0
 whitenoise==3.2.2
 boto3==1.9.189
-django-storages==1.7.1
+google-cloud-storage==1.20.0
+django-storages==1.7.2
 # For retrieving credentials and signing requests to Elasticsearch
 botocore==1.12.33
 aws-requests-auth==0.4.0