Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add automatically setup PostgreSQL database for simple production setupΒ #2321

Closed
@kylecarbs

Description

@kylecarbs

The requirement of a PostgreSQL database to run a production deployment of Coder has led us to create dev mode, which spawns an in-memory database for tinkering with Coder. A downside of this is data loss on exit, which can leave hanging cloud resources.

The ideal user experience is to install and run PostgreSQL transparently so all data is persisted. Using embedded-postgres, we can achieve this in a few lines of code:

ep := embeddedpostgres.NewDatabase(
	embeddedpostgres.DefaultConfig().
		BinariesPath(config.PostgresBinPath()).
		DataPath(config.PostgresDataPath()).
		RuntimePath(config.PostgresRuntimePath()).
		Username(username).
		Password(password).
		Database(database).
		Port(uint32(tcpAddr.Port)),
)
err = ep.Start()
if err != nil {
	return err
}
defer ep.Stop()

embedded-postgres is tested on Mac, Windows, and Linux. This allows us to remove dev more entirely, allowing setup to become:

$ coder server
> To use an external PostgreSQL database, specify `CODER_PG_CONNECTION_URL`.
> Would you like Coder to start a PostgreSQL database for you? *yes* 

Our systemd default would specify this via the command line, allowing for:

# Install Coder
$ curl -fsSL https://coder.com/install.sh | sh

# Start Coder
$ sudo service coder start

# Login to Coder
$ coder login http://localhost:3000

--dev would be removed, as it's likely to cause more setup confusion than it solves. Users can access the database by running:

$ coder server pg

This will output the embedded database connection information, allowing for backups, data migration, and all other functionality of a normal PostgreSQL database.

Will CLI tests use embedded-postgres?

Nope, we'll keep some flag to allow for the in-memory database to be used for speed.

Will we still create an initial user automatically?

Nope, this should simplify and merge these user experiences. On dev mode right now, we automatically create and authenticate for easy setup. We will no longer do this.

Will dogfood user an embedded-postgres?

Yes.

Will we recommend customers to use embedded-postgres in production?

I'd recommend they backup the ~/.config/coder/postgres directory on a CRON, but it should be safe to use.

Will migrations work?

Yes, it's just a normal PostgreSQL database, but started by Coder.

Metadata

Metadata

Assignees

Labels

apiArea: HTTP API

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions