Skip to content

Commit 8879aaf

Browse files
committed
Added optional coolify installation and configurable auto reboot and remove of unused deps
1 parent 3a82a91 commit 8879aaf

File tree

4 files changed

+234
-37
lines changed

4 files changed

+234
-37
lines changed

.github/workflows/deploy.yml

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,45 @@ name: Deploy to VPS
33
on:
44
push:
55
branches: [main]
6-
workflow_dispatch: # Allows manual triggering
6+
workflow_dispatch:
77

88
jobs:
99
deploy:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v3
1313

14-
- name: Create setup script with secrets
15-
run: |
16-
sed -i "s/NEW_USER=\"youruser\"/NEW_USER=\"${{ secrets.VPS_USER }}\"/" setup.sh
17-
sed -i "s/NEW_USER_PASSWORD=\"your-secure-password\"/NEW_USER_PASSWORD=\"${{ secrets.VPS_USER_PASSWORD }}\"/" setup.sh
18-
sed -i "s/SSH_PUBLIC_KEY=\"your-public-key-content\"/SSH_PUBLIC_KEY=\"${{ secrets.SSH_PUBLIC_KEY }}\"/" setup.sh
19-
2014
- name: Deploy to VPS
2115
uses: appleboy/ssh-action@master
16+
env:
17+
NEW_USER: ${{ secrets.VPS_USER }}
18+
NEW_USER_PASSWORD: ${{ secrets.VPS_USER_PASSWORD }}
19+
SSH_PUBLIC_KEY: ${{ secrets.SSH_PUBLIC_KEY }}
20+
INSTALL_COOLIFY: ${{ secrets.INSTALL_COOLIFY }}
21+
AUTO_REBOOT: ${{ secrets.AUTO_REBOOT }}
22+
REMOVE_UNUSED_DEPS: ${{ secrets.REMOVE_UNUSED_DEPS }}
2223
with:
2324
host: ${{ secrets.VPS_HOST }}
2425
username: root
2526
password: ${{ secrets.VPS_ROOT_PASSWORD }}
27+
envs: NEW_USER,NEW_USER_PASSWORD,SSH_PUBLIC_KEY,INSTALL_COOLIFY,AUTO_REBOOT,REMOVE_UNUSED_DEPS
2628
script: |
27-
# Create temporary directory
2829
TEMP_DIR=$(mktemp -d)
2930
cd $TEMP_DIR
30-
31-
# Copy setup script from repository
3231
cat > setup.sh << 'EOL'
3332
${{ github.workspace }}/setup.sh
3433
EOL
35-
36-
# Make script executable and run it
3734
chmod +x setup.sh
3835
./setup.sh
39-
40-
# Cleanup
4136
cd /
4237
rm -rf $TEMP_DIR
4338
4439
- name: Post-setup instructions
45-
run: |
46-
echo "🎉 Setup completed!"
47-
echo "⚠️ IMPORTANT: After verifying SSH key access works, disable password authentication:"
48-
echo "ssh ${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }} 'sudo sed -i \"s/PasswordAuthentication yes/PasswordAuthentication no/\" /etc/ssh/sshd_config && sudo systemctl restart sshd'"
40+
run: |
41+
echo "🎉 Setup completed!"
42+
echo "⚠️ IMPORTANT: After verifying SSH key access works, disable password authentication:"
43+
echo "ssh ${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }} 'sudo sed -i \"s/PasswordAuthentication yes/PasswordAuthentication no/\" /etc/ssh/sshd_config && sudo systemctl restart sshd'"
44+
if [ "${INSTALL_COOLIFY}" = "true" ]; then
45+
echo "⚠️ After configuring your domain in Coolify, remove temporary ports:"
46+
echo "ssh $NEW_USER@<your-vps-ip> 'sudo ufw delete allow 8000/tcp && sudo ufw delete allow 6001/tcp && sudo ufw delete allow 6002/tcp'"
47+
fi

