Skip to content
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

Migrate invocation image push to porter publish #365

Merged
merged 7 commits into from
May 30, 2019

Conversation

jeremyrickard
Copy link
Contributor

This PR migrates the image push functionality to a new command porter publish (the command doesn't actually publish the bundle itself to OCI yet). Now when you do a porter build the invocation image is still built, but it is not pushed to a registry. The bundle.json is generated with whatever tag is present in the porter.yaml.

To push the image and regenerate the bundle.json, you now do a porter publish.

Command outputs below:

porter build
Copying dependencies ===>
Copying porter runtime ===>
Copying mixins ===>
Copying mixin kubernetes ===>

Generating Dockerfile =======>
FROM quay.io/deis/lightweight-docker-go:v0.2.0
FROM debian:stretch
COPY --from=0 /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
RUN apt-get update && \
apt-get install -y apt-transport-https curl && \
curl -o kubectl https://storage.googleapis.com/kubernetes-release/release/v1.13.0/bin/linux/amd64/kubectl && \
mv kubectl /usr/local/bin && \
chmod a+x /usr/local/bin/kubectl

COPY cnab/ /cnab/
COPY porter.yaml /cnab/app/porter.yaml
CMD ["/cnab/app/run"]

Writing Dockerfile =======>
FROM quay.io/deis/lightweight-docker-go:v0.2.0
FROM debian:stretch
COPY --from=0 /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
RUN apt-get update && \
apt-get install -y apt-transport-https curl && \
curl -o kubectl https://storage.googleapis.com/kubernetes-release/release/v1.13.0/bin/linux/amd64/kubectl && \
mv kubectl /usr/local/bin && \
chmod a+x /usr/local/bin/kubectl

COPY cnab/ /cnab/
COPY porter.yaml /cnab/app/porter.yaml
CMD ["/cnab/app/run"]

Starting Invocation Image Build =======>
Step 1/7 : FROM quay.io/deis/lightweight-docker-go:v0.2.0
 ---> acf6712d2918
Step 2/7 : FROM debian:stretch
 ---> de8b49d4b0b3
Step 3/7 : COPY --from=0 /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
 ---> Using cache
 ---> 6bf0ab0d751e
Step 4/7 : RUN apt-get update && apt-get install -y apt-transport-https curl && curl -o kubectl https://storage.googleapis.com/kubernetes-release/release/v1.13.0/bin/linux/amd64/kubectl && mv kubectl /usr/local/bin && chmod a+x /usr/local/bin/kubectl
 ---> Using cache
 ---> 1fd544730ffe
Step 5/7 : COPY cnab/ /cnab/
 ---> ba4fdfd5ef4b
Step 6/7 : COPY porter.yaml /cnab/app/porter.yaml
 ---> eb4a04350e4a
Step 7/7 : CMD ["/cnab/app/run"]
 ---> Running in 043633b8fcca
 ---> 49aaf30f0465
Successfully built 49aaf30f0465
Successfully tagged jeremyrickard/porter-kubernetes:latest

Generating Bundle File with Invocation Image jeremyrickard/porter-kubernetes:latest =======>
Generating parameter definition porter-debug ====>
Generating credential kubeconfig ====>

Then a porter publish

porter publish --tag jeremyrickard/hashi-mashi:v1.0
Pushing CNAB invocation image...
The push refers to repository [docker.io/jeremyrickard/hashi-mashi]
15efbe06773e: Preparing
c7fa3bae30d9: Preparing
49037d9d1b30: Preparing
c7956a703d1e: Preparing
c581f4ede92d: Preparing
15efbe06773e: Mounted from jeremyrickard/porter-kubernetes
c581f4ede92d: Mounted from jeremyrickard/spring-music-installer
c7fa3bae30d9: Mounted from jeremyrickard/porter-kubernetes
c7956a703d1e: Mounted from jeremyrickard/porter-azure-wordpress
49037d9d1b30: Mounted from jeremyrickard/porter-kubernetes
v1.0: digest: sha256:c90044b7bfdab915d213ceccdce3910f51e5815a4dae72592fa357e2044c9717 size: 1370

Generating CNAB bundle.json...

Generating Bundle File with Invocation Image jeremyrickard/hashi-mashi@sha256:c90044b7bfdab915d213ceccdce3910f51e5815a4dae72592fa357e2044c9717 =======>
Generating parameter definition porter-debug ====>
Generating credential kubeconfig ====>

Closes: #354

@jeremyrickard
Copy link
Contributor Author

Need to update the docs still!

@jeremyrickard jeremyrickard self-assigned this May 30, 2019
cmd := cobra.Command{
Use: "publish",
Short: "Publish a bundle",
Long: "Publishes a bundle by pushing the invocation image, updating the reference in the CNAB bundle.json, and publishing to an OCI registry.",
Copy link
Member

Choose a reason for hiding this comment

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

We don't normally put the technical implementation into the help text. I recommend putting this into the documentation, and then putting a more general description here like

"Publishes a bundle by pushing the invocation image and bundle to a registry"


f := cmd.Flags()
f.StringVarP(&opts.File, "file", "f", "", "Path to the Porter manifest. Defaults to `porter.yaml` in the current directory.")
f.StringVarP(&opts.Tag, "tag", "t", "", "Tag to apply to the CNAB invocation image. Defaults to the value currently in the Porter manifest.")
Copy link
Member

Choose a reason for hiding this comment

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

This isn't what was specified in the OP issue #254. That was calling for a new field tag (format registry/image:tag) to be added to the manifest that the bundle will be pushed to).

So this should say

"Tag to apply to the bundle when pushing to the registry. Defaults to the value defined in the Porter manifest."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 i misread that.

if err != nil {
return errors.Wrap(err, "could not get current working directory")
}
fmt.Println(pwd)
Copy link
Member

Choose a reason for hiding this comment

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

Looks like a leftover debug statement that should be removed?

return errors.Wrap(err, "could not get current working directory")
}
fmt.Println(pwd)
files, err := fs.ReadDir(pwd)
Copy link
Member

Choose a reason for hiding this comment

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

Why not use fs.Exists to check if porter.yaml is in the current directory?

Copy link
Contributor Author

@jeremyrickard jeremyrickard May 30, 2019

Choose a reason for hiding this comment

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

I copied this from the existing validation code (that wasn't directly reusable) and then removed something and was lazy. I'll update.


func (p PublishOptions) Validate(porter *Porter) error {
if p.File != "" {
return nil
Copy link
Member

Choose a reason for hiding this comment

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

This is skipping the Tag validation entirely. I think the logic below around checking if porter.yaml is present should be in the if/else instead of doing a hard return, no?

if err != nil {
return err
}
if opts.Tag != "" {
Copy link
Member

Choose a reason for hiding this comment

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

Yeah this entire part I think should be removed since tag = bundle tag, not invocation image tag. Feel free to give things better names anywhere you like. 😀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should still validate that the tag given is a valid OCI tag no?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, in the PublishOptions.Validate method. I was just referring to the lines 81-83 here where we are changing the invocation image tag.

opts.Tag = "someinvalid/repo/thing:10:10"

err = opts.Validate(p.Porter)
require.Error(t, err, "should have no error")
Copy link
Member

Choose a reason for hiding this comment

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

the error message here is confusing, can you remove it or fix it? We actually do want an error.

p.TestConfig.SetupPorterHome()
opts := PublishOptions{}
err := opts.Validate(p.Porter)
require.Error(t, err, "should have no error")
Copy link
Member

Choose a reason for hiding this comment

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

the error message here is confusing, can you remove it or fix it? We actually do want an error.

Copy link
Member

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

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

sorry just one nit and then the rubber stamps will fly! 💸

if p.Tag != "" {
_, err := reference.ParseNormalizedNamed(p.Tag)
if err != nil {
return err
return errors.Wrap(err, "invalid bundle tag value")
Copy link
Member

Choose a reason for hiding this comment

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

nit: Normally in the validate methods we tell them the flag that they need to fix, so the error looks like "invalid --tag value, expected format is REGISTRY/IMAGE:TAG" or something along those lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

$ porter publish --tag jeremyrickard/super-cool-app-image:v1.0:1010
Error: invalid --tag value. expected format is REGISTRY/IMAGE:TAG: invalid reference format

Copy link
Member

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

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

:shipit:

@jeremyrickard jeremyrickard merged commit 75bb688 into getporter:master May 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update Porter Build to Not Push Docker Image
2 participants