Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions internal/functions/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ func Run(ctx context.Context, slugs []string, useDocker bool, noVerifyJWT *bool,
if utils.IsDockerRunning(ctx) {
opt = function.WithBundler(NewDockerBundler(fsys))
} else {
for slug, fc := range functionConfig {
if len(fc.StaticFiles) > 0 {
return errors.Errorf("--use-docker was specified but Docker is not running. Function %s requires Docker to bundle static files. Please start Docker or omit the flag.", slug)
}
}
fmt.Fprintln(os.Stderr, utils.Yellow("WARNING:"), "Docker is not running")
}
}
Expand Down
28 changes: 28 additions & 0 deletions internal/functions/deploy/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,34 @@ import_map = "./import_map.json"
assert.ErrorContains(t, err, "No Functions specified or found in supabase/functions")
})

t.Run("throws error on static files without docker", func(t *testing.T) {
t.Cleanup(func() { clear(utils.Config.Functions) })
// Setup in-memory fs
fsys := afero.NewMemMapFs()
require.NoError(t, utils.WriteConfig(fsys, false))
f, err := fsys.OpenFile(utils.ConfigPath, os.O_APPEND|os.O_WRONLY, 0600)
require.NoError(t, err)
_, err = f.WriteString(`
[functions.` + slug + `]
static_files = ["./static/*"]
`)
require.NoError(t, err)
require.NoError(t, f.Close())
require.NoError(t, afero.WriteFile(fsys, filepath.Join(utils.FunctionsDir, slug, "index.ts"), []byte{}, 0644))
// Setup valid access token
token := apitest.RandomAccessToken(t)
t.Setenv("SUPABASE_ACCESS_TOKEN", string(token))
// Setup mock api
defer gock.OffAll()
gock.New(dockerHost).
Head("/_ping").
Reply(http.StatusServiceUnavailable)
// Run test
err = Run(context.Background(), []string{slug}, true, nil, "", 1, false, fsys)
// Check error
assert.ErrorContains(t, err, "--use-docker was specified but Docker is not running")
})

t.Run("verify_jwt param falls back to config", func(t *testing.T) {
t.Cleanup(func() { clear(utils.Config.Functions) })
// Setup in-memory fs
Expand Down
Loading