From 2c8820161f996aaac7fa0774ab9bceba3f11a217 Mon Sep 17 00:00:00 2001 From: Koopa Date: Tue, 16 Jan 2024 18:12:22 -0500 Subject: [PATCH] tmp --- .env.template | 10 +++++- CONTRIBUTING.md | 33 +++++++++++++++++ README.md | 74 +++++++++++++++++++++++++++++++++++++-- compose.yaml | 3 ++ home/src/lib/server/db.ts | 2 ++ prep/index.ts | 1 + 6 files changed, 119 insertions(+), 4 deletions(-) create mode 100644 CONTRIBUTING.md create mode 100644 prep/index.ts diff --git a/.env.template b/.env.template index 0f4f413..c42a4ed 100644 --- a/.env.template +++ b/.env.template @@ -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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..321967b --- /dev/null +++ b/CONTRIBUTING.md @@ -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 diff --git a/README.md b/README.md index 19d84aa..d4b1567 100644 --- a/README.md +++ b/README.md @@ -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). @@ -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/). @@ -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. diff --git a/compose.yaml b/compose.yaml index ab7cd23..061d777 100644 --- a/compose.yaml +++ b/compose.yaml @@ -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. diff --git a/home/src/lib/server/db.ts b/home/src/lib/server/db.ts index 2e19a6c..92d36f9 100644 --- a/home/src/lib/server/db.ts +++ b/home/src/lib/server/db.ts @@ -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}` ); diff --git a/prep/index.ts b/prep/index.ts new file mode 100644 index 0000000..e430dac --- /dev/null +++ b/prep/index.ts @@ -0,0 +1 @@ +// TODO: check if db needs migration here