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

Auto tag build fails when tag event has no commit sha (Gogs) #229

Closed
Beanow opened this issue Apr 9, 2019 · 14 comments · May be fixed by #230 or #231
Closed

Auto tag build fails when tag event has no commit sha (Gogs) #229

Beanow opened this issue Apr 9, 2019 · 14 comments · May be fixed by #230 or #231

Comments

@Beanow
Copy link

Beanow commented Apr 9, 2019

The build is trigged by a tag event as you would assume: username created tag 2.1.5

However the tag seems to be parsed incorrectly.
Using drone server and agent docker tags: 1.0

kind: pipeline
name: default

steps:
  - name: unit-test
    image: node:10-alpine
    commands:
      - cd app
      - npm i
      - npm test

  - name: build-image
    image: plugins/docker
    settings:
      username:
        from_secret: docker_user
      password:
        from_secret: docker_pass
      repo: docker.example.com/example/hello-cicd
      registry: docker.example.com
      auto_tag: true
    when:
      event: [tag]

Build image step:

+ /usr/local/bin/dockerd --data-root /var/lib/docker
+ /usr/local/bin/docker version
Client: Docker Engine - Community
Version: 18.09.4
API version: 1.39
Go version: go1.10.8
Git commit: d14af54
Built: Wed Mar 27 18:33:40 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.4
API version: 1.39 (minimum version 1.12)
Go version: go1.10.8
Git commit: d14af54
Built: Wed Mar 27 18:41:10 2019
OS/Arch: linux/amd64
Experimental: false
+ /usr/local/bin/docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
WARNING: No swap limit support
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
Server Version: 18.09.4
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: bb71b10fd8f58240ca47fbb579b9d1028eea7c84
runc version: 2b18fe1d885ee5083ef9f0838fee39b62d653e30
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 4.4.0-141-generic
Operating System: Alpine Linux v3.9 (containerized)
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 3.066GiB
Name: 89c58ca4f20e
ID: ES34:VXSB:3J4S:X3HJ:H4PW:7TS3:HWZX:USBO:NTVB:ZS6R:I7O2:GCAJ
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Product License: Community Engine
+ /usr/local/bin/docker build --rm=true -f Dockerfile -t . --pull=true --label org.label-schema.schema-version=1.0 --label org.label-schema.build-date=2019-04-09T19:00:27Z --label org.label-schema.vcs-ref= --label org.label-schema.vcs-url=https://git.example.com/example/hello-cicd.git
invalid argument "" for "-t, --tag" flag: invalid reference format
See 'docker build --help'.
time="2019-04-09T19:00:27Z" level=fatal msg="exit status 125" 
@tboerger
Copy link

tboerger commented Apr 9, 2019

I haven't seen that kind of issue so far, and we are using auto tags for all plugins.

@Beanow
Copy link
Author

Beanow commented Apr 9, 2019

Adding echo $$DRONE_COMMIT_REF in the (node) step before correctly outputs refs/tags/2.1.9
However echo $$DRONE_COMMIT_SHA for a tag event is empty. It uses this hash as build.Name for commandBuild

Maybe not including the hash on tag events is unexpected behavior from the gogs webhook?

@Beanow Beanow changed the title Auto tag build fails on drone 1.0 tag event Auto tag build fails when tag event has no commit sha Apr 9, 2019
@Beanow
Copy link
Author

Beanow commented Apr 17, 2019

Indeed it's known and documented, gogs does not provide the SHA on tag events.

https://github.com/drone/drone/blob/5b6a3d8ff4c37283cf37df20d871cc8dfe439565/service/hook/parser/parse.go#L181
https://github.com/drone/drone/blob/5b6a3d8ff4c37283cf37df20d871cc8dfe439565/service/hook/parser/testdata/gogs_tag.json

Basically I can imagine a few flavors to fix this.

  • Force the drone agent or this plugin to fetch this SHA for us so it's available even with gogs.
  • Find a suitable fallback value to use as a deterministic temporary tag name.
  • Merge the build and tag step to avoid needing a temporary tag name.

To me, the later makes the most sense. What do you think @tboerger?

Edit: #230 is example of the later option

@bradrydzewski
Copy link
Member

bradrydzewski commented Apr 17, 2019

Force the drone agent or this plugin to fetch this SHA for us so it's available even with gogs.

I prefer this is fixed at the Drone server level, and we do not make any major changes to the Docker plugin. This plugin is largely frozen and must remain very stable, since it is critical to the Drone ecosystem.

In terms of a temporary workaround I would support setting a random value in the Name field when the commit sha is empty.

+	if plugin.Build.Name == "" {
+		plugin.Build.Name = uniuri.New()
+	}
	return plugin.Exec()
}

@bradrydzewski bradrydzewski changed the title Auto tag build fails when tag event has no commit sha Auto tag build fails when tag event has no commit sha (Gogs) May 14, 2019
@lework
Copy link

