Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
CodingKoopa committed Jan 16, 2024
1 parent 4a7b7bc commit 2c88201
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 4 deletions.
10 changes: 9 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ POSTGRES_PASSWORD_HOME=
GOOGLE_CLIENT_ID=
# Obtain this from the Google Cloud Console.
GOOGLE_CLIENT_SECRET=
GOOGLE_REDIRECT_URI=http://localhost:5173/sign-up
GOOGLE_REDIRECT_URI=http://localhost:5173/login/google/callback

# Obtain this from the Discord Developer Portal.
DISCORD_CLIENT_ID=
# Obtain this from the Discord Developer Portal.
DISCORD_CLIENT_SECRET=
# Obtain this from the Discord Developer Portal.
DISCORD_TOKEN=
DISCORD_REDIRECT_URI=http://localhost:5173/login/discord/callback
33 changes: 33 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Attributes and props do not sort themselves, so do put thought into how you order them:

- HTML5 attributes first.
- Flowbite props last.

TODO: sort imports

```
docker compose run prep pnpm ...
```

UID 1000

## Static Analysis

Can either be done in root or proj

Lint code using [Prettier](https://prettier.io/) and [ESLint](https://eslint.org/):

```
pnpm lint
```

Check types using

tsc --noemit

## versions to update

GitHub actions runs-on
VPS Ubuntu version

nginx version
74 changes: 71 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

This is a monorepo for a couple of related websites. Not much to see here right now.

prep refers to two things

## HackBU Home

See [`home`](/home).
Expand All @@ -10,11 +12,61 @@ See [`home`](/home).

Maybe coming soon.

## Account setup

First, create credentials for Google:

- Create a project in the [Google Cloud console](https://console.cloud.google.com/).
- Go to https://console.cloud.google.com/apis/credentials > _Create credentials_ > _OAuth client ID_.
- Application type: _Web application_.
- Authorized JavaScript origins:
- Dev: N/A.
- Prod: `https://home.hackbu.org`, `https://hackathon.hackbu.org`.
- Authorized redirect URIs:
- Dev: `http://localhost:5173/login/google/callback`
- Prod: `https://home.hackbu.org/login/google/callback`

Copy the client ID and secret into your `.env` file.

Then, create credentials for Discord:

- Go to https://discord.com/developers/applications > _New Application_ > _Ok_.
- Navigate to the _OAuth2_ settings on the left and reset the client secret. Copy this and the client ID.
- Add a redirect:
- Dev: `http://localhost:5173/login/discord/callback`
- Prod: `https://home.hackbu.org/login/discord/callback`
- Repeat this with the _Bot_ tab and the token.

Copy the client ID, client secret, and bot token into your `.env` file.

Then, invite the Discord bot:

- Navigate to the _URL Generator_ from the above application.
- Check off only `bot`.
- Navigate to the generated URL and add the bot to the desired servers. This is necessary in order to add the linked role to that server.

run prep

## Setup

The only currently supported way to locally host the projects is using Docker.

### With Docker
### With Docker (Recommended)

we use docker compose

The development Compose file declares the following services:

- `prep`, a special service for preparing to run the other services. This is where you will run pnpm commands spanning the whole workspace, and also interact with the `prep` sub-project.
- You will use this service to run one-off tasks such as running database migrations and registering Discord commands.
- Note that, although this has the same name as the `prep` sub-project, the working directory is actually the root of the workspace.
- `db`, the internal Postgres database exposed at `db` to the other services.
- `dbadmin`, an [Adminer](https://www.adminer.org/) instance exposed at http://localhost:8080.
- `home`, a [HackBU Home](#hackbu-home) instance exposed at http://localhost:5173.

The production Compose file

TODO GENERATE PASSWORDS

First, install [Docker Engine](https://docs.docker.com/engine/install/) and [Docker Compose](https://docs.docker.com/compose/install/).

Expand All @@ -27,15 +79,31 @@ docker compose build
Install the dependencies: (**this must be repeated whenever there are dependency changes**)

```sh
docker compose run home pnpm install
docker compose run --rm home pnpm install
```

Run everything:
Register the Discord metadata:

```sh
docker compose run prep pnpm prep:discord
```

docker compose run home pnpm drizzle-kit push:pg

Start the database:

```sh
docker compose up -d db
```

```sh
docker compose up
```

where hm is

docker compose exec db psql hm admin

### Mixed

You may be able to run Postgres within Docker but Node on the host.
Expand Down
3 changes: 3 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# This Compose file runs Hackathon Manager in a development environment.
# also see

services:
db:
# We aren't scaling these up, so give them prettier names.
Expand Down
2 changes: 2 additions & 0 deletions home/src/lib/server/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import postgres from 'postgres';
import { drizzle } from 'drizzle-orm/postgres-js';
import { env } from '$env/dynamic/private';

// TODO: check whether these are null

export const client = postgres(
`postgres://${env.POSTGRES_USER_HOME}:${env.POSTGRES_PASSWORD_HOME}@${env.DB_HOST}/${env.POSTGRES_DB}`
);
Expand Down
1 change: 1 addition & 0 deletions prep/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TODO: check if db needs migration here

0 comments on commit 2c88201

Please sign in to comment.