Skip to content

Commit

Permalink
Merge pull request #345 from mikhailyumanov/master
Browse files Browse the repository at this point in the history
Deploy local beta
  • Loading branch information
znick authored Mar 30, 2021
2 parents edea65f + 7370c24 commit 8c7f72d
Show file tree
Hide file tree
Showing 12 changed files with 504 additions and 25 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/deploy_local_beta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This workflow deploy beta anytask locally

name: Deploy local beta

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Install dependencies
run: sudo apt-get install python-virtualenv
- name: Deploy
run: source deploy_local_beta/run.sh --python-path=python2
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ Development installation commands:

# ... clone ...
# ... cd ...
git submodule init
git submodule update
virtualenv .env
. .env/bin/activate
pip install 'pip==20.3.4' 'setuptools==44.0.0' --upgrade
pip install -r requirements_local.txt
python setup.py develop
./anytask/manage.py # test it # TODO: make a setup entry point
./anytask/manage.py syncdb --migrate --noinput
. deploy_local_beta/run.sh
./anytask/manage.py runserver 127.0.0.1:8019 -v 3 --traceback

To activate environment in already deployed project run

. deploy_local_beta/activate.sh

Run deploy_local_beta/run.sh -h for more information.
8 changes: 0 additions & 8 deletions anytask/generate_test_db.sh

This file was deleted.

14 changes: 6 additions & 8 deletions anytask/users/management/commands/create_shad.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from years.models import Year

from xml.dom.minidom import parse
from optparse import make_option
import sys
import random
import string
Expand All @@ -37,13 +36,12 @@ def get_users_from_cs_xml(cs_xml_fn):
class Command(BaseCommand):
help = "Creating shad users, python course, shad school."

option_list = BaseCommand.option_list + (
make_option('--year',
action='store',
dest='year',
default=None,
help='Course start year'),
)
def add_arguments(self, parser):
parser.add_argument('--year',
action='store',
dest='year',
default=None,
help='Course start year')

def handle(self, **options):
year = options['year']
Expand Down
168 changes: 168 additions & 0 deletions anytask/users/management/commands/create_test_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
"""
A management command which deletes expired accounts (e.g.,
accounts which signed up but never activated) from the database.
Calls ``RegistrationProfile.objects.delete_expired_users()``, which
contains the actual logic for determining which accounts are deleted.
"""

from django.core.management.base import BaseCommand
from django.contrib.auth.models import User

from years.models import Year
from schools.models import School
from groups.models import Group
from courses.models import Course
from tasks.models import Task, TaskGroupRelations
from issues.models import Issue


def parse_name(name):
last_name, first_name = name.split(' ', 1)
username = "_".join([first_name.lower(), last_name.lower()])
return last_name, first_name, username


def save_all(collection):
for item in collection:
item.save()


class Command(BaseCommand):
help = "Creating test database."

def handle(self, **options):
# Raw data
years_raw = [2019, 2020]
courses_raw = [{"name": "Charms", "year": 0,
"groups": (0, 2)},
{"name": "Potions", "year": 1,
"groups": (1,)},
{"name": "Transfigurations", "year": 1,
"groups": (3,)}]
schools_raw = [{"name": "High School of Hersheba",
"link": "hersheba",
"courses": (0, 1)},
{"name": "Fourecks University",
"link": "fourecks",
"courses": (0, 2)}]
groups_raw = [{"name": "Hersheba2019", "year": 0},
{"name": "Hersheba2020", "year": 1},
{"name": "Fourecks2019", "year": 0},
{"name": "Fourecks2020", "year": 1}]
students_raw = [{"name": "Sia Hyde", "group": 0},
{"name": "Wasim Klein", "group": 0},
{"name": "Ella Eastwood", "group": 0},
{"name": "Maha Wilkes", "group": 1},
{"name": "Meg Sutherland", "group": 1},
{"name": "Kya Parsons", "group": 1},
{"name": "Ferne Huff", "group": 2},
{"name": "Jethro Higgs", "group": 2},
{"name": "Prince Knox", "group": 2},
{"name": "Layla Schmitt", "group": 3},
{"name": "Darci Stark", "group": 3},
{"name": "Ezmae Bradford", "group": 3}]
teachers_raw = [{"name": "Eira Buckner", "courses": (0,)},
{"name": "Paul Akhtar", "courses": (1,)},
{"name": "Kristi Todd", "courses": (2,)}]
tasks_raw = [{"title": "Charms | Task 1", "course": 0,
"groups": (0,), "updated_by": 0}]
issues_raw = [{"student": 0, "task": 0}]

