@@ -34,14 +34,17 @@ ENTRYPOINT ["/runner/init"]
3434
3535if __name__ == '__main__' :
3636 user , repo , branch , app = parse_args ()
37- # define image names
38- _id = uuid .uuid4 ().hex [:8 ]
39- tmp_image = "{app}:temp_{_id}" .format (** locals ())
40- target_image = "{{ .deis_registry_host }}:{{ .deis_registry_port }}/{app}" .format (** locals ())
4137 # create required directories
4238 repo_dir = os .path .join (os .getcwd (), repo )
4339 build_dir = os .path .join (repo_dir , 'build' )
4440 cache_dir = os .path .join (repo_dir , 'cache' )
41+ # get sha of branch
42+ with open (os .path .join (repo_dir , branch )) as f :
43+ sha = f .read ().strip ('\n ' )
44+ short_sha = sha [:8 ]
45+ # define image names
46+ tmp_image = "{app}:git-{short_sha}" .format (** locals ())
47+ target_image = "{{ .deis_registry_host }}:{{ .deis_registry_port }}/{tmp_image}" .format (** locals ())
4548 for d in (cache_dir , build_dir ):
4649 if not os .path .exists (d ):
4750 os .mkdir (d )
@@ -111,6 +114,7 @@ if __name__ == '__main__':
111114 raise Exception ('Could not push Docker image' )
112115 # construct json body for posting to the build hook
113116 body = {}
117+ body ['sha' ] = sha
114118 body ['receive_user' ] = user
115119 body ['receive_repo' ] = app
116120 body ['image' ] = target_image
@@ -162,8 +166,8 @@ if __name__ == '__main__':
162166 l = locals ()
163167 shutil .rmtree (temp_dir )
164168 if 'container' in l :
165- subprocess .Popen ('docker rm {container}' .format (** l ), shell = True ,
169+ subprocess .Popen ('docker rm -f {container}' .format (** l ), shell = True ,
166170 stdout = open (os .devnull , 'w' ), stderr = open (os .devnull , 'w' ))
167- if 'tmp_image' in l :
168- subprocess .Popen ('docker rmi {tmp_image}' .format (** l ), shell = True ,
171+ if 'tmp_image' in l and 'target_image' in l :
172+ subprocess .Popen ('docker rmi -f {tmp_image} {target_image }' .format (** l ), shell = True ,
169173 stdout = open (os .devnull , 'w' ), stderr = open (os .devnull , 'w' ))
0 commit comments