Skip to content

Commit

Permalink
Do not use S3 for storing files in local development
Browse files Browse the repository at this point in the history
Requiring S3 access for local development was not ideal, as we
want people to be able to run and contribute to this as easily
as possible.

This adds MEDIA configuration for uploads, which will be used
locally, and will use S3 in staging.
  • Loading branch information
rajadain committed Nov 4, 2022
1 parent a294edb commit 88469d7
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ deployment/ansible/roles/azavea.*
# Django
/src/django/static/
/src/django/data/
/src/django/media/
/.venv

# JS
Expand Down
2 changes: 1 addition & 1 deletion src/app/src/setupProxy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { createProxyMiddleware } = require('http-proxy-middleware');

const pathsToProxy = Object.freeze(['/api']);
const pathsToProxy = Object.freeze(['/api', '/media']);
const djangoProxyTarget = Object.freeze({ target: 'http://django:8181' });

const createProxies = app =>
Expand Down
3 changes: 0 additions & 3 deletions src/django/api/serializers/reference_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ def validate_opacity(self, value):
raise ValidationError("Opacity takes values from 0-100.")
return value

def get_file(self, reference_image):
return reference_image.file.url


class ReferenceImageUpdateSerializer(ReferenceImageSerializer):
class Meta:
Expand Down
6 changes: 5 additions & 1 deletion src/django/iow/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,5 +280,9 @@

# User Imagery Storage

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
if ENVIRONMENT != 'Development':
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

MEDIA_ROOT = os.path.join(BASE_DIR, "media")
MEDIA_URL = f"/media/"
AWS_STORAGE_BUCKET_NAME = f'iow-{ENVIRONMENT.lower()}-data-us-east-1'
16 changes: 10 additions & 6 deletions src/django/iow/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@

from . import settings

urlpatterns = [
path('admin/', admin.site.urls),
path('api/', include('api.urls')),
path('health-check/', include('watchman.urls')),
path('confirm_password_reset/', include('django.contrib.auth.urls')),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns = (
[
path("admin/", admin.site.urls),
path("api/", include("api.urls")),
path("health-check/", include("watchman.urls")),
path("confirm_password_reset/", include("django.contrib.auth.urls")),
]
+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
)

0 comments on commit 88469d7

Please sign in to comment.