# Create object from raw data

print("Create years {}".format(years_raw))
years = [Year.objects.create(start_year=start_year)
for start_year in years_raw]
save_all(years)

print("Create courses {}".format(courses_raw))
courses = [Course.objects.create(name=course["name"],
year=years[course["year"]],
is_active=True)
for course in courses_raw]
save_all(courses)

print("Create schools {}".format(schools_raw))
schools = [School.objects.create(name=school["name"],
link=school["link"])
for school in schools_raw]
save_all(schools)

print("Create groups {}".format(groups_raw))
groups = [Group.objects.create(name=group["name"],
year=years[group["year"]])
for group in groups_raw]
save_all(groups)

print("Create users")
students = []
teachers = []
for user_raw in students_raw + teachers_raw:
last_name, first_name, username = parse_name(user_raw["name"])
user = User.objects.create(username=username)
user.last_name = last_name
user.first_name = first_name
user.set_password(username)

if user_raw in students_raw:
students.append(user)
else:
teachers.append(user)
save_all(students)
save_all(teachers)

print("Create tasks {}".format(tasks_raw))
tasks = [Task.objects.create(title=task["title"],
course=courses[task["course"]])
for task in tasks_raw]
save_all(tasks)

print("Create issues {}".format(issues_raw))
issues = [Issue.objects.create(student=students[issue["student"]],
task=tasks[issue["task"]])
for issue in issues_raw]
save_all(issues)

# Bind objects

print("Bind schools and courses")
for school_id, school in enumerate(schools_raw):
for course_id in school["courses"]:
schools[school_id].courses.add(courses[course_id])

print("Bind courses and groups")
for course_id, course in enumerate(courses_raw):
for group_id in course["groups"]:
courses[course_id].groups.add(groups[group_id])

print("Bind students and groups")
for student_id, student in enumerate(students_raw):
user = students[student_id]
group = groups[student["group"]]
group.students.add(user)

print("Set teachers")
for teacher_id, teacher in enumerate(teachers_raw):
user = teachers[teacher_id]
for course_id in teacher["courses"]:
course = courses[course_id]
course.teachers.add(user)

print("Bind tasks with courses")
for task_id, task in enumerate(tasks_raw):
course = courses[task["course"]]
task = tasks[task_id]
course.task_set.add(task)

print("Bind tasks with groups")
for task_id, task in enumerate(tasks_raw):
task = tasks[task_id]
for group_id in tasks_raw[task_id]["groups"]:
group = groups[group_id]
relation = TaskGroupRelations.objects.create(
task=task, group=group)
relation.save()

print("Completed creating test data.")
10 changes: 10 additions & 0 deletions deploy_local_beta/activate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file must be used with "source deploy_local_beta/activate.sh" *from bash*
# you cannot run it directly

if [ "${BASH_SOURCE-}" = "$0" ]; then
echo "You must source this script: \$ source $0" >&2
exit 33
fi

. deploy_local_beta/settings.sh
ANYBETA_activate
33 changes: 33 additions & 0 deletions deploy_local_beta/deploy_local_beta.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This file must not be run directly.
# Execute `. deploy_local_beta/run.sh` from repository root instead.


if ! test $ANYBETA_ROOT
then
echo "ERROR: This file should not be run directly."
echo "Execute \`. deploy_local_beta/run.sh\` from repository root instead."
exit 1
fi


# GIT SUBMODULES
################

