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

One Command Setup #957

Merged
merged 11 commits into from
Nov 21, 2024
13 changes: 7 additions & 6 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Declare files that will always have LF line endings on checkout.
# Reasoning: Most files don't care about line endings, but shell scripts do.
# Thus, this file has been added to prevent '\r' from interfering with scripts.
# e.g. `/bin/sh^M: bad interpreter: No such file or directory`
# https://docs.github.com/en/github/using-git/configuring-git-to-handle-line-endings
*.sh text eol=lf
# Declare files that will always have LF line endings on checkout.
# Reasoning: Most files don't care about line endings, but shell scripts do.
# Thus, this file has been added to prevent '\r' from interfering with scripts.
# e.g. `/bin/sh^M: bad interpreter: No such file or directory`
# https://docs.github.com/en/github/using-git/configuring-git-to-handle-line-endings
*.sh text eol=lf
db/latest.sql filter=lfs diff=lfs merge=lfs -text
3 changes: 3 additions & 0 deletions db/latest.sql
Git LFS file not shown
31 changes: 22 additions & 9 deletions doc/dev.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,42 @@
# tCF Developer Info

## Setup
Ensure your system has [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git), and [Docker](https://docs.docker.com/install/) installed.

1. Ensure your system has [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git), Node, Python, PostgreSQL, and [Docker](https://docs.docker.com/install/) installed.
2. Clone the project:
## One-Command Setup

Run the following command in a POSIX-compliant shell (i.e. Windows users - use GitBash).

Replace `<install_dir>` with where you'd like to clone the script.

*TODO*: correct branch to main/dev when merged

```console
curl -fL 'https://raw.githubusercontent.com/thecourseforum/theCourseForum2/refs/heads/lfs-db/scripts/setup.sh' | sh -s -- <install_dir>
```

## Setup (Old)

1. Clone the project:

```console
$ git clone https://github.com/thecourseforum/theCourseForum2.git
$ cd theCourseForum
```

3. Download the `.env` secrets file from the [secrets repo](https://github.com/thecourseforum/tCF-env/blob/main/.env) and place it in the project root.
2. Download the `.env` secrets file from the [secrets repo](https://github.com/thecourseforum/tCF-env/blob/main/.env) and place it in the project root.

- _**Note**_: the file should be named exactly `.env`, not `.env.txt` or `env.txt` - rename if necessary.

4. Build the project
3. Build the project

```console
$ docker compose build --no-cache # from scratch (only necessary the first time)
$ docker compose up --build
```

5. Wait for the Django server to finish building (i.e. `tcf_django | Watching for file changes with StatReloader` is visible in stdout).
6. Download and place the [latest database backup](https://drive.google.com/drive/u/0/folders/1a7OkHkepOBWKiDou8nEhpAG41IzLi7mh) from Google Drive into `db/latest.sql` in your local repo.
7. Update the database:
4. Wait for the Django server to finish building (i.e. `tcf_django | Watching for file changes with StatReloader` is visible in stdout).
5. Download and place the [latest database backup](https://drive.google.com/drive/u/0/folders/1a7OkHkepOBWKiDou8nEhpAG41IzLi7mh) from Google Drive into `db/latest.sql` in your local repo.
6. Update the database:

MacOS/Linux (or Windows, if you're using Git-Bash):

Expand All @@ -33,7 +46,7 @@ $ sh scripts/reset-db.sh db/latest.sql

If you're on windows, open up `scripts/reset-db.sh` and run the commands manually (sorry)

8. Ensure the website is up, running, and functional at `localhost:8000`.
7. Ensure the website is up, running, and functional at `localhost:8000`.

### VSCode Setup

Expand Down
49 changes: 49 additions & 0 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/sh

if [ -z "$1" ]; then
echo "Must specify location to clone and set up theCourseForum2 respository."
exit
fi

exists() {
command -v "$1" >/dev/null 2>&1 || {
echo "Error: '$1' is not installed. Please install '$1'." >&2
exit
}
}

exists git

exists docker

git clone git@github.com:thecourseforum/theCourseForum2.git
if [ "$?" -ne 0 ]; then
echo "Unable to clone thecourseforum/theCourseForum2 with SSH. Ensure you have an ssh key set up on your GitHub account."
echo "See https://docs.github.com/en/authentication/connecting-to-github-with-ssh for more info."
exit 1
fi

cd theCourseForum2 || exit
# TODO: remove this when on main
git switch lfs-db

echo ""
echo "============================================"
echo "Please ensure that the '.env' file exists in the repository directory: $(eval echo "$1")"
echo "Once you have created the '.env' file, press Enter to continue."
echo "If the '.env' file does not exist, the script will exit."
echo "============================================"

printf "Press Enter to continue after verifying the '.env' file..."
read -r _ </dev/tty

[ ! -f ".env" ] && echo "Error: '.env' file does not exist in '$1'. Follow the installation instructions in doc/dev.md after creating a '.env' file." && exit 1

docker compose build --no-cache
docker compose up &
(
sleep 1
docker exec -i tcf_db psql tcf_db -U tcf_django -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public;"
docker exec -i tcf_db psql tcf_db -U tcf_django -c "CREATE EXTENSION IF NOT EXISTS pg_trgm;"
docker exec -i tcf_db psql tcf_db -U tcf_django <db/latest.sql
) &
Loading