Skip to content

Commit cc92390

Browse files
committed
feat: tus with linked buckets
2 parents 197cdf0 + 0cf1f70 commit cc92390

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+7753
-14384
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ RUN npm run build
1414
FROM node:18-alpine
1515
WORKDIR /app
1616
COPY migrations migrations
17-
COPY ecosystem.config.js package.json ./
17+
COPY package.json ./
1818
COPY --from=0 /app/node_modules node_modules
1919
COPY --from=1 /app/dist dist
2020
EXPOSE 5000

src/test/db/docker-compose.yml renamed to docker-compose-infra.yml

+16-13
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,27 @@
33
version: '3'
44
services:
55
db:
6-
image: postgres:13
6+
image: postgres:15
77
ports:
88
- '5432:5432'
99
volumes:
10-
- ./src/test/db:/docker-entrypoint-initdb.d/
10+
- ./migrations/base:/docker-entrypoint-initdb.d/
11+
shm_size: 1g
1112
environment:
1213
POSTGRES_DB: postgres
1314
POSTGRES_USER: postgres
1415
POSTGRES_PASSWORD: postgres
1516
POSTGRES_PORT: 5432
1617

18+
multitenant_db:
19+
image: postgres:15
20+
ports:
21+
- '5433:5432'
22+
environment:
23+
POSTGRES_DB: postgres
24+
POSTGRES_USER: postgres
25+
POSTGRES_PASSWORD: postgres
26+
1727
pg_bouncer:
1828
image: bitnami/pgbouncer:latest
1929
ports:
@@ -28,15 +38,6 @@ services:
2838
depends_on:
2939
- db
3040

31-
multitenant_db:
32-
image: postgres:13
33-
ports:
34-
- '5433:5432'
35-
environment:
36-
POSTGRES_DB: postgres
37-
POSTGRES_USER: postgres
38-
POSTGRES_PASSWORD: postgres
39-
4041
redis:
4142
image: redis:6.2-alpine
4243
restart: always
@@ -53,14 +54,16 @@ services:
5354
MINIO_ROOT_PASSWORD: secret1234
5455
command: server --console-address ":9001" /data
5556

56-
createbuckets:
57+
create_default_bucket:
5758
image: minio/mc
5859
depends_on:
5960
- minio
61+
environment:
62+
BUCKET_NAME: ${GLOBAL_S3_BUCKET:-local-bucket}
6063
entrypoint: >
6164
/bin/sh -c "
6265
/usr/bin/mc alias set supa-minio http://minio:9000 supa-storage secret1234;
63-
/usr/bin/mc mb supa-minio/supa-storage-staging-ap-southeast-1;
66+
/usr/bin/mc mb "supa-minio/$${BUCKET_NAME}";
6467
exit 0;
6568
"
6669

