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

Prod deploy #2622

Merged
merged 9 commits into from
Aug 27, 2024
65 changes: 64 additions & 1 deletion api/beta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,8 @@ paths:
responses:
'201':
description: ''
'403':
description: ''
'500':
description: Failed to set up read replica
tags:
Expand Down Expand Up @@ -1344,6 +1346,8 @@ paths:
responses:
'201':
description: ''
'403':
description: ''
'500':
description: Failed to remove read replica
tags:
Expand Down Expand Up @@ -1605,7 +1609,7 @@ paths:
/v1/projects/{ref}/config/auth/third-party-auth:
post:
operationId: createTPAForProject
summary: '[Alpha] Creates a new third-party auth integration'
summary: Creates a new third-party auth integration
parameters:
- name: ref
required: true
Expand Down Expand Up @@ -2439,6 +2443,15 @@ components:
type: boolean
persistent:
type: boolean
status:
enum:
- CREATING_PROJECT
- RUNNING_MIGRATIONS
- MIGRATIONS_PASSED
- MIGRATIONS_FAILED
- FUNCTIONS_DEPLOYED
- FUNCTIONS_FAILED
type: string
BranchResponse:
type: object
properties:
Expand Down Expand Up @@ -2826,10 +2839,14 @@ components:
CreateBranchBody:
type: object
properties:
desired_instance_size:
$ref: '#/components/schemas/DesiredInstanceSize'
branch_name:
type: string
git_branch:
type: string
persistent:
type: boolean
region:
type: string
required:
Expand Down Expand Up @@ -3900,6 +3917,26 @@ components:
mfa_max_enrolled_factors:
type: number
nullable: true
mfa_totp_enroll_enabled:
type: boolean
nullable: true
mfa_totp_verify_enabled:
type: boolean
nullable: true
mfa_phone_enroll_enabled:
type: boolean
nullable: true
mfa_phone_verify_enabled:
type: boolean
nullable: true
mfa_phone_otp_length:
type: number
mfa_phone_template:
type: string
nullable: true
mfa_phone_max_frequency:
type: number
nullable: true
password_hibp_enabled:
type: boolean
nullable: true
Expand Down Expand Up @@ -4166,6 +4203,13 @@ components:
- mailer_templates_reauthentication_content
- mailer_templates_recovery_content
- mfa_max_enrolled_factors
- mfa_totp_enroll_enabled
- mfa_totp_verify_enabled
- mfa_phone_enroll_enabled
- mfa_phone_verify_enabled
- mfa_phone_otp_length
- mfa_phone_template
- mfa_phone_max_frequency
- password_hibp_enabled
- password_min_length
- password_required_characters
Expand Down Expand Up @@ -4585,6 +4629,24 @@ components:
type: number
api_max_request_duration:
type: number
mfa_totp_enroll_enabled:
type: boolean
mfa_totp_verify_enabled:
type: boolean
mfa_phone_enroll_enabled:
type: boolean
mfa_phone_verify_enabled:
type: boolean
mfa_phone_max_frequency:
type: number
minimum: 0
maximum: 32767
mfa_phone_otp_length:
type: number
minimum: 0
maximum: 32767
mfa_phone_template:
type: string
CreateThirdPartyAuthBody:
type: object
properties:
Expand Down Expand Up @@ -4946,6 +5008,7 @@ components:
- PENDING
- REMOVED
- ARCHIVED
- CANCELLED
is_physical_backup:
type: boolean
inserted_at:
Expand Down
2 changes: 1 addition & 1 deletion cmd/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var (
viper.Set("WORKDIR", workdir)
}
}
client := utils.GetGtihubClient(ctx)
client := utils.GetGitHubClient(ctx)
templates, err := bootstrap.ListSamples(ctx, client)
if err != nil {
return err
Expand Down
65 changes: 50 additions & 15 deletions cmd/branches.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,31 @@ var (
}

branchRegion = utils.EnumFlag{
Allowed: make([]string, len(utils.FlyRegions)),
Allowed: flyRegions(),
}
persistent bool

branchCreateCmd = &cobra.Command{
Use: "create [name]",
Short: "Create a preview branch",
Long: "Create a preview branch for the linked project.",
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
var name string
var body api.CreateBranchBody
if len(args) > 0 {
name = args[0]
body.BranchName = args[0]
}
return create.Run(cmd.Context(), name, branchRegion.Value, afero.NewOsFs())
cmdFlags := cmd.Flags()
if cmdFlags.Changed("region") {
body.Region = &branchRegion.Value
}
if cmdFlags.Changed("size") {
body.DesiredInstanceSize = (*api.DesiredInstanceSize)(&size.Value)
}
if cmdFlags.Changed("persistent") {
body.Persistent = &persistent
}
return create.Run(cmd.Context(), body, afero.NewOsFs())
},
}