lework commented Jul 3, 2019

So, what is the temporary solution?

@tboerger
Copy link

tboerger commented Jul 3, 2019

As Gitea received a fix, and the lib drone/go-scm#22 also includes this fix, and I'm pretty sure since than Drone updated this dep I would guess that latest releases of Gitea and Drone will work properly.

Please upgrade to the latest releases, check if it works, and if it fails report it here.

@Beanow
Copy link
Author

Beanow commented Jul 3, 2019

@tboerger the issue for me applies to gogs, not gittea. I've been running gogs/gogs:0.11.86 since opening the issue and is the latest release on github as well. I've not tested gittea, but indeed I would assume the SHA is available and this should work.

@tboerger
Copy link

tboerger commented Jul 3, 2019

As this is an upstream issue you should push the Gogs issue :)

@Beanow
Copy link
Author

Beanow commented Jul 3, 2019

As this is an upstream issue you should push the Gogs issue :)

Sort of. Kind of. I would agree.
Though it isn't a formal spec to include the SHA right?

Either way I did:
gogs/gogs#5689
gogs/go-gogs-client#103
gogs/go-gogs-client#104

And had zero response. I suppose it highlights why gittea exists.

@Beanow
Copy link
Author

Beanow commented Jul 10, 2019

The upstream fix landed in the develop branch. Hopefully it'll work next release 👍

@marcotuna
Copy link

marcotuna commented Aug 2, 2019

@bradrydzewski @Beanow @tboerger

Tried today with latest versions of Gogs (0.11.89.0728) and Drone Server and Agent 1.2.3

Gogs sends this payload to Drone which comes with the SHA

{
  "ref": "v0.1.0",
  "ref_type": "tag",
  "sha": "c56780c4b2b80d72ba73125eadcb214d4674971d",
  "default_branch": "master",
  "repository": {
    "id": 33,
    "owner": {
      "id": 3,
      "username": "OMMITED",
      "login": "OMMITED",
      "full_name": "",
      "email": "",
      "avatar_url": "https://OMMITED/avatars/3"
    },
    "name": "OMMITED",
    "full_name": "OMMITED/OMMITED",
    "description": "OMMITED",
    "private": true,
    "fork": false,
    "parent": null,
    "empty": false,
    "mirror": false,
    "size": 3387392,
    "html_url": "https://OMMITED/OMMITED/OMMITED",
    "ssh_url": "git@OMMITED:OMMITED/OMMITED.git",
    "clone_url": "https://OMMITED/OMMITED/OMMITED.git",
    "website": "",
    "stars_count": 0,
    "forks_count": 0,
    "watchers_count": 3,
    "open_issues_count": 0,
    "default_branch": "master",
    "created_at": "2019-07-15T14:17:32Z",
    "updated_at": "2019-08-02T14:05:05Z"
  },
  "sender": {
    "id": 16,
    "username": "OMMITED",
    "login": "OMMITED",
    "full_name": "OMMITED",
    "email": "OMMITED",
    "avatar_url": "https://OMMITED/avatars/16"
  }
}

However when building the docker image it fails

+ /usr/local/bin/docker build --rm=true -f Dockerfile -t . --pull=true --label org.label-schema.schema-version=1.0 --label org.label-schema.build-date=2019-08-02T14:05:33Z --label org.label-schema.vcs-ref= --label org.label-schema.vcs-url=https://OMMITED/OMMITED/OMMITED.git

invalid argument "" for "-t, --tag" flag: invalid reference format

I created an intermediate container to print all environments variables and the SHA is not present.

