编程语言/Drone/ssh:修订间差异
来自康健生活
无编辑摘要 |
|||
| 第1行: | 第1行: | ||
== 引言 == | |||
[https://github.com/appleboy/drone-ssh appleboy/drone-ssh]: Drone plugin for executing remote ssh commands. | |||
== 模板 == | == 模板 == | ||
<syntaxhighlight lang="yaml"> | <syntaxhighlight lang="yaml"> | ||
- name: clear | |||
image: appleboy/drone-ssh | |||
pull: true | |||
settings: | |||
host: 192.168.1.1 | |||
port: 22 | |||
username: root | |||
password: 12345678 | |||
command_timeout: 2m | |||
script: | |||
- source /etc/profile | |||
- ls -la | |||
- docker info | |||
- docker stop `docker ps -a| grep osharp | awk '{print $1}'` | |||
- docker rm $(docker ps -a | grep Exited | awk '{print $1}') | |||
- docker rm $(docker ps -a | grep Created | awk '{print $1}') | |||
#- docker rmi $(docker images | grep "none" | awk '{print $3}') | |||
- echo 项目清理成功 | |||
</syntaxhighlight> | |||
变量 | |||
<syntaxhighlight lang="yaml"> | |||
- name: commands | - name: commands | ||
image: appleboy/drone-ssh | image: appleboy/drone-ssh | ||
| 第22行: | 第42行: | ||
script: | script: | ||
- nginx -s reload | - nginx -s reload | ||
</syntaxhighlight> | |||
== 示例 == | == 示例 == | ||
=== 示例一 === | === 示例一 === | ||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
- name: build | - name: build | ||
image: docker:dind #选择docker:dind镜像 | image: docker:dind #选择docker:dind镜像 | ||
| 第68行: | 第59行: | ||
#- docker push registry.cn-shanghai.aliyuncs.com/shiningrise/osharp:v7.0.1 | #- docker push registry.cn-shanghai.aliyuncs.com/shiningrise/osharp:v7.0.1 | ||
- echo 项目构建成功 | - echo 项目构建成功 | ||
- name: deploy | - name: deploy | ||
image: appleboy/drone-ssh | image: appleboy/drone-ssh | ||
| 第99行: | 第89行: | ||
kind: pipeline | kind: pipeline | ||
type: ssh | type: ssh | ||
name: | name: ssh-runner | ||
server: | server: | ||
host: 192.168.1.1 | |||
user: root | |||
password: | |||
from_secret: password | |||
steps: | steps: | ||
- name: list | |||
commands: | |||
- ls /var | |||
- name: npm | |||
environment: | |||
PATH: "$$PATH:/opt/node-v14.3.0-linux-x64/bin/" | |||
commands: | |||
- pwd | |||
- node --version | |||
- npm version | |||
- npm install | |||
</syntaxhighlight> | </syntaxhighlight> | ||
2026年3月18日 (三) 15:48的版本
引言
appleboy/drone-ssh: Drone plugin for executing remote ssh commands.
模板
- name: clear
image: appleboy/drone-ssh
pull: true
settings:
host: 192.168.1.1
port: 22
username: root
password: 12345678
command_timeout: 2m
script:
- source /etc/profile
- ls -la
- docker info
- docker stop `docker ps -a| grep osharp | awk '{print $1}'`
- docker rm $(docker ps -a | grep Exited | awk '{print $1}')
- docker rm $(docker ps -a | grep Created | awk '{print $1}')
#- docker rmi $(docker images | grep "none" | awk '{print $3}')
- echo 项目清理成功
变量
- name: commands
image: appleboy/drone-ssh
pull: always
settings:
host:
from_secret: DRONE_HOST
username:
from_secret: DRONE_NAME
port:
from_secret: DRONE_PORT
password:
from_secret: DRONE_PSW
command_timeout: 2m
script:
- nginx -s reload
示例
示例一
- name: build
image: docker:dind #选择docker:dind镜像
volumes:
- name: docker-sock
path: /var/run/docker.sock #映射宿主机Docker
commands:
- docker -v
- docker build -t osharp:v7 -f samples/web/Liuliu.Demo.WebApi/Dockerfile .
#- docker login --username=shiningrise@aliyun.com --password=你的仓库密码 registry.cn-shanghai.aliyuncs.com
#- docker tag osharp:v7 registry.cn-shanghai.aliyuncs.com/shiningrise/osharp:v7.0.1
#- docker push registry.cn-shanghai.aliyuncs.com/shiningrise/osharp:v7.0.1
- echo 项目构建成功
- name: deploy
image: appleboy/drone-ssh
pull: true
settings:
host: wxy.kim
port: 22
username: root
password: 服务器密码
command_timeout: 2m
script:
- source /etc/profile
#- docker run -e VIRTUAL_HOST=class.wxy.work -e VIRTUAL_PORT=80 -v /etc/timezone:/etc/timezone -v /etc/localtime:/etc/localtime -d osharp:v7
- cd /data/
- docker-compose up -d
- echo 项目部署成功
volumes:
- name: docker-sock
host:
path: /var/run/docker.sock
trigger:
branch:
- docker
(来源摘自互联网示例,作者 https://www.cnblogs.com/shiningrise/p/17877483.html)
kind: pipeline
type: ssh
name: ssh-runner
server:
host: 192.168.1.1
user: root
password:
from_secret: password
steps:
- name: list
commands:
- ls /var
- name: npm
environment:
PATH: "$$PATH:/opt/node-v14.3.0-linux-x64/bin/"
commands:
- pwd
- node --version
- npm version
- npm install
No categories