Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backend/btrixcloud/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1666,6 +1666,7 @@ class S3StorageIn(BaseModel):
endpoint_url: str
bucket: str
access_endpoint_url: Optional[str] = None
access_addressing_style: Literal["virtual", "path"] = "virtual"
region: str = ""


Expand All @@ -1680,6 +1681,7 @@ class S3Storage(BaseModel):
access_key: str
secret_key: str
access_endpoint_url: str
access_addressing_style: Literal["virtual", "path"] = "virtual"
region: str = ""


Expand Down
20 changes: 17 additions & 3 deletions backend/btrixcloud/storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@


# ============================================================================
# pylint: disable=broad-except,raise-missing-from
# pylint: disable=broad-except,raise-missing-from,too-many-instance-attributes
class StorageOps:
"""All storage handling, download/upload operations"""

Expand Down Expand Up @@ -104,6 +104,8 @@ def __init__(self, org_ops, crawl_manager, mdb) -> None:
default_namespace = os.environ.get("DEFAULT_NAMESPACE", "default")
self.frontend_origin = f"{frontend_origin}.{default_namespace}"

self.local_minio_access_path = os.environ.get("LOCAL_MINIO_ACCESS_PATH")

with open(os.environ["STORAGES_JSON"], encoding="utf-8") as fh:
storage_list = json.loads(fh.read())

Expand Down Expand Up @@ -158,13 +160,18 @@ def _create_s3_storage(self, storage: dict[str, str]) -> S3Storage:

access_endpoint_url = storage.get("access_endpoint_url") or endpoint_url

addressing_style = storage.get("access_addressing_style", "virtual")
if access_endpoint_url == self.local_minio_access_path:
addressing_style = "path"

return S3Storage(
access_key=storage["access_key"],
secret_key=storage["secret_key"],
region=storage.get("region", ""),
endpoint_url=endpoint_url,
endpoint_no_bucket_url=endpoint_no_bucket_url,
access_endpoint_url=access_endpoint_url,
access_addressing_style=addressing_style,
)

