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.

68 lines
1.6 KiB

1 month ago
kind: pipeline
1 month ago
type: docker
1 month ago
name: default
1 month ago
1 month ago
# --------------------------
# 共享配置(避免重复定义)
# --------------------------
volumes:
1 month ago
- name: docker-sock
1 month ago
host:
path: /var/run/docker.sock
1 month ago
- name: go-mod-cache
1 month ago
temp: {}
- name: go-build-cache # Go 编译缓存(加速构建)
temp: {}
1 month ago
clone:
disable: true
1 month ago
steps:
- name: clone
1 month ago
image: alpine/git:latest
1 month ago
pull: never
1 month ago
volumes:
- name: build
path: /go
1 month ago
commands:
1 month ago
- pwd
1 month ago
- git clone http://47.112.165.44:3000/seekm/prdUploader.git
1 month ago
1 month ago
- name: build
1 month ago
image: golang:1.21-alpine
1 month ago
pull: never
1 month ago
environment:
GO111MODULE: on
1 month ago
CGO_ENABLED: 0
1 month ago
volumes:
1 month ago
- name: build
path: /go
1 month ago
commands:
- echo "Building binary..."
1 month ago
- pwd
1 month ago
- go build -o myapp -ldflags "-X main.RunMode=test -s -w" # 压缩符号表
- ls -lh myapp
# --------------------------
# [Deploy 阶段]
# --------------------------
- name: deploy
1 month ago
image: docker:24.0-cli
1 month ago
pull: never
1 month ago
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}