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

Removed fields added to the build strategy when using --strategy=docker. #9553

Closed
wants to merge 1 commit into from
Closed

Removed fields added to the build strategy when using --strategy=docker. #9553

wants to merge 1 commit into from

Conversation

oatmealraisin
Copy link

Fixes #6347

Old output:

$ oc new-app https://github.com/openshift/ruby-hello-world --strategy=docker -o yaml
...
- apiVersion: v1
  kind: BuildConfig
  metadata:
    annotations:
      openshift.io/generated-by: OpenShiftNewApp
    creationTimestamp: null
    labels:
      app: ruby-hello-world
    name: ruby-hello-world
  spec:
    output:
      to:
        kind: ImageStreamTag
        name: ruby-hello-world:latest
    postCommit: {}
    resources: {}
    source:
      git:
        uri: https://github.com/openshift/ruby-hello-world
      secrets: []
      type: Git
    strategy:
      dockerStrategy:
        from:
          kind: ImageStreamTag
          name: ruby-22-centos7:latest
      type: Docker
    triggers:
    - github:
        secret: 9kT3d_Dtngco-2amnzkE
      type: GitHub
    - generic:
        secret: b5HW8CYUDQqVK7UgTO7F
      type: Generic
    - type: ConfigChange
    - imageChange: {}
      type: ImageChange
  status:
    lastVersion: 0
...

New Output:

$ oc new-app https://github.com/openshift/ruby-hello-world --strategy=docker -o yaml
...
- apiVersion: v1
  kind: BuildConfig
  metadata:
    annotations:
      openshift.io/generated-by: OpenShiftNewApp
    creationTimestamp: null
    labels:
      app: ruby-hello-world
    name: ruby-hello-world
  spec:
    output:
      to:
        kind: ImageStreamTag
        name: ruby-hello-world:latest
    postCommit: {}
    resources: {}
    source:
      git:
        uri: https://github.com/openshift/ruby-hello-world
      secrets: []
      type: Git
    strategy:
      dockerStrategy: {}
      type: Docker
    triggers:
    - github:
        secret: ue-VeLrxT1w_OnBpdQhp
      type: GitHub
    - generic:
        secret: oS3Jr_kkqLvLPQJqsntn
      type: Generic
    - type: ConfigChange
    - imageChange: {}
      type: ImageChange
  status:
    lastVersion: 0
...

@oatmealraisin
Copy link
Author

@bparees @csrwng ptal

@oatmealraisin
Copy link
Author

Rebased

@oatmealraisin
Copy link
Author

[test]

@bparees
Copy link
Contributor

bparees commented Jun 24, 2016

I think the buildconfig you've produced is invalid because it has an ImageChangeTrigger defined, but there is no image for the ICT to trigger from. That should result in a validation error if you actually let new-app try to create these objects:
https://github.com/openshift/origin/blob/master/pkg/build/api/validation/validation.go#L561-L568

I also think is solution is overly aggressive, for example it prevents me from doing:
oc new-app ruby~https://github.com/openshift/ruby-hello-world --strategy=docker

which i might want to do if i definitely do want the FROM line in my Dockerfile to be overwritten by a particular image that i'm basing my build on. As was noted here: #6347 (comment)

@rhcarvalho
Copy link
Contributor

@oatmealraisin thanks for taking a look at this! Suggestions:

  • The new-app code base is complicated, try to start with a test case to nail down the issue. As @bparees noted, we need to distinguish the two cases -- with and without an explicit builder image in the arguments. Find me on IRC if you need help with the tests :)
  • A common practice is to mention the issue in the PR description (already there, good), do not mention it in the commit message: as the PR evolves, every time you rebase your commits the issue page gets a new notification about the commit.

@oatmealraisin
Copy link
Author

I added some logic to check if we got the image from a Dockerfile. @bparees ptal?

Output from [source]:

kind: BuildConfig
  metadata:
    annotations:
      openshift.io/generated-by: OpenShiftNewApp
    creationTimestamp: null
    labels:
      app: ruby-hello-world
    name: ruby-hello-world
  spec:
    output:
      to:
        kind: ImageStreamTag
        name: ruby-hello-world:latest
    postCommit: {}
    resources: {}
    source:
      git:
        uri: https://github.com/openshift/ruby-hello-world
      secrets: []
      type: Git
    strategy:
      dockerStrategy: {}
      type: Docker
    triggers:
    - github:
        secret: 8_gKQQDiSQZonpmb8c-J
      type: GitHub
    - generic:
        secret: afQxGkdXB8Izd6zmIi1c
      type: Generic
    - type: ConfigChange
  status:
    lastVersion: 0

Output from [image]~[source]:

  kind: BuildConfig
  metadata:
    annotations:
      openshift.io/generated-by: OpenShiftNewApp
    creationTimestamp: null
    labels:
      app: ruby-hello-world
    name: ruby-hello-world
  spec:
    output:
      to:
        kind: ImageStreamTag
        name: ruby-hello-world:latest
    postCommit: {}
    resources: {}
    source:
      git:
        uri: https://github.com/openshift/ruby-hello-world
      secrets: []
      type: Git
    strategy:
      dockerStrategy:
        from:
          kind: ImageStreamTag
          name: origin:latest
      type: Docker
    triggers:
    - github:
        secret: BaMQLeLuFW4ZhNJ8wwF_
      type: GitHub
    - generic:
        secret: r3dMynXk8HuW7UlyOwdf
      type: Generic
    - type: ConfigChange
    - imageChange: {}
      type: ImageChange
  status:
    lastVersion: 0

