The backend part of the Globalping dashboard.
To run this project, you need to have the following dependencies installed:
- Docker
- node.js
jq(used in some of the dev scripts)
You can run the project by following these steps:
-
Copy
.env.scripts.development.exampleto.env.scripts.development -
Copy
.env.docker.development.exampleto the.env.docker.development -
Register a new OAuth app on GitHub with values:
Application name: Globalping dash directus local
Homepage URL: http://localhost:18055
Authorization callback URL: http://localhost:18055
Enable Device Flow: disabled
-
Generate a new client secret for the app.
-
Add app id and generated secret to
AUTH_GITHUB_CLIENT_IDandAUTH_GITHUB_CLIENT_SECRETin.env.docker.development -
pnpm i -
docker compose up --build -d -
corepack enable -
pnpm init:dev -
Go to http://localhost:18055 and log in:
- Using your GitHub account
- As a regular user with lots of testing data using email
[email protected]and passworduser - As a regular user with no data (fresh account) using email
[email protected]and passwordnewuser - As an admin using email
[email protected]and passwordpassword
These commands should be enough in most cases:
pnpm run schema:apply
pnpm run migrate:development
docker compose up --build -d
To refresh the seed data if needed:
pnpm run seed
- copy
.env.scripts.development.exampleto.env.scripts.productionand fulfill all empty values exceptADMIN_ACCESS_TOKEN. - copy
.env.docker.production.exampleto the env vars of the container and fulfill all empty values exceptAUTH_GITHUB_DEFAULT_ROLE_IDandAUTH_DISABLE_DEFAULT. - run the remote container.
pnpm run schema:applypnpm run migrate:production- get default role id and set it to the
AUTH_GITHUB_DEFAULT_ROLE_IDenv var - restart the container
- login using github. Re-login as admin and give github user admin rights. Then set that value
AUTH_DISABLE_DEFAULT=true. Then restart the container - Login using github. Generate a static access token for your user and save it to the local .env file as
ADMIN_ACCESS_TOKEN
- fulfill all empty
.env.scripts.productionvalues, make sure ADMIN_ACCESS_TOKEN has your access token - if there are changes in
.env.docker.production.examplecopy them to the env vars of the container pnpm run schema:apply. Restart is required after updating the schema (directus/directus#17117)pnpm run migrate:production- stop prev container, run new container
Create extension:
npx --yes create-directus-extension@latest- Run script from the extension folder to set up unit testing
original_dir=$PWD
pnpm add --save-dev chai @types/chai mocha @types/mocha sinon @types/sinon ts-node @directus/extensions @directus/types
jq --tab 'del(.compilerOptions.rootDir) | .compilerOptions.module = "ESNext" | .compilerOptions.resolveJsonModule = true | .include = ["./src/**/*.ts", "../../lib/**/*.ts", "./test/**/*.ts"]' tsconfig.json > temp.json && mv temp.json tsconfig.json
jq --tab '.scripts.test = "tsc --noEmit && NODE_ENV=test mocha"' package.json > temp.json && mv temp.json package.json
jq --tab '.scripts."test:dev" = "NODE_ENV=test TS_NODE_TRANSPILE_ONLY=true mocha"' package.json > temp.json && mv temp.json package.json
mkdir test
while [[ $PWD != */extensions ]]; do cd ..; done
cp ./operations/gh-webhook-handler/.mocharc.json "$original_dir/"
cp ./operations/gh-webhook-handler/wallaby.js "$original_dir/"
cd "$original_dir"- Run script from the extension to fix wallaby.js
original_dir=$PWD
cd ../../lib/src
ln -s $PWD "$original_dir/lib"# Install haproxy
sudo apt-get update
sudo apt -y install haproxy
# Configure and start haproxy
sudo chmod a+w /etc/haproxy/haproxy.cfg
cat <<EOF | sudo tee -a /etc/haproxy/haproxy.cfg > /dev/null
frontend gp_fe
bind *:80
default_backend gp_be
backend gp_be
server server1 127.0.0.1:18055
EOF
sudo systemctl stop haproxy
sudo systemctl start haproxy
# Install node
sudo apt-get install -y ca-certificates curl gnupg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
NODE_MAJOR=18
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
sudo apt-get update
sudo apt-get install nodejs -y
# Install docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# Install jq
apt install jq -y