From a8b04281cc71d4ec879500dfcc1ec6effbbd5bb4 Mon Sep 17 00:00:00 2001 From: kkfluous Date: Mon, 30 Mar 2026 20:00:31 +0800 Subject: [PATCH] feat: Add CI/CD and deployment configuration Add Woodpecker CI pipeline, Dockerfile, nginx config, and docker-compose for automated build and deployment. Co-Authored-By: Claude Opus 4.6 (1M context) --- Dockerfile | 15 +++++++++++ docker-compose.yml | 17 +++++++++++++ nginx.conf | 15 +++++++++++ woodpecker.yml | 62 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 109 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..d8fcff1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +version: '3.8' + +services: + oneos: + image: harbor.lnh2e.com/lingniu-v1/oneos:main-0.0.0 + network_mode: host + environment: + NGINX_PORT: "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..f914abb --- /dev/null +++ b/nginx.conf @@ -0,0 +1,15 @@ +server { + listen 80; + server_name _; + root /usr/share/nginx/html; + index index.html; + + location / { + try_files $uri $uri/ /index.html; + } + + location /assets { + expires 1y; + add_header Cache-Control "public, immutable"; + } +} diff --git a/woodpecker.yml b/woodpecker.yml new file mode 100644 index 0000000..6eeff8b --- /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=oneos + + 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 <