-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/pp 8 cicd deployment #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a8029f4
feat: add Dockerfile with nginx multi-stage build
nsvk13 4e60052
feat: add .dockerignore to optimize build context
nsvk13 54d8b28
feat: add `docker-compose.yml` for container orchestration
nsvk13 8620033
feat: add nginx.conf for SPA routing support
nsvk13 2d3f597
ci: GitHub actions workflows (build, lint, deploy)
nsvk13 009fdea
fix: vite.config.ts base path for production builds
nsvk13 98a1d1d
fix: remove unused import causing TypeScript build error
nsvk13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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;"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Объясни это изменение плз. Что у тебя ломалось?
Я, если честно, сам плохо помню зачем я это добавлял - мб ради деплоя на GH Pages
There was a problem hiding this comment.
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 сможет их найти.