ScratchImage bool
ExpectToBuild bool
ScratchImage bool
FromDockerfile bool
Copy link
Contributor

Choose a reason for hiding this comment

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

since you were complaining about comments before, comment your new field :)

@bparees
Copy link
Contributor

bparees commented Jul 13, 2016

lgtm but please add some tests that cover the different behaviors so we can confirm we don't regress this behavior later.

@oatmealraisin
Copy link
Author

Added some tests, hopefully they pass this time!

@oatmealraisin
Copy link
Author

[test]

@@ -299,6 +302,9 @@ type ComponentInput struct {

ExpectToBuild bool
ScratchImage bool
// For keeping track of if this image was retrieved from a Dockerfile,
// which changes our BuildConfig results
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit confused, is this about a Dockerfile or about a reference to a Docker image?

In oc new-app php~https://github.com/org/repo, php refers to a Docker image, not a Dockerfile.

Copy link
Contributor

Choose a reason for hiding this comment

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

@rhcarvalho in your scenario, FromDockerfile would be false.

FromDockerfile is true when we figured out which image you want to use by parsing the Dockerfile you supplied (either in the repo or via the -D flag).

@oatmealraisin it would be better if this comment explained how it changes the results. "when true, an imagechangetrigger will not be associated with the buildconfig because the user has not expressed a desire to reference an imagestream, they are directly referencing an image" or some such thing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Aha, so it doesn't relate to that syntax. Thanks @bparees.
Can't say the flow is absolutely clear to me, but at least the name seems accurate :)

Copy link
Author

Choose a reason for hiding this comment

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

@bparees I was thinking about whether it should explain the intent instead of the idea, I'll change the comment

@rhcarvalho When the input [image]~[source] gets converted into a ComponentReference, and then into an ImageRef, the information about where the image came from gets lost. If we just specify the [source], the image gets filled in from the Dockerfile "FROM". I added a flag so that some information gets preserved, and then I use that information to change the outputted BuildConfig. I really don't like the flow either, it's kinda scotch-tape, but couldn't find a better way to do it. I'm definitely open to suggestions!

Copy link
Contributor

@rhcarvalho rhcarvalho Jul 17, 2016

Choose a reason for hiding this comment

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

it's kinda scotch-tape

👍 💯

but couldn't find a better way to do it. I'm definitely open to suggestions!

I think the approach you described is perfectly valid, no concerns there.

@stevekuznetsov
Copy link
Contributor

@oatmealraisin
Copy link
Author

[test]

@oatmealraisin
Copy link
Author

re[test]

@oatmealraisin
Copy link
Author

rebased

@oatmealraisin
Copy link
Author

Changed the comment, @bparees @rhcarvalho ptal?

Also, I've added a test to newapp.sh, should I add one anywhere else?

@@ -140,6 +140,10 @@ type ImageRef struct {
OutputImage bool
Insecure bool
HasEmptyDir bool
// For keeping track of if this image was retrieved from a Dockerfile,
Copy link
Contributor

Choose a reason for hiding this comment

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

proper godoc starts w/ the object name, so "FromDockerfile keeps track of....."

same for the other one above.

@bparees
Copy link
Contributor

bparees commented Jul 19, 2016

@oatmealraisin you still need to fix tests which are broken by these changes, the ones you reported as a flake here: #9879

@@ -204,14 +204,17 @@ func (r *SourceRepository) Detect(d Detector, dockerStrategy bool) error {
if r.info != nil {
return nil
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Are the new lines here intentional? It's strange to change this file as part of this PR just for the empty lines.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1, i'm not averse to introducing whitespace if you're already touching the file anyway, but it does tend to cross a line if you're not making any other changes.

@oatmealraisin
Copy link
Author

re[test]

1 similar comment
@oatmealraisin
Copy link
Author

re[test]

@openshift-bot openshift-bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Aug 12, 2016
@oatmealraisin
Copy link
Author

@bparees I updated some tests to prevent regression, and also removed tests that were invalidated because of this change. ptal?

@bparees bparees added this to the 1.3.1 milestone Aug 25, 2016
@bparees
Copy link
Contributor

bparees commented Aug 25, 2016

@oatmealraisin we can't just remove the tests/checks for warnings, we need to create equivalent ones that will still test the circular build warning logic for scenarios under which it can still happen.

@smarterclayton smarterclayton modified the milestones: 1.3.1, 1.4.0 Sep 19, 2016
@smarterclayton smarterclayton modified the milestones: 1.4.0, 1.3.1 Sep 19, 2016
@bparees
Copy link
Contributor

bparees commented Sep 20, 2016

@oatmealraisin bump

@oatmealraisin
Copy link
Author

@bparees I've modified the tests to trigger the proper responses, but one of the tests relies on the input repository having the same name as the requested builder image (openshift/ruby-20-centos7~https://github.com/oatmealraisin/ruby-20-centos7). I've used my own repository to do this, but we probably want something with the openshift account?

This allows us to check later in new-app whether an Image needs a
ImageChangeTrigger, or whether we should continue to get it from the
Dockerfile it was found in.
@oatmealraisin
Copy link
Author

Flake #11452, [test]

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to 834ce8d

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/11178/) (Base Commit: 046fad4)

@bparees
Copy link
Contributor

bparees commented Nov 6, 2016

@oatmealraisin i apologize because i know you've spent a ton of time on this but with the benefit of hindsight, I think the original issue should be closed (in fact i have closed it) rather than implementing what it proposes. I put my reasoning in the original issue (#6347 (comment))

@oatmealraisin
Copy link
Author

Roger that!

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.

6 participants