README.md

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ This repository contains automation scripts to set up a secure Debian-based VPS
2424
- Sets up unattended-upgrades with email notifications
2525
- Automatic system cleanup
2626

27+
- **Coolify Installation (Optional)**
28+
- Install Coolify
29+
- Open temporary ports (8000, 6001, 6002)
30+
- Provide instructions for securing after domain setup
31+
2732
## 🚀 Usage
2833

2934
### 1. Fork this Repository
@@ -37,23 +42,16 @@ In your forked repository, go to Settings > Secrets and variables > Actions and
3742
- `VPS_USER`: Desired username for the non-root user
3843
- `VPS_USER_PASSWORD`: Password for the new user
3944
- `SSH_PUBLIC_KEY`: Your SSH public key content (from `~/.ssh/id_rsa.pub`)
40-
41-
Example values:
42-
```bash
43-
VPS_HOST: 123.456.789.0
44-
VPS_ROOT_PASSWORD: your-initial-root-password
45-
VPS_USER: john
46-
VPS_USER_PASSWORD: your-secure-user-password
47-
SSH_PUBLIC_KEY: ssh-rsa AAAAB3NzaC1... john@localhost
48-
```
45+
- `INSTALL_COOLIFY`: Set to "true" to install Coolify, "false" to skip (defaults to "false")
46+
- `AUTO_REBOOT`: Set to "true" for automatic reboot after system updates, "false" to skip (defaults to "false")
47+
- `REMOVE_UNUSED_DEPS`: Set to "true" to remove unused dependencies, "false" to skip (defaults to "false")
4948

5049
⚠️ Security Note:
5150
- Never commit these values directly to the repository
5251
- Always use GitHub Secrets for sensitive information
5352
- Use strong passwords for both root and user accounts
5453
- Keep your SSH private key secure
5554

56-
5755
### 3. Deploy
5856
The setup will automatically deploy when you push to the main branch, or you can manually trigger it from the Actions tab.
5957

@@ -77,6 +75,19 @@ ssh your-user@your-vps-host 'sudo sed -i "s/PasswordAuthentication yes/PasswordA
7775
- Store your VPS root password securely (in case of emergencies)
7876
- Monitor the GitHub Actions logs for the setup result
7977

78+
#### Coolify Configuration
79+
80+
The setup includes an optional Coolify installation with temporary open ports:
81+
- 8000/tcp: Coolify Web UI
82+
- 6001/tcp: Coolify Websocket
83+
- 6002/tcp: Coolify Terminal
84+
85+
⚠️ Important: After configuring your domain in Coolify and setting up SSL, remove these temporary ports:
86+
```bash
87+
ssh your-user@your-vps-host 'sudo ufw delete allow 8000/tcp && sudo ufw delete allow 6001/tcp && sudo ufw delete allow 6002/tcp'
88+
```
89+
90+
These ports should only be open during initial setup. Once you've configured your domain and SSL in Coolify, all traffic should go through ports 80/443.
8091

8192
## 📋 What Gets Installed
8293

@@ -85,6 +96,7 @@ ssh your-user@your-vps-host 'sudo sed -i "s/PasswordAuthentication yes/PasswordA
8596
- unattended-upgrades
8697
- Docker & Docker Compose
8798
- Essential system utilities
99+
- Coolify (optinal)
88100

89101
## ⚙️ Configuration Details
90102

@@ -154,10 +166,18 @@ Contributions are welcome! Please feel free to submit a Pull Request.
154166

155167
This project is licensed under the MIT License - see the LICENSE file for details.
156168

