Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy local beta #345

Merged
merged 59 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
5fcafbc
Initial commit. Added environment preparation.
mikhailyumanov Mar 5, 2021
3588b74
Moved environment setup to separate files according to python version
mikhailyumanov Mar 5, 2021
c9bfcb4
Remove unused files, debug scripts
mikhailyumanov Mar 5, 2021
7e720ba
Working version.
mikhailyumanov Mar 6, 2021
18fd778
Working version.
mikhailyumanov Mar 6, 2021
bfe862d
Merge branch 'master' of https://github.com/mikhailyumanov/anytask
mikhailyumanov Mar 6, 2021
eeeafc4
Sugar fixes in comments
mikhailyumanov Mar 6, 2021
cfb64aa
Replaced with if stmt
mikhailyumanov Mar 10, 2021
0e001a0
CST-10 znick#336 BaseCommand.option_list is deprecated since django 1.8
mikhailyumanov Mar 11, 2021
ae6ca56
CST-10 znick#336 fixed deploy beta script
mikhailyumanov Mar 11, 2021
767f1ef
CST-10 znick#336 fixed codestyle
mikhailyumanov Mar 11, 2021
d32def3
CST-10 znick#336 Added venv deactivation
mikhailyumanov Mar 12, 2021
6a5384f
CST-10 znick#336 Moved settings to settings.sh
mikhailyumanov Mar 12, 2021
161ebb6
CST-10 znick#336 Added venv activate function
mikhailyumanov Mar 12, 2021
45e2f78
CST-10 znick#336 fix typo
mikhailyumanov Mar 12, 2021
47a9331
CST-10 znick#336 Moved cleanup.sh to settings.sh
mikhailyumanov Mar 12, 2021
b14b894
CST-10 znick#336 fix typo
mikhailyumanov Mar 12, 2021
e2fe199
CST-10 znick#336 Fixed help message request bug
mikhailyumanov Mar 12, 2021
4ede40b
CST-10 znick#336 test data initial commit
mikhailyumanov Mar 12, 2021
986cd9e
CST-10 znick#336 Added test db
mikhailyumanov Mar 13, 2021
41da9ec
CST-10 znick#336 Added message about python3
mikhailyumanov Mar 13, 2021
5e29c63
CST-10 znick#336 Moved db generator to deploy_local_beta
mikhailyumanov Mar 13, 2021
2e0c482
CST-10 znick#336 Refresh README and help message for run.sh
mikhailyumanov Mar 13, 2021
3612869
CST-10 znick#336 Removed artefact
mikhailyumanov Mar 13, 2021
1dc38fd
CST-10 znick#336 some tuning
mikhailyumanov Mar 13, 2021
8dd5111
CST-10 znick#336 some tuning
mikhailyumanov Mar 13, 2021
7022ce3
CST-10 znick#336 Added some security
mikhailyumanov Mar 13, 2021
c3cd713
CST-10 znick#336 codestyle
mikhailyumanov Mar 13, 2021
9008996
CST-10 znick#336 codestyle
mikhailyumanov Mar 13, 2021
04f3f7c
CST-10 znick#336 Added check of executing run.sh with
mikhailyumanov Mar 14, 2021
1de7013
Create deploy_local_beta.yml
mikhailyumanov Mar 18, 2021
521eecd
Merge remote-tracking branch 'znick_anytask/master'
mikhailyumanov Mar 18, 2021
4957f2b
CST-10 #znick#336 set initial workflow
mikhailyumanov Mar 18, 2021
1059757
CST-10 znick#336 fix typo
mikhailyumanov Mar 18, 2021
1587b23
CST-10 znick#336 added permission
mikhailyumanov Mar 18, 2021
29606f0
CST-10 znick#336 added all permissions
mikhailyumanov Mar 18, 2021
f6e7bc4
CST-10 znick#336 use python2 instead of 3
mikhailyumanov Mar 18, 2021
2b0f12d
CST-10 znick#336 install virtualenv
mikhailyumanov Mar 18, 2021
51858eb
CST-10 znick#336 typo
mikhailyumanov Mar 18, 2021
796d30a
CST-10 znick#336 setup python env
mikhailyumanov Mar 18, 2021
2a62b74
CST-10 znick#336 install virtualenv using pip
mikhailyumanov Mar 18, 2021
30428ae
CST-10 znick#336 fixed deploy
mikhailyumanov Mar 18, 2021
9c453d8
CST-10 znick#336 fix settings
mikhailyumanov Mar 18, 2021
4689c49
CST-10 znick#336 refresh imports
mikhailyumanov Mar 18, 2021
e95978c
Merge remote-tracking branch 'znick_anytask/master'
mikhailyumanov Mar 20, 2021
9f9a368
Pin setupttools-scm version (affected CI jobs)
bcskda Mar 17, 2021
229197d
Fix redirect to same page
znick Mar 19, 2021
49b4b13
Merge branch 'master' of https://github.com/mikhailyumanov/anytask
mikhailyumanov Mar 20, 2021
30b561b
znick#336 added task and issue
mikhailyumanov Mar 21, 2021
85ba8c8
znick#336 moved create_test_data to generate_test_db
mikhailyumanov Mar 21, 2021
6c1a38b
add task, issue in test db
mikhailyumanov Mar 22, 2021
d13aa92
Print credentials, add task correctly
mikhailyumanov Mar 23, 2021
9277abc
Add activate shortcut
mikhailyumanov Mar 26, 2021
627f810
Print credentials, add task correctly
mikhailyumanov Mar 23, 2021
ac90da3
Merge remote-tracking branch 'refs/remotes/origin/create_db' into cre…
mikhailyumanov Mar 26, 2021
eb965e3
Remove automated creating issue
mikhailyumanov Mar 26, 2021
429afba
znick#336 virtualenv -> python-virtualenv (ubuntu update)
mikhailyumanov Mar 28, 2021
49c42f9
znick#336 virtualenv -> python-virtualenv (ubuntu update)
mikhailyumanov Mar 28, 2021
7370c24
znick#336 linter
mikhailyumanov Mar 28, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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