You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.2 KiB

1 month ago
kind: pipeline
1 month ago
type: docker
1 month ago
name: default
1 month ago
1 month ago
# --------------------------
# 共享配置(避免重复定义)
# --------------------------
volumes:
- name: docker-sock # 挂载 Docker 守护进程
host:
path: /var/run/docker.sock
- name: go-mod-cache # Go 模块缓存(加速构建)
temp: {}
- name: go-build-cache # Go 编译缓存(加速构建)
temp: {}
1 month ago
steps:
1 month ago
# # --------------------------
# # [Test 阶段]
# # --------------------------
# - name: test
# image: golang:1.21 # 明确版本号(避免隐式更新)
# image_pull: if-not-present # 优先使用本地镜像
# environment:
# GO111MODULE: on
# commands:
# - echo "Running tests..."
# - go test -v ./... # 实际添加测试命令
# --------------------------
# [Build 阶段]
# --------------------------
- name: build
image: golang:1.21-alpine # 使用官方镜像(而非哈希 ID
image_pull: if-not-present
environment:
GO111MODULE: on
CGO_ENABLED: 0 # 禁用 CGO纯静态二进制
volumes:
- name: go-mod-cache
path: /go/pkg/mod
- name: go-build-cache
path: /root/.cache/go-build
commands:
- echo "Building binary..."
- go build -o myapp -ldflags "-X main.RunMode=test -s -w" # 压缩符号表
- ls -lh myapp
# --------------------------
# [Deploy 阶段]
# --------------------------
- name: deploy
image: docker:24.0-cli # 明确 Docker 版本 + 包含 CLI
image_pull: if-not-present
volumes:
- name: docker-sock
path: /var/run/docker.sock
- name: go-build-cache # 复用之前的缓存卷(如有需要)
path: /app
environment:
DOCKER_HOST: unix:///var/run/docker.sock # 显式指定 Docker 连接
1 month ago
commands:
1 month ago
- echo "Starting deployment..."
- docker rm -f product_uploader || true
- docker build -t prduploader:test-${DRONE_COMMIT_SHA:0:8} .
- docker run -d \
--name product_uploader \
-p 11000:11000 \
--restart on-failure \
--memory 512m \
prduploader:test-${DRONE_COMMIT_SHA:0:8}