Expand Down Expand Up @@ -76,6 +87,15 @@ var (
},
}

branchStatus = utils.EnumFlag{
Allowed: []string{
string(api.BranchResponseStatusRUNNINGMIGRATIONS),
string(api.BranchResponseStatusMIGRATIONSPASSED),
string(api.BranchResponseStatusMIGRATIONSFAILED),
string(api.BranchResponseStatusFUNCTIONSDEPLOYED),
string(api.BranchResponseStatusFUNCTIONSFAILED),
},
}
branchName string
gitBranch string
resetOnPush bool
Expand All @@ -84,18 +104,25 @@ var (
Use: "update [branch-id]",
Short: "Update a preview branch",
Long: "Update a preview branch by its ID.",
Args: cobra.ExactArgs(1),
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cmdFlags := cmd.Flags()
var body api.UpdateBranchBody
if cmd.Flags().Changed("name") {
if cmdFlags.Changed("name") {
body.BranchName = &branchName
}
if cmd.Flags().Changed("git-branch") {
if cmdFlags.Changed("git-branch") {
body.GitBranch = &gitBranch
}
if cmd.Flags().Changed("reset-on-push") {
if cmdFlags.Changed("reset-on-push") {
body.ResetOnPush = &resetOnPush
}
if cmdFlags.Changed("persistent") {
body.Persistent = &persistent
}
if cmdFlags.Changed("status") {
body.Status = (*api.UpdateBranchBodyStatus)(&branchStatus.Value)
}
ctx := cmd.Context()
if len(args) == 0 {
if err := promptBranchId(ctx, flags.ProjectRef); err != nil {
Expand Down Expand Up @@ -139,28 +166,36 @@ var (
func init() {
branchFlags := branchesCmd.PersistentFlags()
branchFlags.StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
// Setup enum flags
i := 0
for k := range utils.FlyRegions {
branchRegion.Allowed[i] = k
i++
}
sort.Strings(branchRegion.Allowed)
createFlags := branchCreateCmd.Flags()
createFlags.Var(&branchRegion, "region", "Select a region to deploy the branch database.")
createFlags.Var(&size, "size", "Select a desired instance size for the branch database.")
createFlags.BoolVar(&persistent, "persistent", false, "Whether to create a persistent branch.")
branchesCmd.AddCommand(branchCreateCmd)
branchesCmd.AddCommand(branchListCmd)
branchesCmd.AddCommand(branchGetCmd)
updateFlags := branchUpdateCmd.Flags()
updateFlags.StringVar(&branchName, "name", "", "Rename the preview branch.")
updateFlags.StringVar(&gitBranch, "git-branch", "", "Change the associated git branch.")
updateFlags.BoolVar(&resetOnPush, "reset-on-push", false, "Reset the preview branch on git push.")
updateFlags.BoolVar(&persistent, "persistent", false, "Switch between ephemeral and persistent branch.")
updateFlags.Var(&branchStatus, "status", "Override the current branch status.")
branchesCmd.AddCommand(branchUpdateCmd)
branchesCmd.AddCommand(branchDeleteCmd)
branchesCmd.AddCommand(branchDisableCmd)
rootCmd.AddCommand(branchesCmd)
}

func flyRegions() []string {
result := make([]string, len(utils.FlyRegions))
i := 0
for k := range utils.FlyRegions {
result[i] = k
i++
}
sort.Strings(result)
return result
}

func promptBranchId(ctx context.Context, ref string) error {
resp, err := utils.GetSupabase().V1ListAllBranchesWithResponse(ctx, ref)
if err != nil {
Expand Down
43 changes: 33 additions & 10 deletions cmd/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,26 @@ var (
dbPassword string

region = utils.EnumFlag{
Allowed: make([]string, len(utils.RegionMap)),
Allowed: awsRegions(),
}
plan = utils.EnumFlag{
Allowed: []string{string(api.V1CreateProjectBodyPlanFree), string(api.V1CreateProjectBodyPlanPro)},
Value: string(api.V1CreateProjectBodyPlanFree),
}
size = utils.EnumFlag{
Allowed: []string{
string(api.Micro),
string(api.Small),
string(api.Medium),
string(api.Large),
string(api.Xlarge),
string(api.N2xlarge),
string(api.N4xlarge),
string(api.N8xlarge),
string(api.N12xlarge),
string(api.N16xlarge),
},
}

projectsCreateCmd = &cobra.Command{
Use: "create [project name]",
Expand All @@ -55,12 +69,16 @@ var (
if len(args) > 0 {
projectName = args[0]
}
return create.Run(cmd.Context(), api.V1CreateProjectBody{
body := api.V1CreateProjectBody{
Name: projectName,
OrganizationId: orgId,
DbPass: dbPassword,
Region: api.V1CreateProjectBodyRegion(region.Value),
}, afero.NewOsFs())
}
if cmd.Flags().Changed("size") {
body.DesiredInstanceSize = (*api.DesiredInstanceSize)(&size.Value)
}
return create.Run(cmd.Context(), body, afero.NewOsFs())
},
}

Expand Down Expand Up @@ -108,13 +126,6 @@ var (
)

func init() {
// Setup enum flags
i := 0
for k := range utils.RegionMap {
region.Allowed[i] = k
i++
}
sort.Strings(region.Allowed)
// Add flags to cobra command
createFlags := projectsCreateCmd.Flags()
createFlags.BoolVarP(&interactive, "interactive", "i", true, "Enables interactive mode.")
Expand All @@ -124,6 +135,7 @@ func init() {
createFlags.Var(&region, "region", "Select a region close to you for the best performance.")
createFlags.Var(&plan, "plan", "Select a plan that suits your needs.")
cobra.CheckErr(createFlags.MarkHidden("plan"))
createFlags.Var(&size, "size", "Select a desired instance size for your project.")
cobra.CheckErr(viper.BindPFlag("DB_PASSWORD", createFlags.Lookup("db-password")))

apiKeysFlags := projectsApiKeysCmd.Flags()
Expand All @@ -136,3 +148,14 @@ func init() {
projectsCmd.AddCommand(projectsApiKeysCmd)
rootCmd.AddCommand(projectsCmd)
}

func awsRegions() []string {
result := make([]string, len(utils.RegionMap))
i := 0
for k := range utils.RegionMap {
result[i] = k
i++
}
sort.Strings(result)
return result
}
2 changes: 1 addition & 1 deletion internal/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func Run(ctx context.Context, starter StarterTemplate, fsys afero.Fs, options ..
}
// 0. Download starter template
if len(starter.Url) > 0 {
client := utils.GetGtihubClient(ctx)
client := utils.GetGitHubClient(ctx)
if err := downloadSample(ctx, client, starter.Url, fsys); err != nil {
return err
}
Expand Down
13 changes: 5 additions & 8 deletions internal/branches/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,20 @@ import (
"github.com/supabase/cli/pkg/api"
)

func Run(ctx context.Context, name, region string, fsys afero.Fs) error {
func Run(ctx context.Context, body api.CreateBranchBody, fsys afero.Fs) error {
gitBranch := keys.GetGitBranchOrDefault("", fsys)
if len(name) == 0 && len(gitBranch) > 0 {
if len(body.BranchName) == 0 && len(gitBranch) > 0 {
title := fmt.Sprintf("Do you want to create a branch named %s?", utils.Aqua(gitBranch))
if shouldCreate, err := utils.NewConsole().PromptYesNo(ctx, title, true); err != nil {
return err
} else if !shouldCreate {
return errors.New(context.Canceled)
}
name = gitBranch
body.BranchName = gitBranch
}
body.GitBranch = &gitBranch

resp, err := utils.GetSupabase().V1CreateABranchWithResponse(ctx, flags.ProjectRef, api.V1CreateABranchJSONRequestBody{
BranchName: name,
GitBranch: &gitBranch,
Region: &region,
})
resp, err := utils.GetSupabase().V1CreateABranchWithResponse(ctx, flags.ProjectRef, body)
if err != nil {
return errors.Errorf("failed to create preview branch: %w", err)
}
Expand Down
Loading
Loading