Skip to content

Commit 1033e02

Browse files
authored
feat: add coder server postgres-builtin-serve to run the built-in DB (#2997)
1 parent eebf0dd commit 1033e02

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

cli/server.go

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ import (
2222
"strings"
2323
"time"
2424

25-
"github.com/coder/coder/buildinfo"
26-
"github.com/coder/coder/cryptorand"
27-
"github.com/coder/coder/provisioner/echo"
28-
2925
"github.com/coreos/go-systemd/daemon"
3026
embeddedpostgres "github.com/fergusstrange/embedded-postgres"
3127
"github.com/google/go-github/v43/github"
@@ -45,6 +41,7 @@ import (
4541

4642
"cdr.dev/slog"
4743
"cdr.dev/slog/sloggers/sloghuman"
44+
"github.com/coder/coder/buildinfo"
4845
"github.com/coder/coder/cli/cliflag"
4946
"github.com/coder/coder/cli/cliui"
5047
"github.com/coder/coder/cli/config"
@@ -58,6 +55,8 @@ import (
5855
"github.com/coder/coder/coderd/tracing"
5956
"github.com/coder/coder/coderd/turnconn"
6057
"github.com/coder/coder/codersdk"
58+
"github.com/coder/coder/cryptorand"
59+
"github.com/coder/coder/provisioner/echo"
6160
"github.com/coder/coder/provisioner/terraform"
6261
"github.com/coder/coder/provisionerd"
6362
"github.com/coder/coder/provisionersdk"
@@ -512,6 +511,33 @@ func server() *cobra.Command {
512511
},
513512
})
514513

514+
root.AddCommand(&cobra.Command{
515+
Use: "postgres-builtin-serve",
516+
Short: "Run the built-in PostgreSQL deployment.",
517+
RunE: func(cmd *cobra.Command, args []string) error {
518+
cfg := createConfig(cmd)
519+
logger := slog.Make(sloghuman.Sink(os.Stderr))
520+
if verbose {
521+
logger = logger.Leveled(slog.LevelDebug)
522+
}
523+
524+
url, closePg, err := startBuiltinPostgres(cmd.Context(), cfg, logger)
525+
if err != nil {
526+
return err
527+
}
528+
defer func() { _ = closePg() }()
529+
530+
cmd.Println(cliui.Styles.Code.Render("psql \"" + url + "\""))
531+
532+
stopChan := make(chan os.Signal, 1)
533+
defer signal.Stop(stopChan)
534+
signal.Notify(stopChan, os.Interrupt)
535+
536+
<-stopChan
537+
return nil
538+
},
539+
})
540+
515541
cliflag.DurationVarP(root.Flags(), &autobuildPollInterval, "autobuild-poll-interval", "", "CODER_AUTOBUILD_POLL_INTERVAL", time.Minute, "Specifies the interval at which to poll for and execute automated workspace build operations.")
516542
cliflag.StringVarP(root.Flags(), &accessURL, "access-url", "", "CODER_ACCESS_URL", "", "Specifies the external URL to access Coder.")
517543
cliflag.StringVarP(root.Flags(), &address, "address", "a", "CODER_ADDRESS", "127.0.0.1:3000", "The address to serve the API and dashboard.")

0 commit comments

Comments
 (0)