diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a7e49e0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +node_modules +build +.DS_Store +.env diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 0000000..d46fbd8 --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,48 @@ +name: Build and deploy + +on: + push: + branches: + - 'main' + + +jobs: + build: + runs-on: self-hosted + steps: + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build and push + uses: docker/build-push-action@v5 + with: + push: true + tags: smallbuster/fe-docs:latest + deploy: + runs-on: self-hosted + needs: build + steps: + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Pull Docker image from Docker Hub + run: | + docker pull smallbuster/fe-docs:latest + + - name: Stop and remove existing container + run: | + docker stop fe-docs || true && docker rm fe-docs || true + + - name: Run Docker container + run: | + docker run -d --restart unless-stopped \ + --name fe-docs smallbuster/fe-docs:latest diff --git a/.gitignore b/.gitignore index 234573a..51a0dde 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ # Misc .DS_Store +.env .env.local .env.development.local .env.test.local diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5e80a15 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +# Используем официальный образ Node.js +FROM node:22-alpine AS builder + +# Устанавливаем рабочий каталог +WORKDIR /app + +# Копируем файлы зависимостей +COPY package.json package-lock.json* ./ + +# Устанавливаем зависимости +RUN npm install + +# Копируем все файлы проекта +COPY . . + +# Собираем проект +RUN npm ci +RUN npm run build + +# Используем nginx для обслуживания статических файлов +FROM nginx:alpine + +# Копируем собранные файлы из builder в nginx +COPY --from=builder /app/build /usr/share/nginx/html + +# Копируем конфигурацию nginx (если нужно) +COPY nginx.conf /etc/nginx/conf.d/default.conf + +# Открываем порт 80 +EXPOSE 80 + +# Запускаем nginx +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..6cfcfdc --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,8 @@ +version: '3.8' + +services: + web: + build: . + ports: + - "5001:80" + restart: always \ No newline at end of file diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..3473f7e --- /dev/null +++ b/nginx.conf @@ -0,0 +1,15 @@ +server { + listen 80; + server_name localhost; + + location / { + root /usr/share/nginx/html; + index index.html; + try_files $uri $uri/ /index.html; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +} \ No newline at end of file