Skip to content

Commit

Permalink
fly launch: support creating Tigris Object Storage (#3403)
Browse files Browse the repository at this point in the history
* `launch`: add tigris to LaunchPlan

* `launch`: remove tigris shadow bucket from plan

supporting shadow buckets adds a lot of complexity that most users won't need for greenfield development

* `launch`: add WebsiteDomainName to tigris plan

* `launch`: provision tigris object storage
  • Loading branch information
alichay committed Apr 26, 2024
1 parent a90b7a8 commit 999091f
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 3 deletions.
42 changes: 42 additions & 0 deletions internal/command/launch/launch_databases.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/samber/lo"
fly "github.com/superfly/fly-go"
"github.com/superfly/flyctl/flypg"
"github.com/superfly/flyctl/gql"
extensions_core "github.com/superfly/flyctl/internal/command/extensions/core"
"github.com/superfly/flyctl/internal/command/postgres"
"github.com/superfly/flyctl/internal/command/redis"
Expand Down Expand Up @@ -41,6 +42,14 @@ func (state *launchState) createDatabases(ctx context.Context) error {
}
}

if state.Plan.ObjectStorage.TigrisObjectStorage != nil {
err := state.createTigrisObjectStorage(ctx)
if err != nil {
// TODO(Ali): Make error printing here better.
fmt.Fprintf(iostreams.FromContext(ctx).ErrOut, "Error creating Tigris object storage: %s\n", err)
}
}

// Run any initialization commands required for Postgres if it was installed
if state.Plan.Postgres.Provider() != nil && state.sourceInfo != nil {
for _, cmd := range state.sourceInfo.PostgresInitCommands {
Expand Down Expand Up @@ -206,3 +215,36 @@ func (state *launchState) createUpstashRedis(ctx context.Context) error {
}
return redis.AttachDatabase(ctx, db, state.Plan.AppName)
}

func (state *launchState) createTigrisObjectStorage(ctx context.Context) error {

tigrisPlan := state.Plan.ObjectStorage.TigrisObjectStorage

org, err := state.Org(ctx)
if err != nil {
return err
}

params := extensions_core.ExtensionParams{
Provider: "tigris",
Organization: org,
AppName: state.Plan.AppName,
OverrideName: tigrisPlan.Name,
OverrideRegion: state.Plan.RegionCode,
Options: gql.AddOnOptions{
"public": tigrisPlan.Public,
"accelerate": tigrisPlan.Accelerate,
"website": map[string]interface{}{
"domain_name": tigrisPlan.WebsiteDomainName,
},
},
}

_, err = extensions_core.ProvisionExtension(ctx, params)

if err != nil {
return err
}

return err
}
28 changes: 28 additions & 0 deletions internal/command/launch/plan/object_storage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package plan

type ObjectStoragePlan struct {
TigrisObjectStorage *TigrisObjectStoragePlan `json:"tigris_object_storage"`
}

func (p *ObjectStoragePlan) Provider() any {
if p == nil {
return nil
}
if p.TigrisObjectStorage != nil {
return p.TigrisObjectStorage
}
return nil
}

func DefaultObjectStorage(plan *LaunchPlan) ObjectStoragePlan {
return ObjectStoragePlan{
TigrisObjectStorage: &TigrisObjectStoragePlan{},
}
}

type TigrisObjectStoragePlan struct {
Name string `json:"name"`
Public bool `json:"public"`
Accelerate bool `json:"accelerate"`
WebsiteDomainName string `json:"website_domain_name"`
}
7 changes: 4 additions & 3 deletions internal/command/launch/plan/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ type LaunchPlan struct {
HttpServicePort int `json:"http_service_port,omitempty"`
HttpServicePortSetByScanner bool `json:"http_service_port_set_by_scanner,omitempty"`

Postgres PostgresPlan `json:"postgres"`
Redis RedisPlan `json:"redis"`
Sentry bool `json:"sentry"`
Postgres PostgresPlan `json:"postgres"`
Redis RedisPlan `json:"redis"`
Sentry bool `json:"sentry"`
ObjectStorage ObjectStoragePlan `json:"object_storage"`

ScannerFamily string `json:"scanner_family"`
FlyctlVersion version.Version `json:"flyctl_version"`
Expand Down

0 comments on commit 999091f

Please sign in to comment.