Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
node_modules
npm-debug.log
dist
.git
.gitignore
README.md
.env
.nyc_output
coverage
.vscode
.idea
*.log
.DS_Store
Thumbs.db
35 changes: 35 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Build

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Build project
run: npm run build

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build-files-${{ github.sha }}
path: dist/
retention-days: 7
75 changes: 75 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Deploy to Server

on:
push:
branches: [ main ]

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run lint
run: npm run lint

- name: TypeScript check
run: npx tsc --noEmit

- name: Build project
run: npm run build

- name: Deploy to server
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
port: ${{ secrets.SERVER_PORT || 22 }}
script: |
echo "🚀 Starting deployment..."

cd /opt

if [ ! -d "frontend-react" ]; then
echo "📥 Cloning repository..."
git clone https://github.com/PrettyPet-Organization/frontend-react.git
else
echo "🔄 Updating repository..."
cd frontend-react
git fetch origin
git reset --hard origin/main
cd ..
fi

cd frontend-react

echo "⏹️ Stopping old containers..."
docker-compose down || true

echo "🔨 Building and starting containers..."
docker-compose up -d --build

echo "⏳ Waiting for startup..."
sleep 10

if docker-compose ps | grep -q "Up"; then
echo "✅ Deployment successful!"
else
echo "❌ Something went wrong"
docker-compose logs
exit 1
fi

docker-compose ps
32 changes: 32 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Lint

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run ESLint
run: npm run lint
continue-on-error: false

- name: Run TypeScript check
run: npx tsc --noEmit
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:20-alpine3.19 AS builder

WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM nginx:alpine

COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '3.8'

services:
frontend:
build: .
container_name: prettypet-frontend
restart: unless-stopped
ports:
- "80:80"
volumes:
- ./logs:/var/log/nginx
environment:
- NODE_ENV=production
15 changes: 15 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;

location / {
try_files $uri $uri/ /index.html;
}

location /health {
return 200 "OK";
add_header Content-Type text/plain;
}
}
1 change: 0 additions & 1 deletion src/app/AppRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import ProtectedRoute from "../shared/ui/ProtectedRoute.tsx";
import {WelcomePage} from "../pages/Welcome/WelcomePage.tsx";
import {LoginPage} from "../pages/Login/LoginPage.tsx";
import {RegisterPage} from "../pages/Register/RegisterPage.tsx";
import {AuthorizedPage} from "../pages/Authorized/AuthorizedPage.tsx";
import AuthorizedLayout from "../widgets/AuthorizedLayout/AuthorizedLayout.tsx";
import {AuthorizedRoutes} from "./routes/AuthorizedRoutes.ts";

Expand Down
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default defineConfig(({ mode }) => {
react(),
tailwindcss(),
],
base: isProduction ? '/frontend-react/' : '/',
base: isProduction ? '/' : '/',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Объясни это изменение плз. Что у тебя ломалось?
Я, если честно, сам плохо помню зачем я это добавлял - мб ради деплоя на GH Pages

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Проблема была в том, что когда приложение собиралось для Docker, Vite генерировал пути к файлам вида /frontend-react/assets/index.js, но nginx раздавал файлы из корня контейнера (/usr/share/nginx/html).
Получалось что браузер искал файлы по пути /frontend-react/assets/..., а nginx их не мог найти, потому что они лежали просто в /assets/.... Из-за этого был белый экран.
Теперь base: '/' для всех режимов - это означает что все пути будут относительно корня, и nginx сможет их найти.

build: {
outDir: 'dist',
},
Expand Down