async def add_custom_storage(
Expand All @@ -189,6 +196,7 @@ async def add_custom_storage(
endpoint_url=endpoint_url,
endpoint_no_bucket_url=endpoint_no_bucket_url,
access_endpoint_url=storagein.access_endpoint_url or storagein.endpoint_url,
access_addressing_style=storagein.access_addressing_style,
)

try:
Expand Down Expand Up @@ -291,9 +299,12 @@ async def get_s3_client(

session = aiobotocore.session.get_session()

config = None
s3 = None

if for_presign and storage.access_endpoint_url != storage.endpoint_url:
config = AioConfig(s3={"addressing_style": "virtual"})
s3 = {"addressing_style": storage.access_addressing_style}

config = AioConfig(signature_version="s3v4", s3=s3)

async with session.create_client(
"s3",
Expand Down Expand Up @@ -498,9 +509,12 @@ async def get_presigned_url(
s3storage.access_endpoint_url
and s3storage.access_endpoint_url != s3storage.endpoint_url
):
virtual = s3storage.access_addressing_style == "virtual"
parts = urlsplit(s3storage.endpoint_url)
host_endpoint_url = (
f"{parts.scheme}://{bucket}.{parts.netloc}/{orig_key}"
if virtual
else f"{parts.scheme}://{parts.netloc}/{bucket}/{orig_key}"
)
presigned_url = presigned_url.replace(
host_endpoint_url, s3storage.access_endpoint_url
Expand Down
4 changes: 3 additions & 1 deletion chart/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ data:

FRONTEND_ORIGIN: {{ .Values.frontend_alias | default "http://browsertrix-cloud-frontend" }}

CRAWLER_FQDN_SUFFIX: ".{{ .Values.crawler_namespace }}.svc.cluster.local"
CRAWLER_FQDN_SUFFIX: ".{{ .Values.crawler_namespace }}{{ .Values.fqdn_suffix }}"

DEFAULT_ORG: "{{ .Values.default_org }}"

Expand Down Expand Up @@ -53,6 +53,8 @@ data:

IS_LOCAL_MINIO: "{{ .Values.minio_local }}"

LOCAL_MINIO_ACCESS_PATH: "{{ .Values.minio_access_path }}"

STORAGES_JSON: "/ops-configs/storages.json"

CRAWLER_CHANNELS_JSON: "/ops-configs/crawler_channels.json"
Expand Down
7 changes: 5 additions & 2 deletions chart/templates/frontend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ spec:
value: {{ .Values.name }}-backend

- name: CRAWLER_FQDN_SUFFIX
value: ".{{ .Values.crawler_namespace }}.svc.cluster.local"
value: ".{{ .Values.crawler_namespace }}{{ .Values.fqdn_suffix }}"

- name: NGINX_ENTRYPOINT_WORKER_PROCESSES_AUTOTUNE
value: "1"
Expand All @@ -60,7 +60,10 @@ spec:

- name: LOCAL_BUCKET
value: "{{ .Values.minio_local_bucket_name }}"
{{- end }}

- name: LOCAL_ACCESS_PATH
value: "{{ .Values.minio_access_path }}"
{{- end }}

{{- if .Values.inject_extra }}
- name: INJECT_EXTRA
Expand Down
17 changes: 17 additions & 0 deletions chart/templates/minio.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,23 @@ spec:
{{- end }}
name: minio

---
apiVersion: v1
kind: Service

metadata:
namespace: {{ .Values.crawler_namespace }}
name: local-minio
labels:
app: local-minio

spec:
type: ExternalName
externalName: "local-minio.{{ .Release.Namespace }}{{ .Values.fqdn_suffix }}"
ports:
- port: 9000


{{- if .Values.minio_local_console_port }}
---
apiVersion: v1
Expand Down
10 changes: 8 additions & 2 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,9 @@ minio_pull_policy: "IfNotPresent"

minio_local_bucket_name: &local_bucket_name "btrix-data"

# path for serving from local minio bucket
minio_access_path: &minio_access_path "/data/"

minio_cpu: "10m"
minio_memory: "1024Mi"

Expand All @@ -413,8 +416,8 @@ storages:
secret_key: "PASSW0RD"
bucket_name: *local_bucket_name

endpoint_url: "http://local-minio.default:9000/"
access_endpoint_url: "/data/"
endpoint_url: "http://local-minio:9000/"
access_endpoint_url: *minio_access_path


# optional: duration in minutes for WACZ download links to be valid
Expand Down Expand Up @@ -495,6 +498,9 @@ signer_memory: "50Mi"
# Other Settings
# =========================================

# default FQDN suffix, shouldn't need to change
fqdn_suffix: .svc.cluster.local

# Optional: configure load balancing annotations
# service:
# annotations:
Expand Down
4 changes: 3 additions & 1 deletion frontend/00-browsertrix-nginx-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ if [ -z "$LOCAL_MINIO_HOST" ]; then
echo "no local minio, clearing out minio route"
echo "" >/etc/nginx/includes/minio.conf
else
echo "local minio: replacing \$LOCAL_MINIO_HOST with \"$LOCAL_MINIO_HOST\", \$LOCAL_BUCKET with \"$LOCAL_BUCKET\""
LOCAL_ACCESS_PATH=$(printf '%s\n' "$LOCAL_ACCESS_PATH" | sed -e 's/[\/&]/\\&/g')
echo "local minio: replacing \$LOCAL_MINIO_HOST with \"$LOCAL_MINIO_HOST\", \$LOCAL_BUCKET with \"$LOCAL_BUCKET\", \$LOCAL_ACCESS_PATH with \"$LOCAL_ACCESS_PATH\""
sed -i "s/\$LOCAL_ACCESS_PATH/$LOCAL_ACCESS_PATH/g" /etc/nginx/includes/minio.conf
sed -i "s/\$LOCAL_MINIO_HOST/$LOCAL_MINIO_HOST/g" /etc/nginx/includes/minio.conf
sed -i "s/\$LOCAL_BUCKET/$LOCAL_BUCKET/g" /etc/nginx/includes/minio.conf
fi
Expand Down
2 changes: 1 addition & 1 deletion frontend/minio.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
location /data/ {
location $LOCAL_ACCESS_PATH {
proxy_pass http://$LOCAL_MINIO_HOST/$LOCAL_BUCKET/;
proxy_redirect off;
proxy_buffering off;
Expand Down
Loading