Skip to content

Commit 8d213e0

Browse files
committed
Mac setup script solid now
1 parent 308d3c0 commit 8d213e0

File tree

3 files changed

+105
-72
lines changed

3 files changed

+105
-72
lines changed

README.md

Lines changed: 26 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# NSS Instructor Applications Project
1+
# Learning Platform Project
22

33
## Installs Needed
44

@@ -20,22 +20,14 @@ Go to [Postgresapp](https://postgresapp.com/) to download and run the Postgres a
2020

2121
pgAdmin is not a required install, but if you ever have the desire to have a browser-based interface for working directly with the database, go to [pgAdmin](https://www.pgadmin.org/download/) to download the administration tool for Postgres.
2222

23-
## Setup
23+
## Getting Started
2424

25-
### Getting Started
25+
1. Fork this repo to your own Github account.
26+
2. Clone it.
27+
3. `cd` into the project directory.
28+
4. Run `pipenv shell` to create a virtual environment.
2629

27-
Fork this repo to your own Github account, and then clone it. Then `cd` into the project directory.
28-
29-
### Project Installs and Config
30-
31-
If you are running on a Mac or Ubuntu, run the following commands.
32-
33-
```sh
34-
pipenv shell
35-
pipenv install
36-
```
37-
38-
### Github OAuth App
30+
## Github OAuth App
3931

4032
1. Go to your Github account settings
4133
2. Open **Developer Settings**
@@ -48,53 +40,36 @@ pipenv install
4840
9. Leave **Enable Device Flow** unchecked
4941
10. Create the app and **do not close** the screen that appears
5042
11. Go to Github and click the **Generate a new client secret** button
51-
14. **DO NOT CLOSE THIS TAB OR NAVIGATE AWAY**
52-
53-
### Environment Variables
54-
55-
Several environment variables need to be set up by you to make the setup process faster and more secure. Set up the following environment variables anywhere in your shell initialization file _(i.e. `.bashrc` or `.zshrc`)_.
43+
12. **DO NOT CLOSE TAB. CLIENT AND SECRET NEEDED BELOW.**
5644

57-
#### OAuth
45+
## Environment Variables
5846

59-
Copy the client ID and secret key that was generated in the previous step as the value of the corresponding variables.
47+
Several environment variables need to be set up by you to make the setup process faster and more secure.
6048

61-
```sh
62-
export LEARN_OPS_CLIENT_ID={Github app client ID}
63-
export LEARN_OPS_SECRET_KEY={Github app secret}
64-
```
49+
### Django Secret Key
6550

66-
#### Database
67-
68-
> **Tip:** You get to pick any Postgres password you want, but don't use spaces in it.
69-
70-
```sh
71-
export LEARN_OPS_DB=learnops
72-
export LEARN_OPS_USER=learnops
73-
export LEARN_OPS_PASSWORD={Postgres user password}
74-
export LEARN_OPS_HOST=localhost
75-
export LEARN_OPS_PORT=5432
76-
```
77-
78-
#### Django Secret Key
79-
80-
To generate a Django secret key, run the following command in your terminal.
51+
You will need a Django secret key environment variable. Run the following command in your terminal to generate one and save it for later.
8152

8253
```sh
8354
python3 -c "from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())"
8455
```
8556

86-
Then add a new variable to your init file.
87-
88-
```sh
89-
export LEARN_OPS_DJANGO_SECRET_KEY="{insert generated key}"
90-
```
91-
92-
#### Django Allowed Hosts
57+
### All Variables Needed
9358

94-
Add the following environment variable to your init file. If you are running the API in a container using a tool like Multipass or Docker, you must add the IP address of the container to this comma-separated list.
59+
Set up the following environment variables anywhere in your shell initialization file _(i.e. `.bashrc` or `.zshrc`)_.
9560

9661
```sh
97-
export LEARN_OPS_ALLOWED_HOSTS="learning.nss.team,learningapi.nss.team,127.0.0.1,localhost"
62+
export LEARN_OPS_DB=learnopsdev
63+
export LEARN_OPS_USER=learnopsdev
64+
export LEARN_OPS_PASSWORD=DatabasePasswordOfYourChoice
65+
export LEARN_OPS_HOST=127.0.0.1
66+
export LEARN_OPS_PORT=5432
67+
export LEARN_OPS_CLIENT_ID=GithubOAuthAppClientId
68+
export LEARN_OPS_SECRET_KEY=GithubOAuthAppSecret
69+
export LEARN_OPS_DJANGO_SECRET_KEY="GeneratedDjangoSecretKey"
70+
export LEARN_OPS_ALLOWED_HOSTS="127.0.0.1,localhost"
71+
export LEARN_OPS_SUPERUSER_NAME=AdminUsernameOfYourChoice
72+
export LEARN_OPS_SUPERUSER_PASSWORD=AdminPasswordOfYourChoice
9873
```
9974

10075
### Activate Environment Variables
@@ -108,7 +83,7 @@ In the main directory there is a bash script that you can run to create the data
10883
It will prompt you for your password.
10984

11085
```sh
111-
./createdb.sh
86+
./setup_mac.sh
11287
```
11388

11489
> For Mac, if you get feedback that `psql command not found`, add the following to your PATH in your shell initialization file _(.bashrc or .zshrc)_. Make sure the version is correct. You may not have version 10 of Postgres. If you don't, determine your version and replace the 10.
@@ -117,20 +92,6 @@ It will prompt you for your password.
11792
> /Applications/Postgres.app/Contents/Versions/10/bin
11893
> ```
11994
120-
121-
### Seed the Database
122-
123-
In the main directory there is a bash script that you can run to create the tables and seed some data. You can run it with the command below.
124-
125-
```sh
126-
./seed.sh
127-
```
128-
129-
130-
### Create a Superuser
131-
132-
Create a Django superuser account with `python manage.py createsuperuser`. This will give you an account with which you can get into the admin site.
133-
13495
## Testing the Installation
13596
13697
1. Start the API in debug mode in Visual Studio Code.

djangopass.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import sys
2+
from django.contrib.auth.hashers import make_password
3+
4+
print(make_password(sys.argv[1]))
5+
sys.exit(0)

setup_mac.sh

Lines changed: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,76 @@
11
#!/bin/bash
22

3-
psql -c "DROP DATABASE IF EXISTS $USER WITH (FORCE);"
4-
psql -c "CREATE DATABASE $USER;"
5-
psql -c "CREATE USER $USER WITH PASSWORD '$LEARN_OPS_PASSWORD';"
6-
psql -c "ALTER ROLE $USER SET client_encoding TO 'utf8';"
7-
psql -c "ALTER ROLE $USER SET default_transaction_isolation TO 'read committed';"
8-
psql -c "ALTER ROLE $USER SET timezone TO 'UTC';"
9-
psql -c "GRANT ALL PRIVILEGES ON DATABASE $USER TO $USER;"
3+
psql -c "DROP DATABASE IF EXISTS $LEARN_OPS_USER WITH (FORCE);"
4+
psql -c "CREATE DATABASE $LEARN_OPS_USER;"
5+
psql -c "CREATE USER $LEARN_OPS_USER WITH PASSWORD '$LEARN_OPS_PASSWORD';"
6+
psql -c "ALTER ROLE $LEARN_OPS_USER SET client_encoding TO 'utf8';"
7+
psql -c "ALTER ROLE $LEARN_OPS_USER SET default_transaction_isolation TO 'read committed';"
8+
psql -c "ALTER ROLE $LEARN_OPS_USER SET timezone TO 'UTC';"
9+
psql -c "GRANT ALL PRIVILEGES ON DATABASE $LEARN_OPS_USER TO $LEARN_OPS_USER;"
10+
11+
echo '[
12+
{
13+
"model": "sites.site",
14+
"pk": 1,
15+
"fields": {
16+
"domain": "learningplatform.com",
17+
"name": "Learning Platform"
18+
}
19+
},
20+
{
21+
"model": "socialaccount.socialapp",
22+
"pk": 1,
23+
"fields": {
24+
"provider": "github",
25+
"name": "Github",
26+
"client_id": "'"$LEARN_OPS_CLIENT_ID"'",
27+
"secret": "'"$LEARN_OPS_SECRET_KEY"'",
28+
"key": "",
29+
"sites": [
30+
1
31+
]
32+
}
33+
}
34+
]
35+
' > ./LearningAPI/fixtures/socialaccount.json
36+
37+
38+
export DJANGO_SETTINGS_MODULE="LearningPlatform.settings"
39+
PWD=$(python3 ./djangopass.py $LEARN_OPS_SUPERUSER_PASSWORD >&1)
40+
41+
42+
echo '[
43+
{
44+
"model": "auth.user",
45+
"pk": null,
46+
"fields": {
47+
"password": "'$PWD'",
48+
"last_login": null,
49+
"is_superuser": true,
50+
"username": "[email protected]",
51+
"first_name": "Admina",
52+
"last_name": "Straytor",
53+
"email": "[email protected]",
54+
"is_staff": true,
55+
"is_active": true,
56+
"date_joined": "2023-03-17T03:03:13.265Z",
57+
"groups": [
58+
2
59+
],
60+
"user_permissions": []
61+
}
62+
}
63+
]' > ./LearningAPI/fixtures/superuser.json
64+
65+
# Install project requirements
66+
pipenv install
67+
68+
# Run existing migrations
69+
python3 manage.py migrate
70+
71+
# Load data from backup
72+
python3 manage.py loaddata socialaccount
73+
python3 manage.py loaddata complete_backup
74+
python3 manage.py loaddata superuser
75+
76+
rm ./LearningAPI/fixtures/superuser.json

0 commit comments

Comments
 (0)