Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow for postgres image to be specified #2158

Merged
merged 1 commit into from
Jul 26, 2024

Conversation

stuartwdouglas
Copy link
Collaborator

Also change the default to 15.4 to match production

fixes #2111

@stuartwdouglas stuartwdouglas requested review from a team and worstell and removed request for a team July 24, 2024 23:09
@ftl-robot ftl-robot mentioned this pull request Jul 24, 2024
@@ -44,6 +44,7 @@ type serveCmd struct {
Stop bool `help:"Stop the running FTL instance. Can be used with --background to restart the server" default:"false"`
StartupTimeout time.Duration `help:"Timeout for the server to start up." default:"1m"`
ObservabilityConfig observability.Config `embed:"" prefix:"o11y-"`
DatabaseImage string `help:"The container image to start for the database" default:"postgres:15.4" env:"FTL_DATABASE_IMAGE"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: formatting

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs some work, it seems like something is still starting the old container

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would postgres:latest be a better default? (not sure if that even works)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The linked ticket was about aligning versions with the production database. One issue with using latest in general is that versions can change underneath you, meaning that code that previously worked can suddenly start to fail.

@stuartwdouglas stuartwdouglas force-pushed the stuartwdouglas/2111 branch 6 times, most recently from 512dc3b to 34c4f1b Compare July 25, 2024 02:53
Copy link
Collaborator

@alecthomas alecthomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM if we think it's necessary.

}
for _, container := range containers {
if container.Image != image {
return false, fmt.Errorf("expecting to use container image %s for container with name %s, bit it was already running with image %s. please delete the container or select a different database image", image, name, container.Image)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go error messages need to be composable by concatenation, so they shouldn't include full stops or full sentences (in general). Instead use ",", ":" or ";" or similar.

Suggested change
return false, fmt.Errorf("expecting to use container image %s for container with name %s, bit it was already running with image %s. please delete the container or select a different database image", image, name, container.Image)
return false, fmt.Errorf("expecting to use container image %s for container with name %s, bit it was already running with image %s, please delete the container or select a different database image", image, name, container.Image)

@@ -44,6 +44,7 @@ type serveCmd struct {
Stop bool `help:"Stop the running FTL instance. Can be used with --background to restart the server" default:"false"`
StartupTimeout time.Duration `help:"Timeout for the server to start up." default:"1m"`
ObservabilityConfig observability.Config `embed:"" prefix:"o11y-"`
DatabaseImage string `help:"The container image to start for the database" default:"postgres:15.4" env:"FTL_DATABASE_IMAGE"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we want this to be configurable? FTL itself will require a specific (minimum, probably) DB version, which shouldn't be configurable in general by users. I can see it being useful for debugging though, so maybe it could be a hidden:"" flag?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured it would be useful for debugging, if we end up with production environments with different versions installed.

@@ -105,28 +115,26 @@ func Run(ctx context.Context, image, name string, hostPort, containerPort int, v
}

// RunDB runs a new detached postgres container with the given name and exposed port.
func RunDB(ctx context.Context, name string, port int) error {
func RunDB(ctx context.Context, name string, port int, image string) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We lean on Option[T] heavily in the codebase where semantically relevant, rather than implicit zero values, so let's replace this with optional.Option[string] to make it clear that it can be omitted.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that RunDB does actually need this, it is DoesExist where it is optional

@@ -37,8 +37,18 @@ func DoesExist(ctx context.Context, name string) (bool, error) {
if err != nil {
return false, fmt.Errorf("failed to list containers: %w", err)
}

return len(containers) > 0, nil
if len(containers) > 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style comment: we practice return-early-return-often, so in this case we'd invert a few of these if cases and unindent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@stuartwdouglas
Copy link
Collaborator Author

Thinking about it I might just make the error on wrong DB version a warning, otherwise it is going to break peoples development environments and it is likely not worth it at this stage.

Also change the default to 15.4 to match production

fixes #2111
@stuartwdouglas stuartwdouglas merged commit be71435 into main Jul 26, 2024
59 checks passed
@stuartwdouglas stuartwdouglas deleted the stuartwdouglas/2111 branch July 26, 2024 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make local env use same postgres version as production
4 participants