def reload(self): cfg_base = read_config(self.path) cfg_running = False try: cfg_running = cfg_base.fetch() self.cannot_read_status = False except docker.errors.NotFound: self.cannot_read_status = True self.is_running = bool(cfg_running) with docker_client() as client: self.containers = { k: container_status(client, v) for k, v in cfg_base.containers.items() } self.container_groups = { k: container_group_status(client, v) for k, v in cfg_base.container_groups.items() } if cfg_running: self.volumes = cfg_running.volumes self.network = cfg_running.network else: self.volumes = {} self.network = None
def pull(cfg): print("Pulling orderly-web images:") with docker_client() as cl: for name, repo in cfg.images.items(): image = str(repo) print(" - {} ({})".format(name, image)) img = cl.images.pull(str(image)) print(" `-> {}".format(img.short_id))
def run(path, args): cfg = fetch_config(path) image = str(cfg.images["admin"]) with docker_client() as cl: mounts = [docker.types.Mount("/orderly", cfg.volumes["orderly"])] result = return_logs_and_remove(cl, image, args, mounts) print(result) return result
def fetch(self): try: with docker_client() as cl: name = self.containers[PATH_CONFIG["container"]] container = cl.containers.get(name) except docker.errors.NotFound: return None path = PATH_CONFIG["path"] txt = string_from_container(container, path) cfg = pickle.loads(base64.b64decode(txt)) # We have to set the path because the relative path (or even # absolute path) might be different between different users of # the same configuration, as the docker container is a global # resource. cfg.path = self.path return cfg
def start(path, extra=None, options=None, pull_images=False): st = status(path) for name, data in st.containers.items(): if data["status"] != "missing": msg = "Container '{}' is {}; please run orderly-web stop".format( name, data["status"]) print(msg) return False cfg = build_config(path, extra, options) cfg.resolve_secrets() if pull_images: pull(cfg) notifier = Notifier(cfg.slack_webhook_url) with docker_client() as cl: notifier.post("*Starting* deploy to {}".format(cfg.web_url)) try: init_all(cl, cfg) notifier.post("*Completed* deploy to {} :shipit:".format( cfg.web_url)) return True except Exception: notifier.post("*Failed* deploy to {} :bomb:".format(cfg.web_url)) raise
def get_container(self, name): with docker_client() as cl: return cl.containers.get(self.containers[name])