Skip to content

Commit 5e8db05

Browse files
authored
fix: env config for psql setup with supertokens (#483)
1 parent 54dbdb2 commit 5e8db05

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

cli/app/commands/install/run.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,20 @@ def _setup_clone_and_config(self):
293293
def _create_env_files(self):
294294
api_env_file = self._get_config("api_env_file_path")
295295
view_env_file = self._get_config("view_env_file_path")
296+
297+
full_source_path = self._get_config("full_source_path")
298+
combined_env_file = os.path.join(full_source_path, ".env")
296299
FileManager.create_directory(FileManager.get_directory_path(api_env_file), logger=self.logger)
297300
FileManager.create_directory(FileManager.get_directory_path(view_env_file), logger=self.logger)
301+
FileManager.create_directory(FileManager.get_directory_path(combined_env_file), logger=self.logger)
302+
298303
services = [
299304
("api", "services.api.env", api_env_file),
300305
("view", "services.view.env", view_env_file),
301306
]
302307
env_manager = BaseEnvironmentManager(self.logger)
303308

309+
# individual service env files
304310
for i, (service_name, service_key, env_file) in enumerate(services):
305311
env_values = _config.get_service_env_values(service_key)
306312
updated_env_values = self._update_environment_variables(env_values)
@@ -312,6 +318,22 @@ def _create_env_files(self):
312318
raise Exception(f"{env_file_permissions_failed} {service_name}: {file_perm_error}")
313319
self.logger.debug(created_env_file.format(service_name=service_name, env_file=env_file))
314320

321+
# combined env file with both API and view variables
322+
api_env_values = _config.get_service_env_values("services.api.env")
323+
view_env_values = _config.get_service_env_values("services.view.env")
324+
325+
combined_env_values = {}
326+
combined_env_values.update(self._update_environment_variables(api_env_values))
327+
combined_env_values.update(self._update_environment_variables(view_env_values))
328+
success, error = env_manager.write_env_file(combined_env_file, combined_env_values)
329+
330+
if not success:
331+
raise Exception(f"{env_file_creation_failed} combined: {error}")
332+
file_perm_success, file_perm_error = FileManager.set_permissions(combined_env_file, 0o644)
333+
if not file_perm_success:
334+
raise Exception(f"{env_file_permissions_failed} combined: {file_perm_error}")
335+
self.logger.debug(created_env_file.format(service_name="combined", env_file=combined_env_file))
336+
315337
def _setup_proxy_config(self):
316338
full_source_path = self._get_config("full_source_path")
317339
caddy_json_template = os.path.join(full_source_path, "helpers", "caddy.json")
@@ -439,7 +461,7 @@ def _update_environment_variables(self, env_values: dict) -> dict:
439461
"SUPERTOKENS_API_KEY": "NixopusSuperTokensAPIKey",
440462
"SUPERTOKENS_API_DOMAIN": f"{protocol}://{api_host}/api",
441463
"SUPERTOKENS_WEBSITE_DOMAIN": f"{protocol}://{view_host}",
442-
"SUPERTOKENS_CONNECTION_URI": f"{protocol}://{api_host}:{supertokens_api_port}/api",
464+
"SUPERTOKENS_CONNECTION_URI": f"{protocol}://{api_host}:{supertokens_api_port}",
443465
}
444466

445467
for key, value in key_map.items():

cli/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "nixopus"
3-
version = "0.1.7"
3+
version = "0.1.8"
44
description = "A CLI for Nixopus"
55
authors = ["Nixopus <[email protected]>"]
66
readme = "README.md"

docker-compose.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ services:
1111
- ${NIXOPUS_HOME:-/etc/nixopus}/source/api/.env
1212
environment:
1313
- HOST_NAME=nixopus-db
14+
1415
volumes:
1516
- ./logs:/app/logs
1617
- ${NIXOPUS_HOME:-/etc/nixopus}:/etc/nixopus
@@ -31,6 +32,7 @@ services:
3132
- POSTGRES_PASSWORD=${PASSWORD}
3233
- POSTGRES_DB=${DB_NAME}
3334
- POSTGRES_HOST_AUTH_METHOD=trust
35+
3436
ports:
3537
- "${DB_PORT:-5432}:5432"
3638
volumes:
@@ -49,6 +51,8 @@ services:
4951
build:
5052
args:
5153
- NEXT_PUBLIC_PORT=${NEXT_PUBLIC_PORT}
54+
- NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
55+
- NEXT_PUBLIC_WEBSITE_DOMAIN=${NEXT_PUBLIC_WEBSITE_DOMAIN}
5256
ports:
5357
- "${NEXT_PUBLIC_PORT:-7443}:${NEXT_PUBLIC_PORT:-7443}"
5458
restart: unless-stopped
@@ -95,11 +99,11 @@ services:
9599
"--config",
96100
"/etc/caddy/Caddyfile",
97101
"--adapter",
98-
"caddyfile"
102+
"caddyfile",
99103
]
100104
networks:
101105
- nixopus-network
102-
106+
103107
supertokens:
104108
image: registry.supertokens.io/supertokens/supertokens-postgresql:latest
105109
depends_on:

view/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ COPY --from=deps /app/node_modules ./node_modules
1111
COPY . .
1212

1313
ARG NEXT_PUBLIC_PORT=7443
14+
ARG NEXT_PUBLIC_API_URL=http://localhost:8443/api
15+
ARG NEXT_PUBLIC_WEBSITE_DOMAIN=http://localhost:7443
1416
ENV NEXT_TELEMETRY_DISABLED=1
1517
ENV PORT=$NEXT_PUBLIC_PORT
1618
ENV NEXT_PUBLIC_PORT=$NEXT_PUBLIC_PORT
19+
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
20+
ENV NEXT_PUBLIC_WEBSITE_DOMAIN=$NEXT_PUBLIC_WEBSITE_DOMAIN
1721

1822
RUN yarn build && \
1923
rm -rf node_modules/.cache

0 commit comments

Comments
 (0)