2222
This commit is contained in:
72
.drone.yml
Normal file
72
.drone.yml
Normal file
@@ -0,0 +1,72 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: nodejs-host-network-pipeline
|
||||
|
||||
steps:
|
||||
# 第一步:准备环境并安装依赖
|
||||
- name: install-dependencies
|
||||
image: node:18-bullseye
|
||||
commands:
|
||||
# 安装iproute2工具
|
||||
- apt-get update && apt-get install -y iproute2
|
||||
# 验证ip命令是否可用
|
||||
- ip -V
|
||||
# 安装项目依赖
|
||||
- npm install
|
||||
volumes:
|
||||
- name: node_modules
|
||||
path: /app/node_modules
|
||||
|
||||
# 第二步:运行代码检查或测试(可选)
|
||||
- name: run-tests
|
||||
image: node:18-bullseye
|
||||
commands:
|
||||
- npm test # 如果有测试脚本
|
||||
volumes:
|
||||
- name: node_modules
|
||||
path: /app/node_modules
|
||||
|
||||
# 第三步:构建Docker镜像
|
||||
- name: build-image
|
||||
image: docker:20.10
|
||||
volumes:
|
||||
- name: docker-socket
|
||||
path: /var/run/docker.sock
|
||||
- name: node_modules
|
||||
path: /app/node_modules
|
||||
commands:
|
||||
- docker build -t node-app:${DRONE_COMMIT_SHA:0:8} -f Dockerfile .
|
||||
|
||||
# 第四步:使用host网络运行应用
|
||||
- name: run-with-host-network
|
||||
image: docker:20.10
|
||||
volumes:
|
||||
- name: docker-socket
|
||||
path: /var/run/docker.sock
|
||||
commands:
|
||||
- |
|
||||
docker run -d \
|
||||
--restart always \
|
||||
--network host \
|
||||
--name node-app-${DRONE_COMMIT_SHA:0:8} \
|
||||
node-app:${DRONE_COMMIT_SHA:0:8}
|
||||
when:
|
||||
branch:
|
||||
- main
|
||||
|
||||
# 定义卷用于共享依赖和Docker socket
|
||||
volumes:
|
||||
- name: node_modules
|
||||
temp: {}
|
||||
- name: docker-socket
|
||||
host:
|
||||
path: /var/run/docker.sock
|
||||
|
||||
# 构建触发条件
|
||||
trigger:
|
||||
branch:
|
||||
- main
|
||||
- develop
|
||||
event:
|
||||
- push
|
||||
- pull_request
|
||||
Reference in New Issue
Block a user