def build_basement_image():
  source_file = './templates/Dockerfile-basement'
  destination_file = './tmp/Dockerfile'

  run("mkdir -p ./tmp")
  files.upload_template(source_file, destination_file, mode=0777)

  image = Image("basement", destination_file)
  image.build()
  run("rm -rf ./tmp")
  return image
def build_web_app_image():
  context = { "parent_image_id": Image.image_id_of("web-basement")[0], "port_maps": [{container: 80}, {container: 443}] }
  source_file = './templates/Dockerfile-web-app'
  destination_file = './tmp/Dockerfile'

  run("mkdir -p ./tmp")
  files.upload_template(source_file, destination_file, context=context, mode=0777)

  image = Image("web-app", destination_file)
  image.build()
  run("rm -rf ./tmp")
  return image
def build_mysql_image():
  context = { "parent_image_id": Image.image_id_of("basement")[0], "root_password": "" }
  source_file = './templates/Dockerfile-mysql'
  destination_file = './tmp/Dockerfile'

  run("mkdir -p ./tmp")
  files.upload_template(source_file, destination_file, mode=0777)

  image = Image("mysql", destination_file)
  image.build()
  run("rm -rf ./tmp")
  return image
def build_web_basement_image():
  context = { "parent_image_id": Image.image_id_of("basement")[0] }
  source_file = './templates/Dockerfile-web-server'
  destination_file = './tmp/Dockerfile'

  run("mkdir -p ./tmp")
  files.upload_template(source_file, destination_file, context=context, mode=0777)
  files.upload_template("./templates/nginx/default", "./tmp/default", mode=0644)
  files.upload_template("./templates/nginx/default-ssl", "./tmp/default-ssl", mode=0644)

  image = Image("web-basement", destination_file)
  image.build()
  run("rm -rf ./tmp")
  return image