Skip to content

Commit a9ad4d5

Browse files
committed
Issue #143 make app nixpacks/coolify compatible
- add ops doc - fix pnpm workspace and shebang - fix startup without ./env
1 parent 2fdff26 commit a9ad4d5

File tree

13 files changed

+210
-13
lines changed

13 files changed

+210
-13
lines changed

.github/CONTRIBUTING.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,36 @@ cp ./env/.env.template ./env/.env.development
4545

4646
Execute the application
4747
```bash
48-
pnpm startDev
48+
pnpm dev
4949
```
5050
or (production mode)
5151
```bash
5252
pnpm start
5353
```
5454

55+
56+
## About nixpacks packaging
57+
58+
This app is a Node.js ESM simple application.
59+
60+
- compatible with [nixpacks](https://nixpacks.com/docs/getting-started)
61+
62+
### nixpacks build
63+
cf. [OPS_app](../doc/OPS_app.md)
64+
65+
5566
## PullRequests additional information
5667
Activated bot:
5768
- [houndci](https://houndci.com/)
5869

5970

6071
# Maintainer HowTos
6172

73+
## HowTo operate bot hosting
74+
- for now, botEnSky is manually deployed via www.render.com free plan in state. There is just ENV to setup.
75+
- there is a plan to move on a dedicated VM (#142), and a draft version of [OPS](../doc/OPS.md) guide exist.
76+
77+
6278
## HowTo create a fresh version
6379
- use patch or minor or major workflow
6480

bin/commonEnv.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
import dotEnvFlow from 'dotenv-flow';
2+
import fs from 'fs';
3+
4+
//~ project init of environment
25
export const initEnv = () => {
3-
//~ project init of environment
4-
dotEnvFlow.config({ path: './env/' });
5-
}
6+
if (!fs.existsSync('./env/.env.development') && !fs.existsSync('./env/.env.production')) {
7+
console.log('🔌 Environment must be configured inline');
8+
} else {
9+
dotEnvFlow.config({ path: './env/' });
10+
}
11+
if (!process.env.BLUESKY_USERNAME) {
12+
console.error('❌ BLUESKY_USERNAME environment variable is required');
13+
process.exit(1);
14+
}
15+
}

bin/start.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
if [ -z "$NODE_ENV" ]; then
3+
echo "Error: NODE_ENV environment variable is not set"
4+
exit 1
5+
fi
6+
exec node --unhandled-rejections=strict ./bin/www

bin/startDev.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
. ./env/.env.bash.development
33
exec node ./bin/www

bin/startServer.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
. ./env/.env.bash.production
33
exec node --unhandled-rejections=strict ./bin/www

doc/OPS.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
[< botEnSky](../README.md)
2+
3+
# Operator guide - OPS guide --- DRAFT VERSION
4+
5+
BotEnSky application is currently deployed on render.com free plan without special requirements out of setting environment.
6+
This page don't talk about render.com as there is nothing to add to official doc.
7+
8+
BotEnSky application planB (#142) is to deploy it on a private VM having special requirements : ex. #143 Coolify PaaS
9+
10+
💁 NOTE: this is a DRAFT VERSION, as for now only local test has been done
11+
12+
This page describe VM requirements + Coolify PaaS installation.
13+
14+
For BotEnSky applications install, cf. [OPS_app](./OPS_app.md)
15+
16+
## Requirements
17+
18+
### A Secure Linux Virtual machine (VM)
19+
- Example : OVH dedicated VM ([VPS help doc](https://help.ovhcloud.com/csm/fr-vps-getting-started?id=kb_article_view&sysparm_article=KB0047736))
20+
- you could use your own VM, or VM provider to instantiate a new Linux VM.
21+
- you must have an ssh access to the VM.
22+
23+
### Ssh notice
24+
25+
- configure VM ssh service, and keep pk in a secure place,
26+
- refuse ssh root login with password (mandatory),
27+
- add an ssh script `/etc/ssh/scripts/sshnotify.sh` that will notify ssh connexions to your favorite tchat app channel.
28+
29+
TODO: add more details on this
30+
31+
### Fail2Ban service is recommended
32+
- add [fail2ban](https://github.com/fail2ban/fail2ban) : a project that monitor and ban IP of ssh attempts too many failures
33+
````
34+
systemctl start/enable/stop fail2ban
35+
````
36+
37+
To see banned ip :
38+
```
39+
sudo fail2ban-client status
40+
sudo fail2ban-client status sshd
41+
```
42+
43+
### Coolify
44+
💁 NOTE: this is a DRAFT VERSION, for now only local QA using WSL2 has been done.
45+
46+
#### Coolify install
47+
- Follow [Coolify installation guide](https://coolify.io/docs/installation)
48+
- On issue, you could rely on [manual as fallback](https://coolify.io/docs/get-started/installation#manual-installation)
49+
- ✔️ at the end, you have docker installed on your VM, and coolify visible from your browser.
50+
- ➕👤 create a Coolify administrator account with a secure password.
51+
52+
53+
### Coolify - TIPS
54+
#### Coolify Start
55+
```bash
56+
sudo su -
57+
cd /data/coolify
58+
docker compose \
59+
--env-file /data/coolify/source/.env \
60+
-f /data/coolify/source/docker-compose.yml \
61+
-f /data/coolify/source/docker-compose.prod.yml \
62+
up -d --pull always --remove-orphans --force-recreate
63+
````
64+
65+
go to http://youserver:8000
66+
67+
#### Coolify Stop
68+
```bash
69+
docker compose \
70+
--env-file /data/coolify/source/.env \
71+
-f /data/coolify/source/docker-compose.yml \
72+
-f /data/coolify/source/docker-compose.prod.yml down
73+
```
74+
75+
#### Coolify Recover admin account
76+
77+
💁 TIP: I dont remember the email used by account creation
78+
79+
```bash
80+
docker exec -it coolify-db psql -U coolify
81+
````
82+
83+
Then in Postgres console :
84+
85+
````sql
86+
\c coolify
87+
SELECT email FROM users;
88+
````
89+
90+
💁 TIP: I want to reset admin account creation (not tested)
91+
92+
```bash
93+
docker exec -it coolify bash
94+
php artisan coolify:reset-password
95+
```
96+
97+
TIP: save it in a safe place (like Keepass)

doc/OPS_app.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
[< OPS](./OPS.md)
2+
3+
## BotEnSky Application deployment --- DRAFT VERSION
4+
5+
Coolify is used to deploy app.
6+
7+
The app need to be nixpacks compatible to be deployed.
8+
9+
### HowTo verify nixpacks compatibility
10+
11+
````bash
12+
# NB: this works under WSL2
13+
# git clone and cd botensky/
14+
# cat ./nixpacks.toml
15+
nixpacks build . --name botensky-app
16+
````
17+
18+
### run
19+
Once nixpacks build is done, you could start app container.
20+
21+
````bash
22+
docker run -it -p 5000:5000 botensky-app
23+
````
24+
25+
26+
27+
### HowTo deploy botEnSky on Coolify
28+
29+
- once Coolify is installed,
30+
- `Servers` : check you have a server installed with ssh access (ie. start ssh server if needed)
31+
- `Projects > +add` : add and name a new project ex. Name `boly38/bot-en-sky:localQA` - Description `this is my bot`
32+
- You could name your environment ex. replace `Production` by `wsl2`
33+
- `Dashboard > boly38/bot-en-sky:localQA > +Add resource` :
34+
- choose `Public repository`,
35+
- if needed to validate the server to use
36+
- Repository URL: `https://github.com/boly38/botEnSky` | Build Pack : `Nixpacks` | Base dir : `/` | Port `5000` | uncheck static site + `Continue`
37+
- `General` > adapt name suffix ex `boly38/bot-en-sky:nixpacks/coolify-withWsl2` | Port mapping `5000:5000` (or your need)
38+
- `Environment` > Paste in developper mode your env variables list
39+
+ `Save` + `Deploy` et voilà 🚀
40+
41+
TIP: show debug log to see the very first deployment in details. Coolify is very friendly.
42+
43+
TIP: to test using local WSL2, you could map 127.0.0.1 to a given name ex `coolify.local` and set `General > Domains` with `http://coolify.local/`. In that context, your app is visible from http://coolify.local:5000/

nixpacks.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# nixpacks.toml for botEnSky
2+
# This configuration allows using the same file in both production and development
3+
# environments, controlled by the NODE_ENV variable.
4+
[phases.setup]
5+
nixPkgs = ["nodejs_23", "pnpm"]
6+
7+
[phases.install]
8+
cmds = [
9+
# In production:
10+
# > pnpm install --prod --frozen-lockfile --ignore-workspace-root-check
11+
# Install only runtime dependencies
12+
# In development:
13+
# > pnpm install
14+
# Install all dependencies, including devDependencies
15+
"if [ \"$NODE_ENV\" = \"production\" ]; then pnpm install --prod --frozen-lockfile; else pnpm install; fi"
16+
]
17+
18+
[phases.build]
19+
cmds = [] # No build step required for this project
20+
21+
[start]
22+
cmd = "bash ./bin/start.sh"

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "BlueSky botEnSky - a bot account that reply to bluesky post with Pla@ntNet identification",
55
"scripts": {
66
"audit": "npm audit&&npm outdated --depth=3",
7-
"startDev": "bash ./bin/startDev.sh",
7+
"dev": "bash ./bin/startDev.sh",
88
"start": "bash ./bin/startServer.sh",
99
"setupDev": "npm install -g jshint",
1010
"lint": "eslint .",
@@ -81,5 +81,5 @@
8181
"notes": {
8282
"chai-http": "with last version 5.0.0 : 20 tst issue 'chai.request is not a function'"
8383
},
84-
"packageManager": "pnpm@10.15.0+sha512.486ebc259d3e999a4e8691ce03b5cac4a71cbeca39372a9b762cb500cfdf0873e2cb16abe3d951b1ee2cf012503f027b98b6584e4df22524e0c7450d9ec7aa7b"
84+
"packageManager": "pnpm@10.18.0+sha512.e804f889f1cecc40d572db084eec3e4881739f8dec69c0ff10d2d1beff9a4e309383ba27b5b750059d7f4c149535b6cd0d2cb1ed3aeb739239a4284a68f40cfa"
8585
}

pnpm-workspace.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
packages:
2+
- .
3+
14
onlyBuiltDependencies:
25
- bufferutil
36
- msw

0 commit comments

Comments
 (0)