Dev #1
53
.github/workflows/main.yaml
vendored
Normal file
53
.github/workflows/main.yaml
vendored
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
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/fire-exam:latest
|
||||||
|
deploy:
|
||||||
|
runs-on: self-hosted
|
||||||
|
needs: build
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Set up Docker Compose
|
||||||
|
run: |
|
||||||
|
docker compose version
|
||||||
|
|
||||||
|
- name: Stop and remove existing containers
|
||||||
|
run: |
|
||||||
|
docker compose -f docker-compose.yaml down || true
|
||||||
|
|
||||||
|
- name: Pull Docker images
|
||||||
|
run: |
|
||||||
|
docker compose -f docker-compose.yaml pull
|
||||||
|
|
||||||
|
- name: Start containers
|
||||||
|
run: |
|
||||||
|
docker compose -f docker-compose.yaml up -d
|
||||||
41
Dockerfile
Normal file
41
Dockerfile
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
# Стадия сборки (builder)
|
||||||
|
FROM node:22-alpine AS builder
|
||||||
|
|
||||||
|
# Устанавливаем рабочую директорию
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Копируем package.json и package-lock.json (или yarn.lock)
|
||||||
|
COPY package*.json ./
|
||||||
|
|
||||||
|
# Устанавливаем зависимости
|
||||||
|
RUN npm install --frozen-lockfile
|
||||||
|
|
||||||
|
# Копируем все файлы проекта
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Собираем приложение
|
||||||
|
RUN npm build
|
||||||
|
|
||||||
|
# Стадия запуска (runner)
|
||||||
|
FROM node:22-alpine AS runner
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Включаем node пользователя
|
||||||
|
RUN addgroup -g 1001 -S nodejs
|
||||||
|
RUN adduser -S nextjs -u 1001
|
||||||
|
|
||||||
|
# Копируем необходимые файлы из стадии builder
|
||||||
|
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
|
||||||
|
COPY --from=builder --chown=nextjs:nodejs /app/node_modules ./node_modules
|
||||||
|
COPY --from=builder --chown=nextjs:nodejs /app/package.json ./package.json
|
||||||
|
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
|
||||||
|
COPY --from=builder --chown=nextjs:nodejs /app/next.config.js ./next.config.js
|
||||||
|
|
||||||
|
# Переключаем на пользователя nextjs
|
||||||
|
USER nextjs
|
||||||
|
|
||||||
|
# Открываем порт
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
# Запускаем приложение
|
||||||
|
CMD ["npm", "start"]
|
||||||
10
docker-compose.yaml
Normal file
10
docker-compose.yaml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
fire-exam:
|
||||||
|
image: smallbuster/fire-exam:latest
|
||||||
|
container_name: fire-exam
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "5002:3000"
|
||||||
|
|
||||||
Reference in New Issue
Block a user