def one_off(args='', verbose=False): hide = not verbose config_yaml, settings_py = read_config_files() server = config_yaml['server'] app_name = config_yaml["app"]["name"] wsgi = config_yaml['app']['wsgi'] asgi = config_yaml['app']['asgi'] if wsgi: image_name = 'wsgi' elif asgi: image_name = 'asgi' else: print( 'At least wsgi or asgi service should be defined to run one-off command.' ) return with Connection(host=server['host'], user=server['username'], connect_kwargs={'key_filename': server['pem']}) as cnx: try: with cnx.cd(f'{server_dir}/{app_name}'): print(f'docker-compose run {image_name} {" ".join(args)}') cnx.run(f'docker-compose run {image_name} {" ".join(args)}') except exceptions.UnexpectedExit: print('Some exception')
def restart(verbose=False): hide = not verbose config_yaml, settings_py = read_config_files() app_dir = config_yaml['app']['path'] app_name = config_yaml["app"]["name"] shutil.make_archive(app_name, 'zip', app_dir) server = config_yaml['server'] with Connection(host=server['host'], user=server['username'], connect_kwargs={'key_filename': server['pem']}) as cnx: try: with cnx.cd(f'{server_dir}/{app_name}'): cnx.run('docker-compose restart') except exceptions.UnexpectedExit as e: print('Some exception') print(e) os.remove(f'{app_name}.zip')
def deploy(verbose=False): hide = not verbose config_yaml, settings_py = read_config_files() print('Zipping the django project') app_dir = config_yaml['app']['path'] app_name = config_yaml["app"]["name"] shutil.make_archive(app_name, 'zip', app_dir) server = config_yaml['server'] with Connection(host=server['host'], user=server['username'], connect_kwargs={'key_filename': server['pem']}) as cnx: try: prepare_dir_structs(cnx, config_yaml, settings_py, hide) run_docker_app(cnx, config_yaml, server, hide) except exceptions.UnexpectedExit as e: print('Some exception') print(e) os.remove(f'{app_name}.zip')