diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..0b47d58 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,23 @@ +{ + "name": "Ubuntu", + "image": "mcr.microsoft.com/devcontainers/base:noble", + "features": { + "ghcr.io/devcontainers/features/docker-in-docker:2": {}, + "ghcr.io/devcontainers/features/go:1": {}, + "ghcr.io/devcontainers/features/node:1": {}, + "ghcr.io/devcontainers-extra/features/mkcert:1": {} + }, + "customizations": { + "vscode": { + "settings": { + "files.watcherExclude": { + "docker/volumes/**": true + } + }, + "extensions": [ + "golang.go" + ] + } + }, + "postCreateCommand": "chmod +x ./.devcontainer/post-create && ./.devcontainer/post-create" +} diff --git a/.devcontainer/post-create b/.devcontainer/post-create new file mode 100755 index 0000000..8724871 --- /dev/null +++ b/.devcontainer/post-create @@ -0,0 +1,8 @@ +#!/bin/bash + +npm run setup + +sed -i "s/^SECRET_KEY=.*/SECRET_KEY=$(openssl rand -hex 12)/" backend/.env + +go install github.com/air-verse/air@latest +go install github.com/swaggo/swag/cmd/swag@latest diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..285cb49 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,29 @@ +.devcontainer/ +docker/ +frontend/ +rankings/ +.dockerignore +.env.example +.gitignore +CONTRIBUTING.md +docker-compose.yaml +Dockerfile +FUNDING.yml +LICENSE +package-lock.json +package.json +README.md +RULES.md + +# from .gitignore + +.env +.vscode +.vim +*.sh +*.txt +*.dem +backend/lphub +backend/tmp +rankings/rankings +rankings/tmp diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..d3d0fbf --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +DB_PORT=5432 +DB_USER=lphub +DB_PASS=lphub +DB_NAME=lphub diff --git a/.gitignore b/.gitignore index a9bec86..89b5d04 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,10 @@ .env .vscode +.vim *.sh *.txt *.dem +backend/lphub +backend/tmp +rankings/rankings +rankings/tmp diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..afa190b --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,125 @@ +# How to contribute + +## Requirements + +* [Go] +* [Node/npm] +* [Docker Engine] +* [mkcert] +* [Steam API key] +* [Backblaze Account] + +[Go]: https://go.dev/doc/install +[Node/npm]: https://nodejs.org/en/download/package-manager +[Docker Engine]: https://docs.docker.com/engine/install +[mkcert]: https://github.com/FiloSottile/mkcert +[Steam API key]: https://steamcommunity.com/dev/apikey +[Backblaze Account]: https://www.backblaze.com + +## Setup + +### Local + +* `npm run setup` +* Edit `backend/.env` +* `npm run up` +* `npm run frontend` (2nd terminal) +* Add a host entry `127.0.0.1 lp.hub.local` to `C:\Windows\System32\drivers\etc\hosts` or `/etc/hosts` +* Navigate to `https://lp.hub.local/api/v1/` to test the backend +* Navigate to `https://lp.hub.local:3000` to test the frontend + +### Using GitHub + +[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/pektezol/lphub) + +* Edit `backend/.env` +* `npm run up` +* Backend development: + * Navigate to `https://-443.app.github.dev/api/v1/` +* Frontend development: + * Edit "proxy" field in package.json to point to the backend `-443.app.github.dev` + * Add `127.0.0.1 -3000.app.github.dev` to `/etc/hosts` + * Run `HOST_DOMAIN=-3000.app.github.dev npm run frontend` (2nd terminal) + * Open frontend in the browser (VSCode will incorrectly suggest app.github.dev:3000 so remove the port at the end) + * NOTE: Hot reloading won't work. Use Ctrl+R or F5 instead + * NOTE: The `token` cookie must be copied manually from the backend domain when trying to login + +## Config + +Configure `backend/.env` file. + +|Config|Description| +|---|---| +|SECRET_KEY|Securely generated random secret for login tokens. Example: `openssl rand -hex 16`| +|API_KEY|Steam API key for fetching profile data.| +|B2_BUCKET_NAME|Bucket name from Backblaze.| +|B2_KEY_ID|Key ID from Backblaze.| +|B2_API_KEY|Application key from Backblaze.| +|B2_DOWNLOAD_URL|Bucket download friendly URL from Backblaze.| + +Configure `rankings/.env` file. + +|Config|Description| +|---|---| +|API_KEY|Steam API key for fetching profile data.| + +## Login + +* Navigate to frontend +* Log in with Steam +* Navigate to frontend again (port 3000) + +## Demo storage + +* Create new public Backblaze bucket +* Create new application key giving access to the bucket +* Modify `backend/.env` and set: + * `B2_BUCKET_NAME` name of the created bucket + * `B2_KEY_ID` key ID + * `B2_API_KEY` application key + * `B2_DOWNLOAD_URL` download friendly URL of the bucket + * Get ID from **endpoint** of the bucket e.g. `005` from `s3.us-east-005.backblazeb2.com` + * Get bucket name e.g. `lphub-demos` + * Construct the download URL e.g. `https://f005.backblazeb2.com/file/lphub-demos/` + +## Build + +Use `npm run build:frontend` to create an optimized build which the proxy will serve. + +## Generate rankings locally + +* Install [air CLI](https://github.com/air-verse/air) +* Run `npm run rankings` to update files in `./rankings/output` + +## Update docs locally + +* Install [swag CLI](https://github.com/swaggo/swag) +* Run `npm run docs` to update files in `./backend/docs` + +## Scripts + +Execute with `npm run