def upload(self, context='services'): CLI.info('Uploading...') steps = 1 if context == 'services': CLI.step( 1, steps, 'Uploading configs for context "services" [webserver, cache, htpasswd]' ) elif context == 'compose': CLI.step( 1, steps, 'Uploading configs for context "compose" [docker compose configs and environment]' ) elif context == 'mantis': CLI.step(1, steps, 'Uploading configs for mantis [mantis.json]') else: CLI.error(f'Unknown context "{context}"') if self.environment_id == 'dev': print('Skipping for dev...') elif self.mode == 'host': CLI.warning( 'Not uploading due to host mode! Be sure your configs on host are up to date!' ) else: if context == 'services': os.system( f'rsync -arvz -e \'ssh -p {self.port}\' -rvzh --progress {self.cache_config} {self.user}@{self.host}:/home/{self.user}/public_html/web/configs/{self.CACHE}/' ) os.system( f'rsync -arvz -e \'ssh -p {self.port}\' -rvzh --progress {self.webserver_config} {self.user}@{self.host}:/home/{self.user}/public_html/web/configs/{self.WEBSERVER}/' ) os.system( f'rsync -arvz -e \'ssh -p {self.port}\' -rvzh --progress {self.webserver_config_proxy} {self.user}@{self.host}:/etc/nginx/conf.d/proxy/' ) os.system( f'rsync -arvz -e \'ssh -p {self.port}\' -rvzh --progress {self.htpasswd} {self.user}@{self.host}:/etc/nginx/conf.d/' ) elif context == 'mantis': os.system( f'rsync -arvz -e \'ssh -p {self.port}\' -rvzh --progress {self.config_file} {self.user}@{self.host}:/home/{self.user}/public_html/web/configs/' ) elif context == 'compose': os.system( f'rsync -arvz -e \'ssh -p {self.port}\' -rvzh --progress {self.environment_file} {self.user}@{self.host}:/home/{self.user}/public_html/web/configs/environments/' ) for config in self.compose_configs: os.system( f'rsync -arvz -e \'ssh -p {self.port}\' -rvzh --progress {config} {self.user}@{self.host}:/home/{self.user}/public_html/web/configs/docker/' )
def main(): # check params params = parse_args() # print(params) if len(params['commands']) == 0: CLI.error('Missing commands') environment_id = params['environment_id'] commands = params['commands'] mode = params['settings'].get('mode', 'docker-host') hostname = os.popen('hostname').read().rstrip("\n") # setup manager manager = Mantis(environment_id=environment_id, mode=mode) print(f'Mantis (v{VERSION}) attached to ' f'{Colors.BOLD}{manager.environment_id}{Colors.ENDC}: ' f'{Colors.RED}{manager.host}{Colors.ENDC}, ' f'mode: {Colors.GREEN}{manager.mode}{Colors.ENDC}, ' f'hostname: {Colors.BLUE}{hostname}{Colors.ENDC}') if mode == 'ssh': cmds = [ f'cd {manager.project_path}', f'time mantis {environment_id} --mode=host {" ".join(commands)}' ] cmd = ';'.join(cmds) exec = f"ssh -t {manager.user}@{manager.host} -p {manager.port} '{cmd}'" os.system(exec) else: # execute all commands for command in commands: if ':' in command: command, params = command.split(':') else: params = None execute(manager, command, params)
def execute(manager, command, params=None): if manager.environment_id is None: CLI.error('Missing environment') else: manager_method = { '--build': 'build', '-b': 'build', '--push': 'push', '--pull': 'pull', '-p': 'pull', '--upload': 'upload', '--upload-docker-configs': 'upload_docker_configs', '-u': 'upload', '--reload': 'reload', '--restart': 'restart', '--deploy': 'deploy', '-d': 'deploy', '--stop': 'stop', '--start': 'start', '--clean': 'clean', '-c': 'clean', '--remove': 'remove', '--reload-webserver': 'reload_webserver', '--restart-proxy': 'restart_proxy', '--status': 'status', '-s': 'status', '--networks': 'networks', '-n': 'networks', '--logs': 'logs', '-l': 'logs', '--shell': 'shell', '--ssh': 'ssh', '--manage': 'manage', '--exec': 'exec', '--psql': 'psql', '--pg-dump': 'pg_dump', '--pg-restore': 'pg_restore', '--send-test-email': 'send_test_email', }.get(command) methods_with_params = [ 'build', 'ssh', 'exec', 'manage', 'pg_restore', 'start', 'stop', 'logs', 'remove', 'upload' ] if manager_method is None or not hasattr(manager, manager_method): CLI.error( f'Invalid command "{command}" \n\nUsage: mantis <ENVIRONMENT> ' '\n--no-ssh |' '\n--build/-b |' '\n--push |' '\n--pull/-p |' '\n--upload/-u | ' '\n--deploy/-d | ' '\n--stop | ' '\n--start | ' '\n--reload | ' '\n--restart | ' '\n--remove | ' '\n--clean/-c | ' '\n--status/-s | ' '\n--networks/-n | ' '\n--logs/-l | ' '\n--reload-webserver | ' '\n--restart-proxy | ' '\n--manage | ' '\n--shell | ' '\n--ssh | ' '\n--exec | ' '\n--psql | ' '\n--pg-dump | ' '\n--pg-restore | ' '\n--send-test-email') else: if manager_method in methods_with_params and params: getattr(manager, manager_method)(params) else: getattr(manager, manager_method)()