From d76a64a0d7f58c118acf093d93b6a8da003382f3 Mon Sep 17 00:00:00 2001 From: kkfluous Date: Wed, 29 Apr 2026 18:27:21 +0800 Subject: [PATCH] ci: add woodpecker pipeline, Dockerfile and deploy configs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mirrors the oneos- project layout: multi-stage node:22 → nginx:alpine build, Woodpecker pipeline that tags images as - and pushes to harbor.lnh2e.com/lingniu-v1/bi, and a swarm-style docker-compose for deployment. Co-Authored-By: Claude Opus 4.7 (1M context) --- Dockerfile | 15 +++++++++++ docker-compose.yml | 16 ++++++++++++ nginx.conf | 17 +++++++++++++ woodpecker.yml | 62 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 110 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 nginx.conf create mode 100644 woodpecker.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5d5abbd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM node:22-alpine AS builder + +WORKDIR /app +COPY package.json package-lock.json ./ +RUN npm ci +COPY . . +RUN npm run build + +FROM nginx:alpine + +COPY --from=builder /app/dist /usr/share/nginx/html +COPY nginx.conf /etc/nginx/conf.d/default.conf + +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d2cf2c4 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,16 @@ +version: '3.8' + +services: + bi: + image: harbor.lnh2e.com/lingniu-v1/bi:main-0.0.0 + ports: + - "8114:80" + deploy: + replicas: 1 + restart_policy: + condition: on-failure + placement: + constraints: [node.role == manager] + labels: + - portainer.hide=false + - project=lingniu diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..7a71826 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,17 @@ +server { + listen 80; + server_name _; + root /usr/share/nginx/html; + index index.html; + + location /bi/ { + alias /usr/share/nginx/html/; + try_files $uri $uri/ /bi/index.html; + } + + location /bi/assets/ { + alias /usr/share/nginx/html/assets/; + expires 1y; + add_header Cache-Control "public, immutable"; + } +} diff --git a/woodpecker.yml b/woodpecker.yml new file mode 100644 index 0000000..d9eceef --- /dev/null +++ b/woodpecker.yml @@ -0,0 +1,62 @@ +steps: + - name: npm-build + image: node:22-alpine + when: + event: + - push + - pull_request + - manual + branch: + - master + - develop + - main + commands: | + cd $CI_WORKSPACE + npm ci + npm run build + + # 获取分支名 + BRANCH_NAME=$(echo $CI_COMMIT_BRANCH | tr / -) + echo "Branch name: $BRANCH_NAME" + + # 版本号: 分支名-package.json版本 + PKG_VERSION=$(node -e "console.log(require('./package.json').version)") + PROJECT_VERSION="$BRANCH_NAME-$PKG_VERSION" + echo "Docker tag: $PROJECT_VERSION" + echo $PROJECT_VERSION > $CI_WORKSPACE/project_version.txt + + - name: docker-build + image: docker:24.0.5-cli + when: + event: + - push + - pull_request + - manual + branch: + - master + - develop + - main + volumes: + - /var/run/docker.sock:/var/run/docker.sock + commands: | + PROJECT_VERSION=$(cat $CI_WORKSPACE/project_version.txt) + MODULE_NAME=bi + + echo "Building Docker image: $MODULE_NAME:$PROJECT_VERSION" + + cd $CI_WORKSPACE + + docker build -t harbor.lnh2e.com/lingniu-v1/$MODULE_NAME:$PROJECT_VERSION . + + mkdir -p /root/.docker + cat > /root/.docker/config.json <