Skip to content

Commit 9a5a8c6

Browse files
authored
add minio implementation (#2817)
* integrate minio added docker configuration and environment variables for minio integrated minio client fastify plugin instance into the talawa api server and the mercurius graphql handler exposed a new `/objects` route for streaming the files from minio server to the clients * add graphql implementation for file upload scalar * remove noUncheckedIndexAccess from tsconfig.json * add graphql implementation for deleting minio objects added the implementation for deleting minio objects associated to the postgres entities at the time of their deletion in a transaction * replace _ with - in minio docker service names
1 parent 8bdf2f4 commit 9a5a8c6

File tree

210 files changed

+4756
-1317
lines changed

Some content is hidden

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

210 files changed

+4756
-1317
lines changed

compose.yaml

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: ${COMPOSE_PROJECT_NAME:?error}
22
# https://docs.docker.com/reference/compose-file/networks/
33
networks:
44
api:
5+
minio:
56
postgres:
67
# https://docs.docker.com/reference/compose-file/services
78
services:
@@ -20,6 +21,10 @@ services:
2021
target: production
2122
# https://docs.docker.com/reference/compose-file/services/#depends_on
2223
depends_on:
24+
minio:
25+
condition: service_healthy
26+
# Should be set to false when a third party minio service could be used in the api service and the `minio` compose profile is disabled.
27+
required: false
2328
postgres:
2429
condition: service_healthy
2530
# Should be set to false when a third party postgres service could be used in the api service the and the `postgres` compose profile is disabled.
@@ -29,13 +34,19 @@ services:
2934
environment:
3035
- API_ADMINISTRATOR_USER_EMAIL_ADDRESS=${API_ADMINISTRATOR_USER_EMAIL_ADDRESS:?error}
3136
- API_ADMINISTRATOR_USER_PASSWORD=${API_ADMINISTRATOR_USER_PASSWORD:?error}
37+
- API_BASE_URL=${API_BASE_URL:?error}
3238
- API_HOST=${API_HOST:?error}
3339
- API_IS_APPLY_DRIZZLE_MIGRATIONS=${API_IS_APPLY_DRIZZLE_MIGRATIONS:?error}
3440
- API_IS_GRAPHIQL=${API_IS_GRAPHIQL:?error}
3541
- API_IS_PINO_PRETTY=${API_IS_PINO_PRETTY:?error}
3642
- API_JWT_EXPIRES_IN=${API_JWT_EXPIRES_IN:?error}
3743
- API_JWT_SECRET=${API_JWT_SECRET:?error}
3844
- API_LOG_LEVEL=${API_LOG_LEVEL:?error}
45+
- API_MINIO_ACCESS_KEY=${API_MINIO_ACCESS_KEY:?error}
46+
- API_MINIO_END_POINT=${API_MINIO_END_POINT:?error}
47+
- API_MINIO_PORT=${API_MINIO_PORT:?error}
48+
- API_MINIO_SECRET_KEY=${API_MINIO_SECRET_KEY:?error}
49+
- API_MINIO_USE_SSL=${API_MINIO_USE_SSL:?error}
3950
- API_PORT=${API_PORT:?error}
4051
- API_POSTGRES_DATABASE=${API_POSTGRES_DATABASE:?error}
4152
- API_POSTGRES_HOST=${API_POSTGRES_HOST:?error}
@@ -64,6 +75,7 @@ services:
6475
# https://docs.docker.com/reference/compose-file/services/#networks
6576
networks:
6677
- api
78+
- minio
6779
- postgres
6880
# https://docs.docker.com/reference/compose-file/services/#profiles
6981
profiles:
@@ -121,6 +133,44 @@ services:
121133
# - source: ./docker/admin
122134
# target: /srv
123135
# type: bind
136+
minio:
137+
# https://docs.docker.com/compose/environment-variables/
138+
# https://docs.docker.com/reference/compose-file/services/#environment
139+
environment:
140+
- MINIO_BROWSER=${MINIO_BROWSER:?error}
141+
# https://min.io/docs/minio/linux/reference/minio-server/settings/root-credentials.html#envvar.MINIO_ROOT_PASSWORD
142+
- MINIO_ROOT_PASSWORD=${MINIO_ROOT_PASSWORD:?error}
143+
# https://min.io/docs/minio/linux/reference/minio-server/settings/root-credentials.html#root-user
144+
- MINIO_ROOT_USER=${MINIO_ROOT_USER:?error}
145+
# https://docs.docker.com/reference/compose-file/services/#command
146+
command: server /data --console-address ":9001"
147+
# https://docs.docker.com/reference/dockerfile/#healthcheck
148+
# https://docs.docker.com/reference/compose-file/services/#healthcheck
149+
healthcheck:
150+
interval: 10s
151+
retries: 3
152+
start_interval: 1s
153+
start_period: 5s
154+
# https://github.com/minio/minio/issues/18373
155+
# https://min.io/docs/minio/linux/reference/minio-mc/mc-ready.html
156+
test: ["CMD-SHELL", "mc ready local"]
157+
timeout: 10s
158+
# https://docs.docker.com/reference/compose-file/services/#image
159+
# https://hub.docker.com/r/minio/minio
160+
image: minio/minio:RELEASE.2024-12-18T13-15-44Z
161+
# https://docs.docker.com/reference/compose-file/services/#networks
162+
networks:
163+
- minio
164+
# https://docs.docker.com/reference/compose-file/services/#profiles
165+
profiles:
166+
- minio
167+
# https://docs.docker.com/reference/compose-file/services/#restart
168+
restart: unless-stopped
169+
# https://docs.docker.com/reference/compose-file/services/#volumes
170+
volumes:
171+
- source: minio_data
172+
target: /data
173+
type: volume
124174
postgres:
125175
# https://docs.docker.com/compose/environment-variables/
126176
# https://docs.docker.com/reference/compose-file/services/#environment
@@ -144,7 +194,7 @@ services:
144194
timeout: 10s
145195
# https://docs.docker.com/reference/compose-file/services/#image
146196
# https://hub.docker.com/_/postgres
147-
image: postgres:17.0-alpine3.20
197+
image: postgres:17.2-alpine3.21
148198
# https://docs.docker.com/reference/compose-file/services/#networks
149199
networks:
150200
- postgres
@@ -162,4 +212,5 @@ services:
162212
volumes:
163213
caddy_config:
164214
caddy_data:
215+
minio_data:
165216
postgres_data:

docker/compose.development.yaml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ services:
1212
# https://docs.docker.com/reference/compose-file/build/#target
1313
target: devcontainer
1414
depends_on:
15+
minio:
16+
condition: service_healthy
17+
required: true
1518
postgres:
1619
condition: service_healthy
1720
required: true
@@ -81,7 +84,7 @@ services:
8184
timeout: 10s
8285
# https://dbeaver.com/docs/cloudbeaver/Run-Docker-Container/
8386
# https://hub.docker.com/r/dbeaver/cloudbeaver
84-
image: dbeaver/cloudbeaver:24.2.0
87+
image: dbeaver/cloudbeaver:24.3.1
8588
# https://docs.docker.com/reference/compose-file/services/#networks
8689
networks:
8790
- postgres
@@ -102,6 +105,29 @@ services:
102105
- source: cloudbeaver_data
103106
target: /opt/cloudbeaver/workspace
104107
type: volume
108+
minio:
109+
# https://docs.docker.com/reference/compose-file/services/#ports
110+
ports:
111+
- host_ip: ${MINIO_API_MAPPED_HOST_IP:?error}
112+
name: minio_api
113+
published: ${MINIO_API_MAPPED_PORT:?error}
114+
target: 9000
115+
- host_ip: ${MINIO_CONSOLE_MAPPED_HOST_IP:?error}
116+
name: minio_console
117+
published: ${MINIO_CONSOLE_MAPPED_PORT:?error}
118+
target: 9001
119+
# https://github.com/minio/minio/issues/13025
120+
minio-test:
121+
# https://docs.docker.com/reference/compose-file/services/#ports
122+
ports:
123+
- host_ip: ${MINIO_TEST_API_MAPPED_HOST_IP:?error}
124+
name: minio_api
125+
published: ${MINIO_TEST_API_MAPPED_PORT:?error}
126+
target: 9000
127+
- host_ip: ${MINIO_TEST_CONSOLE_MAPPED_HOST_IP:?error}
128+
name: minio_console
129+
published: ${MINIO_TEST_CONSOLE_MAPPED_PORT:?error}
130+
target: 9001
105131
postgres:
106132
# https://docs.docker.com/reference/compose-file/services/#ports
107133
ports:

docker/compose.testing.yaml

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# https://docs.docker.com/reference/compose-file/networks/
22
networks:
3+
minio_test:
34
postgres_test:
45
# https://docs.docker.com/reference/compose-file/services
56
services:
@@ -11,23 +12,68 @@ services:
1112
command: pnpm run_tests
1213
# https://docs.docker.com/reference/compose-file/services/#depends_on
1314
depends_on:
15+
minio-test:
16+
condition: service_healthy
17+
# Should be set to false when a third party minio test service could be used in the api service and the `minio_test` compose profile is disabled.
18+
required: true
1419
postgres_test:
1520
condition: service_healthy
1621
# Should be set to false when a third party postgres test service could be used in the api service the and the `postgres_test` compose profile is disabled.
1722
required: true
1823
# https://docs.docker.com/compose/environment-variables/
1924
# https://docs.docker.com/reference/compose-file/services/#environment
2025
environment:
26+
- API_MINIO_TEST_END_POINT=${API_MINIO_TEST_END_POINT:?error}
2127
- API_POSTGRES_TEST_HOST=${API_POSTGRES_TEST_HOST:?error}
2228
# https://docs.docker.com/reference/dockerfile/#healthcheck
2329
# https://docs.docker.com/reference/compose-file/services/#healthcheck
2430
healthcheck:
2531
disable: true
2632
# https://docs.docker.com/reference/compose-file/services/#networks
2733
networks:
34+
- minio_test
2835
- postgres_test
2936
# https://docs.docker.com/reference/compose-file/services/#restart
3037
restart: no
38+
# https://github.com/minio/minio/issues/13025
39+
minio-test:
40+
# https://docs.docker.com/compose/environment-variables/
41+
# https://docs.docker.com/reference/compose-file/services/#environment
42+
environment:
43+
- MINIO_BROWSER=${MINIO_TEST_BROWSER:?error}
44+
# https://min.io/docs/minio/linux/reference/minio-server/settings/root-credentials.html#envvar.MINIO_ROOT_PASSWORD
45+
- MINIO_ROOT_PASSWORD=${MINIO_TEST_ROOT_PASSWORD:?error}
46+
# https://min.io/docs/minio/linux/reference/minio-server/settings/root-credentials.html#root-user
47+
- MINIO_ROOT_USER=${MINIO_TEST_ROOT_USER:?error}
48+
# https://docs.docker.com/reference/compose-file/services/#command
49+
command: server /data --console-address ":9001"
50+
# https://docs.docker.com/reference/dockerfile/#healthcheck
51+
# https://docs.docker.com/reference/compose-file/services/#healthcheck
52+
healthcheck:
53+
interval: 10s
54+
retries: 3
55+
start_interval: 1s
56+
start_period: 5s
57+
# https://github.com/minio/minio/issues/18373
58+
# https://min.io/docs/minio/linux/reference/minio-mc/mc-ready.html
59+
test: ["CMD-SHELL", "mc ready local"]
60+
timeout: 10s
61+
# https://docs.docker.com/reference/compose-file/services/#image
62+
# https://hub.docker.com/r/minio/minio
63+
image: minio/minio:RELEASE.2024-12-18T13-15-44Z
64+
# https://docs.docker.com/reference/compose-file/services/#networks
65+
networks:
66+
- minio_test
67+
# https://docs.docker.com/reference/compose-file/services/#profiles
68+
profiles:
69+
- minio_test
70+
# https://docs.docker.com/reference/compose-file/services/#restart
71+
restart: unless-stopped
72+
# https://docs.docker.com/reference/compose-file/services/#volumes
73+
volumes:
74+
- source: minio_test_data
75+
target: /data
76+
type: volume
3177
postgres_test:
3278
# https://docs.docker.com/compose/environment-variables/
3379
# https://docs.docker.com/reference/compose-file/services/#environment
@@ -51,7 +97,7 @@ services:
5197
timeout: 10s
5298
# https://docs.docker.com/reference/compose-file/services/#image
5399
# https://hub.docker.com/_/postgres
54-
image: postgres:17.0-alpine3.20
100+
image: postgres:17.2-alpine3.21
55101
# https://docs.docker.com/reference/compose-file/services/#networks
56102
networks:
57103
- postgres_test
@@ -67,4 +113,5 @@ services:
67113
type: volume
68114
# https://docs.docker.com/reference/compose-file/volumes/
69115
volumes:
116+
minio_test_data:
70117
postgres_test_data:

drizzle_migrations/20241226151206_massive_grey_gargoyle.sql renamed to drizzle_migrations/20241231123945_true_dorian_gray.sql

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ CREATE TABLE "advertisement_attachments" (
3131
"advertisement_id" uuid NOT NULL,
3232
"created_at" timestamp (3) with time zone DEFAULT now() NOT NULL,
3333
"creator_id" uuid,
34-
"type" text NOT NULL,
34+
"mime_type" text NOT NULL,
35+
"name" text NOT NULL,
3536
"updated_at" timestamp (3) with time zone,
36-
"updater_id" uuid,
37-
"uri" text NOT NULL
37+
"updater_id" uuid
3838
);
3939
--> statement-breakpoint
4040
CREATE TABLE "advertisements" (
@@ -99,7 +99,8 @@ CREATE TABLE "chat_messages" (
9999
);
100100
--> statement-breakpoint
101101
CREATE TABLE "chats" (
102-
"avatar_uri" text,
102+
"avatar_mime_type" text,
103+
"avatar_name" text,
103104
"created_at" timestamp (3) with time zone DEFAULT now() NOT NULL,
104105
"creator_id" uuid,
105106
"description" text,
@@ -135,10 +136,10 @@ CREATE TABLE "event_attachments" (
135136
"created_at" timestamp (3) with time zone DEFAULT now() NOT NULL,
136137
"creator_id" uuid,
137138
"event_id" uuid NOT NULL,
138-
"type" text NOT NULL,
139+
"mime_type" text NOT NULL,
140+
"name" text NOT NULL,
139141
"updated_at" timestamp (3) with time zone,
140-
"updater_id" uuid,
141-
"uri" text NOT NULL
142+
"updater_id" uuid
142143
);
143144
--> statement-breakpoint
144145
CREATE TABLE "event_attendances" (
@@ -236,7 +237,8 @@ CREATE TABLE "organization_memberships" (
236237
--> statement-breakpoint
237238
CREATE TABLE "organizations" (
238239
"address" text,
239-
"avatar_uri" text,
240+
"avatar_mime_type" text,
241+
"avatar_name" text,
240242
"city" text,
241243
"country_code" text,
242244
"created_at" timestamp (3) with time zone DEFAULT now() NOT NULL,
@@ -255,10 +257,10 @@ CREATE TABLE "post_attachments" (
255257
"created_at" timestamp (3) with time zone DEFAULT now() NOT NULL,
256258
"creator_id" uuid,
257259
"post_id" uuid NOT NULL,
258-
"type" text NOT NULL,
260+
"mime_type" text NOT NULL,
261+
"name" text NOT NULL,
259262
"updated_at" timestamp (3) with time zone,
260-
"updater_id" uuid,
261-
"uri" text NOT NULL
263+
"updater_id" uuid
262264
);
263265
--> statement-breakpoint
264266
CREATE TABLE "post_votes" (
@@ -314,7 +316,8 @@ CREATE TABLE "tags" (
314316
--> statement-breakpoint
315317
CREATE TABLE "users" (
316318
"address" text,
317-
"avatar_uri" text,
319+
"avatar_mime_type" text,
320+
"avatar_name" text,
318321
"birth_date" date,
319322
"city" text,
320323
"country_code" text,
@@ -344,10 +347,10 @@ CREATE TABLE "users" (
344347
CREATE TABLE "venue_attachments" (
345348
"created_at" timestamp (3) with time zone DEFAULT now() NOT NULL,
346349
"creator_id" uuid,
347-
"type" text NOT NULL,
350+
"mime_type" text NOT NULL,
351+
"name" text NOT NULL,
348352
"updated_at" timestamp (3) with time zone,
349353
"updater_id" uuid,
350-
"uri" text NOT NULL,
351354
"venue_id" uuid NOT NULL
352355
);
353356
--> statement-breakpoint

0 commit comments

Comments
 (0)