Skip to content

Commit

Permalink
Formatting and Add formatting to CI workflow (#292)
Browse files Browse the repository at this point in the history
* Add prettier formatting feature and also add it as a job in CI.yml file

* Update CI.yml file

* Add format job to CI.yml file

* Fix formatting issues in CI workflow file
  • Loading branch information
bhavik001 authored Nov 25, 2023
1 parent 1cefc49 commit 38e8192
Show file tree
Hide file tree
Showing 46 changed files with 3,818 additions and 3,342 deletions.
38 changes: 25 additions & 13 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,39 @@ name: Node.js CI

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
- run: npm test
env:
CI: true
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
- run: npm test
env:
CI: true

format:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install dependencies
run: npm install

- name: Run Prettier check
run: npx prettier --check .
20 changes: 10 additions & 10 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
name: deploy
on:
push:
tags:
tags:
- v*

jobs:
build:
name: deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Dokku
uses: dokku/github-action@bbb8818f9bad88edd3099a2399ef9be366754ff9
with:
git_remote_url: ssh://dokku@${{ secrets.SSH_SERVER }}:22/wbo
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
git_push_flags: --force
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Dokku
uses: dokku/github-action@bbb8818f9bad88edd3099a2399ef9be366754ff9
with:
git_remote_url: ssh://dokku@${{ secrets.SSH_SERVER }}:22/wbo
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
git_push_flags: --force
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
Expand Down
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package.json
package-lock.json
node_modules/
.DS_Store
*.html
12 changes: 12 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"arrowParens": "always",
"bracketSpacing": true,
"embeddedLanguageFormatting": "auto",
"endOfLine": "lf",
"insertPragma": false,
"proseWrap": "preserve",
"requirePragma": false,
"tabWidth": 2,
"useTabs": false,
"printWidth": 80
}
34 changes: 23 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ If you have your own web server, and want to run a private instance of WBO on it

### Running the code in a container (safer)

If you use the [docker](https://www.docker.com/) containerization service, you can easily run WBO as a container.
If you use the [docker](https://www.docker.com/) containerization service, you can easily run WBO as a container.
An official docker image for WBO is hosted on dockerhub as [`lovasoa/wbo`](https://hub.docker.com/r/lovasoa/wbo): [![WBO 1M docker pulls](https://img.shields.io/docker/pulls/lovasoa/wbo?style=flat)](https://hub.docker.com/repository/docker/lovasoa/wbo).

You can run the following bash command to launch WBO on port 5001, while persisting the boards outside of docker:
Expand All @@ -45,6 +45,7 @@ You can then access WBO at `http://localhost:5001`.
Alternatively, you can run the code with [node.js](https://nodejs.org/) directly, without docker.

First, download the sources:

```
git clone https://github.com/lovasoa/whitebophir.git
cd whitebophir
Expand All @@ -58,14 +59,17 @@ npm install --production
```

Finally, you can start the server:

```
PORT=5001 npm start
```

This will run WBO directly on your machine, on port 5001, without any isolation from the other services. You can also use an invokation like

```
PORT=5001 HOST=127.0.0.1 npm start
```

to make whitebophir only listen on the loopback device. This is useful if you want to put whitebophir behind a reverse proxy.

### Running WBO on a subfolder
Expand All @@ -76,7 +80,7 @@ See instructions on our Wiki about [how to setup a reverse proxy for WBO](https:

## Translations

WBO is available in multiple languages. The translations are stored in [`server/translations.json`](./server/translations.json).
WBO is available in multiple languages. The translations are stored in [`server/translations.json`](./server/translations.json).
If you feel like contributing to this collaborative project, you can [translate WBO into your own language](https://github.com/lovasoa/whitebophir/wiki/How-to-translate-WBO-into-your-own-language).

## Authentication
Expand All @@ -86,10 +90,10 @@ WBO supports authentication using [Json Web Tokens](https://jwt.io/introduction)
The `AUTH_SECRET_KEY` variable in [`configuration.js`](./server/configuration.js) should be filled with the secret key for the JWT.

Within the payload, you can declare the user's roles as an array.
Currently the only accepted roles are `moderator` and `editor`.
Currently the only accepted roles are `moderator` and `editor`.

- `moderator` will give the user an additional tool to wipe all data from the board. To declare this role, see the example below.
- `editor` will give the user the ability to edit the board. This is the default role for all users.
- `moderator` will give the user an additional tool to wipe all data from the board. To declare this role, see the example below.
- `editor` will give the user the ability to edit the board. This is the default role for all users.

```json
{
Expand All @@ -98,6 +102,7 @@ Currently the only accepted roles are `moderator` and `editor`.
"roles": ["moderator"]
}
```

Moderators have access to the Clear tool, which will wipe all content from the board.

## Board name verification in the JWT
Expand All @@ -108,9 +113,15 @@ To check for a valid board name just add the board name to the role with a ":".

```json
{
"roles": ["moderator:<boardName1>","moderator:<boardName2>","editor:<boardName3>","editor:<boardName4>"]
"roles": [
"moderator:<boardName1>",
"moderator:<boardName2>",
"editor:<boardName3>",
"editor:<boardName4>"
]
}
```

eg, `http://myboard.com/boards/mySecretBoardName?token={token}`

```json
Expand All @@ -128,9 +139,10 @@ You can now be sure that only users who have the correct token have access to th
When you start a WBO server, it loads its configuration from several environment variables.
You can see a list of these variables in [`configuration.js`](./server/configuration.js).
Some important environment variables are :
- `WBO_HISTORY_DIR` : configures the directory where the boards are saved. Defaults to `./server-data/`.
- `WBO_MAX_EMIT_COUNT` : the maximum number of messages that a client can send per unit of time. Increase this value if you want smoother drawings, at the expense of being susceptible to denial of service attacks if your server does not have enough processing power. By default, the units of this quantity are messages per 4 seconds, and the default value is `192`.
- `AUTH_SECRET_KEY` : If you would like to authenticate your boards using jwt, this declares the secret key.

- `WBO_HISTORY_DIR` : configures the directory where the boards are saved. Defaults to `./server-data/`.
- `WBO_MAX_EMIT_COUNT` : the maximum number of messages that a client can send per unit of time. Increase this value if you want smoother drawings, at the expense of being susceptible to denial of service attacks if your server does not have enough processing power. By default, the units of this quantity are messages per 4 seconds, and the default value is `192`.
- `AUTH_SECRET_KEY` : If you would like to authenticate your boards using jwt, this declares the secret key.

## Troubleshooting

Expand All @@ -146,5 +158,5 @@ metrics collection agent.

Example: `docker run -e STATSD_URL=udp://127.0.0.1:8125 lovasoa/wbo`.

- If you use **prometheus**, you can collect the metrics with [statsd-exporter](https://hub.docker.com/r/prom/statsd-exporter).
- If you use **datadog**, you can collect the metrics with [dogstatsd](https://docs.datadoghq.com/developers/dogstatsd).
- If you use **prometheus**, you can collect the metrics with [statsd-exporter](https://hub.docker.com/r/prom/statsd-exporter).
- If you use **datadog**, you can collect the metrics with [dogstatsd](https://docs.datadoghq.com/developers/dogstatsd).
Loading

0 comments on commit 38e8192

Please sign in to comment.