Exemple #1
0
def _execute_deployment():
    # Check that the current directory is correct.
    common.require_cwd_to_be_oppia()

    current_git_revision = subprocess.check_output(
        ['git', 'rev-parse', 'HEAD']).strip()

    print ''
    print 'Starting deployment process.'

    if not os.path.exists(THIRD_PARTY_DIR):
        raise Exception(
            'Could not find third_party directory at %s. Please run start.sh '
            'prior to running this script.' % THIRD_PARTY_DIR)

    # Create a folder in which to save the release candidate.
    print 'Ensuring that the release directory parent exists'
    common.ensure_directory_exists(os.path.dirname(RELEASE_DIR_PATH))

    # Copy files to the release directory. Omits the .git subfolder.
    print 'Copying files to the release directory'
    shutil.copytree(os.getcwd(),
                    RELEASE_DIR_PATH,
                    ignore=shutil.ignore_patterns('.git'))

    # Change the current directory to the release candidate folder.
    with common.CD(RELEASE_DIR_PATH):
        if not os.getcwd().endswith(RELEASE_DIR_NAME):
            raise Exception(
                'Invalid directory accessed during deployment: %s' %
                os.getcwd())

        print 'Changing directory to %s' % os.getcwd()

        print 'Preprocessing release...'
        preprocess_release()

        update_cache_slug()
        # Do a build; ensure there are no errors.
        print 'Building and minifying scripts...'
        subprocess.check_output(['python', 'scripts/build.py'])

        # Deploy to GAE.
        subprocess.check_output([APPCFG_PATH, 'update', '.', '--oauth2'])

        # Writing log entry.
        common.ensure_directory_exists(os.path.dirname(LOG_FILE_PATH))
        with open(LOG_FILE_PATH, 'a') as log_file:
            log_file.write(
                'Successfully deployed to %s at %s (version %s)\n' %
                (APP_NAME, CURRENT_DATETIME.strftime('%Y-%m-%d %H:%M:%S'),
                 current_git_revision))

        print 'Returning to oppia/ root directory.'

    print 'Done!'
    raise Exception(
        'Could not find third_party directory at %s. Please run start.sh '
        'prior to running this script.' % THIRD_PARTY_DIR)

# Create a folder in which to save the release candidate.
print 'Ensuring that the release directory parent exists'
common.ensure_directory_exists(os.path.dirname(RELEASE_DIR_PATH))

# Copy files to the release directory. Omits the .git subfolder.
print 'Copying files to the release directory'
shutil.copytree(os.getcwd(),
                RELEASE_DIR_PATH,
                ignore=shutil.ignore_patterns('.git'))

# Change the current directory to the release candidate folder.
with common.CD(RELEASE_DIR_PATH):
    if not os.getcwd().endswith(RELEASE_DIR_NAME):
        raise Exception('Invalid directory accessed during deployment: %s' %
                        os.getcwd())

    print 'Changing directory to %s' % os.getcwd()

    print 'Preprocessing release...'
    preprocess_release()

    # Do a build; ensure there are no errors.
    print 'Building and minifying scripts...'
    subprocess.check_output(['python', 'scripts/build.py'])

    # Deploy to GAE.
    subprocess.check_output([APPCFG_PATH, 'update', '.', '--oauth2'])
Exemple #3
0
def _execute_deployment():
    # Do prerequisite checks.
    common.require_cwd_to_be_oppia()
    common.ensure_release_scripts_folder_exists_and_is_up_to_date()

    current_git_revision = subprocess.check_output(
        ['git', 'rev-parse', 'HEAD']).strip()

    if not os.path.exists(THIRD_PARTY_DIR):
        raise Exception(
            'Could not find third_party directory at %s. Please run start.sh '
            'prior to running this script.' % THIRD_PARTY_DIR)

    # Create a folder in which to save the release candidate.
    print 'Ensuring that the release directory parent exists'
    common.ensure_directory_exists(os.path.dirname(RELEASE_DIR_PATH))

    # Copy files to the release directory. Omits the .git subfolder.
    print 'Copying files to the release directory'
    shutil.copytree(
        os.getcwd(), RELEASE_DIR_PATH, ignore=shutil.ignore_patterns('.git'))

    # Change the current directory to the release candidate folder.
    with common.CD(RELEASE_DIR_PATH):
        if not os.getcwd().endswith(RELEASE_DIR_NAME):
            raise Exception(
                'Invalid directory accessed during deployment: %s'
                % os.getcwd())

        print 'Changing directory to %s' % os.getcwd()

        print 'Preprocessing release...'
        preprocess_release()

        # Do a build, while outputting to the terminal.
        print 'Building and minifying scripts...'
        build_process = subprocess.Popen(
            ['python', 'scripts/build.py', '--prod_env'],
            stdout=subprocess.PIPE)
        while True:
            line = build_process.stdout.readline().strip()
            if not line:
                break
            print line

        # Wait for process to terminate, then check return code.
        build_process.communicate()
        if build_process.returncode > 0:
            raise Exception('Build failed.')

        # Deploy to GAE.
        subprocess.check_output([APPCFG_PATH, 'update', '.'])

        # Writing log entry.
        common.ensure_directory_exists(os.path.dirname(LOG_FILE_PATH))
        with open(LOG_FILE_PATH, 'a') as log_file:
            log_file.write(
                'Successfully deployed to %s at %s (version %s)\n' % (
                    APP_NAME, CURRENT_DATETIME.strftime('%Y-%m-%d %H:%M:%S'),
                    current_git_revision))

        print 'Returning to oppia/ root directory.'

    # If this is a test server deployment and the current release version is
    # already serving, open the library page (for sanity checking) and the GAE
    # error logs.
    if (APP_NAME == APP_NAME_OPPIATESTSERVER or 'migration' in APP_NAME) and (
            _get_served_version() == _get_current_release_version()):
        common.open_new_tab_in_browser_if_possible(
            'https://console.cloud.google.com/logs/viewer?'
            'project=%s&key1=default&minLogLevel=500'
            % APP_NAME_OPPIATESTSERVER)
        common.open_new_tab_in_browser_if_possible(
            'https://%s.appspot.com/library' % APP_NAME_OPPIATESTSERVER)

    print 'Done!'
