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

Alternative fix for #229, random temp ID #231

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Alternative fix for #229, random temp ID #231

wants to merge 1 commit into from

Conversation

Beanow
Copy link

@Beanow Beanow commented Apr 17, 2019

Closes #229

@@ -242,6 +244,7 @@ func run(c *cli.Context) error {
},
Build: docker.Build{
Remote: c.String("remote.url"),
Ref: c.String("commit.sha"),
Copy link
Member

Choose a reason for hiding this comment

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

the ref should be set to c.String("commit.ref")

Copy link
Author

Choose a reason for hiding this comment

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

The goal here was to not pollute the org.label-schema.vcs-ref label with the random ID, so I copied "Name" which was the sha hash. If the term is confusing, maybe it should be called CommitSha?

Copy link
Member

@bradrydzewski bradrydzewski Apr 17, 2019

Choose a reason for hiding this comment

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

the ref is not a random string, it is a git ref, for example refs/heads/master. I think the overall change is fine, but the ref should use the actual ref value.

Copy link
Author

Choose a reason for hiding this comment

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

That's true, however it would break existing behavior as this label contained the commit sha before the change by using the Name value.

Copy link
Member

Choose a reason for hiding this comment

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

I see, org.label-schema.vcs-ref is supposed to be the commit sha. I recommend removing this and sending a separate pull request. This requires additional discussion. We can merge the random Name in the short term.

Copy link
Member

Choose a reason for hiding this comment

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

@techknowlogick that would be awesome! Last I checked Gitea did not send this information in the payload. See https://github.com/drone/go-scm/blob/master/scm/driver/gitea/testdata/webhooks/tag_create.json

Copy link
Contributor

Choose a reason for hiding this comment

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

Just tested and there is a key in the webhook response labled: sha. Let me send a PR to go-scm to add this information.

Copy link
Contributor

Choose a reason for hiding this comment

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

PR is here: drone/go-scm#22

Copy link
Author

@Beanow Beanow Apr 19, 2019

Choose a reason for hiding this comment

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

Thank you for a great fix there @techknowlogick.
I had a dig to see if the same would apply to gogs, but unfortunately it seems there's no sha here.
https://github.com/gogs/go-gogs-client/blob/5898069c37e1044229e3853adba654d61e45816b/repo_hook.go#L114

Example tag payload
{
    "ref": "v2.4.3",
    "ref_type": "tag",
    "default_branch": "master",
    "repository": {
        "id": 1,
        "owner": {
            "id": 1,
            "username": "example",
            "login": "example",
            "full_name": "",
            "email": "[email protected]",
            "avatar_url": "https://git.example.com/avatars/1"
        },
        "name": "hello-cicd",
        "full_name": "example/hello-cicd",
        "description": "",
        "private": true,
        "fork": false,
        "parent": null,
        "empty": false,
        "mirror": false,
        "size": 1300480,
        "html_url": "https://git.example.com/example/hello-cicd",
        "ssh_url": "ssh://[email protected]/example/hello-cicd.git",
        "clone_url": "https://git.example.com/example/hello-cicd.git",
        "website": "",
        "stars_count": 0,
        "forks_count": 0,
        "watchers_count": 1,
        "open_issues_count": 0,
        "default_branch": "master",
        "created_at": "2018-04-17T20:45:00Z",
        "updated_at": "2019-04-19T09:20:56Z"
    },
    "sender": {
        "id": 1,
        "username": "example",
        "login": "example",
        "full_name": "",
        "email": "[email protected]",
        "avatar_url": "https://git.example.com/avatars/1"
    }
}

vs gittea's counterpart here
https://github.com/go-gitea/go-sdk/blob/master/gitea/hook.go#L196

Copy link
Author

Choose a reason for hiding this comment

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

I've opened the PR there, we'll have to see what they feel about this change.
gogs/gogs#5689

if plugin.Build.Name == "" {
// Use hex encoding as docker requires lowercase.
// Note: we can't use 64 characters as it conflicts with sha256 image hashes.
plugin.Build.Name = uniuri.NewLenChars(40, hexChars)

Choose a reason for hiding this comment

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

40 chars? Why do you want to define such a long random name?

Copy link
Author

Choose a reason for hiding this comment

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

40 matches the keyspace of git's sha1 so it has similar properties in terms of collisions.

@@ -242,6 +244,7 @@ func run(c *cli.Context) error {
},
Build: docker.Build{
Remote: c.String("remote.url"),
Ref: c.String("commit.sha"),

Choose a reason for hiding this comment

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

Just add an SHA attribute and rename Ref to it. That's not so much confusing. Beside this change from Name to Ref/SHA you should not change the label schema, we still got to discuss how to continue with that since label-schema.org is deprecated.

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.

Auto tag build fails when tag event has no commit sha (Gogs)
4 participants