Skip to content

Commit 088c20a

Browse files
committed
feat: happy new year <3
0 parents  commit 088c20a

19 files changed

+1468
-0
lines changed

.github/workflows/nduloweb.yml

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
name: nduloWeb CI/CD
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
paths:
7+
- "**"
8+
- ".github/workflows/nduloweb.yml"
9+
pull_request:
10+
branches: ["main"]
11+
12+
jobs:
13+
test:
14+
name: Test & Lint Rust
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Setup Rust
22+
uses: dtolnay/rust-toolchain@stable
23+
with:
24+
components: rustfmt, clippy
25+
26+
- name: Cache Rust dependencies
27+
uses: actions/cache@v3
28+
with:
29+
path: |
30+
~/.cargo/bin/
31+
~/.cargo/registry/index/
32+
~/.cargo/registry/cache/
33+
~/.cargo/git/db/
34+
target/
35+
key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}
36+
restore-keys: |
37+
${{ runner.os }}-cargo-
38+
39+
- name: Build release
40+
run: cargo build --release
41+
42+
deploy:
43+
name: Deploy to VPS
44+
runs-on: ubuntu-latest
45+
needs: test
46+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
47+
48+
steps:
49+
- name: Setup SSH
50+
run: |
51+
mkdir -p ~/.ssh
52+
chmod 700 ~/.ssh
53+
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/deploy_key
54+
chmod 600 ~/.ssh/deploy_key
55+
ssh-keyscan -p ${{ secrets.SSH_PORT || '22' }} ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
56+
57+
- name: Deploy nduloWeb on VPS
58+
run: |
59+
ssh -i ~/.ssh/deploy_key \
60+
-p ${{ secrets.SSH_PORT || '22' }} \
61+
${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} bash << 'ENDSSH'
62+
set -e
63+
64+
REPO_PATH="/home/edgar/work/nduloweb"
65+
LOGS_PATH="$REPO_PATH/logs"
66+
PM2_APP_NAME="nduloweb"
67+
68+
if [ ! -d "$REPO_PATH" ]; then
69+
echo "Repository not found, cloning..."
70+
cd /home/edgar/work
71+
git clone https://github.com/ndulomk/nduloWeb.Vol2-made-by-ndulo.git nduloweb
72+
fi
73+
74+
cd "$REPO_PATH"
75+
76+
echo "Fetching latest changes..."
77+
git fetch origin
78+
git reset --hard origin/main
79+
80+
echo "Building nduloweb in release mode..."
81+
export PATH=$HOME/.cargo/bin:$PATH
82+
cargo build --release
83+
84+
echo "Build completed!"
85+
86+
echo "Restarting application with PM2..."
87+
pm2 delete $PM2_APP_NAME --silent || true
88+
89+
mkdir -p "$LOGS_PATH"
90+
91+
pm2 start "$REPO_PATH/target/release/portfolio-seo-server" \
92+
--name $PM2_APP_NAME \
93+
--time \
94+
--log-date-format "YYYY-MM-DD HH:mm:ss Z" \
95+
-o "$LOGS_PATH/nduloweb-out.log" \
96+
-e "$LOGS_PATH/nduloweb-error.log" \
97+
--silent
98+
99+
pm2 save --silent
100+
101+
echo "nduloweb deployed successfully!"
102+
ENDSSH
103+
104+
- name: Health check
105+
run: |
106+
ssh -i ~/.ssh/deploy_key \
107+
-p ${{ secrets.SSH_PORT || '22' }} \
108+
${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} bash << 'ENDSSH'
109+
set -e
110+
111+
echo "Waiting for application to start..."
112+
sleep 10
113+
114+
HEALTH_URL="http://localhost:3010"
115+
echo "Health check at $HEALTH_URL..."
116+
117+
for i in {1..5}; do
118+
if curl -f -s "$HEALTH_URL" > /dev/null; then
119+
echo "Health check passed!"
120+
curl -s "$HEALTH_URL"
121+
exit 0
122+
fi
123+
echo "Attempt $i/5 failed, waiting..."
124+
sleep 5
125+
done
126+
127+
echo "Health check failed after 5 attempts"
128+
exit 1
129+
ENDSSH
130+
131+
- name: Notify deployment
132+
if: always()
133+
run: |
134+
if [ "${{ job.status }}" == "success" ]; then
135+
echo "nduloweb deployed successfully to https://ndulo.store"
136+
else
137+
echo "nduloweb deployment failed!"
138+
fi

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

0 commit comments

Comments
 (0)