-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbootstrap
executable file
·90 lines (72 loc) · 3 KB
/
bootstrap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
#
# Bootstrap!
#
# The "bootstrap" script is intended to be the quick-and-easy way to get
# started working on a project. After running the script a developer should be
# able to start right into doing development work.
#
# A bootstrap script typically does the following:
# - Dependencies
# - OS dependencies (Python, MySQL, etc.)
# - virtualenv/requirements.txt
# - Create the database
# - Sync/Migrate the database
# - Database seeding
#
# Most of what goes into a bootstrap script will be standard. If, however, your
# project is special and needs some extra things to happen before a developer
# can get up and running then this is place to put that logic.
#
# Exit immediately if a command exits with a nonzero exit status.
set -e
# Helper subroutines to help with "logging".
info () { printf " [ \033[00;34m..\033[0m ] $1"; }
success () { printf "\r\033[2K [ \033[00;32mOK\033[0m ] $1\n"; }
fail () { printf "\r\033[2K [\033[0;31mFAIL\033[0m] $1\n"; echo ''; exit; }
# Bootstrap!
echo "Bootstrapping the project..."
## Dependency Check
info "Ensuring that the OS dependencies are present..."
# TODO
# MySQL, Python, virtualenv, etc. doesn't exist? Here's how to install it...
success "Done ensuring that the OS dependencies are present."
info "Ensuring that the virtualenv exists..."
if [ ! -d ./.venv ]; then
# - The --no-site-packages option is used to help ensure that all
# dependencies are declared/tracked in the requirements.txt file.
virtualenv --no-site-packages .venv
fi
success "Done ensuring that the virtualenv exists."
info "Activating the virtualenv..."
source ".venv/bin/activate"
success "Done activating the virtualenv."
# Install/Update dependencies.
info "Installing/Upgrading dependencies..."
pip install -r requirements.txt
success "Done installing/upgrading dependencies."
## Database Creation
if [ ! -f ./project/development.sqlite3 ]; then
info "Creating the development database..."
## Sync/Migrate
# Using "South" for database migrations requires a little extra work. A
# normal "syncdb" must be performed before you can run "./manage.py
# migrate". (South requires a database table to be present before it can
# do its thing.) The "--noinput" option is specified since attempting to
# create the superuser will also attempt to create a corresponding
# Profile for that User. This will fail, however, since the Profile isn't
# created until "migrate" has been run.
./manage.py syncdb --noinput
./manage.py migrate
## Seed Data
# Create the superuser account for the development database using a
# simple username/password.
create_superuser_cmd="from django.contrib.auth.models import User; "
create_superuser_cmd+="User.objects.create_superuser("
create_superuser_cmd+="'admin', '[email protected]', 'test')"
echo "${create_superuser_cmd}" | ./manage.py shell
success "Done creating the development database."
fi
# Collect Static
./manage.py collectstatic --noinput
success "Bootstrapping complete."