Exemple #4
0
def _execute_deployment():
    """Executes the deployment process after doing the prerequisite checks."""

    if not common.is_current_branch_a_release_branch():
        raise Exception(
            'The deployment script must be run from a release branch.')
    current_release_version = CURRENT_BRANCH_NAME[
        len(common.RELEASE_BRANCH_NAME_PREFIX):].replace('.', '-')

    # Do prerequisite checks.
    common.require_cwd_to_be_oppia()
    common.ensure_release_scripts_folder_exists_and_is_up_to_date()
    gcloud_adapter.require_gcloud_to_be_available()
    if APP_NAME in [APP_NAME_OPPIASERVER, APP_NAME_OPPIATESTSERVER]:
        if not common.is_current_branch_a_release_branch():
            raise Exception(
                'The deployment script must be run from a release branch.')
    if APP_NAME == APP_NAME_OPPIASERVER:
        with open('./feconf.py', 'r') as f:
            feconf_contents = f.read()
            if ('MAILGUN_API_KEY' not in feconf_contents
                    or 'MAILGUN_API_KEY = None' in feconf_contents):
                raise Exception(
                    'The mailgun API key must be added before deployment.')
    if not os.path.exists(THIRD_PARTY_DIR):
        raise Exception(
            'Could not find third_party directory at %s. Please run start.sh '
            'prior to running this script.' % THIRD_PARTY_DIR)

    current_git_revision = subprocess.check_output(
        ['git', 'rev-parse', 'HEAD']).strip()

    # Create a folder in which to save the release candidate.
    print 'Ensuring that the release directory parent exists'
    common.ensure_directory_exists(os.path.dirname(RELEASE_DIR_PATH))

    # Copy files to the release directory. Omits the .git subfolder.
    print 'Copying files to the release directory'
    shutil.copytree(os.getcwd(),
                    RELEASE_DIR_PATH,
                    ignore=shutil.ignore_patterns('.git'))

    # Change the current directory to the release candidate folder.
    with common.CD(RELEASE_DIR_PATH):
        if not os.getcwd().endswith(RELEASE_DIR_NAME):
            raise Exception(
                'Invalid directory accessed during deployment: %s' %
                os.getcwd())

        print 'Changing directory to %s' % os.getcwd()

        print 'Preprocessing release...'
        preprocess_release()

        # Update indexes, then prompt for a check that they are all serving
        # before continuing with the deployment.
        # NOTE: This assumes that the build process does not modify the
        # index.yaml file or create a different version of it to use in
        # production.
        gcloud_adapter.update_indexes(INDEX_YAML_PATH, APP_NAME)
        datastore_indexes_url = (
            'https://console.cloud.google.com/datastore/indexes?project=%s' %
            APP_NAME)
        common.open_new_tab_in_browser_if_possible(datastore_indexes_url)
        while True:
            print '******************************************************'
            print(
                'PLEASE CONFIRM: are all datastore indexes serving? See %s '
                '(y/n)' % datastore_indexes_url)
            answer = raw_input().lower()
            if answer in ['y', 'ye', 'yes']:
                break
            elif answer:
                raise Exception(
                    'Please wait for all indexes to serve, then run this '
                    'script again to complete the deployment. Exiting.')

        # Do a build, while outputting to the terminal.
        print 'Building and minifying scripts...'
        build_process = subprocess.Popen(
            ['python', 'scripts/build.py', '--prod_env'],
            stdout=subprocess.PIPE)
        while True:
            line = build_process.stdout.readline().strip()
            if not line:
                break
            print line
        # Wait for process to terminate, then check return code.
        build_process.communicate()
        if build_process.returncode > 0:
            raise Exception('Build failed.')

        # Deploy export service to GAE.
        gcloud_adapter.deploy_application('export/app.yaml', APP_NAME)
        # Deploy app to GAE.
        gcloud_adapter.deploy_application(
            './app.yaml',
            APP_NAME,
            version=(CUSTOM_VERSION
                     if CUSTOM_VERSION else current_release_version))

        # Writing log entry.
        common.ensure_directory_exists(os.path.dirname(LOG_FILE_PATH))
        with open(LOG_FILE_PATH, 'a') as log_file:
            log_file.write(
                'Successfully deployed to %s at %s (version %s)\n' %
                (APP_NAME, CURRENT_DATETIME.strftime('%Y-%m-%d %H:%M:%S'),
                 current_git_revision))

        print 'Returning to oppia/ root directory.'

    # If this is a test server deployment and the current release version is
    # already serving, open the library page (for sanity checking) and the GAE
    # error logs.
    currently_served_version = (
        gcloud_adapter.get_currently_served_version(APP_NAME))
    if (APP_NAME == APP_NAME_OPPIATESTSERVER
            or 'migration' in APP_NAME) and (currently_served_version
                                             == current_release_version):
        common.open_new_tab_in_browser_if_possible(
            'https://%s.appspot.com/library' % APP_NAME_OPPIATESTSERVER)
        common.open_new_tab_in_browser_if_possible(
            'https://console.cloud.google.com/logs/viewer?'
            'project=%s&key1=default&minLogLevel=500' %
            APP_NAME_OPPIATESTSERVER)

    print 'Done!'