Skip to content

Commit b3ae2c2

Browse files
Merge branch 'feat-profiles' of https://github.com/appwrite/console into feat-profiles-org-platform
2 parents 692991e + 39e37f0 commit b3ae2c2

4 files changed

Lines changed: 95 additions & 5 deletions

File tree

Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,8 @@ EXPOSE 80
5757

5858
COPY docker/nginx.conf /etc/nginx/conf.d/default.conf
5959
COPY --from=build /app/build /usr/share/nginx/html/console
60+
61+
# feat-profiles
62+
RUN mkdir -p /app
63+
COPY docker/generate-env.sh /app/generate-env.sh
64+
RUN chmod +x /app/generate-env.sh

docker/generate-env.sh

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# Regenerate env.js from runtime PUBLIC_ environment variables
5+
6+
echo "========================================="
7+
echo "Regenerating env.js from environment variables..."
8+
echo "========================================="
9+
10+
# Check if any PUBLIC_ env vars exist
11+
public_vars=$(printenv | grep '^PUBLIC_' | awk -F= '{print $1}' | sort)
12+
13+
if [ -z "$public_vars" ]; then
14+
echo "⚠ WARNING: No PUBLIC_ environment variables found!"
15+
echo "The application may not work correctly."
16+
echo "Expected variables like:"
17+
echo " - PUBLIC_APPWRITE_ENDPOINT"
18+
echo " - PUBLIC_CONSOLE_MODE"
19+
echo " - PUBLIC_CONSOLE_PROFILE"
20+
echo "========================================="
21+
fi
22+
23+
# Build JSON object from PUBLIC_ env vars
24+
env_json="{"
25+
first=true
26+
27+
for var in $public_vars; do
28+
value=$(printenv "$var")
29+
30+
# Escape special characters for JSON
31+
escaped_value=$(echo "$value" | sed 's/\\/\\\\/g' | sed 's/"/\\"/g')
32+
33+
if [ "$first" = true ]; then
34+
first=false
35+
else
36+
env_json="$env_json,"
37+
fi
38+
39+
env_json="$env_json\"$var\":\"$escaped_value\""
40+
echo "$var=$value"
41+
done
42+
43+
env_json="$env_json}"
44+
45+
# Write to env.js
46+
# Use CONSOLE_BUILD_PATH env var if set, otherwise try common locations
47+
if [ -n "$CONSOLE_BUILD_PATH" ]; then
48+
env_file="$CONSOLE_BUILD_PATH/_app/env.js"
49+
elif [ -f "/usr/share/nginx/html/console/_app/env.js" ]; then
50+
env_file="/usr/share/nginx/html/console/_app/env.js"
51+
elif [ -f "./build/_app/env.js" ]; then
52+
env_file="./build/_app/env.js"
53+
elif [ -f "./_app/env.js" ]; then
54+
env_file="./_app/env.js"
55+
else
56+
echo "⚠ Error: Cannot find env.js file. Set CONSOLE_BUILD_PATH env var to the build directory."
57+
echo "Searched in:"
58+
echo " - /usr/share/nginx/html/console/_app/env.js"
59+
echo " - ./build/_app/env.js"
60+
echo " - ./_app/env.js"
61+
exit 1
62+
fi
63+
64+
echo "Writing to: $env_file"
65+
echo "export const env=$env_json" > "$env_file"
66+
67+
# Verify the file was written
68+
if [ ! -f "$env_file" ]; then
69+
echo "⚠ Error: Failed to write $env_file"
70+
exit 1
71+
fi
72+
73+
echo "✓ Successfully generated $env_file"
74+
echo "File contents:"
75+
cat "$env_file"
76+
77+
# NUKE all pre-compressed files so nginx serves fresh content
78+
echo "Nuking all .br and .gz files..."
79+
find /usr/share/nginx/html/console -type f \( -name "*.br" -o -name "*.gz" \) -delete
80+
echo "✓ Nuked all compressed files"
81+
82+
echo "========================================="
83+
echo "Starting nginx..."
84+
echo "========================================="
85+
86+
exec "$@"

src/lib/profiles/index.svelte.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { asset, resolve } from '$app/paths';
22
import type { ResolvedPathname } from '$app/types';
3-
import { PUBLIC_CONSOLE_PROFILE } from '$env/static/public';
43
import { Platform } from '@appwrite.io/console';
4+
import { env } from '$env/dynamic/public';
55

66
export const enum ProfileMode {
77
STUDIO = 'studio',
@@ -118,7 +118,7 @@ export const studio: Profile = {
118118
};
119119

120120
const resolver = $derived(() => {
121-
switch (PUBLIC_CONSOLE_PROFILE) {
121+
switch (env.PUBLIC_CONSOLE_PROFILE) {
122122
case 'studio':
123123
return studio;
124124
default:

src/lib/studio/studio-widget.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { PUBLIC_APPWRITE_ENDPOINT, PUBLIC_AI_SERVICE_BASE_URL } from '$env/static/public';
21
import { env } from '$env/dynamic/public';
32
import { app } from '$lib/stores/app';
43
import { get } from 'svelte/store';
@@ -283,8 +282,8 @@ export async function initImagine(
283282
if (!configInitialized) {
284283
initImagineConfig(
285284
{
286-
AI_SERVICE_ENDPOINT: PUBLIC_AI_SERVICE_BASE_URL,
287-
APPWRITE_ENDPOINT: PUBLIC_APPWRITE_ENDPOINT,
285+
AI_SERVICE_ENDPOINT: env.PUBLIC_AI_SERVICE_BASE_URL,
286+
APPWRITE_ENDPOINT: env.PUBLIC_APPWRITE_ENDPOINT,
288287
APPWRITE_SITES_BASE_URL: ''
289288
},
290289
{

0 commit comments

Comments
 (0)