157-
## ⭐ Support
169+
## 💪 Support This Project
170+
171+
Please give it a ⭐!
172+
173+
If you find this project useful and are looking for a VPS provider, consider using my affiliate link:
174+
175+
- [Get a Netcup VPS](https://www.netcup.com/en/?ref=223843) - Starting from €3.99/month
176+
- Excellent performance and reliability
177+
- Perfect for running this setup
158178

159-
If you find this useful, please give it a star!
179+
> 🙏 Using this link supports the maintenance and development of this project at no extra cost to you.
160180
161181
## 🔐 Security
162182

163-
If you discover any security issues, please send an email to [your-email] instead of using the issue tracker.
183+
If you discover any security issues, please send an email to [email protected] instead of using the issue tracker.

setup.sh

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#!/bin/bash
22

33
# Variables
4-
NEW_USER="youruser"
5-
NEW_USER_PASSWORD="your-secret-password"
6-
SSH_PUBLIC_KEY="your-public-key-content"
4+
NEW_USER="${NEW_USER:-youruser}"
5+
NEW_USER_PASSWORD="${NEW_USER_PASSWORD:-your-secret-password}"
6+
SSH_PUBLIC_KEY="${SSH_PUBLIC_KEY:-your-public-key-content}"
7+
INSTALL_COOLIFY="${INSTALL_COOLIFY:-false}"
8+
AUTO_REBOOT="${AUTO_REBOOT:-false}"
9+
REMOVE_UNUSED_DEPS="${REMOVE_UNUSED_DEPS:-false}"
710

811
# Update system
912
apt update && apt upgrade -y
@@ -31,8 +34,8 @@ Unattended-Upgrade::Mail "root";
3134
Unattended-Upgrade::MailReport "on-change";
3235
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
3336
Unattended-Upgrade::Remove-New-Unused-Dependencies "true";
34-
Unattended-Upgrade::Remove-Unused-Dependencies "false";
35-
Unattended-Upgrade::Automatic-Reboot "true";
37+
Unattended-Upgrade::Remove-Unused-Dependencies "${REMOVE_UNUSED_DEPS}";
38+
Unattended-Upgrade::Automatic-Reboot "${AUTO_REBOOT}";
3639
Unattended-Upgrade::Automatic-Reboot-Time "02:00";
3740
EOF
3841

@@ -75,7 +78,6 @@ ufw default allow outgoing
7578
ufw allow ssh
7679
ufw allow http
7780
ufw allow https
78-
echo "y" | ufw enable
7981

8082
# Install Docker
8183
apt install -y ca-certificates curl gnupg
@@ -91,11 +93,75 @@ echo \
9193
apt update
9294
apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
9395

96+
# Optionally install and configure coolify
97+
if [ "${INSTALL_COOLIFY}" = "true" ]; then
98+
99+
echo "Installing Coolify..."
100+
101+
# Temporary Coolify ports
102+
echo "⚠️ Adding temporary Coolify ports. Remember to remove them after configuring your domain!"
103+
ufw allow 8000/tcp comment 'Temporary Coolify Web UI'
104+
ufw allow 6001/tcp comment 'Temporary Coolify Websocket'
105+
ufw allow 6002/tcp comment 'Temporary Coolify API'
106+
107+
108+
mkdir -p /data/coolify/{source,ssh,applications,databases,backups,services,proxy,webhooks-during-maintenance}
109+
mkdir -p /data/coolify/ssh/{keys,mux}
110+
mkdir -p /data/coolify/proxy/dynamic
111+
112+
ssh-keygen -f /data/coolify/ssh/keys/[email protected] -t ed25519 -N '' -C root@coolify
113+
114+
cat /data/coolify/ssh/keys/[email protected] >>~/.ssh/authorized_keys
115+
chmod 600 ~/.ssh/authorized_keys
116+
117+
curl -fsSL https://cdn.coollabs.io/coolify/docker-compose.yml -o /data/coolify/source/docker-compose.yml
118+
curl -fsSL https://cdn.coollabs.io/coolify/docker-compose.prod.yml -o /data/coolify/source/docker-compose.prod.yml
119+
curl -fsSL https://cdn.coollabs.io/coolify/.env.production -o /data/coolify/source/.env
120+
curl -fsSL https://cdn.coollabs.io/coolify/upgrade.sh -o /data/coolify/source/upgrade.sh
121+
122+
chown -R 9999:root /data/coolify
123+
chmod -R 700 /data/coolify
124+
125+
sed -i "s|APP_ID=.*|APP_ID=$(openssl rand -hex 16)|g" /data/coolify/source/.env
126+
sed -i "s|APP_KEY=.*|APP_KEY=base64:$(openssl rand -base64 32)|g" /data/coolify/source/.env
127+
sed -i "s|DB_PASSWORD=.*|DB_PASSWORD=$(openssl rand -base64 32)|g" /data/coolify/source/.env
128+
sed -i "s|REDIS_PASSWORD=.*|REDIS_PASSWORD=$(openssl rand -base64 32)|g" /data/coolify/source/.env
129+
sed -i "s|PUSHER_APP_ID=.*|PUSHER_APP_ID=$(openssl rand -hex 32)|g" /data/coolify/source/.env
130+
sed -i "s|PUSHER_APP_KEY=.*|PUSHER_APP_KEY=$(openssl rand -hex 32)|g" /data/coolify/source/.env
131+
sed -i "s|PUSHER_APP_SECRET=.*|PUSHER_APP_SECRET=$(openssl rand -hex 32)|g" /data/coolify/source/.env
132+
133+
docker network create --attachable coolify
134+
135+
docker compose --env-file /data/coolify/source/.env -f /data/coolify/source/docker-compose.yml -f /data/coolify/source/docker-compose.prod.yml up -d --pull always --remove-orphans --force-recreate
136+
137+
echo "⚠️ After configuring your domain in Coolify, remove temporary ports:"
138+
echo "ssh $VPS_USER@$VPS_HOST 'sudo ufw delete allow 8000/tcp && sudo ufw delete allow 6001/tcp && sudo ufw delete allow 6002/tcp'"
139+
fi
140+
141+
# enable ufw
142+
echo "y" | ufw enable
143+
94144
# Add user to docker group
95145
usermod -aG docker $NEW_USER
96146

97147
# Restart services
98148
systemctl restart sshd
99149
systemctl restart fail2ban
100150

151+
# Print access information
152+
echo "=== IMPORTANT: SAVE THIS INFORMATION ==="
153+
echo "New user: $NEW_USER"
154+
echo "Password: $NEW_USER_PASSWORD"
155+
echo ""
156+
echo "Test SSH access with: ssh $NEW_USER@<your-vps-ip>"
157+
echo ""
158+
echo "After confirming SSH key access works, run:"
159+
echo "ssh $NEW_USER@<your-vps-ip> 'sudo sed -i \"s/PasswordAuthentication yes/PasswordAuthentication no/\" /etc/ssh/sshd_config && sudo systemctl restart sshd'"
160+
echo ""
161+
if [ "${INSTALL_COOLIFY}" = "true" ]; then
162+
echo "⚠️ After configuring your domain in Coolify, remove temporary ports:"
163+
echo "ssh $NEW_USER@<your-vps-ip> 'sudo ufw delete allow 8000/tcp && sudo ufw delete allow 6001/tcp && sudo ufw delete allow 6002/tcp'"
164+
fi
165+
echo ""
166+
echo "==================================="
101167
echo "Setup completed!"

setup_without_coolify.sh

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/bin/bash
2+
3+
# Variables
4+
NEW_USER="youruser"
5+
NEW_USER_PASSWORD="your-secret-password"
6+
SSH_PUBLIC_KEY="your-public-key-content"
7+
8+
# Update system
9+
apt update && apt upgrade -y
10+
11+
# Install required packages
12+
apt install -y sudo ufw fail2ban unattended-upgrades apt-listchanges
13+
14+
# Configure unattended-upgrades
15+
cat > /etc/apt/apt.conf.d/20auto-upgrades << EOF
16+
APT::Periodic::Update-Package-Lists "1";
17+
APT::Periodic::Unattended-Upgrade "1";
18+
APT::Periodic::Download-Upgradeable-Packages "1";
19+
APT::Periodic::AutocleanInterval "7";
20+
EOF
21+
22+
cat > /etc/apt/apt.conf.d/50unattended-upgrades << EOF
23+
Unattended-Upgrade::Origins-Pattern {
24+
"origin=Debian,codename=\${distro_codename},label=Debian-Security";
25+
"origin=Debian,codename=\${distro_codename}-security,label=Debian-Security";
26+
};
27+
Unattended-Upgrade::AutoFixInterruptedDpkg "true";
28+
Unattended-Upgrade::MinimalSteps "true";
29+
Unattended-Upgrade::InstallOnShutdown "false";
30+
Unattended-Upgrade::Mail "root";
31+
Unattended-Upgrade::MailReport "on-change";
32+
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
33+
Unattended-Upgrade::Remove-New-Unused-Dependencies "true";
34+
Unattended-Upgrade::Remove-Unused-Dependencies "false";
35+
Unattended-Upgrade::Automatic-Reboot "true";
36+
Unattended-Upgrade::Automatic-Reboot-Time "02:00";
37+
EOF
38+
39+
# Enable unattended-upgrades
40+
systemctl enable unattended-upgrades
41+
systemctl start unattended-upgrades
42+
43+
# Create new user and add to sudo group
44+
useradd -m -s /bin/bash $NEW_USER
45+
echo "$NEW_USER:$NEW_USER_PASSWORD" | chpasswd
46+
usermod -aG sudo $NEW_USER
47+
48+
# Setup SSH key for new user
49+
mkdir -p /home/$NEW_USER/.ssh
50+
echo "$SSH_PUBLIC_KEY" > /home/$NEW_USER/.ssh/authorized_keys
51+
chmod 700 /home/$NEW_USER/.ssh
52+
chmod 600 /home/$NEW_USER/.ssh/authorized_keys
53+
chown -R $NEW_USER:$NEW_USER /home/$NEW_USER/.ssh
54+
55+
# Configure SSH
56+
sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
57+
sed -i 's/#PubkeyAuthentication yes/PubkeyAuthentication yes/' /etc/ssh/sshd_config
58+
sed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
59+
60+
# Configure fail2ban
61+
cat > /etc/fail2ban/jail.local << EOF
62+
[sshd]
63+
enabled = true
64+
port = ssh
65+
filter = sshd
66+
logpath = /var/log/auth.log
67+
maxretry = 3
68+
bantime = 3600
69+
findtime = 600
70+
EOF
71+
72+
# Configure firewall
73+
ufw default deny incoming
74+
ufw default allow outgoing
75+
ufw allow ssh
76+
ufw allow http
77+
ufw allow https
78+
echo "y" | ufw enable
79+
80+
# Install Docker
81+
apt install -y ca-certificates curl gnupg
82+
install -m 0755 -d /etc/apt/keyrings
83+
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
84+
chmod a+r /etc/apt/keyrings/docker.gpg
85+
86+
echo \
87+
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
88+
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
89+
tee /etc/apt/sources.list.d/docker.list > /dev/null
90+
91+
apt update
92+
apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
93+
94+
# Add user to docker group
95+
usermod -aG docker $NEW_USER
96+
97+
# Restart services
98+
systemctl restart sshd
99+
systemctl restart fail2ban
100+
101+
# Print access information
102+
echo "=== IMPORTANT: SAVE THIS INFORMATION ==="
103+
echo "New user: $NEW_USER"
104+
echo "Password: $NEW_USER_PASSWORD"
105+
echo ""
106+
echo "Test SSH access with: ssh $NEW_USER@<your-vps-ip>"
107+
echo ""
108+
echo "After confirming SSH key access works, run:"
109+
echo "ssh $NEW_USER@<your-vps-ip> 'sudo sed -i \"s/PasswordAuthentication yes/PasswordAuthentication no/\" /etc/ssh/sshd_config && sudo systemctl restart sshd'"
110+
echo "==================================="
111+
112+
echo "Setup completed!"

0 commit comments

Comments
 (0)