-
Notifications
You must be signed in to change notification settings - Fork 210
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
Enhance azd init
to auto-detect Dockerfile ARGS and update azure.yaml
#4639
base: main
Are you sure you want to change the base?
Conversation
Azure Dev CLI Install InstructionsInstall scriptsMacOS/Linux
bash:
pwsh:
WindowsPowerShell install
MSI install
Standalone Binary
MSI
Documentationlearn.microsoft.com documentationtitle: Azure Developer CLI reference
|
if strings.HasPrefix(line, "ARG ") { | ||
argLine := strings.TrimPrefix(line, "ARG ") | ||
if len(argLine) > 0 { | ||
buildArgs = append(buildArgs, osutil.NewExpandableString(argLine)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if creating an osutil.ExpandableString
here is the right thing? I think that we probably just want to use string
(or maybe a structured type that contains the arg name and optional default value). I don't think you'd ever want to call Envsubst
or MustEnvsubst
on this value since the docker language doesn't think about doing env-var substitution for ARG
s.
For the docs, it looks like the ARG
directive in a dockerfile could look like this:
ARG foo=${BAR}
Which from my understanding would mean an argument called "foo" with the default value of ${BAR}
.
I'm a little worried that when faced with a file like this, we'd end up doing the wrong thing end to end (but I will admit that from the linked issue, I also don't have a great idea of what the expectation is here either).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ellismg The use of the osutil.ExpandableString
type to store buildArgs
is to populate the buildArgs
configuration in the azure.yaml
file. Later, when parsing the azure.yaml
file, Envsubst()
will be used to replace the environment variable of arg in buildArgs
.
For the ARG instruction ARG foo=${BAR}
in the Dockerfile, the underlying processing flow of Azd is as follows:
-
If the
foo
arg is not configured in thebuildArgs
in azure.yaml, the bottom layer finally runs thedocker build .
command to build the project. Since--build-arg foo
is not specified, the value offoo
is the defined default value${BAR}
. -
If the
foo
arg is configured inbuildArgs
in azure.yaml:- When the value of the arg
foo
is hardcode, the Azd bottom layer will build the project by running the commanddocker build . --build-arg foo=xxxxxx
. - When the value of the arg
foo
is the environment variable${AZURE_BAR}
, the environment variable is replaced with the corresponding value, and the Azd bottom layer will finally build the project by runningdocker build . --build-arg foo=xxxxxx
.
- When the value of the arg
Fix issue #4606, this PR adds automatic detection of ARG parameters in Dockerfiles during
azd init
.When a user runs
azd init
to initialize an existing application as an azd project, the command will now scan the Dockerfile, identify all defined ARG parameters, and automatically populate them into thebuildArgs
section of the generatedazure.yaml
file.@rajeshkamal5050 for notification.