Skip to content

Commit edf36ed

Browse files
committed
chore: add production deployment scripts
1 parent eebea59 commit edf36ed

File tree

5 files changed

+197
-5
lines changed

5 files changed

+197
-5
lines changed

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Just to make life a bit easier :P
2+
3+
setup:
4+
./scripts/setup.sh
5+
6+
delete:
7+
./scripts/setup_delete.sh
8+
9+
update:
10+
./scripts/update.sh

README.md

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,28 @@ Feedr strives for constant improvement, so here's what will be implemented
4040

4141
# Developer Instructions
4242

43+
> [!NOTE]
44+
> Rewrite soon!
45+
4346
Feedr requires Bun in order to work
4447

4548
1. To install, run `bun i`
4649
2. Fill out all the required values in `.env.example` and rename it to `.env` once done
4750
3. To run in developer mode, just run `bun --watch . --dev`, otherwise `bun run .`
4851

52+
## Make (Optional)
53+
54+
> [!NOTE]
55+
> This is completely optional. This is just for deploying easier to production
56+
57+
There are several `make` commands to execute the different scripts in `/scripts`:
58+
59+
- `make setup`: Setup the services for Feedr's components
60+
- `make delete`: Delete the services (for testing purposes)
61+
- `make update`: Update the repo and restart the services
62+
63+
Make is normally installed with other GNU apps on Linux distros
64+
4965
## Design Rules
5066

5167
These rules are what to follow when working and developing on Feedr. There aren't a lot, but important for error handling.
@@ -75,29 +91,48 @@ These guidelines ensure predictable behavior and simplify error handling across
7591

7692
# Changelog
7793

78-
## 1.4.0
94+
## 2.0.0
95+
96+
> [!NOTE]
97+
> WIP update!
98+
99+
### Bot
100+
101+
- Fixed the double notification bug
102+
- Moved to Postgres as our database engine
103+
- Improved flow of `/track` command
104+
- Autocomplete for YouTube
105+
- Filter by videos, shorts and streams for YouTube!
106+
107+
### API
108+
109+
### Site
110+
111+
## V1
112+
113+
### 1.4.0
79114

