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.

65 lines
1.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

kind: pipeline
type: docker
name: default
# --------------------------
# 共享配置(避免重复定义)
# --------------------------
volumes:
- name: docker-sock
host:
path: /var/run/docker.sock
- name: go-mod-cache
temp: {}
- name: go-build-cache # Go 编译缓存(加速构建)
temp: {}
clone:
disable: true
steps:
- name: clone
image: alpine/git:latest
pull: never
commands:
- git pull http://47.112.165.44:3000/seekm/prdUploader.git
- name: build
image: golang:1.21-alpine
pull: never
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
pull: never
volumes:
- name: docker-sock
path: /var/run/docker.sock
- name: go-build-cache # 复用之前的缓存卷(如有需要)
path: /app
environment:
DOCKER_HOST: unix:///var/run/docker.sock # 显式指定 Docker 连接
commands:
- 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}