Add skaffold 'init'#919
Conversation
|
@nkubala linter is failing |
|
@dgageot I guess my local golangci-lint version was old, but the hack/linter.sh script doesn't fail because of it. Should be fixed now |
| revision = "0c8571ac0ce161a5feb57375a9cdf148c98c0f70" | ||
|
|
||
| [[constraint]] | ||
| name = "github.com/moby/buildkit" |
There was a problem hiding this comment.
looks like a bad merge resolution here, you'll have to add these back in?
There was a problem hiding this comment.
Ugh, yeah somehow this is hitting dep issues even though it builds locally for me. Working on it
There was a problem hiding this comment.
FYI these should be resolved now. I think we're fine removing these and letting dep figure resolve the correct version based on transitive dependencies
|
|
||
| [[override]] | ||
| name = "github.com/docker/docker" | ||
| revision = "71cd53e4a197b303c6ba086bd584ffd67a884281" |
There was a problem hiding this comment.
is 71cd53e4a197b303c6ba086bd584ffd67a884281 newer than 162ba6016def672690ee4a1f3978368853a1e149?
| func AddInitFlags(cmd *cobra.Command) { | ||
| cmd.Flags().StringVarP(&outfile, "file", "f", "", "File to write generated skaffold config") | ||
| cmd.Flags().BoolVar(&skipBuild, "skip-build", false, "Skip generating build artifacts in skaffold config") | ||
| cmd.Flags().StringArrayVarP(&cliArtifacts, "artifact", "a", nil, "'='-delimited dockerfile/image pair to generate build artifact\n(example: --artifact=/web/Dockerfile.web=gcr.io/web-project/image)") |
There was a problem hiding this comment.
you can consider making this its own flagtype, like the TemplateFlag
| } | ||
| } | ||
|
|
||
| func generateSkaffoldConfig(k8sConfigs []string, dockerfilePairs []dockerfilePair) ([]byte, error) { |
There was a problem hiding this comment.
Can you add an integration test to make sure the config that we generate is actually a valid and runnable config? Something like
skaffold init
.. (input options)
skaffold run
| if f.IsDir() { | ||
| return nil | ||
| } | ||
| if util.IsSupportedKubernetesFormat(path) { |
There was a problem hiding this comment.
This will return JSON files as well
There was a problem hiding this comment.
That should be ok. Skaffold will first try and parse it as a Dockerfile (this will fail), then it will try and parse it as a skaffold config (this will also fail), then finally as a kubernetes manifest, which should succeed. I just realized that my code doesn't try and read the k8s manifests as JSON though, let me fix that
| } | ||
|
|
||
| img, err := remote.Image(ref, auth, tr) | ||
| img, err := remote.Image(ref, remote.WithAuth(auth), remote.WithTransport(tr)) |
There was a problem hiding this comment.
was this meant to be changed?
There was a problem hiding this comment.
Yeah, this was a change I made in the go-containerregistry code that then got picked up here when I updated the version. Shouldn't have any effect.
Codecov Report
@@ Coverage Diff @@
## master #919 +/- ##
==========================================
- Coverage 43.94% 40.87% -3.07%
==========================================
Files 64 66 +2
Lines 2667 2867 +200
==========================================
Hits 1172 1172
- Misses 1373 1573 +200
Partials 122 122
Continue to review full report at Codecov.
|
d82c392 to
d650fd9
Compare
| } | ||
|
|
||
| for _, test := range tests { | ||
| t.Run(test.name, func(t *testing.T) { |
There was a problem hiding this comment.
if you do skaffold run -f - you can pipe in the skaffold yaml over stdin!
There was a problem hiding this comment.
if only I had been a clever boy, I would have done this
| for _, test := range tests { | ||
| t.Run(test.name, func(t *testing.T) { | ||
| oldYamlPath := filepath.Join(test.dir, "skaffold.yaml") | ||
| oldYaml, err := removeOldSkaffoldYaml(oldYamlPath) |
There was a problem hiding this comment.
or you could just use skaffold run -f skaffold.yaml.out
There was a problem hiding this comment.
that's what I'm doing :) the reason I had to do this funky business is because the example directories all have skaffold.yamls in them, and skaffold init won't run if it detects a valid skaffold config in your directory. this just temporarily removes it so we can autogenerate one, then pass it to skaffold with skaffold run -f <generatedYaml>
There was a problem hiding this comment.
- bug: the Dockerfile lister picks up files and directories starting with ".":
See on @ahmetb's microservices-demo:
$ ~/go/src/github.com/GoogleContainerTools/skaffold/out/skaffold init
? Choose the dockerfile to build image gcr.io/****/cartservice [Use arrows to move, type to filter]
❯ .git/info/exclude
src/cartservice/.vs/cartservice/v15/Server/sqlite3/db.lock
src/cartservice/Dockerfile
- idea: we could probably introduce a heuristic to find the Dockerfile for the image using a "longest common substring" matching on the path and the imagename - this feels like we could do more than just listing all the Dockerfiles when there are a lot of them (could be a new issue!):
$ ~/go/src/github.com/GoogleContainerTools/skaffold/out/skaffold init
? Choose the dockerfile to build image gcr.io/****/cartservice [Use arrows to move, type to filter]
src/cartservice/.vs/cartservice/v15/Server/sqlite3/db.lock
❯ src/cartservice/Dockerfile
src/checkoutservice/Dockerfile
src/currencyservice/Dockerfile
src/emailservice/Dockerfile
src/frontend/.gitkeep
- bug: for some reason shippingservice comes up twice, and I can't choose the second one:
~/go/src/github.com/GoogleContainerTools/skaffold/out/skaffold init
? Choose the dockerfile to build image gcr.io/******/cartservice src/cartservice/Dockerfile
? Choose the dockerfile to build image gcr.io/******/currencyservice src/currencyservice/Dockerfile
? Choose the dockerfile to build image gcr.io/******/frontend src/frontend/Dockerfile
? Choose the dockerfile to build image gcr.io/******/loadgenerator src/loadgenerator/Dockerfile
? Choose the dockerfile to build image gcr.io/******/productcatalogservice src/productcatalogservice/Dockerfile
? Choose the dockerfile to build image redis:alpine None (image not built from these sources)
? Choose the dockerfile to build image gcr.io/******/shippingservice src/shippingservice/Dockerfile
? Choose the dockerfile to build image gcr.io/******/shippingservice [Use arrows to move, type to filter]
.git/info/exclude
src/cartservice/.vs/cartservice/v15/Server/sqlite3/db.lock
src/checkoutservice/Dockerfile
❯ src/emailservice/Dockerfile
src/frontend/.gitkeep
src/paymentservice/Dockerfile
src/recommendationservice/Dockerfile
This adds a new CLI command, 'init', for initializing repositories with basic skaffold configuration. Skaffold will prompt the users for some basic configuration options, and then autogenerate a skaffold.yaml with sane defaults.
…nd fix image loop when processing dockerfiles
|
@balopat thanks for finding those issues! I addressed 1 and 3, I think I'll leave 2 to a separate issue (though I definitely think we should do it, for the microservices example it would be very useful). PTAL |
This adds a new CLI command, 'init', for initializing
repositories with basic skaffold configuration.
Skaffold will prompt the users for some basic configuration
options, and then autogenerate a skaffold.yaml with sane defaults.
skaffold initwill find all valid Dockerfiles in the source directory, all valid k8s manifests in the directory, and parse out all image names from the k8s manifests. The default behavior will then be to prompt the user for which Dockerfile builds each image (since we can't infer this ourselves), though these pairs can also be passed through a repeated--artifactflag.By default, this will write the generated skaffold.yaml to stdout, though a
--fileflag can be passed to write the generated config to a file.An optional
--skip-buildflag can be passed to bypass generating build artifacts for the config.Demo using the

microservicesexample: