chore: update docker uploads (#1202)

This commit is contained in:
pablohashescobar 2023-06-05 12:51:12 +05:30 committed by GitHub
parent bffc6a60e7
commit 50060a0bf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 21 deletions

View File

@ -34,10 +34,7 @@ class FileAssetEndpoint(BaseAPIView):
)
serializer.save(workspace_id=request.user.last_workspace_id)
response_data = serializer.data
if settings.DOCKERIZED and settings.USE_MINIO:
response_data["asset"] = response_data["asset"].replace(settings.AWS_S3_ENDPOINT_URL, settings.WEB_URL)
return Response(response_data, status=status.HTTP_201_CREATED)
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except Exception as e:
capture_exception(e)
@ -85,10 +82,7 @@ class UserAssetsEndpoint(BaseAPIView):
serializer = FileAssetSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
response_data = serializer.data
if settings.DOCKERIZED and settings.USE_MINIO:
response_data["asset"] = response_data["asset"].replace(settings.AWS_S3_ENDPOINT_URL, settings.WEB_URL)
return Response(response_data, status=status.HTTP_201_CREATED)
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except Exception as e:
capture_exception(e)

View File

@ -817,14 +817,6 @@ class IssueAttachmentEndpoint(BaseAPIView):
serializer = IssueAttachmentSerializer(data=request.data)
if serializer.is_valid():
serializer.save(project_id=project_id, issue_id=issue_id)
response_data = serializer.data
if (
settings.DOCKERIZED
and settings.USE_MINIO
):
response_data["asset"] = response_data["asset"].replace(
settings.AWS_S3_ENDPOINT_URL, settings.WEB_URL
)
issue_activity.delay(
type="attachment.activity.created",
requested_data=None,
@ -836,7 +828,7 @@ class IssueAttachmentEndpoint(BaseAPIView):
cls=DjangoJSONEncoder,
),
)
return Response(response_data, status=status.HTTP_201_CREATED)
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except Exception as e:
capture_exception(e)

View File

@ -30,9 +30,7 @@ DATABASES["default"] = dj_database_url.config()
SITE_ID = 1
# Set the variable true if running in docker environment
DOCKERIZED = int(os.environ.get(
"DOCKERIZED", 0
)) == 1
DOCKERIZED = int(os.environ.get("DOCKERIZED", 0)) == 1
USE_MINIO = int(os.environ.get("USE_MINIO"), 0) == 1
@ -86,7 +84,8 @@ if bool(os.environ.get("SENTRY_DSN", False)):
)
if DOCKERIZED and USE_MINIO:
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
INSTALLED_APPS += ("storages",)
DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
# The AWS access key to use.
AWS_ACCESS_KEY_ID = os.environ.get("AWS_ACCESS_KEY_ID", "access-key")
# The AWS secret access key to use.
@ -99,6 +98,11 @@ if DOCKERIZED and USE_MINIO:
AWS_DEFAULT_ACL = "public-read"
AWS_QUERYSTRING_AUTH = False
AWS_S3_FILE_OVERWRITE = False
# Custom Domain settings
parsed_url = urlparse(os.environ.get("WEB_URL", "http://localhost"))
AWS_S3_CUSTOM_DOMAIN = f"{parsed_url.netloc}/{AWS_STORAGE_BUCKET_NAME}"
AWS_S3_URL_PROTOCOL = f"{parsed_url.scheme}:"
else:
# The AWS region to connect to.
AWS_REGION = os.environ.get("AWS_REGION", "")