Dodal CI/CD pipeline konfiguracijo in express server za produkcijo

This commit is contained in:
Mark Poljanšek 2025-04-23 20:25:58 +02:00
parent 328731b32f
commit db247f04a4
5 changed files with 118 additions and 1 deletions

View File

@ -0,0 +1,43 @@
name: Build and Deploy
on:
push:
branches:
- master
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm ci
- name: Build project
run: npm run build
- name: Deploy to server
run: |
echo "Deploying to app.spletnimojster.si on port 3169"
# Create deployment package
mkdir -p deploy
cp -r dist/* deploy/
# Setup SSH for deployment
mkdir -p ~/.ssh
echo "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -t rsa 130.61.236.31 >> ~/.ssh/known_hosts
# Deploy to server
rsync -avz --delete deploy/ deployer@130.61.236.31:~/app.spletnimojster.si/
# Restart service if needed
ssh deployer@130.61.236.31 'cd ~/app.spletnimojster.si && pm2 restart rezervacije || pm2 start npm --name "rezervacije" -- start -- --port 3169'

34
.gitignore vendored Normal file
View File

@ -0,0 +1,34 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
# Environment variables
.env
.env.local
.env.development.local
.env.test.local
.env.production.local
# Deploy folder
deploy/

View File

@ -16,14 +16,35 @@ npm run build
# Predogled produkcijske gradnje
npm run preview
# Zagon produkcijskega strežnika
npm start
```
## CI/CD Pipeline
Projekt uporablja Gitea Actions za avtomatsko gradnjo in namestitev na strežnik. Konfiguracija se nahaja v `.gitea/workflows/build-deploy.yml`.
Ob vsakem potisku na vejo `master` se sproži pipeline, ki:
1. Preveri kodo iz repozitorija
2. Nastavi okolje Node.js
3. Namesti odvisnosti
4. Zgradi projekt
5. Namesti aplikacijo na strežnik
## Zahteve za strežnik
- Node.js verzija 18 ali višja
- PM2 za upravljanje procesov
- Dostop SSH za uporabnika "deployer"
## Uporabljene tehnologije
- React 19
- TypeScript
- Vite
- Tailwind CSS
- Express.js za produkcijski strežnik
# React + TypeScript + Vite

View File

@ -7,13 +7,15 @@
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
"preview": "vite preview",
"start": "node server.cjs"
},
"dependencies": {
"@emotion/react": "^11.14.0",
"@emotion/styled": "^11.14.0",
"@mui/icons-material": "^7.0.2",
"@mui/material": "^7.0.2",
"express": "^4.18.2",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-router-dom": "^7.5.1"

17
server.cjs Normal file
View File

@ -0,0 +1,17 @@
const express = require('express');
const path = require('path');
const app = express();
const port = process.env.PORT || 3169;
// Serve static files from the React build
app.use(express.static(path.join(__dirname, '.')));
// Catch all routes and redirect to the index.html
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'));
});
// Start server
app.listen(port, () => {
console.log(`Server running on port ${port}`);
});