Kubernetes/CICD/Drone/YML/.drone-dind.yml

61 lines
1.5 KiB
YAML
Raw Normal View History

2024-08-07 10:54:39 +00:00
kind: pipeline
type: docker
name: Build Dockerfile
# platform:
# os: linux
# arch: amd64
# 手动触发或接口触发
trigger:
event:
- custom
steps:
- name: Dockerfile
image: docker:dind
# 挂载Docker守护进程
volumes:
- name: dockersock
path: /var/run/docker.sock
# 环境变量
environment:
DOCKER_USERNAME:
from_secret: DOCKER_USERNAME
DOCKER_PASSWORD:
from_secret: DOCKER_PASSWORD
NAMESPACE:
from_secret: NAMESPACE
# 镜像名
IMAGENAME: demo
# 镜像标签
IMAGETAG: latest
# 镜像仓库私有地址
REGISTRY:
from_secret: REGISTRY
# 执行命令
commands:
# 推送镜像至阿里云
# - docker build -t registry.cn-hangzhou.aliyuncs.com/$NAMESPACE/$IMAGENAME:$IMAGETAG .
# - docker login registry.cn-hangzhou.aliyuncs.com -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
# - docker push registry.cn-hangzhou.aliyuncs.com/$NAMESPACE/$IMAGENAME:$IMAGETAG
# 推送镜像至DockerHub
# - docker build -t $DOCKER_USERNAME/$IMAGENAME:$IMAGETAG .
# - docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
# - docker push $DOCKER_USERNAME/$IMAGENAME:$IMAGETAG
# 推送镜像至私有仓库
- docker build -t $REGISTRY/$NAMESPACE/$IMAGENAME:$IMAGETAG .
- docker login $REGISTRY -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
- docker push $REGISTRY/$NAMESPACE/$IMAGENAME:$IMAGETAG
# 挂载Docker守护进程
volumes:
- name: dockersock
host:
path: /var/run/docker.sock