docker-compose.yml

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# docker-compose.yml
2+
3+
version: '3'
4+
services:
5+
storage-api:
6+
build: .
7+
ports:
8+
- '5003:5000' # service port
9+
- '5004:5001' # admin port
10+
env_file: .env
11+
environment:
12+
DATABASE_URL: postgres://postgres:postgres@db/postgres
13+
DATABASE_POOL_URL: postgresql://postgres:postgres@pg_bouncer:6432/postgres
14+
RATE_LIMITER_REDIS_URL: redis://redis:6379
15+
GLOBAL_S3_ENDPOINT: http://minio:9000
16+
IS_MULTITENANT: true
17+
MULTITENANT_DATABASE_URL: postgresql://postgres:postgres@multitenant_db/postgres
18+
depends_on:
19+
- db
20+
- multitenant_db
21+
- minio
22+
- create_default_bucket
23+
- imgproxy
24+
- redis
25+
26+
db:
27+
image: postgres:15
28+
ports:
29+
- '5432:5432'
30+
volumes:
31+
- ./migrations/base:/docker-entrypoint-initdb.d/
32+
shm_size: 1g
33+
environment:
34+
POSTGRES_DB: postgres
35+
POSTGRES_USER: postgres
36+
POSTGRES_PASSWORD: postgres
37+
POSTGRES_PORT: 5432
38+
39+
multitenant_db:
40+
image: postgres:15
41+
ports:
42+
- '5433:5432'
43+
environment:
44+
POSTGRES_DB: postgres
45+
POSTGRES_USER: postgres
46+
POSTGRES_PASSWORD: postgres
47+
48+
pg_bouncer:
49+
image: bitnami/pgbouncer:latest
50+
ports:
51+
- '6453:6432'
52+
environment:
53+
POSTGRESQL_USERNAME: postgres
54+
POSTGRESQL_HOST: db
55+
POSTGRESQL_PASSWORD: postgres
56+
PGBOUNCER_POOL_MODE: transaction
57+
PGBOUNCER_IGNORE_STARTUP_PARAMETERS: "extra_float_digits, options"
58+
PGBOUNCER_STATS_USERS: postgres
59+
depends_on:
60+
- db
61+
62+
redis:
63+
image: redis:6.2-alpine
64+
restart: always
65+
ports:
66+
- '6379:6379'
67+
68+
minio:
69+
image: minio/minio
70+
ports:
71+
- '9000:9000'
72+
- '9001:9001'
73+
environment:
74+
MINIO_ROOT_USER: supa-storage
75+
MINIO_ROOT_PASSWORD: secret1234
76+
command: server --console-address ":9001" /data
77+
78+
create_default_bucket:
79+
image: minio/mc
80+
depends_on:
81+
- minio
82+
environment:
83+
BUCKET_NAME: ${GLOBAL_S3_BUCKET:-local-bucket}
84+
entrypoint: >
85+
/bin/sh -c "
86+
/usr/bin/mc alias set supa-minio http://minio:9000 supa-storage secret1234;
87+
/usr/bin/mc mb "supa-minio/$${BUCKET_NAME}";
88+
exit 0;
89+
"
90+
91+
imgproxy:
92+
image: darthsim/imgproxy
93+
ports:
94+
- '50020:8080'
95+
volumes:
96+
- ./data:/images/data
97+
environment:
98+
- IMGPROXY_WRITE_TIMEOUT=20
99+
- IMGPROXY_READ_TIMEOUT=20
100+
- IMGPROXY_REQUESTS_QUEUE_SIZE=24
101+
- IMGPROXY_LOCAL_FILESYSTEM_ROOT=/images
102+
- IMGPROXY_USE_ETAG=true
103+
- IMGPROXY_ENABLE_WEBP_DETECTION=true

docker-entrypoint.sh

100755100644
File mode changed.

ecosystem.config.js

-11
This file was deleted.

src/test/db/02-storage-schema.sql renamed to migrations/base/01-storage-schema.sql

-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ CREATE TABLE "storage"."buckets" (
1212
"owner" uuid,
1313
"created_at" timestamptz DEFAULT now(),
1414
"updated_at" timestamptz DEFAULT now(),
15-
CONSTRAINT "buckets_owner_fkey" FOREIGN KEY ("owner") REFERENCES "auth"."users"("id"),
1615
PRIMARY KEY ("id")
1716
);
1817
CREATE UNIQUE INDEX "bname" ON "storage"."buckets" USING BTREE ("name");
@@ -28,7 +27,6 @@ CREATE TABLE "storage"."objects" (
2827
"last_accessed_at" timestamptz DEFAULT now(),
2928
"metadata" jsonb,
3029
CONSTRAINT "objects_bucketId_fkey" FOREIGN KEY ("bucket_id") REFERENCES "storage"."buckets"("id"),
31-
CONSTRAINT "objects_owner_fkey" FOREIGN KEY ("owner") REFERENCES "auth"."users"("id"),
3230
PRIMARY KEY ("id")
3331
);
3432
CREATE UNIQUE INDEX "bucketid_objname" ON "storage"."objects" USING BTREE ("bucket_id","name");
File renamed without changes.

migrations/multitenant/0006-add-tenants-external-credentials.sql

-38
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
alter table storage.objects add column if not exists owner_id text default null;
2+
alter table storage.buckets add column if not exists owner_id text default null;
3+
4+
comment on column storage.objects.owner is 'Field is deprecated, use owner_id instead';
5+
comment on column storage.buckets.owner is 'Field is deprecated, use owner_id instead';
6+
7+
ALTER TABLE storage.buckets
8+
DROP CONSTRAINT IF EXISTS buckets_owner_fkey;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CREATE TABLE bucket_credentials (
2+
"id" uuid NOT NULL DEFAULT extensions.uuid_generate_v4(),
3+
name text NOT NULL unique,
4+
access_key text NULL,
5+
secret_key text NULL,
6+
role text null,
7+
region text not null,
8+
endpoint text NULL,
9+
force_path_style boolean NOT NULL default false,
10+
PRIMARY KEY (id)
11+
);
12+
13+
ALTER TABLE storage.buckets ADD COLUMN credential_id uuid DEFAULT NULL;
14+
ALTER TABLE storage.buckets ADD CONSTRAINT fk_bucket_credential FOREIGN KEY (credential_id) REFERENCES bucket_credentials(id);

0 commit comments

Comments
 (0)