Skip to content

Commit

Permalink
Add the release script to the codebase (oppia#3839)
Browse files Browse the repository at this point in the history
  • Loading branch information
wxyxinyu authored and BenHenning committed Sep 21, 2017
1 parent 9b297ea commit e7d8dd4
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
74 changes: 74 additions & 0 deletions scripts/prepare_automatic_backups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# coding: utf-8
#
# Copyright 2016 The Oppia Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Contains routines which will add a backup cron job to prepare Oppia for a
deployment push to https://oppia.org/.
"""
import sys
import utils

_BACKUP_NAME_PREFIX = 'opbkp'
_BACKUP_EVENT_QUEUE_NAME = 'backups'
_BACKUP_EVENT_QUEUE_RATE = '5/s'
_MAX_BACKUP_URL_LENGTH = 2000
_CRON_YAML_FILE_NAME = 'cron.yaml'


def generate_backup_url():
sys_args = sys.argv
cloud_storage_bucket_name = sys_args[1]
module_class_names = sys_args[2:]
return (
'/_ah/datastore_admin/backup.create?name=%s&kind=%s&queue=%s'
'&filesystem=gs&gs_bucket_name=%s' % (
_BACKUP_NAME_PREFIX,
'&kind='.join(module_class_names),
_BACKUP_EVENT_QUEUE_NAME,
cloud_storage_bucket_name))


def update_cron_dict(cron_dict):
backup_url = generate_backup_url()
if len(backup_url) > _MAX_BACKUP_URL_LENGTH:
raise Exception('Backup URL exceeds app engine limit')
cron_dict['cron'].append({
'description': 'weekly backup',
'url': '%s' % backup_url,
'schedule': 'every thursday 09:00',
'target': 'ah-builtin-python-bundle'
})


def get_cron_dict():
return utils.dict_from_yaml(utils.get_file_contents(_CRON_YAML_FILE_NAME))


def save_cron_dict(cron_dict):
with open(_CRON_YAML_FILE_NAME, 'wt') as cron_yaml_file:
cron_yaml_file.write(utils.yaml_from_dict(cron_dict))


def update_yaml_files():
cron_dict = get_cron_dict()
update_cron_dict(cron_dict)
save_cron_dict(cron_dict)


def _prepare_for_prod():
update_yaml_files()

if __name__ == '__main__':
_prepare_for_prod()
20 changes: 20 additions & 0 deletions scripts/prepare_automatic_backups.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

# Copyright 2016 The Oppia Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

##########################################################################

export PYTHONPATH=.:$PYTHONPATH
find core/storage -not -path "core/storage/base_model/*" -name "gae_models.py" | xargs grep -E "class .+?Model" | awk '{print $2}' | cut -d "(" -f 1 | tr '\n' ' ' | xargs python scripts/prepare_automatic_backups.py $1

0 comments on commit e7d8dd4

Please sign in to comment.