Skip to content

Update skaffold init --artifact to use JSON structs instead of paths#2364

Merged
TadCordle merged 66 commits intoGoogleContainerTools:masterfrom
TadCordle:skaffold-init-artifact
Aug 5, 2019
Merged

Update skaffold init --artifact to use JSON structs instead of paths#2364
TadCordle merged 66 commits intoGoogleContainerTools:masterfrom
TadCordle:skaffold-init-artifact

Conversation

@TadCordle
Copy link
Copy Markdown
Contributor

@TadCordle TadCordle commented Jun 27, 2019

Follow up to #2276 (last one probably).

This PR makes changes to skaffold init --artifact to allow passing in non-Docker builders via CLI. Rather than passing a path/image pair, which doesn't provide enough information for some builders, --artifact now takes a JSON struct/image pair. Example below:

skaffold init \
    -a='{"name":"Docker","payload":{"path":"notification-service/Dockerfile"},"image":"gcr.io/docker/image"}' \
    -a='{"name":"Jib Gradle Plugin","payload":{"path":"vote-service/build.gradle"},"image":"gcr.io/gradle/image"}'

This new format isn't very user friendly due to the verbosity of the JSON (although the old method of path=image is still available), but it should make passing non-docker builder information from IDEs using a skaffold init --analyze --> skaffold init --artifact=... workflow fairly straightforward.

TadCordle added 30 commits June 17, 2019 14:31
@balopat balopat changed the title Update skaffold --artifact to use JSON structs instead of paths Update skaffold init --artifact to use JSON structs instead of paths Jul 24, 2019
f.BoolVar(&force, "force", false, "Force the generation of the Skaffold config")
f.StringVar(&composeFile, "compose-file", "", "Initialize from a docker-compose file")
f.StringSliceVarP(&cliArtifacts, "artifact", "a", nil, "'='-delimited dockerfile/image pair to generate build artifact\n(example: --artifact=/web/Dockerfile.web=gcr.io/web-project/image)")
f.StringArrayVarP(&cliArtifacts, "artifact", "a", nil, "'='-delimited builder JSON/image pair to generate build artifact\n(example: --artifact='{\"name\":\"Docker\",\"payload\":{\"path\":\"/web/Dockerfile.web\"}}=gcr.io/web-project/image')")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just asking... won't /web/Dockerfile.web read more natural without the leading /? It may usually be a relative path? I can't remember exactly, but can this handle absolute path properly?

Copy link
Copy Markdown
Member

@chanseokoh chanseokoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@TadCordle TadCordle dismissed dgageot’s stale review July 31, 2019 20:43

Comments addressed

Copy link
Copy Markdown
Contributor

@nkubala nkubala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in principle I think I'm fine with this approach. the JSON fields feel a little weird to me though.

--artifact '{"name": "Docker", "payload": {"path": "/path"}}=gcr.io/repo/image'

this reads to me like "the name of this artifact is Docker" rather than "the name of the builder this artifact is meant for is Docker", and it's confusing what the "payload" is. also, we have this entire JSON struct "equal to" the image name, so it's just kind of hard to parse out the semantics of what is actually being provided to skaffold.

WDYT about moving the image name into the JSON payload itself? then we can change the name field to builder, get rid of the payload field and just have the path and the image inside the JSON.

--artifact '{"builder": "Docker", "path": "/path", "image": "gcr.io/repo/image"}'

this feels a little more clear to me, and should still work with the backwards compatibility logic.

@TadCordle
Copy link
Copy Markdown
Contributor Author

@nkubala The reason there's a separate "payload" field rather than just putting the rest of the fields in one flat json struct is because different builders have different builder-specific configuration values. Things like jib's module name, or build system (maven/gradle), or jib's to.image configuration don't apply if you're using a builder like Docker, which only uses a path to a dockerfile. This is why we went with the design of determining the builder type using the "name" field, then correctly parsing "payload" based on the type, rather than just having every configuration value for every builder mixed together in the same struct (which I think would become really messy, especially if more builders are added to skaffold init).

I do agree about changing "name" to "builder", and moving the image after the '=' into the json as well.

Copy link
Copy Markdown
Contributor

@nkubala nkubala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM when CI is green

@TadCordle
Copy link
Copy Markdown
Contributor Author

RUN hack/check-docs.sh
There are        1 changes in docs, testing site generation...
./deploy/docs/local-preview.sh hugo --baseURL=https://skaffold.dev
./deploy/docs/local-preview.sh: line 29: docker: command not found
make[1]: *** [build-docs-preview] Error 127
FAILED hack/check-docs.sh

Is there some command I can run to fix this? This doesn't happen locally.

@nkubala
Copy link
Copy Markdown
Contributor

nkubala commented Aug 1, 2019

yeah i'm not really sure why that's happening....i've never seen this happen on any other PRs, but it seems like a travis issue. let's try rerunning and see if it fixes itself

@TadCordle
Copy link
Copy Markdown
Contributor Author

No luck. Looks like it's just mac too.

@TadCordle TadCordle merged commit f48e7dd into GoogleContainerTools:master Aug 5, 2019
@TadCordle TadCordle deleted the skaffold-init-artifact branch August 5, 2019 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants