Skip to content

Commit

Permalink
compose: add command (#4527)
Browse files Browse the repository at this point in the history
`add` command that adds resource configuration to `azure.yaml`.

In this experience, users are able to proceed with running `provision` or `up` after committing the `azure.yaml` change.

Contributes to #4397,  Azure/azure-dev-pr#1682
  • Loading branch information
weikanglim authored Nov 12, 2024
1 parent db09270 commit ddafa38
Show file tree
Hide file tree
Showing 35 changed files with 2,415 additions and 200 deletions.
1 change: 1 addition & 0 deletions .vscode/cspell-github-user-aliases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ otiai10
pamelafox
pbnj
sebastianmattar
sergi
sethvargo
stretchr
theckman
Expand Down
3 changes: 3 additions & 0 deletions cli/azd/.vscode/cspell-azd-dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ devcenters
devcentersdk
devdeviceid
devel
diffmatchpatch
discarder
docf
dockerfiles
Expand All @@ -94,6 +95,7 @@ doublestar
dskip
eastus
endregion
entra
entraid
envlist
envname
Expand Down Expand Up @@ -192,6 +194,7 @@ semconv
serverfarms
servicebus
setenvs
skus
snapshotter
springapp
sqlserver
Expand Down
6 changes: 6 additions & 0 deletions cli/azd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/azure/azure-dev/cli/azd/internal"
"github.com/azure/azure-dev/cli/azd/internal/cmd"
"github.com/azure/azure-dev/cli/azd/internal/cmd/add"
"github.com/azure/azure-dev/cli/azd/internal/telemetry"
"github.com/azure/azure-dev/cli/azd/pkg/output"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -320,6 +321,11 @@ func NewRootCmd(
},
}).
UseMiddleware("hooks", middleware.NewHooksMiddleware)
root.
Add("add", &actions.ActionDescriptorOptions{
Command: add.NewAddCmd(),
ActionResolver: add.NewAddAction,
})

// Register any global middleware defined by the caller
if len(middlewareChain) > 0 {
Expand Down
18 changes: 18 additions & 0 deletions cli/azd/cmd/testdata/TestUsage-azd-add.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

Add a component to your project. (Alpha)

Usage
azd add [flags]

Flags
--docs : Opens the documentation for azd add in your web browser.
-h, --help : Gets help for add.

Global Flags
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.

Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats.


2 changes: 1 addition & 1 deletion cli/azd/internal/appdetect/appdetect.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func detectAny(ctx context.Context, detectors []projectDetector, path string, en
log.Printf("Found project %s at %s", project.Language, path)

// docker is an optional property of a project, and thus is different than other detectors
docker, err := detectDocker(path, entries)
docker, err := detectDockerInDirectory(path, entries)
if err != nil {
return nil, fmt.Errorf("detecting docker project: %w", err)
}
Expand Down
7 changes: 4 additions & 3 deletions cli/azd/internal/appdetect/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ import (
"strings"
)

func detectDocker(path string, entries []fs.DirEntry) (*Docker, error) {
func detectDockerInDirectory(path string, entries []fs.DirEntry) (*Docker, error) {
for _, entry := range entries {
if strings.ToLower(entry.Name()) == "dockerfile" {
dockerFilePath := filepath.Join(path, entry.Name())
return detectDockerFromFile(dockerFilePath)
return AnalyzeDocker(dockerFilePath)
}
}

return nil, nil
}

func detectDockerFromFile(dockerFilePath string) (*Docker, error) {
// AnalyzeDocker analyzes the Dockerfile and returns the Docker result.
func AnalyzeDocker(dockerFilePath string) (*Docker, error) {
file, err := os.Open(dockerFilePath)
if err != nil {
return nil, fmt.Errorf("reading Dockerfile at %s: %w", dockerFilePath, err)
Expand Down
9 changes: 5 additions & 4 deletions cli/azd/internal/appdetect/docker_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package appdetect

import (
"github.com/azure/azure-dev/cli/azd/pkg/osutil"
"github.com/stretchr/testify/assert"
"os"
"path/filepath"
"testing"

"github.com/azure/azure-dev/cli/azd/pkg/osutil"
"github.com/stretchr/testify/assert"
)

func TestParsePortsInLine(t *testing.T) {
Expand All @@ -28,7 +29,7 @@ func TestParsePortsInLine(t *testing.T) {
}
}

func TestDetectDockerFromFile(t *testing.T) {
func TestAnalyzeDockerFromFile(t *testing.T) {
tests := []struct {
dockerFileContent string
expectedPorts []Port
Expand All @@ -52,7 +53,7 @@ func TestDetectDockerFromFile(t *testing.T) {
err = os.WriteFile(tempFile, []byte(tt.dockerFileContent), osutil.PermissionFile)
assert.NoError(t, err)

docker, err := detectDockerFromFile(tempFile)
docker, err := AnalyzeDocker(tempFile)
assert.NoError(t, err)
actual := docker.Ports
assert.Equal(t, tt.expectedPorts, actual)
Expand Down
Loading

0 comments on commit ddafa38

Please sign in to comment.