diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..15f6538 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +.git +.gitlab +node_modules +.next/cache +Dockerfile +docker-compose.yml +*.log \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2caf235..737a3fb 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,31 +1,22 @@ stages: - - build - - test - - deploy + - build + - deploy -build-job: - stage: build - script: - - echo "Compiling the code..." - - echo "Compile complete." +workflow: + rules: + - if: '$CI_COMMIT_BRANCH == "main"' -unit-test-job: - stage: test - script: - - echo "Running unit tests... This will take about 60 seconds." - - sleep 60 - - echo "Code coverage is 90%" +build: + stage: build + script: + - echo "Building Docker image..." + - docker build -t travelmarine-frontend:latest . -lint-test-job: - stage: test - script: - - echo "Linting code... This will take about 10 seconds." - - sleep 10 - - echo "No lint issues found." - -deploy-job: - stage: deploy - environment: production - script: - - echo "Deploying application..." - - echo "Application successfully deployed." +deploy: + stage: deploy + needs: ["build"] + script: + - echo "Restarting container..." + - docker ps -a --filter 'name=^/travelmarine-frontend$' --format '{{.Names}}' | grep -q '^travelmarine-frontend$' && docker rm -f travelmarine-frontend || true + - docker run -d --name travelmarine-frontend --restart unless-stopped -p 127.0.0.1:3000:3000 travelmarine-frontend:latest + when: on_success diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b66efdb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM node:22-alpine AS builder +WORKDIR /app +RUN apk add --no-cache libc6-compat + +COPY package-lock.json ./ +COPY package.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-lock.json ./ +COPY --from=builder /app/package.json ./ +EXPOSE 3000 + +CMD ["npm", "run", "start"] \ No newline at end of file