add CI/CD

This commit is contained in:
Иван 2025-10-22 22:11:27 +03:00
parent 0bf248ac64
commit 5d21b4b32b
3 changed files with 49 additions and 27 deletions

7
.dockerignore Normal file
View File

@ -0,0 +1,7 @@
.git
.gitlab
node_modules
.next/cache
Dockerfile
docker-compose.yml
*.log

View File

@ -1,31 +1,24 @@
stages: stages:
- build - build
- test - deploy
- deploy
build-job: workflow:
stage: build rules:
script: - if: '$CI_COMMIT_BRANCH == "main"'
- echo "Compiling the code..."
- echo "Compile complete."
unit-test-job: build:
stage: test stage: build
script: script:
- echo "Running unit tests... This will take about 60 seconds." - echo "Building Docker image..."
- sleep 60 - docker build -t travelmarine-frontend:latest .
- echo "Code coverage is 90%"
lint-test-job: deploy:
stage: test stage: deploy
script: needs: ["build"]
- echo "Linting code... This will take about 10 seconds." script:
- sleep 10 - echo "Restarting container..."
- echo "No lint issues found." - docker rm -f travelmarine-frontend || true
- docker run -d --name travelmarine-frontend --restart unless-stopped \
deploy-job: -p 127.0.0.1:3000:3000 \
stage: deploy travelmarine-frontend:latest
environment: production when: on_success
script:
- echo "Deploying application..."
- echo "Application successfully deployed."

22
Dockerfile Normal file
View File

@ -0,0 +1,22 @@
FROM node:22-alpine AS builder
WORKDIR /app
RUN apk add --no-cache libc6-compat
COPY package-lock.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM node:22-alpine AS runner
WORKDIR /app
RUN apk add --no-cache libc6-compat
ENV NODE_ENV=production
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package*.json ./
EXPOSE 3000
CMD ["npm", "run", "start"]