ANYBETA_report
ANYBETA_report "Init submodules"
git submodule init
ANYBETA_crash_on_error
git submodule update
ANYBETA_crash_on_error

# CHOOSE RIGHT VERSION
######################

ANYBETA_PYTHON_VERSION_CHECK="from __future__ import print_function; import sys; print(int(sys.version_info < (3, 3)))"

if test `$ANYBETA_PYTHON_PATH -c "$ANYBETA_PYTHON_VERSION_CHECK"` -eq 1
then
. $ANYBETA_DEPLOY/deploy_local_beta_python2.sh
else
. $ANYBETA_DEPLOY/deploy_local_beta_python3.sh
fi
53 changes: 53 additions & 0 deletions deploy_local_beta/deploy_local_beta_python2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# This file must not be run directly.
# Execute `. deploy_local_beta/run.sh` from repository root instead.


if ! test $ANYBETA_ROOT
then
echo "ERROR: This file should not be run directly."
echo "Execute \`. deploy_local_beta/run.sh\` from repository root instead."
exit 1
fi


#SETUP VIRTUALENV
#################

ANYBETA_report
ANYBETA_report "Enable virtualenv"
virtualenv -p $ANYBETA_PYTHON_PATH $ANYBETA_VENV_NAME
ANYBETA_activate
ANYBETA_crash_on_error


# REQUIREMENTS
##############

ANYBETA_report
ANYBETA_report "Install requirements"
pip install 'pip>=20.3.4' 'setuptools>=44.0.0' --upgrade
ANYBETA_crash_on_error
pip install -r requirements_local.txt
ANYBETA_crash_on_error


# MANAGE DJANGO
###############

ANYBETA_report
ANYBETA_report "Manage django project"
python setup.py develop
ANYBETA_crash_on_error


# CREATE DB
###########

ANYBETA_report
ANYBETA_report "Create test database"
$ANYBETA_DEPLOY/generate_test_db.sh
ANYBETA_crash_on_error

ANYBETA_report
ANYBETA_report "Deploy completed!"
ANYBETA_report "You can now start django server using \`manage.py runserver\`"
1 change: 1 addition & 0 deletions deploy_local_beta/deploy_local_beta_python3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo "Python 3 coming soon..."
38 changes: 38 additions & 0 deletions deploy_local_beta/generate_test_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

if test -e $ANYBETA_ROOT/sqlite3.db
then
rm $ANYBETA_ROOT/sqlite3.db
fi

$ANYBETA_ROOT/anytask/manage.py migrate --no-input
ANYBETA_crash_on_error

$ANYBETA_ROOT/anytask/manage.py createsuperuser --username=anytask [email protected] --noinput
ANYBETA_crash_on_error

echo 'from django.contrib.auth.models import User ; user=User.objects.get(username="anytask") ; user.set_password("pass") ; user.save() ; print "Password changed"' | $ANYBETA_ROOT/anytask/manage.py shell --plain
ANYBETA_crash_on_error

ANYBETA_report "root"
ANYBETA_report "Login: anytask"
ANYBETA_report "Password: pass"
ANYBETA_report
ANYBETA_report "student"
ANYBETA_report "Login: hyde_sia"
ANYBETA_report "Password: hyde_sia"
ANYBETA_report
ANYBETA_report "teacher"
ANYBETA_report "Login: buckner_eira"
ANYBETA_report "Password: buckner_eira"

ANYBETA_DEPLOY_FILES_DIR=$ANYBETA_ROOT/anytask/media/files/deploy_local_beta_files
if ! test -d $ANYBETA_DEPLOY_FILES_DIR
then
mkdir $ANYBETA_DEPLOY_FILES_DIR
fi
echo "print('hello')" >> $ANYBETA_DEPLOY_FILES_DIR/file1.py
echo "text" >> $ANYBETA_DEPLOY_FILES_DIR/file2.txt

$ANYBETA_ROOT/anytask/manage.py create_test_data
ANYBETA_crash_on_error
Loading

0 comments on commit 8c7f72d

Please sign in to comment.