def handle(self, *args, **options): root_dir = settings.FILEPATH git_snapshot = gitinfo.get_project_snapshot(root_dir, submodules=True) compare_url = git_snapshot['diff_url'] = options.get('url', None) deploy = HqDeploy( date=datetime.utcnow(), user=options['user'], environment=options['environment'], code_snapshot=git_snapshot, ) deploy.save() # reset PillowTop errors in the hope that a fix has been deployed rows_updated = PillowError.bulk_reset_attempts(datetime.utcnow()) if rows_updated: print "\n---------------- Pillow Errors Reset ----------------\n" \ "{} pillow errors queued for retry\n".format(rows_updated) deploy_notification_text = ( "CommCareHQ has been successfully deployed to *{}* by *{}*. " "Find the diff {{diff_link}}".format( options['environment'], options['user'], ) ) if hasattr(settings, 'MIA_THE_DEPLOY_BOT_API'): link = diff_link(STYLE_SLACK, compare_url) requests.post(settings.MIA_THE_DEPLOY_BOT_API, data=json.dumps({ "username": "******", "text": deploy_notification_text.format(diff_link=link), })) if settings.DATADOG_API_KEY: tags = ['environment:{}'.format(options['environment'])] link = diff_link(STYLE_MARKDOWN, compare_url) datadog_api.Event.create( title="Deploy Success", text=deploy_notification_text.format(diff_link=link), tags=tags, alert_type="success" ) print "\n=============================================================\n" \ "Congratulations! Deploy Complete.\n\n" \ "Don't forget to keep an eye on the deploy dashboard to " \ "make sure everything is running smoothly.\n\n" \ "https://p.datadoghq.com/sb/5c4af2ac8-1f739e93ef" \ "\n=============================================================\n" if options['mail_admins']: message_body = get_deploy_email_message_body( environment=options['environment'], user=options['user'], compare_url=compare_url) call_command('mail_admins', message_body, **{'subject': 'Deploy successful', 'html': True})
def handle(self, **options): compare_url = options.get('url', None) minutes = options.get('minutes', None) deploy = HqDeploy(date=datetime.utcnow(), user=options['user'], environment=options['environment'], diff_url=compare_url) deploy.save() # reset PillowTop errors in the hope that a fix has been deployed rows_updated = PillowError.bulk_reset_attempts(datetime.utcnow()) if rows_updated: print("\n---------------- Pillow Errors Reset ----------------\n" \ "{} pillow errors queued for retry\n".format(rows_updated)) deploy_notification_text = ( "CommCareHQ has been successfully deployed to *{}* by *{}* in *{}* minutes. " .format( options['environment'], options['user'], minutes or '?', )) if options['environment'] == 'production': deploy_notification_text += "Monitor the {dashboard_link}. " if settings.MOBILE_INTEGRATION_TEST_TOKEN: deploy_notification_text += "Check the integration {integration_tests_link}. " requests.get( 'https://jenkins.dimagi.com/job/integration-tests/build', params={'token': settings.MOBILE_INTEGRATION_TEST_TOKEN}, ) requests.get( 'https://jenkins.dimagi.com/job/integration-tests-pipeline/build', params={'token': settings.MOBILE_INTEGRATION_TEST_TOKEN}, ) deploy_notification_text += "Find the diff {diff_link}" if hasattr(settings, 'MIA_THE_DEPLOY_BOT_API'): link = diff_link(STYLE_SLACK, compare_url) if options['environment'] == 'staging': channel = '#staging' elif options['environment'] == 'icds': channel = '#nic-server-standup' else: channel = '#hq-ops' requests.post( settings.MIA_THE_DEPLOY_BOT_API, data=json.dumps({ "username": "******", "channel": channel, "text": deploy_notification_text.format( dashboard_link=dashboard_link(STYLE_SLACK, DASHBOARD_URL), diff_link=link, integration_tests_link=integration_tests_link( STYLE_SLACK, INTEGRATION_TEST_URL)), })) if settings.DATADOG_API_KEY: tags = ['environment:{}'.format(options['environment'])] link = diff_link(STYLE_MARKDOWN, compare_url) datadog_api.Event.create( title="Deploy Success", text=deploy_notification_text.format( dashboard_link=dashboard_link(STYLE_MARKDOWN, DASHBOARD_URL), diff_link=link, integration_tests_link=integration_tests_link( STYLE_MARKDOWN, INTEGRATION_TEST_URL)), tags=tags, alert_type="success") print("\n=============================================================\n" \ "Congratulations! Deploy Complete.\n\n" \ "Don't forget to keep an eye on the deploy dashboard to " \ "make sure everything is running smoothly.\n\n" \ "https://p.datadoghq.com/sb/5c4af2ac8-1f739e93ef" \ "\n=============================================================\n") if options['mail_admins']: message_body = get_deploy_email_message_body( user=options['user'], compare_url=compare_url) call_command('mail_admins', message_body, **{ 'subject': 'Deploy successful', 'html': True }) if settings.DAILY_DEPLOY_EMAIL: recipient = settings.DAILY_DEPLOY_EMAIL subject = 'Deploy Successful - {}'.format( options['environment']) send_HTML_email(subject=subject, recipient=recipient, html_content=message_body) if settings.SENTRY_CONFIGURED and settings.SENTRY_API_KEY: create_update_sentry_release() notify_sentry_deploy(minutes)
def handle(self, **options): compare_url = options.get('url', None) minutes = options.get('minutes', None) deploy = HqDeploy( date=datetime.utcnow(), user=options['user'], environment=options['environment'], diff_url=compare_url, commit=options['commit'] ) deploy.save() # reset PillowTop errors in the hope that a fix has been deployed rows_updated = PillowError.bulk_reset_attempts(datetime.utcnow()) if rows_updated: print("\n---------------- Pillow Errors Reset ----------------\n" \ "{} pillow errors queued for retry\n".format(rows_updated)) deploy_notification_text = ( "CommCareHQ has been successfully deployed to *{}* by *{}* in *{}* minutes. ".format( options['environment'], options['user'], minutes or '?', ) ) if options['environment'] == 'production': deploy_notification_text += "Monitor the {dashboard_link}. " if settings.MOBILE_INTEGRATION_TEST_TOKEN: deploy_notification_text += "Check the integration {integration_tests_link}. " requests.get( 'https://jenkins.dimagi.com/job/integration-tests/build', params={'token': settings.MOBILE_INTEGRATION_TEST_TOKEN}, ) requests.get( 'https://jenkins.dimagi.com/job/integration-tests-pipeline/build', params={'token': settings.MOBILE_INTEGRATION_TEST_TOKEN}, ) deploy_notification_text += "Find the diff {diff_link}" if settings.DATADOG_API_KEY: link = diff_link(compare_url) create_metrics_event( title="Deploy Success", text=deploy_notification_text.format( dashboard_link=dashboard_link(DASHBOARD_URL), diff_link=link, integration_tests_link=integration_tests_link(INTEGRATION_TEST_URL) ), tags={'environment': options['environment']}, alert_type="success" ) print( "\n=============================================================\n" "Congratulations! Deploy Complete.\n\n" "Don't forget to keep an eye on the deploy dashboard to " "make sure everything is running smoothly.\n\n" "https://app.datadoghq.com/dashboard/xch-zwt-vzv/hq-deploy-dashboard?tpl_var_environment={}" "\n=============================================================\n".format( settings.SERVER_ENVIRONMENT ) ) if options['mail_admins']: message_body = get_deploy_email_message_body(user=options['user'], compare_url=compare_url) subject = 'Deploy Successful - {}'.format(options['environment']) call_command('mail_admins', message_body, **{'subject': subject, 'html': True}) if settings.DAILY_DEPLOY_EMAIL: recipient = settings.DAILY_DEPLOY_EMAIL send_HTML_email(subject=subject, recipient=recipient, html_content=message_body) if settings.SENTRY_CONFIGURED and settings.SENTRY_API_KEY: create_update_sentry_release() notify_sentry_deploy(minutes)
def handle(self, *args, **options): compare_url = options.get('url', None) minutes = options.get('minutes', None) deploy = HqDeploy(date=datetime.utcnow(), user=options['user'], environment=options['environment'], diff_url=compare_url) deploy.save() # reset PillowTop errors in the hope that a fix has been deployed rows_updated = PillowError.bulk_reset_attempts(datetime.utcnow()) if rows_updated: print "\n---------------- Pillow Errors Reset ----------------\n" \ "{} pillow errors queued for retry\n".format(rows_updated) deploy_notification_text = ( "CommCareHQ has been successfully deployed to *{}* by *{}* in *{}* minutes. " "Monitor the {{dashboard_link}}. " "Check the integration {{integration_tests_link}}. " "Find the diff {{diff_link}}".format( options['environment'], options['user'], minutes or '?', )) if settings.MOBILE_INTEGRATION_TEST_TOKEN: requests.get( 'https://jenkins.dimagi.com/job/integration-tests/build', params={'token': settings.MOBILE_INTEGRATION_TEST_TOKEN}, ) if hasattr(settings, 'MIA_THE_DEPLOY_BOT_API'): link = diff_link(STYLE_SLACK, compare_url) requests.post( settings.MIA_THE_DEPLOY_BOT_API, data=json.dumps({ "username": "******", "text": deploy_notification_text.format( dashboard_link=dashboard_link(STYLE_SLACK, DASHBOARD_URL), diff_link=link, integration_tests_link=integration_tests_link( STYLE_SLACK, INTEGRATION_TEST_URL)), })) if settings.DATADOG_API_KEY: tags = ['environment:{}'.format(options['environment'])] link = diff_link(STYLE_MARKDOWN, compare_url) datadog_api.Event.create( title="Deploy Success", text=deploy_notification_text.format( dashboard_link=dashboard_link(STYLE_MARKDOWN, DASHBOARD_URL), diff_link=link, integration_tests_link=integration_tests_link( STYLE_MARKDOWN, INTEGRATION_TEST_URL)), tags=tags, alert_type="success") print "\n=============================================================\n" \ "Congratulations! Deploy Complete.\n\n" \ "Don't forget to keep an eye on the deploy dashboard to " \ "make sure everything is running smoothly.\n\n" \ "https://p.datadoghq.com/sb/5c4af2ac8-1f739e93ef" \ "\n=============================================================\n" if options['mail_admins']: message_body = get_deploy_email_message_body( environment=options['environment'], user=options['user'], compare_url=compare_url) call_command('mail_admins', message_body, **{ 'subject': 'Deploy successful', 'html': True })
def handle(self, **options): compare_url = options.get('url', None) minutes = options.get('minutes', None) deploy = HqDeploy( date=datetime.utcnow(), user=options['user'], environment=options['environment'], diff_url=compare_url ) deploy.save() # reset PillowTop errors in the hope that a fix has been deployed rows_updated = PillowError.bulk_reset_attempts(datetime.utcnow()) if rows_updated: print("\n---------------- Pillow Errors Reset ----------------\n" \ "{} pillow errors queued for retry\n".format(rows_updated)) deploy_notification_text = ( "CommCareHQ has been successfully deployed to *{}* by *{}* in *{}* minutes. ".format( options['environment'], options['user'], minutes or '?', ) ) if options['environment'] == 'production': deploy_notification_text += "Monitor the {dashboard_link}. " if settings.MOBILE_INTEGRATION_TEST_TOKEN: deploy_notification_text += "Check the integration {integration_tests_link}. " requests.get( 'https://jenkins.dimagi.com/job/integration-tests/build', params={'token': settings.MOBILE_INTEGRATION_TEST_TOKEN}, ) requests.get( 'https://jenkins.dimagi.com/job/integration-tests-pipeline/build', params={'token': settings.MOBILE_INTEGRATION_TEST_TOKEN}, ) deploy_notification_text += "Find the diff {diff_link}" if hasattr(settings, 'MIA_THE_DEPLOY_BOT_API'): link = diff_link(STYLE_SLACK, compare_url) if options['environment'] == 'staging': channel = '#staging' elif options['environment'] == 'icds': channel = '#nic-server-standup' else: channel = '#hq-ops' requests.post(settings.MIA_THE_DEPLOY_BOT_API, data=json.dumps({ "username": "******", "channel": channel, "text": deploy_notification_text.format( dashboard_link=dashboard_link(STYLE_SLACK, DASHBOARD_URL), diff_link=link, integration_tests_link=integration_tests_link(STYLE_SLACK, INTEGRATION_TEST_URL) ), })) if settings.DATADOG_API_KEY: tags = ['environment:{}'.format(options['environment'])] link = diff_link(STYLE_MARKDOWN, compare_url) datadog_api.Event.create( title="Deploy Success", text=deploy_notification_text.format( dashboard_link=dashboard_link(STYLE_MARKDOWN, DASHBOARD_URL), diff_link=link, integration_tests_link=integration_tests_link(STYLE_MARKDOWN, INTEGRATION_TEST_URL) ), tags=tags, alert_type="success" ) print("\n=============================================================\n" \ "Congratulations! Deploy Complete.\n\n" \ "Don't forget to keep an eye on the deploy dashboard to " \ "make sure everything is running smoothly.\n\n" \ "https://p.datadoghq.com/sb/5c4af2ac8-1f739e93ef" \ "\n=============================================================\n") if options['mail_admins']: message_body = get_deploy_email_message_body(user=options['user'], compare_url=compare_url) call_command('mail_admins', message_body, **{'subject': 'Deploy successful', 'html': True}) if settings.DAILY_DEPLOY_EMAIL: recipient = settings.DAILY_DEPLOY_EMAIL subject = 'Deploy Successful - {}'.format(options['environment']) send_HTML_email(subject=subject, recipient=recipient, html_content=message_body) if settings.SENTRY_CONFIGURED and settings.SENTRY_API_KEY: create_update_sentry_release() notify_sentry_deploy(minutes)