@@ -14,6 +14,7 @@ import (
14
14
"github.com/docker/docker/pkg/stdcopy"
15
15
"github.com/joho/godotenv"
16
16
"github.com/spf13/afero"
17
+ "github.com/spf13/viper"
17
18
"github.com/supabase/cli/internal/utils"
18
19
)
19
20
@@ -40,7 +41,11 @@ func ParseEnvFile(envFilePath string) ([]string, error) {
40
41
return env , nil
41
42
}
42
43
43
- func Run (ctx context.Context , slug string , envFilePath string , noVerifyJWT * bool , importMapPath string , fsys afero.Fs ) error {
44
+ func Run (ctx context.Context , slug string , envFilePath string , noVerifyJWT * bool , importMapPath string , serveAll bool , fsys afero.Fs ) error {
45
+ if serveAll {
46
+ return runServeAll (ctx , envFilePath , noVerifyJWT , importMapPath , fsys )
47
+ }
48
+
44
49
// 1. Sanity checks.
45
50
{
46
51
if err := utils .LoadConfigFS (fsys ); err != nil {
@@ -216,3 +221,94 @@ func Run(ctx context.Context, slug string, envFilePath string, noVerifyJWT *bool
216
221
fmt .Println ("Stopped serving " + utils .Bold (localFuncDir ))
217
222
return nil
218
223
}
224
+
225
+ func runServeAll (ctx context.Context , envFilePath string , noVerifyJWT * bool , importMapPath string , fsys afero.Fs ) error {
226
+ // 1. Sanity checks.
227
+ {
228
+ if err := utils .LoadConfigFS (fsys ); err != nil {
229
+ return err
230
+ }
231
+ if err := utils .AssertSupabaseDbIsRunning (); err != nil {
232
+ return err
233
+ }
234
+ if envFilePath != "" {
235
+ if _ , err := fsys .Stat (envFilePath ); err != nil {
236
+ return fmt .Errorf ("Failed to read env file: %w" , err )
237
+ }
238
+ }
239
+ if importMapPath != "" {
240
+ // skip
241
+ } else if f , err := fsys .Stat (utils .FallbackImportMapPath ); err == nil && ! f .IsDir () {
242
+ importMapPath = utils .FallbackImportMapPath
243
+ }
244
+ if importMapPath != "" {
245
+ if _ , err := fsys .Stat (importMapPath ); err != nil {
246
+ return fmt .Errorf ("Failed to read import map: %w" , err )
247
+ }
248
+ }
249
+ }
250
+
251
+ // 2. Parse user defined env
252
+ userEnv , err := ParseEnvFile (envFilePath )
253
+ if err != nil {
254
+ return err
255
+ }
256
+
257
+ // 3. Start container
258
+ {
259
+ _ = utils .Docker .ContainerRemove (ctx , utils .DenoRelayId , types.ContainerRemoveOptions {
260
+ RemoveVolumes : true ,
261
+ Force : true ,
262
+ })
263
+
264
+ env := []string {
265
+ "JWT_SECRET=" + utils .JWTSecret ,
266
+ "SUPABASE_URL=http://" + utils .KongId + ":8000" ,
267
+ "SUPABASE_ANON_KEY=" + utils .AnonKey ,
268
+ "SUPABASE_SERVICE_ROLE_KEY=" + utils .ServiceRoleKey ,
269
+ "SUPABASE_DB_URL=postgresql://postgres:postgres@localhost:" + strconv .FormatUint (uint64 (utils .Config .Db .Port ), 10 ) + "/postgres" ,
270
+ }
271
+ verifyJWTEnv := "VERIFY_JWT=true"
272
+ if noVerifyJWT != nil {
273
+ verifyJWTEnv = "VERIFY_JWT=false"
274
+ }
275
+ env = append (env , verifyJWTEnv )
276
+
277
+ cwd , err := os .Getwd ()
278
+ if err != nil {
279
+ return err
280
+ }
281
+
282
+ binds := []string {
283
+ filepath .Join (cwd , utils .FunctionsDir ) + ":" + relayFuncDir + ":ro,z" ,
284
+ utils .DenoRelayId + ":/root/.cache/deno:rw,z" ,
285
+ }
286
+ // If a import map path is explcitly provided, mount it as a separate file
287
+ if importMapPath != "" {
288
+ binds = append (binds , filepath .Join (cwd , importMapPath )+ ":" + customDockerImportMapPath + ":ro,z" )
289
+ }
290
+
291
+ fmt .Println ("Serving " + utils .Bold (utils .FunctionsDir ))
292
+
293
+ cmd := []string {"start" , "--dir" , relayFuncDir , "-p" , "8081" }
294
+ if viper .GetBool ("DEBUG" ) {
295
+ cmd = append (cmd , "--verbose" )
296
+ }
297
+ if err := utils .DockerRunOnceWithStream (
298
+ ctx ,
299
+ utils .EdgeRuntimeImage ,
300
+ append (env , userEnv ... ),
301
+ cmd ,
302
+ binds ,
303
+ utils .DenoRelayId ,
304
+ os .Stdout ,
305
+ os .Stderr ,
306
+ ); err != nil {
307
+ return err
308
+ }
309
+ }
310
+
311
+ fmt .Println ("Stopped serving " + utils .Bold (utils .FunctionsDir ))
312
+ return nil
313
+
314
+ }
0 commit comments