70
70
71
71
echo -e " \e[34m[Info] Using config file at: '$CONFIG_PATH '.\e[0m"
72
72
73
- # Update nextjs public env variables w/o requiring a rebuild.
73
+ # Update NextJs public env variables w/o requiring a rebuild.
74
74
# @see: https://phase.dev/blog/nextjs-public-runtime-variables/
75
+ {
76
+ # Infer NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED if it is not set
77
+ if [ -z " $NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED " ] && [ ! -z " $SOURCEBOT_TELEMETRY_DISABLED " ]; then
78
+ export NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED=" $SOURCEBOT_TELEMETRY_DISABLED "
79
+ fi
75
80
76
- # Infer NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED if it is not set
77
- if [ -z " $NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED " ] && [ ! -z " $SOURCEBOT_TELEMETRY_DISABLED " ]; then
78
- export NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED =" $SOURCEBOT_TELEMETRY_DISABLED "
79
- fi
81
+ # Infer NEXT_PUBLIC_SOURCEBOT_VERSION if it is not set
82
+ if [ -z " $NEXT_PUBLIC_SOURCEBOT_VERSION " ] && [ ! -z " $SOURCEBOT_VERSION " ]; then
83
+ export NEXT_PUBLIC_SOURCEBOT_VERSION =" $SOURCEBOT_VERSION "
84
+ fi
80
85
81
- # Infer NEXT_PUBLIC_SOURCEBOT_VERSION if it is not set
82
- if [ -z " $NEXT_PUBLIC_SOURCEBOT_VERSION " ] && [ ! -z " $SOURCEBOT_VERSION " ]; then
83
- export NEXT_PUBLIC_SOURCEBOT_VERSION=" $SOURCEBOT_VERSION "
84
- fi
86
+ # Iterate over all .js files in .next & public, making substitutions for the `BAKED_` sentinal values
87
+ # with their actual desired runtime value.
88
+ find /app/packages/web/public /app/packages/web/.next -type f -name " *.js" |
89
+ while read file; do
90
+ sed -i " s|BAKED_NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED|${NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED} |g" " $file "
91
+ sed -i " s|BAKED_NEXT_PUBLIC_SOURCEBOT_VERSION|${NEXT_PUBLIC_SOURCEBOT_VERSION} |g" " $file "
92
+ done
93
+ }
94
+
95
+
96
+ # Update specifically NEXT_PUBLIC_DOMAIN_SUB_PATH w/o requiring a rebuild.
97
+ # Ultimately, the DOMAIN_SUB_PATH sets the `basePath` param in the next.config.mjs.
98
+ # Similar to above, we pass in a `BAKED_` sentinal value into next.config.mjs at build
99
+ # time. Unlike above, the `basePath` configuration is set in files other than just javascript
100
+ # code (e.g., manifest files, css files, etc.), so this section has subtle differences.
101
+ #
102
+ # @see: https://nextjs.org/docs/app/api-reference/next-config-js/basePath
103
+ # @see: https://phase.dev/blog/nextjs-public-runtime-variables/
104
+ {
105
+ if [ ! -z " $DOMAIN_SUB_PATH " ]; then
106
+ # If the sub-path is "/", this creates problems with certain replacements. For example:
107
+ # /BAKED_NEXT_PUBLIC_DOMAIN_SUB_PATH/_next/image -> //_next/image (notice the double slash...)
108
+ # To get around this, we default to an empty sub-path, which is the default when no sub-path is defined.
109
+ if [ " $DOMAIN_SUB_PATH " = " /" ]; then
110
+ DOMAIN_SUB_PATH=" "
111
+
112
+ # Otherwise, we need to ensure that the sub-path starts with a slash, since this is a requirement
113
+ # for the basePath property. For example, assume DOMAIN_SUB_PATH=/bot, then:
114
+ # /BAKED_NEXT_PUBLIC_DOMAIN_SUB_PATH/_next/image -> /bot/_next/image
115
+ elif [[ ! " $DOMAIN_SUB_PATH " =~ ^/ ]]; then
116
+ DOMAIN_SUB_PATH=" /$DOMAIN_SUB_PATH "
117
+ fi
118
+ fi
119
+
120
+ if [ ! -z " $DOMAIN_SUB_PATH " ]; then
121
+ echo -e " \e[34m[Info] DOMAIN_SUB_PATH was set to " $DOMAIN_SUB_PATH " . Overriding default path.\e[0m"
122
+ fi
123
+
124
+ # Always set NEXT_PUBLIC_DOMAIN_SUB_PATH to DOMAIN_SUB_PATH (even if it is empty!!)
125
+ export NEXT_PUBLIC_DOMAIN_SUB_PATH=" $DOMAIN_SUB_PATH "
126
+
127
+ # Iterate over _all_ files in the web directory, making substitutions for the `BAKED_` sentinal values
128
+ # with their actual desired runtime value.
129
+ find /app/packages/web -type f |
130
+ while read file; do
131
+ # @note: the leading "/" is required here as it is included at build time. See Dockerfile.
132
+ sed -i " s|/BAKED_NEXT_PUBLIC_DOMAIN_SUB_PATH|${NEXT_PUBLIC_DOMAIN_SUB_PATH} |g" " $file "
133
+ done
134
+ }
85
135
86
- find /app/packages/web/public /app/packages/web/.next -type f -name " *.js" |
87
- while read file; do
88
- sed -i " s|BAKED_NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED|${NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED} |g" " $file "
89
- sed -i " s|BAKED_NEXT_PUBLIC_SOURCEBOT_VERSION|${NEXT_PUBLIC_SOURCEBOT_VERSION} |g" " $file "
90
- done
91
136
137
+ # Run supervisord
92
138
exec supervisord -c /etc/supervisor/conf.d/supervisord.conf
0 commit comments