add config cicd
Some checks failed
Deploy on Master Change / deploy (push) Failing after 15s

This commit is contained in:
2026-07-01 07:39:55 +07:00
parent 7b3f29ee73
commit 42fc2d9136
4 changed files with 84 additions and 6 deletions

View File

@@ -0,0 +1,64 @@
name: Deploy on Master Change
on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened]
branches:
- master
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code (with full history + correct branch)
uses: actions/checkout@v4
with:
fetch-depth: 0 # Lấy toàn bộ history
ref: master # Đảm bảo checkout đúng branch master
- name: Deploy to server
env:
SSH_IP: ${{ secrets.SSH_IP }}
SSH_PORT: ${{ secrets.SSH_PORT }}
SSH_USER: ${{ secrets.SSH_USER }}
SSH_PASS: ${{ secrets.SSH_PASSWORD }}
run: |
# Cài sshpass
sudo apt-get update -y
sudo apt-get install -y sshpass
echo "Đang deploy lên server..."
sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no -p "$SSH_PORT" "$SSH_USER@$SSH_IP" << 'EOF'
set -e
cd /var/www/simple_care
echo "Force update code từ remote (hỗ trợ cả force push)"
git fetch --all
git reset --hard origin/master
git clean -fd
# Load NVM for node/npm
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
echo "Build management frontend..."
cd management
npm install
VITE_API_BASE=https://sv.rikkeiraia.org/api npm run build
cd ..
echo "Build server backend..."
cd server
go build -o serverlinux main.go
echo "Khởi động lại PM2..."
pm2 delete raia_v3_server || pm2 delete serverlinux || true
pm2 start ./serverlinux --name raia_v3_server
pm2 save # lưu lại trạng thái pm2
echo "Deploy thành công!"
EOF

View File

@@ -1,4 +1,19 @@
const API_BASE = 'http://127.0.0.1:8080/api'; export const API_BASE = import.meta.env.VITE_API_BASE || 'http://127.0.0.1:8080/api';
export function getWsUrl(path: string): string {
try {
if (API_BASE.startsWith('http://') || API_BASE.startsWith('https://')) {
const url = new URL(API_BASE);
const protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
return `${protocol}//${url.host}${path}`;
}
} catch (e) {
// ignore
}
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
return `${protocol}//${window.location.host}${path}`;
}
function getToken(): string | null { function getToken(): string | null {
return localStorage.getItem('sc_staff_token'); return localStorage.getItem('sc_staff_token');

View File

@@ -1,4 +1,5 @@
import React, { useEffect, useState, useRef, useCallback } from 'react'; import React, { useEffect, useState, useRef, useCallback } from 'react';
import { getWsUrl } from '../api';
interface ProctorStreamPanelsProps { interface ProctorStreamPanelsProps {
studentId: number; studentId: number;
@@ -30,8 +31,7 @@ export const ProctorStreamPanels: React.FC<ProctorStreamPanelsProps> = ({
const webcamZoom = ZOOM_STEPS[webcamZoomIdx]; const webcamZoom = ZOOM_STEPS[webcamZoomIdx];
useEffect(() => { useEffect(() => {
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; const wsUrl = getWsUrl('/ws?role=teacher');
const wsUrl = `${protocol}//${window.location.hostname}:8080/ws?role=teacher`;
intentionalClose.current = false; intentionalClose.current = false;
hasOpened.current = false; hasOpened.current = false;

View File

@@ -1,5 +1,5 @@
import { useCallback, useEffect, useRef } from 'react'; import { useCallback, useEffect, useRef } from 'react';
import { type ChatMessage } from '../api'; import { type ChatMessage, getWsUrl } from '../api';
import { useAuth } from '../auth/AuthContext'; import { useAuth } from '../auth/AuthContext';
import { playChatSound } from '../utils/notifySound'; import { playChatSound } from '../utils/notifySound';
@@ -28,8 +28,7 @@ export function StaffChatSocket() {
useEffect(() => { useEffect(() => {
if (!token || !staff?.id) return; if (!token || !staff?.id) return;
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; const wsUrl = getWsUrl(`/ws?role=teacher&staffId=${staff.id}`);
const wsUrl = `${protocol}//${window.location.hostname}:8080/ws?role=teacher&staffId=${staff.id}`;
let ws: WebSocket | null = null; let ws: WebSocket | null = null;
let retryTimer: ReturnType<typeof setTimeout> | null = null; let retryTimer: ReturnType<typeof setTimeout> | null = null;
let closed = false; let closed = false;