Compare commits
2 Commits
06ef615e59
...
d0d49a96a0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d0d49a96a0 | ||
|
|
55d31a9ca3 |
42
.github/workflows/deploy.yml
vendored
42
.github/workflows/deploy.yml
vendored
@@ -1,42 +0,0 @@
|
||||
name: Deploy RIT Freshers Hub to VPS
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
name: Deploy to Live VPS
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: SSH into VPS and Deploy
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.VPS_HOST }}
|
||||
username: ${{ secrets.VPS_USERNAME }}
|
||||
key: ${{ secrets.VPS_SSH_KEY }}
|
||||
port: 22
|
||||
script: |
|
||||
echo "🚀 Starting Automated CI/CD Deployment..."
|
||||
cd /var/www/freshers-hub
|
||||
|
||||
echo "📥 Pulling latest code from GitHub..."
|
||||
git pull origin main
|
||||
|
||||
echo "⚡ Building Frontend PWA..."
|
||||
npm install --production=false
|
||||
npm run build
|
||||
|
||||
echo "🤖 Building Go Chatbot..."
|
||||
cd /var/www/freshers-hub/chatbot-service
|
||||
go build -o chatbot-service main.go
|
||||
|
||||
echo "🔄 Restarting Systemd Services..."
|
||||
systemctl restart springboot chatbot telegram-bot nginx
|
||||
|
||||
echo "🎉 Deployment Completed Successfully!"
|
||||
25
scripts/post-receive.sh
Normal file
25
scripts/post-receive.sh
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Configuration (or set in environment variables on VPS)
|
||||
export SENDER_EMAIL="your-gmail-id@gmail.com"
|
||||
export SENDER_PASSWORD="your-16-digit-app-password"
|
||||
export RECIPIENT_EMAIL="your-recipient-email@gmail.com"
|
||||
|
||||
while read oldrev newrev refname
|
||||
do
|
||||
BRANCH=$(echo $refname | cut -d/ -f3)
|
||||
COMMIT_HASH=$(git log -1 --format="%h" $newrev)
|
||||
AUTHOR=$(git log -1 --format="%an <%ae>" $newrev)
|
||||
MESSAGE=$(git log -1 --format="%B" $newrev)
|
||||
TIMESTAMP=$(git log -1 --format="%cd" --date=local $newrev)
|
||||
CHANGED_FILES=$(git diff-tree --no-commit-id --name-status -r $newrev | head -n 15)
|
||||
|
||||
python3 /var/www/freshers-hub/scripts/send_git_email.py \
|
||||
"$BRANCH" \
|
||||
"$AUTHOR" \
|
||||
"$COMMIT_HASH" \
|
||||
"$TIMESTAMP" \
|
||||
"$MESSAGE" \
|
||||
"$CHANGED_FILES"
|
||||
|
||||
done
|
||||
83
scripts/send_git_email.py
Normal file
83
scripts/send_git_email.py
Normal file
@@ -0,0 +1,83 @@
|
||||
import sys
|
||||
import smtplib
|
||||
import os
|
||||
from email.mime.text import MIMEText
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
|
||||
# Load configuration from environment or fallback defaults
|
||||
SMTP_SERVER = os.environ.get("SMTP_SERVER", "smtp.gmail.com")
|
||||
SMTP_PORT = int(os.environ.get("SMTP_PORT", 587))
|
||||
SENDER_EMAIL = os.environ.get("SENDER_EMAIL", "YOUR_EMAIL@gmail.com")
|
||||
SENDER_PASSWORD = os.environ.get("SENDER_PASSWORD", "YOUR_GMAIL_APP_PASSWORD")
|
||||
RECIPIENT_EMAIL = os.environ.get("RECIPIENT_EMAIL", "YOUR_EMAIL@gmail.com")
|
||||
|
||||
if len(sys.argv) < 7:
|
||||
print("Usage: python send_git_email.py <branch> <author> <commit_hash> <timestamp> <message> <changed_files>")
|
||||
sys.exit(1)
|
||||
|
||||
branch = sys.argv[1]
|
||||
author = sys.argv[2]
|
||||
commit_hash = sys.argv[3]
|
||||
timestamp = sys.argv[4]
|
||||
message = sys.argv[5]
|
||||
changed_files = sys.argv[6]
|
||||
|
||||
subject = f"[Freshers-Hub VPS] Code Push Report - Commit {commit_hash} ({branch})"
|
||||
|
||||
html_content = f"""
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<style>
|
||||
body {{ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: #f4f6f8; color: #333; padding: 20px; }}
|
||||
.card {{ background: #ffffff; border-radius: 10px; padding: 28px; max-width: 650px; margin: auto; box-shadow: 0 4px 12px rgba(0,0,0,0.08); border: 1px solid #e2e8f0; }}
|
||||
.header {{ color: #2563eb; font-size: 22px; font-weight: 700; border-bottom: 2px solid #3b82f6; padding-bottom: 12px; margin-bottom: 20px; }}
|
||||
.field {{ margin-bottom: 12px; font-size: 14px; }}
|
||||
.label {{ font-weight: 600; color: #475569; display: inline-block; width: 120px; }}
|
||||
.value {{ color: #0f172a; font-weight: 500; }}
|
||||
.badge {{ background-color: #e0e7ff; color: #3730a3; padding: 3px 8px; border-radius: 4px; font-family: monospace; font-size: 13px; }}
|
||||
.message-box {{ background: #f8fafc; border-left: 4px solid #3b82f6; padding: 12px; border-radius: 4px; font-style: italic; margin-top: 6px; font-size: 14px; color: #334155; }}
|
||||
.code-box {{ background: #0f172a; color: #38bdf8; padding: 14px; border-radius: 6px; font-family: Consolas, Monaco, monospace; white-space: pre-wrap; word-break: break-all; margin-top: 6px; font-size: 13px; line-height: 1.5; }}
|
||||
.footer {{ font-size: 12px; color: #94a3b8; margin-top: 28px; text-align: center; border-top: 1px solid #f1f5f9; padding-top: 14px; }}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="card">
|
||||
<div class="header">🚀 Freshers-Hub Deployment & Push Report</div>
|
||||
|
||||
<div class="field"><span class="label">Branch:</span> <span class="badge">{branch}</span></div>
|
||||
<div class="field"><span class="label">Author:</span> <span class="value">{author}</span></div>
|
||||
<div class="field"><span class="label">Commit Hash:</span> <span class="badge">{commit_hash}</span></div>
|
||||
<div class="field"><span class="label">Time:</span> <span class="value">{timestamp}</span></div>
|
||||
|
||||
<div class="field" style="margin-top: 18px;">
|
||||
<span class="label" style="width: 100%;">Commit Message:</span>
|
||||
<div class="message-box">{message}</div>
|
||||
</div>
|
||||
|
||||
<div class="field" style="margin-top: 18px;">
|
||||
<span class="label" style="width: 100%;">Changed Files (Top Modified):</span>
|
||||
<div class="code-box">{changed_files}</div>
|
||||
</div>
|
||||
|
||||
<div class="footer">Automated push report generated by RIT Freshers-Hub VPS Git Hook</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
msg = MIMEMultipart("alternative")
|
||||
msg["Subject"] = subject
|
||||
msg["From"] = SENDER_EMAIL
|
||||
msg["To"] = RECIPIENT_EMAIL
|
||||
msg.attach(MIMEText(html_content, "html"))
|
||||
|
||||
try:
|
||||
with smtplib.SMTP(SMTP_SERVER, SMTP_PORT) as server:
|
||||
server.starttls()
|
||||
server.login(SENDER_EMAIL, SENDER_PASSWORD)
|
||||
server.sendmail(SENDER_EMAIL, RECIPIENT_EMAIL, msg.as_string())
|
||||
print("✅ Email report sent successfully.")
|
||||
except Exception as e:
|
||||
print(f"❌ Failed to send email report: {e}")
|
||||
Reference in New Issue
Block a user