-
Notifications
You must be signed in to change notification settings - Fork 424
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
feat(manifest): allow additional docker build overrides in manifest #1059
Conversation
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'm not sure if adding context
field will help completely fix our problematic docker build. Currently if your pwd
is not the root workspace then it is very likely svc deploy
will fail because our dockerfile path is a relative one and ./subscribers/Dockerfile
doesn't exist since .
denotes different path. #1030
Have a use case for that. If the user has two services "frontend" and "backend". After they deploy those services, the frontend service has bug and they'd like to cd into the folder to run svc show/logs/status
easier. However, they have to cd back to the workspace root in order to run svc deploy
again, which might not make sense.
I think maybe we could probably completely get rid of the .
and require users to put their dockerfile in the workspace. The build
field will be like build: subscribers/myDockerfile
. What do you think?
@iamhopaul123 My thought was that our current behavior is pretty bad especially for go. Consider the following use cases:
This is a separate problem from |
Oh then that makes sense to me. Thanks for explaining! |
This PR now includes a fix for #1030. Dockerfile paths and contexts are interpreted from the workspace root (one level up from the |
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.
Looks awesome! Just two suggestions
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.
🚢
This PR should be updated to ensure image:
build:
context: context/dir
dockerfile: path/to/dockerfile As described in https://docs.docker.com/compose/compose-file/#build I've added the do-not-merge label until we can work through our next decision on this matter |
* Convert CopilotDirPath to public function on ws for use in docker build calls in Service Deploy. * Generate mocks * Make context default to Dockerfile directory for backwards compatibility.
…ext into one call
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.
Only minor comments, also great tests!
internal/pkg/cli/svc_deploy.go
Outdated
// Assemble other parameters for build input. | ||
dockerBuildInput.URI = uri | ||
dockerBuildInput.ImageTag = o.ImageTag |
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.
nit: what do you think of moving this to within getBuildArgs()
?
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.
Done. Respository now handles making the URI, and getBuildArgs adds the image tag.
m.EXPECT().ReadServiceManifest("serviceA").Times(1).Return(mockManifest, nil) | ||
}, | ||
}, | ||
"using simple buildstring (backwards compatible)": { |
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.
nice!
func (r Runner) Build(uri, path, imageTag string, additionalTags ...string) error { | ||
dfDir := filepath.Dir(path) | ||
// BuildArguments holds the arguments we can pass in as flags from the manifest. | ||
type BuildArguments struct { |
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.
v nice comments!
Build *string `yaml:"build"` // Path to the Dockerfile. | ||
Build BuildArgsOrString `yaml:"build"` // Path to the Dockerfile. | ||
} | ||
|
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.
Looks good! I am not sure about returning a docker.BuildArguments
instead of a manifest.DockerBuildArgs
from the manifest
pkg, but I'm okay with keeping it as is.
Co-authored-by: Efe Karakus <[email protected]>
Co-authored-by: Efe Karakus <[email protected]>
…Opts.getBuildArgs to return docker.BuildArguments
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.
THANK YOU.
if !ok { | ||
return "", fmt.Errorf("service %s does not have a dockerfile path", o.Name) | ||
return nil, fmt.Errorf("service %s does not have required method Build()", o.Name) |
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.
Maybe something our users could grok easier:
manifest for service %s does not have a `build` section
Or something like that?
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.
This is a weird error because it specifically has to do with the interface conversion to the dfArgs interface and making sure that the unmarshaled yaml fits into a BackendService
or LoadBalancedWebService
struct with the right methods attached.
} | ||
return mf.DockerfilePath(), nil | ||
wsRoot := filepath.Dir(copilotDir) |
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.
Is this needed? I believe CopilotDirPath
returns a directory.
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.
Yes, because we want the workspace root, not the Copilot dir. filepath.Dir
is equivalent to the shell dirname
command.
"success with build args": { | ||
path: mockPath, | ||
args: map[string]string{ | ||
"GOPROXY": "direct", |
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.
love it
} | ||
|
||
//BuildArgs returns a docker.BuildArguments object given a ws root directory. | ||
func (s *LoadBalancedWebService) BuildArgs(wsRoot string) *DockerBuildArgs { |
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.
Can we add this method to Service
struct, so we don't always have to redefine it for every pattern? Or is it not possible (no prob if it's not, just curioust)
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 tried but it's weird, because the method needs access to the Image member of the LoadBalancedWebService or BackendService struct, but I don't know how to cast a particular member of an unmarshaled struct to an interface instead of just the whole struct
This PR adds the ability to specify docker compose style build directives in the manifest.
For example, customers can now specify
dockerfile
,context
, andargs
underneath thebuild
key in the manifest, or simply specify a dockerfile path atbuild
.Example 1
This manifest will build the dockerfile specified at
build
, using the directorypath/to
as the build context.Example 2
This example will build the dockerfile at
path/to/MyDockerfile
using the directorypath/to/service/code
as the build context and passing the args as--build-arg
flags.Fixes #822 and #1030
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.