-
Notifications
You must be signed in to change notification settings - Fork 437
feat: add support for docker build args to the task run command #5377
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
Changes from 2 commits
7b1000d
391279c
f0efb9f
b8eea51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -114,6 +114,7 @@ type runTaskVars struct { | |
| image string | ||
| dockerfilePath string | ||
| dockerfileContextPath string | ||
| dockerfileBuildArgs map[string]string | ||
| imageTag string | ||
|
|
||
| taskRole string | ||
|
|
@@ -372,6 +373,10 @@ func (o *runTaskOpts) Validate() error { | |
| return errors.New("cannot specify both `--image` and `--build-context`") | ||
| } | ||
|
|
||
| if o.image != "" && o.dockerfileBuildArgs != nil { | ||
| return errors.New("cannot specify both `--image` and `--build-args`") | ||
| } | ||
|
|
||
| if o.isDockerfileSet { | ||
| if _, err := o.fs.Stat(o.dockerfilePath); err != nil { | ||
| return fmt.Errorf("invalid `--dockerfile` path: %w", err) | ||
|
|
@@ -963,6 +968,7 @@ func (o *runTaskOpts) buildAndPushImage(uri string) error { | |
| Dockerfile: o.dockerfilePath, | ||
| Context: ctx, | ||
| Tags: append([]string{imageTagLatest}, additionalTags...), | ||
| Args: o.dockerfileBuildArgs, | ||
| } | ||
| buildArgsList, err := buildArgs.GenerateDockerBuildArgs(dockerengine.New(exec.NewCmd())) | ||
| if err != nil { | ||
|
|
@@ -1175,7 +1181,9 @@ func BuildTaskRunCmd() *cobra.Command { | |
| Run a task using the current workspace with specific subnets and security groups. | ||
| /code $ copilot task run --subnets subnet-123,subnet-456 --security-groups sg-123,sg-456 | ||
| Run a task with a command. | ||
| /code $ copilot task run --command "python migrate-script.py"`, | ||
| /code $ copilot task run --command "python migrate-script.py" | ||
| Run a task with Docker build-args. | ||
Lou1415926 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /code $ copilot task run --build-args GO_VERSION=1.19"`, | ||
| RunE: runCmdE(func(cmd *cobra.Command, args []string) error { | ||
| opts, err := newTaskRunOpts(vars) | ||
| if err != nil { | ||
|
|
@@ -1193,6 +1201,7 @@ func BuildTaskRunCmd() *cobra.Command { | |
| cmd.Flags().StringVarP(&vars.groupName, taskGroupNameFlag, nameFlagShort, "", taskGroupFlagDescription) | ||
|
|
||
| cmd.Flags().StringVar(&vars.dockerfilePath, dockerFileFlag, defaultDockerfilePath, dockerFileFlagDescription) | ||
| cmd.Flags().StringToStringVar(&vars.dockerfileBuildArgs, dockerFileBuildArgsFlag, nil, dockerFileBuildArgsFlagDescription) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add an example to the [task run help menu] about how we can run task from dockerfile 🙏
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added an example to the help menu showing how to use the --build-args flag. Thanks for the suggestion! |
||
| cmd.Flags().StringVar(&vars.dockerfileContextPath, dockerFileContextFlag, "", dockerFileContextFlagDescription) | ||
| cmd.Flags().StringVarP(&vars.image, imageFlag, imageFlagShort, "", imageFlagDescription) | ||
| cmd.Flags().StringVar(&vars.imageTag, imageTagFlag, "", taskImageTagFlagDescription) | ||
|
|
@@ -1228,6 +1237,7 @@ func BuildTaskRunCmd() *cobra.Command { | |
|
|
||
| buildFlags := pflag.NewFlagSet("Build", pflag.ContinueOnError) | ||
| buildFlags.AddFlag(cmd.Flags().Lookup(dockerFileFlag)) | ||
| buildFlags.AddFlag(cmd.Flags().Lookup(dockerFileBuildArgsFlag)) | ||
| buildFlags.AddFlag(cmd.Flags().Lookup(dockerFileContextFlag)) | ||
| buildFlags.AddFlag(cmd.Flags().Lookup(imageFlag)) | ||
| buildFlags.AddFlag(cmd.Flags().Lookup(imageTagFlag)) | ||
|
|
||
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.
aw yay thank you for adding this in the help menu message !