DRONE_COMMIT_AUTHOR_AVATAR=https://OMMITED/avatars/16
DRONE_SYSTEM_HOST=OMMITED
DRONE_NETRC_MACHINE=OMMITED
DRONE_BRANCH=v0.1.0
DRONE_GIT_SSH_URL=git@OMMITED:OMMITED/OMMITED.git
DRONE_JOB_FINISHED=1564754713
CI_BUILD_TARGET=
CI=true
HOSTNAME=95189c7cf886
DRONE_TARGET_BRANCH=v0.1.0
DRONE_COMMIT_AUTHOR=OMMITED
DRONE_REPO_LINK=
DRONE_REPO_NAMESPACE=OMMITED
CI_BUILD_NUMBER=132
DRONE_STAGE_OS=linux
CI_BUILD_STARTED=1564754711
CI_BUILD_LINK=
CI_WORKSPACE=/drone/src
DRONE_RUNNER_HOSTNAME=OMMITED
DRONE_GIT_HTTP_URL=https://OMMITED/OMMITED/OMMITED.git
DRONE_COMMIT_BRANCH=v0.1.0
HOME=/root
DRONE_REPO_PRIVATE=true
DRONE_REPO_SCM=
DRONE_SYSTEM_PROTO=https
DRONE_STEP_NUMBER=2
DRONE_REPO_VISIBILITY=private
DRONE_BUILD_STATUS=success
CI_WORKSPACE_PATH=
DRONE_STAGE_ARCH=amd64
CI_JOB_STARTED=1564754711
DRONE_COMMIT_BEFORE=
CI_PARENT_BUILD_NUMBER=0
DRONE_BUILD_ACTION=create
DRONE_RUNNER_PLATFORM=linux/amd64
CI_BUILD_EVENT=tag
DRONE_WORKSPACE_BASE=/drone/src
CI_COMMIT_SHA=
CI_REPO_NAME=OMMITED/OMMITED
CI_BUILD_CREATED=1564754710
CI_COMMIT_AUTHOR_EMAIL=OMMITED
CI_COMMIT_REF=refs/tags/v0.1.0
DRONE_STAGE_STATUS=success
DRONE_SOURCE_BRANCH=v0.1.0
DRONE_STAGE_NAME=Release
DRONE_COMMIT_MESSAGE=
DRONE_REPO_BRANCH=master
DRONE_DEPLOY_TO=
CI_BUILD_FINISHED=1564754713
DRONE_SYSTEM_HOSTNAME=OMMITED
DRONE_JOB_STATUS=success
DRONE_REMOTE_URL=https://OMMITED/OMMITED/OMMITED.git
CI_REPO=OMMITED/OMMITED
DRONE_REPO_OWNER=OMMITED
CI_COMMIT_AUTHOR_NAME=OMMITED
DRONE_STAGE_KIND=pipeline
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
DRONE=true
CI_COMMIT_AUTHOR_AVATAR=https://OMMITED/avatars/16
CI_NETRC_MACHINE=OMMITED
DRONE_BUILD_NUMBER=132
DRONE_BUILD_STARTED=1564754711
DRONE_BUILD_LINK=https://OMMITED/OMMITED/OMMITED/132
CI_JOB_FINISHED=1564754713
DRONE_WORKSPACE=/drone/src
DRONE_STAGE_VARIANT=
DRONE_COMMIT_AFTER=
DRONE_STAGE_DEPENDS_ON=
DRONE_TAG=v0.1.0
CI_COMMIT_AUTHOR=OMMITED
CI_REPO_LINK=
DRONE_STAGE_STARTED=1564754711
DRONE_STAGE_NUMBER=1
DRONE_COMMIT=
CI_COMMIT_BRANCH=v0.1.0
CI_REPO_REMOTE=https://OMMITED/OMMITED/OMMITED.git
CI_REPO_PRIVATE=true
DRONE_RUNNER_HOST=OMMITED
DRONE_JOB_STARTED=1564754711
DRONE_BUILD_EVENT=tag
DRONE_WORKSPACE_PATH=
DRONE_REPO_NAME=OMMITED
DRONE_BUILD_CREATED=1564754710
DRONE_COMMIT_SHA=
DRONE_COMMIT_AUTHOR_EMAIL=OMMITED
CI_BUILD_STATUS=success
DRONE_STAGE_MACHINE=OMMITED
DRONE_COMMIT_REF=refs/tags/v0.1.0
DRONE_MACHINE=OMMITED
CI_WORKSPACE_BASE=/drone/src
PWD=/drone/src
DRONE_COMMIT_LINK=
DRONE_BUILD_FINISHED=1564754713
DOCKER_NETWORK_ID=cn3b53pyor67jpq1nxae4vo8ltln5o4m
CI_COMMIT_MESSAGE=
DRONE_STEP_NAME=docker-tag-demo
DRONE_REPO=OMMITED/OMMITED
DRONE_SYSTEM_VERSION=1.2.3
DRONE_COMMIT_AUTHOR_NAME=OMMITED
DRONE_DOCKER_NETWORK_ID=cn3b53pyor67jpq1nxae4vo8ltln5o4m
DRONE_STAGE_FINISHED=1564754713
CI_JOB_STATUS=success
CI_REMOTE_URL=https://OMMITED/OMMITED/OMMITED.git

What am I missing?

@bradrydzewski
Copy link
Member

bradrydzewski commented Aug 2, 2019

Previous versions of Gogs did not provide the sha in the tag create webhook. It is great to see that Gogs is now providing the sha, however, that does not mean that Drone will automatically read the sha. Someone now needs to add code to go-scm to read the sha from the json payload.

For example, when Gitea added the sha value to the webhook someone sent us this pull request to read the sha drone/go-scm#22.

@lawrence-peng
Copy link

Hi @marcotuna ,
I also have this issue. Is your issue awkward?

@tboerger
Copy link

This is only the case for old Gogs version, upgrade your Gogs instance.

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 a pull request may close this issue.

6 participants