From e399f0070e8e1521f533d8b1dbabe0bcf8b8f888 Mon Sep 17 00:00:00 2001 From: Chever John Date: Wed, 17 Jun 2026 10:01:55 +0800 Subject: [PATCH] feat: add Dockerfile and GitLab CI pipeline for Harbor Multi-stage Docker build: node:20-alpine + nginx:1.27-alpine. CI builds and pushes to harbor-in-k3s.cheverjohn.me/iloom/iloom-frontend. Co-Authored-By: Claude --- .gitlab-ci.yml | 27 +++++++++++++++++++++++++++ Dockerfile | 11 +++++++++++ 2 files changed, 38 insertions(+) create mode 100644 .gitlab-ci.yml create mode 100644 Dockerfile diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..988da58 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,27 @@ +stages: + - build + +variables: + HARBOR_REGISTRY: harbor-in-k3s.cheverjohn.me + HARBOR_PROJECT: iloom + DOCKER_TLS_CERTDIR: "/certs" + +build-frontend: + stage: build + image: docker:27 + services: + - docker:27-dind + before_script: + - echo "$HARBOR_PASSWORD" | docker login $HARBOR_REGISTRY -u "$HARBOR_USER" --password-stdin + script: + - | + if [ -n "$CI_COMMIT_TAG" ]; then + TAG="$CI_COMMIT_TAG" + else + TAG="main-${CI_COMMIT_SHORT_SHA}" + fi + - docker build -t $HARBOR_REGISTRY/$HARBOR_PROJECT/iloom-frontend:$TAG . + - docker push $HARBOR_REGISTRY/$HARBOR_PROJECT/iloom-frontend:$TAG + rules: + - if: $CI_COMMIT_BRANCH == "main" + - if: $CI_COMMIT_TAG =~ /^v/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6ce9bb7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM node:20-alpine AS builder +WORKDIR /app +COPY package.json package-lock.json ./ +RUN npm ci +COPY . . +RUN npm run build + +FROM nginx:1.27-alpine +COPY --from=builder /app/dist /usr/share/nginx/html +EXPOSE 3015 +CMD ["nginx", "-g", "daemon off;"]