Skip to content

Commit

Permalink
Add naming for docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
evanyeyeye committed Jan 29, 2024
1 parent 8348ab5 commit 8c6122c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion restful_tango/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def post(self, key):
"""post - Handles the post request to build."""
name = self.tempfile.name
self.tempfile.close()
self.write(tangoREST.build(key, name))
self.write(tangoREST.build(key, name, self.request.headers["imageName"]))


async def main(port: int):
Expand Down
15 changes: 12 additions & 3 deletions restful_tango/tangoREST.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def prealloc(self, key, image, num, vmStr):
self.log.info("Key not recognized: %s" % key)
return self.status.wrong_key

def build(self, key, tempfile):
def build(self, key, tempfile, imageName):
self.log.debug("Received build request(%s)" % (key))
if self.validateKey(key):
if Config.VMMS_NAME != "localDocker":
Expand All @@ -454,13 +454,22 @@ def build(self, key, tempfile):
client = docker.from_env()
imageTarStr = open(tempfile, "rb").read()
images = client.images.load(imageTarStr)
id_list = ", ".join(image.short_id for image in images)
if len(images) != 1:
raise Exception(
"Wrong number of images built: %s" % str(len(images))
)
image = images[0]
imageName = imageName + ":latest"
image.tag(imageName)
for tag in image.tags:
if tag != imageName:
client.images.remove(tag)
except Exception as e:
self.log.error("Image build failed: " + str(e))
os.unlink(tempfile)
return self.status.image_build_failed

self.log.info("Successfully loaded images: %s" % (id_list))
self.log.info("Successfully loaded image: %s" % (imageName))
os.unlink(tempfile)
return self.status.image_built
else:
Expand Down

0 comments on commit 8c6122c

Please sign in to comment.