def push_cmd(target, version, username, password, email, apikey, insecure, skip_tests): # Test the image content after building it if not skip_tests: test_cmd(target, version) client = utils.get_docker_client() config = load_shub_config() image = config.get_image(target) username, password = utils.get_credentials( username=username, password=password, insecure=insecure, apikey=apikey, target_apikey=config.get_apikey(target)) if username: _execute_push_login(client, image, username, password, email) image_name = utils.format_image_name(image, version) click.echo("Pushing {} to the registry.".format(image_name)) events = client.push(image_name, stream=True, decode=True, insecure_registry=not bool(username)) if utils.is_verbose(): push_progress_cls = _LoggedPushProgress else: push_progress_cls = _PushProgress push_progress = push_progress_cls(events) push_progress.show() click.echo("The image {} pushed successfully.".format(image_name))
def push_cmd(target, version, username, password, email, apikey, insecure, skip_tests): # Test the image content after building it if not skip_tests: test_cmd(target, version) client = utils.get_docker_client() config = load_shub_config() image = config.get_image(target) username, password = utils.get_credentials( username=username, password=password, insecure=insecure, apikey=apikey, target_apikey=config.get_apikey(target)) if username: _execute_push_login(client, image, username, password, email) image_name = utils.format_image_name(image, version) click.echo("Pushing {} to the registry.".format(image_name)) events = client.push(image_name, stream=True, decode=True, insecure_registry=not bool(username)) if utils.is_verbose(): push_progress_cls = _LoggedPushProgress else: push_progress_cls = _PushProgress push_progress = push_progress_cls(events) push_progress.show() click.echo("The image {} pushed successfully.".format(image_name))
def test_get_credentials(self): assert get_credentials(insecure=True) == (None, None) assert get_credentials(apikey='apikey') == ('apikey', ' ') assert get_credentials(username='******', password='******') == ('user', 'pass') with pytest.raises(click.BadParameter): get_credentials(username='******') assert get_credentials(target_apikey='tapikey') == ('tapikey', ' ')
def deploy_cmd(target, version, username, password, email, apikey, insecure, async): config = load_shub_config() target_conf = config.get_target_conf(target) endpoint, target_apikey = target_conf.endpoint, target_conf.apikey image = config.get_image(target) version = version or config.get_version() image_name = utils.format_image_name(image, version) username, password = utils.get_credentials(username=username, password=password, insecure=insecure, apikey=apikey, target_apikey=target_apikey) apikey = apikey or target_apikey params = _prepare_deploy_params(target_conf.project_id, version, image_name, endpoint, apikey, username, password, email) utils.debug_log('Deploy with params: {}'.format(params)) req = requests.post(urljoin(endpoint, '/api/releases/deploy.json'), data=params, auth=(apikey, ''), timeout=300, allow_redirects=False) try: req.raise_for_status() except requests.exceptions.HTTPError: _handle_deploy_errors(req) click.echo("Deploy task results: {}".format(req)) status_url = req.headers['location'] status_id = utils.store_status_url(status_url, limit=STORE_N_LAST_STATUS_URLS) click.echo("You can check deploy results later with " "'shub image check --id {}'.".format(status_id)) click.echo("Deploy results:") actual_state = _check_status_url(status_url) click.echo(" {}".format(actual_state)) if not async: status = actual_state['status'] while status in SYNC_DEPLOY_WAIT_STATUSES: time.sleep(SYNC_DEPLOY_REFRESH_TIMEOUT) actual_state = _check_status_url(status_url) if actual_state['status'] != status: click.echo(" {}".format(actual_state)) status = actual_state['status']
def deploy_cmd(target, version, username, password, email, apikey, insecure, async_): config = load_shub_config() target_conf = config.get_target_conf(target) endpoint, target_apikey = target_conf.endpoint, target_conf.apikey image = config.get_image(target) version = version or config.get_version() image_name = utils.format_image_name(image, version) username, password = utils.get_credentials( username=username, password=password, insecure=insecure, apikey=apikey, target_apikey=target_apikey) apikey = apikey or target_apikey params = _prepare_deploy_params( target_conf.project_id, version, image_name, endpoint, apikey, username, password, email) click.echo("Deploying {}".format(image_name)) utils.debug_log('Deploy parameters: {}'.format(params)) req = requests.post( urljoin(endpoint, '/api/releases/deploy.json'), data=params, auth=(apikey, ''), timeout=300, allow_redirects=False ) if req.status_code == 400: reason = req.json().get('non_field_errors') raise ShubException('\n'.join(reason) if reason else req.text) req.raise_for_status() status_url = req.headers['location'] status_id = utils.store_status_url( status_url, limit=STORE_N_LAST_STATUS_URLS) click.echo( "You can check deploy results later with " "'shub image check --id {}'.".format(status_id)) if async_: return if utils.is_verbose(): deploy_progress_cls = _LoggedDeployProgress else: deploy_progress_cls = _DeployProgress events = _convert_status_requests_to_events(status_url) deploy_progress = deploy_progress_cls(events) deploy_progress.show()
def deploy_cmd(target, version, username, password, email, apikey, insecure, async_): config = load_shub_config() target_conf = config.get_target_conf(target) endpoint, target_apikey = target_conf.endpoint, target_conf.apikey image = config.get_image(target) version = version or config.get_version() image_name = utils.format_image_name(image, version) username, password = utils.get_credentials( username=username, password=password, insecure=insecure, apikey=apikey, target_apikey=target_apikey) apikey = apikey or target_apikey params = _prepare_deploy_params( target_conf.project_id, version, image_name, endpoint, apikey, username, password, email) click.echo("Deploying {}".format(image_name)) utils.debug_log('Deploy parameters: {}'.format(params)) req = requests.post( urljoin(endpoint, '/api/releases/deploy.json'), data=params, auth=(apikey, ''), timeout=300, allow_redirects=False ) if req.status_code == 400: reason = req.json().get('non_field_errors') raise ShubException('\n'.join(reason) if reason else req.text) req.raise_for_status() status_url = req.headers['location'] status_id = utils.store_status_url( status_url, limit=STORE_N_LAST_STATUS_URLS) click.echo( "You can check deploy results later with " "'shub image check --id {}'.".format(status_id)) if async_: return if utils.is_verbose(): deploy_progress_cls = _LoggedDeployProgress else: deploy_progress_cls = _DeployProgress events = _convert_status_requests_to_events(status_url) deploy_progress = deploy_progress_cls(events) deploy_progress.show()