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

compose: refactor to add alpha switch #4500

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions cli/azd/internal/repository/app_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/azure/azure-dev/cli/azd/internal/scaffold"
"github.com/azure/azure-dev/cli/azd/internal/tracing"
"github.com/azure/azure-dev/cli/azd/internal/tracing/fields"
"github.com/azure/azure-dev/cli/azd/pkg/alpha"
"github.com/azure/azure-dev/cli/azd/pkg/apphost"
"github.com/azure/azure-dev/cli/azd/pkg/environment"
"github.com/azure/azure-dev/cli/azd/pkg/environment/azdcontext"
Expand Down Expand Up @@ -242,9 +243,13 @@ func (i *Initializer) InitFromApp(
tracing.SetUsageAttributes(fields.AppInitLastStep.String("config"))

// Create the infra spec
infraSpec, err := i.infraSpecFromDetect(ctx, detect)
if err != nil {
return err
var infraSpec *scaffold.InfraSpec
if !i.features.IsEnabled(alpha.Compose) { // backwards compatibility
spec, err := i.infraSpecFromDetect(ctx, detect)
if err != nil {
return err
}
infraSpec = &spec
}

// Prompt for environment before proceeding with generation
Expand All @@ -265,14 +270,16 @@ func (i *Initializer) InitFromApp(
}
i.console.StopSpinner(ctx, title, input.StepDone)

title = "Generating Infrastructure as Code files in " + output.WithHighLightFormat("./infra")
i.console.ShowSpinner(ctx, title, input.Step)
err = i.genFromInfra(ctx, azdCtx, infraSpec)
if err != nil {
i.console.StopSpinner(ctx, title, input.GetStepResultFormat(err))
return err
if infraSpec != nil {
title = "Generating Infrastructure as Code files in " + output.WithHighLightFormat("./infra")
i.console.ShowSpinner(ctx, title, input.Step)
err = i.genFromInfra(ctx, azdCtx, *infraSpec)
if err != nil {
i.console.StopSpinner(ctx, title, input.GetStepResultFormat(err))
return err
}
i.console.StopSpinner(ctx, title, input.StepDone)
}
i.console.StopSpinner(ctx, title, input.StepDone)

return nil
}
Expand Down
3 changes: 2 additions & 1 deletion cli/azd/test/functional/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func Test_CLI_Init_CanUseTemplate(t *testing.T) {
require.FileExists(t, filepath.Join(dir, "README.md"))
}

func Test_CLI_Init_From_App(t *testing.T) {
func Test_CLI_Init_From_App_With_Infra(t *testing.T) {
// running this test in parallel is ok as it uses a t.TempDir()
t.Parallel()
ctx, cancel := newTestContext(t)
Expand All @@ -189,6 +189,7 @@ func Test_CLI_Init_From_App(t *testing.T) {
cli.WorkingDirectory = dir
cli.Env = append(os.Environ(), "AZURE_LOCATION=eastus2")
cli.Env = append(cli.Env, "AZD_CONFIG_DIR="+dir)
cli.Env = append(cli.Env, "AZD_ALPHA_ENABLE_COMPOSE=0")
cli.Env = append(cli.Env, "AZURE_DEV_COLLECT_TELEMETRY=no")

err = copySample(appDir, "py-postgres")
Expand Down
Loading