80115
- Added a new command! `/tracked` ([#50](https://github.com/GalvinPython/feedr/issues/50))
81116
- See all the tracked channels in your server
82117
- The channel you ran the command in will appear first as there is no option to only see the current channel for now
83118
- Locale improvments ([#43](https://github.com/GalvinPython/feedr/issues/43))
84119

85-
## 1.3.0
120+
### 1.3.0
86121

87122
- Moved database to SQLite
88123

89-
## 1.2.0
124+
### 1.2.0
90125

91126
- Added Twitch feed
92127
- `platform` added to both **/track** and **/untrack**
93128

94-
## 1.1.0
129+
### 1.1.0
95130

96131
- Replies are no longer deferred
97132
- Messages can now be sent in Announcement channels [1.0.3]
98133
- Better checking for valid YouTube channel IDs
99134
- Channels with no uploads will be tracked now
100135

101-
## 1.0.0
136+
### 1.0.0
102137

103138
- Initial release

scripts/setup.sh

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/bin/bash
2+
3+
#################################################
4+
### !Run from the root folder of the project! ###
5+
#################################################
6+
7+
# Ensure Bun is installed and available in the environment
8+
BUN_PATH="$(which bun)"
9+
if [[ -z "$BUN_PATH" ]]; then
10+
echo "❌ Bun not found in PATH. Please install it first."
11+
exit 1
12+
fi
13+
14+
# Ensure Cargo is installed and available in the environment
15+
CARGO_PATH="$(which cargo)"
16+
if [[ -z "$CARGO_PATH" ]]; then
17+
echo "❌ Cargo not found in PATH. Please install it first."
18+
exit 1
19+
fi
20+
21+
##############################
22+
### Set up the bot service ###
23+
##############################
24+
SERVICE_NAME_BOT="feedr-bot"
25+
SERVICE_PATH_BOT="/etc/systemd/system/${SERVICE_NAME_BOT}.service"
26+
WORKDIR="$(pwd)"
27+
28+
# Create the service file
29+
cat <<EOF | sudo tee "$SERVICE_PATH_BOT" > /dev/null
30+
[Unit]
31+
Description=Feedr Bot Service
32+
After=network.target
33+
34+
[Service]
35+
WorkingDirectory=${WORKDIR}/src
36+
ExecStart=${BUN_PATH} run index.ts
37+
Restart=on-failure
38+
User=$USER
39+
Environment=NODE_ENV=production
40+
MemoryMax=1G
41+
42+
[Install]
43+
WantedBy=multi-user.target
44+
EOF
45+
46+
##############################
47+
### Set up the web service ###
48+
##############################
49+
SERVICE_NAME_WEB="feedr-web"
50+
SERVICE_PATH_WEB="/etc/systemd/system/${SERVICE_NAME_WEB}.service"
51+
WORKDIR="$(pwd)"
52+
53+
# Create the service file
54+
cat <<EOF | sudo tee "$SERVICE_PATH_WEB" > /dev/null
55+
[Unit]
56+
Description=Feedr Web Service
57+
After=network.target
58+
59+
[Service]
60+
WorkingDirectory=${WORKDIR}/web
61+
ExecStart=${BUN_PATH} run start
62+
Restart=on-failure
63+
User=$USER
64+
Environment=NODE_ENV=production
65+
MemoryMax=1G
66+
67+
[Install]
68+
WantedBy=multi-user.target
69+
EOF
70+
71+
##############################
72+
### Set up the API service ###
73+
##############################
74+
SERVICE_NAME_API="feedr-api"
75+
SERVICE_PATH_API="/etc/systemd/system/${SERVICE_NAME_API}.service"
76+
WORKDIR="$(pwd)"
77+
78+
# Create the service file
79+
cat <<EOF | sudo tee "$SERVICE_PATH_API" > /dev/null
80+
[Unit]
81+
Description=Feedr API Service
82+
After=network.target
83+
84+
[Service]
85+
WorkingDirectory=${WORKDIR}/api
86+
ExecStart=${CARGO_PATH} run --release
87+
Restart=on-failure
88+
User=$USER
89+
MemoryMax=1G
90+
91+
[Install]
92+
WantedBy=multi-user.target
93+
EOF
94+
95+
### Reload systemd and enable/start the service
96+
sudo systemctl daemon-reload
97+
sudo systemctl enable "$SERVICE_NAME_BOT"
98+
sudo systemctl start "$SERVICE_NAME_BOT"
99+
sudo systemctl enable "$SERVICE_NAME_WEB"
100+
sudo systemctl start "$SERVICE_NAME_WEB"
101+
sudo systemctl enable "$SERVICE_NAME_API"
102+
sudo systemctl start "$SERVICE_NAME_API"
103+
104+
echo "✅ Service '$SERVICE_NAME_BOT' installed and started from '$WORKDIR'."
105+
echo "✅ Service '$SERVICE_NAME_WEB' installed and started from '$WORKDIR'."
106+
echo "✅ Service '$SERVICE_NAME_API' installed and started from '$WORKDIR'."

scripts/setup_delete.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
#################################################
4+
### !Run from the root folder of the project! ###
5+
#################################################
6+
7+
# To run after testing
8+
9+
# Stop the services
10+
sudo systemctl stop feedr-bot.service
11+
sudo systemctl stop feedr-web.service
12+
sudo systemctl stop feedr-api.service
13+
14+
# Disable the services
15+
sudo systemctl disable feedr-bot.service
16+
sudo systemctl disable feedr-web.service
17+
sudo systemctl disable feedr-api.service
18+
19+
# Remove the service files
20+
sudo rm /etc/systemd/system/feedr-bot.service
21+
sudo rm /etc/systemd/system/feedr-web.service
22+
sudo rm /etc/systemd/system/feedr-api.service
23+
24+
# Reload the systemd daemon to apply changes
25+
sudo systemctl daemon-reload

scripts/update.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
#################################################
4+
### !Run from the root folder of the project! ###
5+
#################################################
6+
7+
# Update the repo
8+
git pull origin main
9+
10+
# Install dependencies
11+
bun install
12+
13+
# Restart the services
14+
sudo systemctl restart feedr-bot
15+
sudo systemctl restart feedr-web
16+
sudo systemctl restart feedr-api

0 commit comments

Comments
 (0)