-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from DFanso/rebase/dev
Rebase/dev
- Loading branch information
Showing
3 changed files
with
149 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
name: Deploy to Production | ||
|
||
on: | ||
push: | ||
branches: [ rebase/dev ] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '20' | ||
cache: 'npm' | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Build | ||
run: npm run build | ||
|
||
- name: Install sshpass | ||
run: sudo apt-get install sshpass | ||
|
||
- name: Deploy to VM | ||
env: | ||
VM_HOST: ${{ secrets.VM_HOST }} | ||
VM_PASSWORD: ${{ secrets.VM_PASSWORD }} | ||
DEPLOY_PATH: "/root/dfanso-tunnel-server" | ||
SSHPASS: ${{ secrets.VM_PASSWORD }} | ||
run: | | ||
echo "Starting deployment..." | ||
echo "Creating deploy directory..." | ||
sshpass -e ssh -o StrictHostKeyChecking=no root@${{ secrets.VM_HOST }} "mkdir -p $DEPLOY_PATH" | ||
echo "Copying files to VM..." | ||
sshpass -e rsync -azP --delete \ | ||
-e "ssh -o StrictHostKeyChecking=no" \ | ||
--exclude '.git' \ | ||
--exclude 'node_modules' \ | ||
./ root@${{ secrets.VM_HOST }}:$DEPLOY_PATH/ | ||
echo "Setting up application..." | ||
sshpass -e ssh -o StrictHostKeyChecking=no root@${{ secrets.VM_HOST }} "cd $DEPLOY_PATH && \ | ||
echo '=== Checking Node.js installation ===' && \ | ||
if ! command -v node &> /dev/null; then | ||
echo 'Installing Node.js...' && \ | ||
curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \ | ||
apt-get install -y nodejs && \ | ||
echo 'Node.js installation complete:' && \ | ||
node --version && \ | ||
npm --version | ||
else | ||
echo 'Node.js is already installed:' && \ | ||
node --version && \ | ||
npm --version | ||
fi && \ | ||
echo '=== Installing PM2 ===' && \ | ||
npm install -g pm2@latest && \ | ||
echo '=== Installing dependencies ===' && \ | ||
npm ci --production && \ | ||
echo '=== Creating ecosystem config ===' && \ | ||
echo 'module.exports = { | ||
apps: [{ | ||
name: \"dfanso-tunnel\", | ||
script: \"./dist/index.js\", | ||
instances: 1, | ||
autorestart: true, | ||
watch: true, | ||
max_memory_restart: \"1G\", | ||
env: { | ||
NODE_ENV: \"${{ secrets.NODE_ENV }}\", | ||
DOMAIN: \"${{ secrets.DOMAIN }}\", | ||
WS_PORT: \"${{ secrets.WS_PORT }}\", | ||
HTTP_PORT: \"${{ secrets.HTTP_PORT }}\", | ||
HTTPS_PORT: \"${{ secrets.HTTPS_PORT }}\", | ||
SSL_DIR: \"${{ secrets.SSL_DIR }}\" | ||
} | ||
}] | ||
};' > ecosystem.config.js && \ | ||
echo '=== Setting up PM2 ===' && \ | ||
export PATH=$PATH:/usr/local/bin:/root/.npm-global/bin && \ | ||
echo 'Stopping any existing processes...' && \ | ||
pm2 kill || true && \ | ||
echo 'Starting application...' && \ | ||
if ! pm2 start ecosystem.config.js; then | ||
echo 'Failed to start PM2 process' && \ | ||
pm2 logs dfanso-tunnel --lines 50 && \ | ||
exit 1 | ||
fi && \ | ||
echo 'Setting up PM2 startup...' && \ | ||
pm2 save && \ | ||
env PATH=$PATH:/usr/local/bin:/root/.npm-global/bin pm2 startup systemd -u root --hp /root && \ | ||
systemctl enable pm2-root && \ | ||
echo 'Checking process status...' && \ | ||
if ! pm2 pid dfanso-tunnel > /dev/null; then | ||
echo 'PM2 process is not running' && \ | ||
pm2 logs dfanso-tunnel --lines 50 && \ | ||
exit 1 | ||
fi && \ | ||
echo '=== Final Status ===' && \ | ||
echo 'PM2 process list:' && \ | ||
pm2 list \ | ||
" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ Internet (HTTPS) -> Tunnel Server (dfanso.dev) -> WebSocket -> Local Server | |
- Node.js 16+ | ||
- Let's Encrypt SSL certificate | ||
- Domain with wildcard DNS (*.dfanso.dev) | ||
- Add a CNAME record for your domain to point to the tunnel server | ||
|
||
### Installation | ||
|
||
|
@@ -58,6 +59,26 @@ sudo apt-get install certbot | |
sudo certbot certonly --manual --preferred-challenges dns -d *.dfanso.dev -d dfanso.dev | ||
``` | ||
|
||
|
||
```bash | ||
# First install the Cloudflare certbot plugin | ||
sudo apt install python3-certbot-dns-cloudflare # for Ubuntu/Debian | ||
|
||
# Create a Cloudflare API token configuration file | ||
sudo mkdir -p /etc/cloudflare | ||
sudo nano /etc/cloudflare/cloudflare.ini | ||
|
||
# Add these lines to cloudflare.ini: | ||
# dns_cloudflare_email = [email protected] | ||
# dns_cloudflare_api_key = your-global-api-key | ||
|
||
# Secure the file | ||
sudo chmod 600 /etc/cloudflare/cloudflare.ini | ||
|
||
# Then run certbot with the Cloudflare plugin | ||
sudo certbot certonly --dns-cloudflare --dns-cloudflare-credentials /etc/cloudflare/cloudflare.ini -d *.dfanso.dev -d dfanso.dev | ||
``` | ||
|
||
3. Follow certbot instructions to add DNS TXT records | ||
|
||
### Running the Server | ||
|
@@ -81,7 +102,7 @@ The recommended way to connect to this tunnel server is using our official npm p | |
|
||
1. Install the package: | ||
```bash | ||
npm install @dfanso/tunnel-client | ||
npm install @dfanso/tunnel-client@1.0.2 | ||
``` | ||
|
||
2. Basic usage: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters