{"action":"created","issue":{"url":"https://api.github.com/repos/DBuildService/dock/issues/67","labels_url":"https://api.github.com/repos/DBuildService/dock/issues/67/labels{/name}","comments_url":"https://api.github.com/repos/DBuildService/dock/issues/67/comments","events_url":"https://api.github.com/repos/DBuildService/dock/issues/67/events","html_url":"https://github.com/DBuildService/dock/issues/67","id":65688364,"number":67,"title":"Race condition when running two builds with the same registry, image name and tag","user":{"login":"mmilata","id":85857,"avatar_url":"https://avatars.githubusercontent.com/u/85857?v=3","gravatar_id":"","url":"https://api.github.com/users/mmilata","html_url":"https://github.com/mmilata","followers_url":"https://api.github.com/users/mmilata/followers","following_url":"https://api.github.com/users/mmilata/following{/other_user}","gists_url":"https://api.github.com/users/mmilata/gists{/gist_id}","starred_url":"https://api.github.com/users/mmilata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mmilata/subscriptions","organizations_url":"https://api.github.com/users/mmilata/orgs","repos_url":"https://api.github.com/users/mmilata/repos","events_url":"https://api.github.com/users/mmilata/events{/privacy}","received_events_url":"https://api.github.com/users/mmilata/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-04-01T13:48:26Z","updated_at":"2015-04-02T05:48:05Z","closed_at":null,"body":"Running two same builds results in\r\n```\r\n2015-04-01 04:13:30,841 - dock.build - INFO - push built image to registry\r\n2015-04-01 04:13:30,841 - dock.core - INFO - tag and push image\r\n2015-04-01 04:13:30,841 - dock.core - DEBUG - image = 'user/image', target_image_name = 'user/image', reg_uri = 'registry.example.org', tag = ''\r\n2015-04-01 04:13:30,841 - dock.core - INFO - tag image\r\n2015-04-01 04:13:30,841 - dock.core - DEBUG - image = 'user/image', target_image_name = 'user/image', reg_uri = 'registry.example.org', tag = ''\r\nTraceback (most recent call last):\r\n  File \"/usr/bin/dock\", line 9, in <module>\r\n    load_entry_point('dock==1.1.1', 'console_scripts', 'dock')()\r\n  File \"/usr/lib/python2.7/site-packages/dock/cli/main.py\", line 187, in run\r\n    cli.run()\r\n  File \"/usr/lib/python2.7/site-packages/dock/cli/main.py\", line 170, in run\r\n    args.func(args)\r\n  File \"/usr/lib/python2.7/site-packages/dock/cli/main.py\", line 66, in cli_inside_build\r\n    build_inside(input=args.input, input_args=args.input_arg, substitutions=args.substitute)\r\n  File \"/usr/lib/python2.7/site-packages/dock/inner.py\", line 215, in build_inside\r\n    image = dbw.build_docker_image()\r\n  File \"/usr/lib/python2.7/site-packages/dock/inner.py\", line 152, in build_docker_image\r\n    self.builder.push_built_image(target_registry, insecure=self.target_registries_insecure)\r\n  File \"/usr/lib/python2.7/site-packages/dock/build.py\", line 159, in push_built_image\r\n    response = self.tasker.tag_and_push_image(self.image, local_registry, registry, tag=self.tag, insecure=insecure)\r\n  File \"/usr/lib/python2.7/site-packages/dock/core.py\", line 394, in tag_and_push_image\r\n    final_tag = self.tag_image(image, target_image_name, reg_uri=reg_uri, tag=tag)\r\n  File \"/usr/lib/python2.7/site-packages/dock/core.py\", line 355, in tag_image\r\n    response = self.d.tag(image, repository, tag=tag, force=force)  # returns True/False\r\n  File \"/usr/lib/python2.7/site-packages/docker/client.py\", line 897, in tag\r\n    self._raise_for_status(res)\r\n  File \"/usr/lib/python2.7/site-packages/docker/client.py\", line 95, in _raise_for_status\r\n    raise errors.APIError(e, response, explanation=explanation)\r\ndocker.errors.APIError: 409 Client Error: Conflict (\"Conflict: Tag latest is already set to image 38b331ae434a3490e76ab6d10979a53ffb8ef003991d39fb253c2dbcb1bd2f59, if you want to replace it, please use -f option\")\r\n```\r\n\r\nI suppose what happened is that build1 tagged the image and build2 tried to tag the image with the same tag before build1 deleted the tag.\r\n\r\nI'm not sure what the expected behavior should be - if we force-tag in the second build then one of the builds will fail because it will try to delete nonexistent tag. We'd have to make the tag & push sequence atomic somehow ...\r\n\r\nFound by @goern.\r\n"},"comment":{"url":"https://api.github.com/repos/DBuildService/dock/issues/comments/88749327","html_url":"https://github.com/DBuildService/dock/issues/67#issuecomment-88749327","issue_url":"https://api.github.com/repos/DBuildService/dock/issues/67","id":88749327,"user":{"login":"TomasTomecek","id":1662493,"avatar_url":"https://avatars.githubusercontent.com/u/1662493?v=3","gravatar_id":"","url":"https://api.github.com/users/TomasTomecek","html_url":"https://github.com/TomasTomecek","followers_url":"https://api.github.com/users/TomasTomecek/followers","following_url":"https://api.github.com/users/TomasTomecek/following{/other_user}","gists_url":"https://api.github.com/users/TomasTomecek/gists{/gist_id}","starred_url":"https://api.github.com/users/TomasTomecek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TomasTomecek/subscriptions","organizations_url":"https://api.github.com/users/TomasTomecek/orgs","repos_url":"https://api.github.com/users/TomasTomecek/repos","events_url":"https://api.github.com/users/TomasTomecek/events{/privacy}","received_events_url":"https://api.github.com/users/TomasTomecek/received_events","type":"User","site_admin":false},"created_at":"2015-04-02T05:48:05Z","updated_at":"2015-04-02T05:48:05Z","body":"You can explicitely ask for `latest` tag, then it won't fail (but one of your images will be lost, pretty much).\r\n\r\nWith prod strategy we are constructing image names that we put timestamps inside:\r\n```python\r\ntimestamp = datetime.datetime.now().strftime('%Y%m%d%H%M%S')\r\nimage = \"%s/%s:%s-%s\" % (self.user, self.component, self.koji_target, timestamp)\r\n```\r\n\r\nMaybe we could solve this by applying unique tag, e.g. `\":ttomecek-20150402-133759357\"` (and then tag it according to user request -- and if that fails, we will inform user and offer our tag)."}}