Edit Readme & Clean up anything left over from the already outdated template I made

This commit is contained in:
2025-06-19 13:48:13 -05:00
parent 301a9acec0
commit 4a9c1a7fec
9 changed files with 285 additions and 113 deletions

125
README.md
View File

@ -1,19 +1,124 @@
# T3 Template with Self Hosted Supabase
<h1 align="center">
<br>
<a href="https://techtracker.gbrown.org"><img src="https://git.gbrown.org/gib/tech-tracker-next/raw/branch/master/public/favicon.png" alt="Tech Tracker Logo" width="100"></a>
<br>
<b>Tech Tracker</b>
<br>
</h1>
This is my template for self hosting both Next.js & Supabase in order to create a perfect app!!
# [Find Here](https://techtracker.gbrown.org/)
## What to do
- Application used by COG employees to update their status & location throughout the day.
- [Self Host Supabase](https://supabase.com/docs/guides/self-hosting/docker)
- You will need to make sure you have some way to connect to the postgres database from the host. I had to remove the database port from the supabase-pooler and add it to the supabase-db in order to directly connect to it. This will be important for generating our types.
- Clone this repo.
- Go to src/server/db/schema.sql & run this SQL in the SQL editor on the Web UI of your Supabase instance.
- Generate your types
- This part is potentially super weird if you are self hosting. If you are connecting directly to your database that you plan to use for production, you will need to clone your repo on the host running supabase so that you can then use the supabase cli tool. Once you have done that, you will need to install the supabase-cli tool with sudo. I just run something like `sudo npx supabase --help` and then accept the prompt to install the program. Once you have done this, you can then run the following command, replacing the password and the port to match your supabase database. You can also try running the provided script `./scripts/generate_types`
<details>
<summary>
<h2>How to run:</h2>
</summary>
### Clone the Repository & Install Dependencies
```bash
git clone https://git.gbrown.org/gib/tech-tracker-next.git
```
```bash
cd tech-tracker-next
```
I would recommend using [pnpm](https://pnpm.io/) to install dependencies.
```bash
pnpm install
```
You will also need docker installed on whatever host you plan to run the Supabase instance from, whether locally, or on a home server or a VPS or whatever. Or you can just use the Supabase SaaS if you want to have a much easier time, probably. I wouldn't know!
### Add your environment variables
Copy the example environment variable files and paste them in the same directory named `.env`.
```bash
cp ./env.example ./.env
```
```bash
cp ./src/server/docker/env.example ./src/server/docker/.env
```
Add your secrets to the `.env` files you just copied.
### Host Supabase Locally
- Follow the instructions [here](https://supabase.com/docs/guides/self-hosting/docker) to host Supabase with Docker.
- You will need to make sure you have some way to connect to the postgres database from the host. I had to remove the database port from the supabase-pooler and add it to the supabase-db in order to directly connect to it. This will be important for generating our types. This is not strictly necessary, and honestly I think I may even just have the docker compose set up to do this already, as I can't figure out why I would want to port to the spooler open on my host anyways.
### Create your database schema & generate your types.
- Copy the contents of the schema file located in `./src/server/db/schema.sql` & paste it into the SQL editor on the Web UI of your Supabase instance. Run the SQL. There should be no errors & you should now be able to see the profiles & statuses tables in the table editor.
```bash
cat ./src/server/db/schema.sql | wl-copy # If you are on Linux
```
- Generate your types.
- This can be a bit weird depending on what your setup is. If you are running Supabase locally on the same host that you are running your dev server, then this should be straightforward. If you are using the Supabase SaaS, then this is even more straightforward. If you are like me, and you are connecting to a self hosted instance of Supabase on your home server while developing, then you must clone this reposity on your server so that the command line tool can generate the types from your open postgres port on your Host, which is why the docker compose is configured how it was & why I mentioned this earlier.
You will need to run the supabase cli tool with sudo in my experience. What I would recommend to you is to run the command
```bash
sudo npx supabase --help
```
You will be prompted to install the supabase cli tool if you do not already have it installed, which you probably don't since root is running this. After that, you can run the following command below, replacing the password and the port to match your own Supabase Postgres Database port & password.
```bash
sudo npx supabase gen types typescript \
--db-url "postgres://postgres:password@localhost:5432/postgres" \
--schema public \
> ./src/lib/types
> ./src/utils/supabase/types.ts
```
There is also a script in the `scripts` folder called `generate_types` which *should* do this for you.
```bash
./scripts/generate_types
```
### Start your development environment.
Run
```bash
pnpm dev
```
to start your development environment with turbopack
You can also run
```bash
pnpm dev:slow
```
to start your development environment with webpack
### Start your Production Environment.
There are Dockerfiles & docker compose files that can be found in the `./scripts/docker` folder for the Next.js website. There is also a script called `reload_container` located in the `./scripts/` folder which was created to quickly update the container, but this will give you a better idea of what you need to do. First, build the image with
```bash
sudo docker compose -f ./scripts/docker/production/compose.yml build
```
then you can run the container with
```bash
sudo docker compose -f ./scripts/docker/production/compose up -d
```
Now, you may end up with some build errors. The `reload_containers` script swaps out the next config before it runs the docker build to skip any build errors, so you may want to do this as well, though you are welcome to fix the build errors as well, of course!
### Fin
I am sure I am missing a lot of stuff so feel free to open an issue if you have any questions or if you feel that I should add something here!
</details>