mirror of
https://github.com/appleboy/drone-ssh.git
synced 2026-06-16 14:49:25 +08:00
Compare commits
34 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4d46a02d53 | |||
| 7994d5555e | |||
| c7d8b0f2e9 | |||
| 7755fdb39f | |||
| 83417639b9 | |||
| 7344ac6529 | |||
| 1288a4b20d | |||
| 11ec0bec7e | |||
| a2c6be3c19 | |||
| 923defc397 | |||
| ec9d02ec38 | |||
| 9c9e7914ce | |||
| 9e205a756f | |||
| 99f63aaaa8 | |||
| 6bdace5138 | |||
| 54cdb693e4 | |||
| 81d0430ffd | |||
| a046be092b | |||
| 6b488f1203 | |||
| 8d0b62974a | |||
| 9b57f85e47 | |||
| 648e3c1321 | |||
| 9ef0a47bc0 | |||
| 530cb1df6e | |||
| 414ebba911 | |||
| ff6e63366c | |||
| 553894abe6 | |||
| 79584d6cfa | |||
| cacb93d984 | |||
| 160519dca6 | |||
| b8149fe18c | |||
| 5e47c61788 | |||
| bd8532afdc | |||
| 44cc1f409f |
+29
-52
@@ -9,47 +9,39 @@ platform:
|
|||||||
steps:
|
steps:
|
||||||
- name: vet
|
- name: vet
|
||||||
pull: always
|
pull: always
|
||||||
image: golang:1.12
|
image: golang:1.14
|
||||||
commands:
|
commands:
|
||||||
- make vet
|
- make vet
|
||||||
environment:
|
|
||||||
GO111MODULE: on
|
|
||||||
volumes:
|
volumes:
|
||||||
- name: gopath
|
- name: gopath
|
||||||
path: /go
|
path: /go
|
||||||
|
|
||||||
- name: lint
|
- name: lint
|
||||||
pull: always
|
pull: always
|
||||||
image: golang:1.12
|
image: golang:1.14
|
||||||
commands:
|
commands:
|
||||||
- make lint
|
- make lint
|
||||||
environment:
|
|
||||||
GO111MODULE: on
|
|
||||||
volumes:
|
volumes:
|
||||||
- name: gopath
|
- name: gopath
|
||||||
path: /go
|
path: /go
|
||||||
|
|
||||||
- name: misspell
|
- name: misspell
|
||||||
pull: always
|
pull: always
|
||||||
image: golang:1.12
|
image: golang:1.14
|
||||||
commands:
|
commands:
|
||||||
- make misspell-check
|
- make misspell-check
|
||||||
environment:
|
|
||||||
GO111MODULE: on
|
|
||||||
volumes:
|
volumes:
|
||||||
- name: gopath
|
- name: gopath
|
||||||
path: /go
|
path: /go
|
||||||
|
|
||||||
- name: test
|
- name: test
|
||||||
pull: always
|
pull: always
|
||||||
image: golang:1.12-alpine
|
image: golang:1.14-alpine
|
||||||
commands:
|
commands:
|
||||||
- apk add git make curl perl bash build-base zlib-dev ucl-dev
|
- apk add git make curl perl bash build-base zlib-dev ucl-dev
|
||||||
- make ssh-server
|
- make ssh-server
|
||||||
- make test
|
- make test
|
||||||
- make coverage
|
- make coverage
|
||||||
environment:
|
|
||||||
GO111MODULE: on
|
|
||||||
volumes:
|
volumes:
|
||||||
- name: gopath
|
- name: gopath
|
||||||
path: /go
|
path: /go
|
||||||
@@ -76,12 +68,11 @@ platform:
|
|||||||
steps:
|
steps:
|
||||||
- name: build-push
|
- name: build-push
|
||||||
pull: always
|
pull: always
|
||||||
image: golang:1.12
|
image: golang:1.14
|
||||||
commands:
|
commands:
|
||||||
- "go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/amd64/drone-ssh"
|
- go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/amd64/drone-ssh
|
||||||
environment:
|
environment:
|
||||||
CGO_ENABLED: 0
|
CGO_ENABLED: 0
|
||||||
GO111MODULE: on
|
|
||||||
when:
|
when:
|
||||||
event:
|
event:
|
||||||
exclude:
|
exclude:
|
||||||
@@ -89,19 +80,18 @@ steps:
|
|||||||
|
|
||||||
- name: build-tag
|
- name: build-tag
|
||||||
pull: always
|
pull: always
|
||||||
image: golang:1.12
|
image: golang:1.14
|
||||||
commands:
|
commands:
|
||||||
- "go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/amd64/drone-ssh"
|
- go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/amd64/drone-ssh
|
||||||
environment:
|
environment:
|
||||||
CGO_ENABLED: 0
|
CGO_ENABLED: 0
|
||||||
GO111MODULE: on
|
|
||||||
when:
|
when:
|
||||||
event:
|
event:
|
||||||
- tag
|
- tag
|
||||||
|
|
||||||
- name: executable
|
- name: executable
|
||||||
pull: always
|
pull: always
|
||||||
image: golang:1.12
|
image: golang:1.14
|
||||||
commands:
|
commands:
|
||||||
- ./release/linux/amd64/drone-ssh --help
|
- ./release/linux/amd64/drone-ssh --help
|
||||||
|
|
||||||
@@ -140,8 +130,8 @@ steps:
|
|||||||
trigger:
|
trigger:
|
||||||
ref:
|
ref:
|
||||||
- refs/heads/master
|
- refs/heads/master
|
||||||
- "refs/pull/**"
|
- refs/pull/**
|
||||||
- "refs/tags/**"
|
- refs/tags/**
|
||||||
|
|
||||||
depends_on:
|
depends_on:
|
||||||
- testing
|
- testing
|
||||||
@@ -157,12 +147,11 @@ platform:
|
|||||||
steps:
|
steps:
|
||||||
- name: build-push
|
- name: build-push
|
||||||
pull: always
|
pull: always
|
||||||
image: golang:1.12
|
image: golang:1.14
|
||||||
commands:
|
commands:
|
||||||
- "go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm64/drone-ssh"
|
- go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm64/drone-ssh
|
||||||
environment:
|
environment:
|
||||||
CGO_ENABLED: 0
|
CGO_ENABLED: 0
|
||||||
GO111MODULE: on
|
|
||||||
when:
|
when:
|
||||||
event:
|
event:
|
||||||
exclude:
|
exclude:
|
||||||
@@ -170,19 +159,18 @@ steps:
|
|||||||
|
|
||||||
- name: build-tag
|
- name: build-tag
|
||||||
pull: always
|
pull: always
|
||||||
image: golang:1.12
|
image: golang:1.14
|
||||||
commands:
|
commands:
|
||||||
- "go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm64/drone-ssh"
|
- go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm64/drone-ssh
|
||||||
environment:
|
environment:
|
||||||
CGO_ENABLED: 0
|
CGO_ENABLED: 0
|
||||||
GO111MODULE: on
|
|
||||||
when:
|
when:
|
||||||
event:
|
event:
|
||||||
- tag
|
- tag
|
||||||
|
|
||||||
- name: executable
|
- name: executable
|
||||||
pull: always
|
pull: always
|
||||||
image: golang:1.12
|
image: golang:1.14
|
||||||
commands:
|
commands:
|
||||||
- ./release/linux/arm64/drone-ssh --help
|
- ./release/linux/arm64/drone-ssh --help
|
||||||
|
|
||||||
@@ -221,8 +209,8 @@ steps:
|
|||||||
trigger:
|
trigger:
|
||||||
ref:
|
ref:
|
||||||
- refs/heads/master
|
- refs/heads/master
|
||||||
- "refs/pull/**"
|
- refs/pull/**
|
||||||
- "refs/tags/**"
|
- refs/tags/**
|
||||||
|
|
||||||
depends_on:
|
depends_on:
|
||||||
- testing
|
- testing
|
||||||
@@ -238,12 +226,11 @@ platform:
|
|||||||
steps:
|
steps:
|
||||||
- name: build-push
|
- name: build-push
|
||||||
pull: always
|
pull: always
|
||||||
image: golang:1.12
|
image: golang:1.14
|
||||||
commands:
|
commands:
|
||||||
- "go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm/drone-ssh"
|
- go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm/drone-ssh
|
||||||
environment:
|
environment:
|
||||||
CGO_ENABLED: 0
|
CGO_ENABLED: 0
|
||||||
GO111MODULE: on
|
|
||||||
when:
|
when:
|
||||||
event:
|
event:
|
||||||
exclude:
|
exclude:
|
||||||
@@ -251,19 +238,18 @@ steps:
|
|||||||
|
|
||||||
- name: build-tag
|
- name: build-tag
|
||||||
pull: always
|
pull: always
|
||||||
image: golang:1.12
|
image: golang:1.14
|
||||||
commands:
|
commands:
|
||||||
- "go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm/drone-ssh"
|
- go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm/drone-ssh
|
||||||
environment:
|
environment:
|
||||||
CGO_ENABLED: 0
|
CGO_ENABLED: 0
|
||||||
GO111MODULE: on
|
|
||||||
when:
|
when:
|
||||||
event:
|
event:
|
||||||
- tag
|
- tag
|
||||||
|
|
||||||
- name: executable
|
- name: executable
|
||||||
pull: always
|
pull: always
|
||||||
image: golang:1.12
|
image: golang:1.14
|
||||||
commands:
|
commands:
|
||||||
- ./release/linux/arm/drone-ssh --help
|
- ./release/linux/arm/drone-ssh --help
|
||||||
|
|
||||||
@@ -302,8 +288,8 @@ steps:
|
|||||||
trigger:
|
trigger:
|
||||||
ref:
|
ref:
|
||||||
- refs/heads/master
|
- refs/heads/master
|
||||||
- "refs/pull/**"
|
- refs/pull/**
|
||||||
- "refs/tags/**"
|
- refs/tags/**
|
||||||
|
|
||||||
depends_on:
|
depends_on:
|
||||||
- testing
|
- testing
|
||||||
@@ -319,11 +305,9 @@ platform:
|
|||||||
steps:
|
steps:
|
||||||
- name: build-all-binary
|
- name: build-all-binary
|
||||||
pull: always
|
pull: always
|
||||||
image: golang:1.12
|
image: golang:1.14
|
||||||
commands:
|
commands:
|
||||||
- make release
|
- make release
|
||||||
environment:
|
|
||||||
GO111MODULE: on
|
|
||||||
when:
|
when:
|
||||||
event:
|
event:
|
||||||
- tag
|
- tag
|
||||||
@@ -335,14 +319,14 @@ steps:
|
|||||||
api_key:
|
api_key:
|
||||||
from_secret: github_release_api_key
|
from_secret: github_release_api_key
|
||||||
files:
|
files:
|
||||||
- "dist/release/*"
|
- dist/release/*
|
||||||
when:
|
when:
|
||||||
event:
|
event:
|
||||||
- tag
|
- tag
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
ref:
|
ref:
|
||||||
- "refs/tags/**"
|
- refs/tags/**
|
||||||
|
|
||||||
depends_on:
|
depends_on:
|
||||||
- testing
|
- testing
|
||||||
@@ -367,17 +351,10 @@ steps:
|
|||||||
username:
|
username:
|
||||||
from_secret: docker_username
|
from_secret: docker_username
|
||||||
|
|
||||||
- name: microbadger
|
|
||||||
pull: always
|
|
||||||
image: plugins/webhook:1
|
|
||||||
settings:
|
|
||||||
url:
|
|
||||||
from_secret: microbadger_url
|
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
ref:
|
ref:
|
||||||
- refs/heads/master
|
- refs/heads/master
|
||||||
- "refs/tags/**"
|
- refs/tags/**
|
||||||
|
|
||||||
depends_on:
|
depends_on:
|
||||||
- linux-amd64
|
- linux-amd64
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
---
|
---
|
||||||
date: 2017-01-29T00:00:00+00:00
|
date: 2019-08-04T00:00:00+00:00
|
||||||
title: SSH
|
title: SSH
|
||||||
author: appleboy
|
author: appleboy
|
||||||
tags: [ publish, ssh ]
|
tags: [ deploy, publish, ssh ]
|
||||||
repo: appleboy/drone-ssh
|
repo: appleboy/drone-ssh
|
||||||
logo: term.svg
|
logo: term.svg
|
||||||
image: appleboy/drone-ssh
|
image: appleboy/drone-ssh
|
||||||
@@ -11,24 +11,22 @@ image: appleboy/drone-ssh
|
|||||||
Use the SSH plugin to execute commands on a remote server. The below pipeline configuration demonstrates simple usage:
|
Use the SSH plugin to execute commands on a remote server. The below pipeline configuration demonstrates simple usage:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
pipeline:
|
- name: ssh commands
|
||||||
ssh:
|
image: appleboy/drone-ssh
|
||||||
image: appleboy/drone-ssh
|
settings:
|
||||||
settings:
|
host: foo.com
|
||||||
host: foo.com
|
username: root
|
||||||
username: root
|
password: 1234
|
||||||
password: 1234
|
port: 22
|
||||||
port: 22
|
script:
|
||||||
script:
|
- echo hello
|
||||||
- echo hello
|
- echo world
|
||||||
- echo world
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Example configuration in your `.drone.yml` file for multiple hosts:
|
Example configuration in your `.drone.yml` file for multiple hosts:
|
||||||
|
|
||||||
```diff
|
```diff
|
||||||
pipeline:
|
- name: ssh commands
|
||||||
ssh:
|
|
||||||
image: appleboy/drone-ssh
|
image: appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host:
|
host:
|
||||||
@@ -38,22 +36,21 @@ pipeline:
|
|||||||
password: 1234
|
password: 1234
|
||||||
port: 22
|
port: 22
|
||||||
script:
|
script:
|
||||||
- echo hello
|
- echo hello
|
||||||
- echo world
|
- echo world
|
||||||
```
|
```
|
||||||
|
|
||||||
Example configuration for command timeout, default value is 60 seconds:
|
Example configuration for command timeout, default value is 60 seconds:
|
||||||
|
|
||||||
```diff
|
```diff
|
||||||
pipeline:
|
- name: ssh commands
|
||||||
ssh:
|
|
||||||
image: appleboy/drone-ssh
|
image: appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host: foo.com
|
host: foo.com
|
||||||
username: root
|
username: root
|
||||||
password: 1234
|
password: 1234
|
||||||
port: 22
|
port: 22
|
||||||
+ command_timeout: 2m
|
+ command_timeout: 2m
|
||||||
script:
|
script:
|
||||||
- echo hello
|
- echo hello
|
||||||
- echo world
|
- echo world
|
||||||
@@ -62,8 +59,7 @@ pipeline:
|
|||||||
Example configuration for execute commands on a remote server using `SSHProxyCommand`:
|
Example configuration for execute commands on a remote server using `SSHProxyCommand`:
|
||||||
|
|
||||||
```diff
|
```diff
|
||||||
pipeline:
|
- name: ssh commands
|
||||||
ssh:
|
|
||||||
image: appleboy/drone-ssh
|
image: appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host: foo.com
|
host: foo.com
|
||||||
@@ -82,8 +78,7 @@ pipeline:
|
|||||||
Example configuration using password from secrets:
|
Example configuration using password from secrets:
|
||||||
|
|
||||||
```diff
|
```diff
|
||||||
pipeline:
|
- name: ssh commands
|
||||||
ssh:
|
|
||||||
image: appleboy/drone-ssh
|
image: appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host: foo.com
|
host: foo.com
|
||||||
@@ -99,8 +94,7 @@ pipeline:
|
|||||||
Example configuration using ssh key from secrets:
|
Example configuration using ssh key from secrets:
|
||||||
|
|
||||||
```diff
|
```diff
|
||||||
pipeline:
|
- name: ssh commands
|
||||||
ssh:
|
|
||||||
image: appleboy/drone-ssh
|
image: appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host: foo.com
|
host: foo.com
|
||||||
@@ -116,21 +110,53 @@ pipeline:
|
|||||||
Example configuration for exporting custom secrets:
|
Example configuration for exporting custom secrets:
|
||||||
|
|
||||||
```diff
|
```diff
|
||||||
pipeline:
|
- name: ssh commands
|
||||||
ssh:
|
|
||||||
image: appleboy/drone-ssh
|
image: appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host: foo.com
|
host: foo.com
|
||||||
username: root
|
username: root
|
||||||
password: 1234
|
password: 1234
|
||||||
port: 22
|
port: 22
|
||||||
+ envs:
|
+ envs:
|
||||||
- aws_access_key_id
|
- aws_access_key_id
|
||||||
script:
|
script:
|
||||||
- export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
|
- export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
|
||||||
```
|
```
|
||||||
|
|
||||||
# Secret Reference
|
Example configuration for stoping script after first failure:
|
||||||
|
|
||||||
|
```diff
|
||||||
|
- name: ssh commands
|
||||||
|
image: appleboy/drone-ssh
|
||||||
|
settings:
|
||||||
|
host: foo.com
|
||||||
|
username: root
|
||||||
|
password: 1234
|
||||||
|
port: 22
|
||||||
|
+ script_stop: true
|
||||||
|
script:
|
||||||
|
- mkdir abc/def/efg
|
||||||
|
- echo "you can't see the steps."
|
||||||
|
```
|
||||||
|
|
||||||
|
Example configuration for passphrase which protecting a private key:
|
||||||
|
|
||||||
|
```diff
|
||||||
|
- name: ssh commands
|
||||||
|
image: appleboy/drone-ssh
|
||||||
|
settings:
|
||||||
|
host: foo.com
|
||||||
|
username: root
|
||||||
|
+ key:
|
||||||
|
+ from_secret: ssh_key
|
||||||
|
+ passphrase: 1234
|
||||||
|
port: 22
|
||||||
|
script:
|
||||||
|
- mkdir abc/def/efg
|
||||||
|
- echo "you can't see the steps."
|
||||||
|
```
|
||||||
|
|
||||||
|
## Secret Reference
|
||||||
|
|
||||||
ssh_username
|
ssh_username
|
||||||
: account for target host user
|
: account for target host user
|
||||||
@@ -138,6 +164,9 @@ ssh_username
|
|||||||
ssh_password
|
ssh_password
|
||||||
: password for target host user
|
: password for target host user
|
||||||
|
|
||||||
|
ssh_passphrase
|
||||||
|
: The purpose of the passphrase is usually to encrypt the private key.
|
||||||
|
|
||||||
ssh_key
|
ssh_key
|
||||||
: plain text of user private key
|
: plain text of user private key
|
||||||
|
|
||||||
@@ -147,10 +176,13 @@ proxy_ssh_username
|
|||||||
proxy_ssh_password
|
proxy_ssh_password
|
||||||
: password for user of proxy server
|
: password for user of proxy server
|
||||||
|
|
||||||
|
proxy_ssh_passphrase
|
||||||
|
: The purpose of the passphrase is usually to encrypt the private key.
|
||||||
|
|
||||||
proxy_ssh_key
|
proxy_ssh_key
|
||||||
: plain text of user private key for proxy server
|
: plain text of user private key for proxy server
|
||||||
|
|
||||||
# Parameter Reference
|
## Parameter Reference
|
||||||
|
|
||||||
host
|
host
|
||||||
: target hostname or IP
|
: target hostname or IP
|
||||||
@@ -176,11 +208,14 @@ envs
|
|||||||
script
|
script
|
||||||
: execute commands on a remote server
|
: execute commands on a remote server
|
||||||
|
|
||||||
|
script_stop
|
||||||
|
: stop script after first failure
|
||||||
|
|
||||||
timeout
|
timeout
|
||||||
: Timeout is the maximum amount of time for the TCP connection to establish.
|
: Timeout is the maximum amount of time for the ssh connection to establish, default is 30 seconds.
|
||||||
|
|
||||||
command_timeout
|
command_timeout
|
||||||
: Command timeout is the maximum amount of time for the execute commands, default is 60 secs.
|
: Command timeout is the maximum amount of time for the execute commands, default is 10 minutes.
|
||||||
|
|
||||||
proxy_host
|
proxy_host
|
||||||
: proxy hostname or IP
|
: proxy hostname or IP
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ DEPLOY_IMAGE := $(EXECUTABLE)
|
|||||||
|
|
||||||
TARGETS ?= linux darwin windows
|
TARGETS ?= linux darwin windows
|
||||||
ARCHS ?= amd64 386
|
ARCHS ?= amd64 386
|
||||||
PACKAGES ?= $(shell $(GO) list ./...)
|
|
||||||
SOURCES ?= $(shell find . -name "*.go" -type f)
|
SOURCES ?= $(shell find . -name "*.go" -type f)
|
||||||
TAGS ?=
|
TAGS ?=
|
||||||
LDFLAGS ?= -X 'main.Version=$(VERSION)'
|
LDFLAGS ?= -X 'main.Version=$(VERSION)'
|
||||||
@@ -32,7 +31,7 @@ fmt:
|
|||||||
$(GOFMT) -w $(SOURCES)
|
$(GOFMT) -w $(SOURCES)
|
||||||
|
|
||||||
vet:
|
vet:
|
||||||
$(GO) vet $(PACKAGES)
|
$(GO) vet ./...
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
@hash revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
@hash revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
||||||
@@ -64,7 +63,7 @@ fmt-check:
|
|||||||
fi;
|
fi;
|
||||||
|
|
||||||
test: fmt-check
|
test: fmt-check
|
||||||
@$(GO) test -v -cover -coverprofile coverage.txt $(PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1
|
@$(GO) test -v -cover -coverprofile coverage.txt ./... && echo "\n==>\033[32m Ok\033[m\n" || exit 1
|
||||||
|
|
||||||
install: $(SOURCES)
|
install: $(SOURCES)
|
||||||
$(GO) install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)'
|
$(GO) install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)'
|
||||||
@@ -118,15 +117,18 @@ endif
|
|||||||
docker push $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE):$(tag)
|
docker push $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE):$(tag)
|
||||||
|
|
||||||
ssh-server:
|
ssh-server:
|
||||||
adduser -h /home/drone-scp -s /bin/bash -D -S drone-scp
|
adduser -h /home/drone-scp -s /bin/sh -D -S drone-scp
|
||||||
echo drone-scp:1234 | chpasswd
|
echo drone-scp:1234 | chpasswd
|
||||||
mkdir -p /home/drone-scp/.ssh
|
mkdir -p /home/drone-scp/.ssh
|
||||||
chmod 700 /home/drone-scp/.ssh
|
chmod 700 /home/drone-scp/.ssh
|
||||||
cp tests/.ssh/id_rsa.pub /home/drone-scp/.ssh/authorized_keys
|
cat tests/.ssh/id_rsa.pub >> /home/drone-scp/.ssh/authorized_keys
|
||||||
|
cat tests/.ssh/test.pub >> /home/drone-scp/.ssh/authorized_keys
|
||||||
|
chmod 600 /home/drone-scp/.ssh/authorized_keys
|
||||||
chown -R drone-scp /home/drone-scp/.ssh
|
chown -R drone-scp /home/drone-scp/.ssh
|
||||||
# install ssh and start server
|
# install ssh and start server
|
||||||
apk add --update openssh openrc
|
apk add --update openssh openrc
|
||||||
rm -rf /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_dsa_key
|
rm -rf /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_dsa_key
|
||||||
|
sed -i 's/^#PubkeyAuthentication yes/PubkeyAuthentication yes/g' /etc/ssh/sshd_config
|
||||||
sed -i 's/AllowTcpForwarding no/AllowTcpForwarding yes/g' /etc/ssh/sshd_config
|
sed -i 's/AllowTcpForwarding no/AllowTcpForwarding yes/g' /etc/ssh/sshd_config
|
||||||
./tests/entrypoint.sh /usr/sbin/sshd -D &
|
./tests/entrypoint.sh /usr/sbin/sshd -D &
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
<img src="images/ssh.png">
|
|
||||||
|
|
||||||
# drone-ssh
|
# drone-ssh
|
||||||
|
|
||||||
[](https://github.com/appleboy/drone-ssh/releases)
|

|
||||||
[](https://godoc.org/github.com/appleboy/drone-ssh)
|
|
||||||
|
[](https://github.com/appleboy/drone-ssh/releases)
|
||||||
|
[](https://godoc.org/github.com/appleboy/drone-ssh)
|
||||||
[](https://cloud.drone.io/appleboy/drone-ssh)
|
[](https://cloud.drone.io/appleboy/drone-ssh)
|
||||||
[](https://codecov.io/gh/appleboy/drone-ssh)
|
[](https://codecov.io/gh/appleboy/drone-ssh)
|
||||||
[](https://goreportcard.com/report/github.com/appleboy/drone-ssh)
|
[](https://goreportcard.com/report/github.com/appleboy/drone-ssh)
|
||||||
[](https://hub.docker.com/r/appleboy/drone-ssh/)
|
[](https://hub.docker.com/r/appleboy/drone-ssh/)
|
||||||
[](https://microbadger.com/images/appleboy/drone-ssh "Get your own image badge on microbadger.com")
|
[](https://microbadger.com/images/appleboy/drone-ssh "Get your own image badge on microbadger.com")
|
||||||
|
|
||||||
Drone plugin to execute commands on a remote host through SSH. For the usage
|
Drone plugin to execute commands on a remote host through SSH. For the usage
|
||||||
information and a listing of the available options please take a look at [the docs](http://plugins.drone.io/appleboy/drone-ssh/).
|
information and a listing of the available options please take a look at [the docs](http://plugins.drone.io/appleboy/drone-ssh/).
|
||||||
@@ -49,29 +49,29 @@ The pre-compiled binaries can be downloaded from [release page](https://github.c
|
|||||||
|
|
||||||
With `Go` installed
|
With `Go` installed
|
||||||
|
|
||||||
|
```sh
|
||||||
|
go get -u -v github.com/appleboy/drone-ssh
|
||||||
```
|
```
|
||||||
$ go get -u -v github.com/appleboy/drone-ssh
|
|
||||||
```
|
|
||||||
|
|
||||||
or build the binary with the following command:
|
or build the binary with the following command:
|
||||||
|
|
||||||
```
|
```sh
|
||||||
$ export GOOS=linux
|
export GOOS=linux
|
||||||
$ export GOARCH=amd64
|
export GOARCH=amd64
|
||||||
$ export CGO_ENABLED=0
|
export CGO_ENABLED=0
|
||||||
$ export GO111MODULE=on
|
export GO111MODULE=on
|
||||||
|
|
||||||
$ go test -cover ./...
|
go test -cover ./...
|
||||||
|
|
||||||
$ go build -v -a -tags netgo -o release/linux/amd64/drone-ssh .
|
go build -v -a -tags netgo -o release/linux/amd64/drone-ssh .
|
||||||
```
|
```
|
||||||
|
|
||||||
## Docker
|
## Docker
|
||||||
|
|
||||||
Build the docker image with the following commands:
|
Build the docker image with the following commands:
|
||||||
|
|
||||||
```
|
```sh
|
||||||
$ make docker
|
make docker
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
module github.com/appleboy/drone-ssh
|
module github.com/appleboy/drone-ssh
|
||||||
|
|
||||||
go 1.12
|
go 1.14
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/appleboy/easyssh-proxy v1.2.0
|
github.com/appleboy/easyssh-proxy v1.3.7
|
||||||
github.com/joho/godotenv v1.3.0
|
github.com/joho/godotenv v1.3.0
|
||||||
github.com/stretchr/testify v1.3.0
|
github.com/stretchr/testify v1.5.1
|
||||||
github.com/urfave/cli v1.20.0
|
github.com/urfave/cli v1.22.4
|
||||||
|
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,17 +1,41 @@
|
|||||||
github.com/appleboy/easyssh-proxy v1.2.0 h1:KvaUGC18WkBFet+N1oofQy03jkC5HaKFn2XGxFxCTtg=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/appleboy/easyssh-proxy v1.2.0/go.mod h1:vHskChUNhxwW4dXMe2MNE/k+UBCkBagrQDm70UWZrS0=
|
github.com/ScaleFT/sshkeys v0.0.0-20181112160850-82451a803681 h1:JS2rl38kZmHgWa0xINSaSYH0Whtvem64/4+Ef0+Y5pE=
|
||||||
|
github.com/ScaleFT/sshkeys v0.0.0-20181112160850-82451a803681/go.mod h1:WfDateMPQ/55dPbZRp5Zxrux5WiEaHsjk9puUhz0KgY=
|
||||||
|
github.com/appleboy/easyssh-proxy v1.3.7 h1:4XsChI8PuAd6jwTIKvTCH97vWmknvMJGxYi0PLiULG8=
|
||||||
|
github.com/appleboy/easyssh-proxy v1.3.7/go.mod h1:Kk57I3w7OCafOjp5kgZFvxk2fO8Tca5CriBTOsbSbjY=
|
||||||
|
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
|
||||||
|
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a h1:saTgr5tMLFnmy/yg3qDTft4rE5DY2uJ/cCxCe3q0XTU=
|
||||||
|
github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a/go.mod h1:Bw9BbhOJVNR+t0jCqx2GC6zv0TGBsShs56Y3gfSCvl0=
|
||||||
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
|
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
|
||||||
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
|
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
|
||||||
|
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
|
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
||||||
|
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||||
|
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
|
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
|
||||||
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||||
golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25 h1:jsG6UpNLt9iAsb0S2AGW28DveNzzgmbXR+ENoPjUeIU=
|
github.com/urfave/cli v1.22.4 h1:u7tSpNPPswAFymm8IehJhy4uJMlUuU/GmqSkvJ1InXA=
|
||||||
golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
github.com/urfave/cli v1.22.4/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.0.0-20191227163750-53104e6ec876 h1:sKJQZMuxjOAR/Uo2LBfU90onWEf1dF4C+0hPJCc9Mpc=
|
||||||
|
golang.org/x/crypto v0.0.0-20191227163750-53104e6ec876/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 h1:cg5LA/zNPRzIXIWSCxQW10Rvpy94aQh3LT/ShoCpkHw=
|
||||||
|
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
|
||||||
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||||
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ func main() {
|
|||||||
if filename, found := os.LookupEnv("PLUGIN_ENV_FILE"); found {
|
if filename, found := os.LookupEnv("PLUGIN_ENV_FILE"); found {
|
||||||
_ = godotenv.Load(filename)
|
_ = godotenv.Load(filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
app.Name = "Drone SSH"
|
app.Name = "Drone SSH"
|
||||||
app.Usage = "Executing remote ssh commands"
|
app.Usage = "Executing remote ssh commands"
|
||||||
@@ -36,107 +35,154 @@ func main() {
|
|||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "ssh-key",
|
Name: "ssh-key",
|
||||||
Usage: "private ssh key",
|
Usage: "private ssh key",
|
||||||
EnvVar: "PLUGIN_SSH_KEY,PLUGIN_KEY,SSH_KEY,KEY",
|
EnvVar: "PLUGIN_SSH_KEY,PLUGIN_KEY,SSH_KEY,KEY,INPUT_KEY",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "ssh-passphrase",
|
||||||
|
Usage: "The purpose of the passphrase is usually to encrypt the private key.",
|
||||||
|
EnvVar: "PLUGIN_SSH_PASSPHRASE,PLUGIN_PASSPHRASE,SSH_PASSPHRASE,PASSPHRASE,INPUT_PASSPHRASE",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "key-path,i",
|
Name: "key-path,i",
|
||||||
Usage: "ssh private key path",
|
Usage: "ssh private key path",
|
||||||
EnvVar: "PLUGIN_KEY_PATH,SSH_KEY_PATH,PATH",
|
EnvVar: "PLUGIN_KEY_PATH,SSH_KEY_PATH,INPUT_KEY_PATH",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "username,user,u",
|
Name: "username,user,u",
|
||||||
Usage: "connect as user",
|
Usage: "connect as user",
|
||||||
EnvVar: "PLUGIN_USERNAME,PLUGIN_USER,SSH_USERNAME,USERNAME",
|
EnvVar: "PLUGIN_USERNAME,PLUGIN_USER,SSH_USERNAME,USERNAME,INPUT_USERNAME",
|
||||||
Value: "root",
|
Value: "root",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "password,P",
|
Name: "password,P",
|
||||||
Usage: "user password",
|
Usage: "user password",
|
||||||
EnvVar: "PLUGIN_PASSWORD,SSH_PASSWORD,PASSWORD",
|
EnvVar: "PLUGIN_PASSWORD,SSH_PASSWORD,PASSWORD,INPUT_PASSWORD",
|
||||||
},
|
},
|
||||||
cli.StringSliceFlag{
|
cli.StringSliceFlag{
|
||||||
Name: "host,H",
|
Name: "ciphers",
|
||||||
Usage: "connect to host",
|
Usage: "The allowed cipher algorithms. If unspecified then a sensible",
|
||||||
EnvVar: "PLUGIN_HOST,SSH_HOST,HOST",
|
EnvVar: "PLUGIN_CIPHERS,SSH_CIPHERS,CIPHERS,INPUT_CIPHERS",
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "useInsecureCipher",
|
||||||
|
Usage: "include more ciphers with use_insecure_cipher",
|
||||||
|
EnvVar: "PLUGIN_USE_INSECURE_CIPHER,SSH_USE_INSECURE_CIPHER,USE_INSECURE_CIPHER,INPUT_USE_INSECURE_CIPHER",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "fingerprint",
|
||||||
|
Usage: "fingerprint SHA256 of the host public key, default is to skip verification",
|
||||||
|
EnvVar: "PLUGIN_FINGERPRINT,SSH_FINGERPRINT,FINGERPRINT,INPUT_FINGERPRINT",
|
||||||
|
},
|
||||||
|
cli.StringSliceFlag{
|
||||||
|
Name: "host,H",
|
||||||
|
Usage: "connect to host",
|
||||||
|
EnvVar: "PLUGIN_HOST,SSH_HOST,HOST,INPUT_HOST",
|
||||||
|
FilePath: ".host",
|
||||||
},
|
},
|
||||||
cli.IntFlag{
|
cli.IntFlag{
|
||||||
Name: "port,p",
|
Name: "port,p",
|
||||||
Usage: "connect to port",
|
Usage: "connect to port",
|
||||||
EnvVar: "PLUGIN_PORT,SSH_PORT,PORT",
|
EnvVar: "PLUGIN_PORT,SSH_PORT,PORT,INPUT_PORT",
|
||||||
Value: 22,
|
Value: 22,
|
||||||
},
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "sync",
|
Name: "sync",
|
||||||
Usage: "sync mode",
|
Usage: "sync mode",
|
||||||
EnvVar: "PLUGIN_SYNC,SYNC",
|
EnvVar: "PLUGIN_SYNC,SYNC,INPUT_SYNC",
|
||||||
},
|
},
|
||||||
cli.DurationFlag{
|
cli.DurationFlag{
|
||||||
Name: "timeout,t",
|
Name: "timeout,t",
|
||||||
Usage: "connection timeout",
|
Usage: "connection timeout",
|
||||||
EnvVar: "PLUGIN_TIMEOUT,SSH_TIMEOUT,TIMEOUT",
|
EnvVar: "PLUGIN_TIMEOUT,SSH_TIMEOUT,TIMEOUT,INPUT_TIMEOUT",
|
||||||
|
Value: 30 * time.Second,
|
||||||
},
|
},
|
||||||
cli.DurationFlag{
|
cli.DurationFlag{
|
||||||
Name: "command.timeout,T",
|
Name: "command.timeout,T",
|
||||||
Usage: "command timeout",
|
Usage: "command timeout",
|
||||||
EnvVar: "PLUGIN_COMMAND_TIMEOUT,SSH_COMMAND_TIMEOUT,COMMAND_TIMEOUT",
|
EnvVar: "PLUGIN_COMMAND_TIMEOUT,SSH_COMMAND_TIMEOUT,COMMAND_TIMEOUT,INPUT_COMMAND_TIMEOUT",
|
||||||
Value: 60 * time.Second,
|
Value: 10 * time.Minute,
|
||||||
},
|
},
|
||||||
cli.StringSliceFlag{
|
cli.StringSliceFlag{
|
||||||
Name: "script,s",
|
Name: "script,s",
|
||||||
Usage: "execute commands",
|
Usage: "execute commands",
|
||||||
EnvVar: "PLUGIN_SCRIPT,SSH_SCRIPT,SCRIPT",
|
EnvVar: "PLUGIN_SCRIPT,SSH_SCRIPT,SCRIPT",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "script.string",
|
||||||
|
Usage: "execute single commands for github action",
|
||||||
|
EnvVar: "INPUT_SCRIPT",
|
||||||
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "script.stop",
|
Name: "script.stop",
|
||||||
Usage: "stop script after first failure",
|
Usage: "stop script after first failure",
|
||||||
EnvVar: "PLUGIN_SCRIPT_STOP,STOP",
|
EnvVar: "PLUGIN_SCRIPT_STOP,STOP,INPUT_SCRIPT_STOP",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "proxy.ssh-key",
|
Name: "proxy.ssh-key",
|
||||||
Usage: "private ssh key of proxy",
|
Usage: "private ssh key of proxy",
|
||||||
EnvVar: "PLUGIN_PROXY_SSH_KEY,PLUGIN_PROXY_KEY,PROXY_SSH_KEY",
|
EnvVar: "PLUGIN_PROXY_SSH_KEY,PLUGIN_PROXY_KEY,PROXY_SSH_KEY,INPUT_PROXY_KEY",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "proxy.ssh-passphrase",
|
||||||
|
Usage: "The purpose of the passphrase is usually to encrypt the private key.",
|
||||||
|
EnvVar: "PLUGIN_PROXY_SSH_PASSPHRASE,PLUGIN_PROXY_PASSPHRASE,PROXY_SSH_PASSPHRASE,PROXY_PASSPHRASE,INPUT_PROXY_PASSPHRASE",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "proxy.key-path",
|
Name: "proxy.key-path",
|
||||||
Usage: "ssh private key path of proxy",
|
Usage: "ssh private key path of proxy",
|
||||||
EnvVar: "PLUGIN_PROXY_KEY_PATH,PROXY_SSH_KEY_PATH",
|
EnvVar: "PLUGIN_PROXY_KEY_PATH,PROXY_SSH_KEY_PATH,INPUT_PROXY_KEY_PATH",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "proxy.username",
|
Name: "proxy.username",
|
||||||
Usage: "connect as user of proxy",
|
Usage: "connect as user of proxy",
|
||||||
EnvVar: "PLUGIN_PROXY_USERNAME,PLUGIN_PROXY_USER,PROXY_SSH_USERNAME",
|
EnvVar: "PLUGIN_PROXY_USERNAME,PLUGIN_PROXY_USER,PROXY_SSH_USERNAME,INPUT_PROXY_USERNAME",
|
||||||
Value: "root",
|
Value: "root",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "proxy.password",
|
Name: "proxy.password",
|
||||||
Usage: "user password of proxy",
|
Usage: "user password of proxy",
|
||||||
EnvVar: "PLUGIN_PROXY_PASSWORD,PROXY_SSH_PASSWORD",
|
EnvVar: "PLUGIN_PROXY_PASSWORD,PROXY_SSH_PASSWORD,INPUT_PROXY_PASSWORD",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "proxy.host",
|
Name: "proxy.host",
|
||||||
Usage: "connect to host of proxy",
|
Usage: "connect to host of proxy",
|
||||||
EnvVar: "PLUGIN_PROXY_HOST,PROXY_SSH_HOST",
|
EnvVar: "PLUGIN_PROXY_HOST,PROXY_SSH_HOST,INPUT_PROXY_HOST",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "proxy.port",
|
Name: "proxy.port",
|
||||||
Usage: "connect to port of proxy",
|
Usage: "connect to port of proxy",
|
||||||
EnvVar: "PLUGIN_PROXY_PORT,PROXY_SSH_PORT",
|
EnvVar: "PLUGIN_PROXY_PORT,PROXY_SSH_PORT,INPUT_PROXY_PORT",
|
||||||
Value: "22",
|
Value: "22",
|
||||||
},
|
},
|
||||||
cli.DurationFlag{
|
cli.DurationFlag{
|
||||||
Name: "proxy.timeout",
|
Name: "proxy.timeout",
|
||||||
Usage: "proxy connection timeout",
|
Usage: "proxy connection timeout",
|
||||||
EnvVar: "PLUGIN_PROXY_TIMEOUT,PROXY_SSH_TIMEOUT",
|
EnvVar: "PLUGIN_PROXY_TIMEOUT,PROXY_SSH_TIMEOUT,INPUT_PROXY_TIMEOUT",
|
||||||
|
},
|
||||||
|
cli.StringSliceFlag{
|
||||||
|
Name: "proxy.ciphers",
|
||||||
|
Usage: "The allowed cipher algorithms. If unspecified then a sensible",
|
||||||
|
EnvVar: "PLUGIN_PROXY_CIPHERS,SSH_PROXY_CIPHERS,PROXY_CIPHERS,INPUT_PROXY_CIPHERS",
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "proxy.useInsecureCipher",
|
||||||
|
Usage: "include more ciphers with use_insecure_cipher",
|
||||||
|
EnvVar: "PLUGIN_PROXY_USE_INSECURE_CIPHER,SSH_PROXY_USE_INSECURE_CIPHER,PROXY_USE_INSECURE_CIPHER,INPUT_PROXY_USE_INSECURE_CIPHER",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "proxy.fingerprint",
|
||||||
|
Usage: "fingerprint SHA256 of the host public key, default is to skip verification",
|
||||||
|
EnvVar: "PLUGIN_PROXY_FINGERPRINT,SSH_PROXY_FINGERPRINT,PROXY_FINGERPRINT,INPUT_PROXY_FINGERPRINT",
|
||||||
},
|
},
|
||||||
cli.StringSliceFlag{
|
cli.StringSliceFlag{
|
||||||
Name: "envs",
|
Name: "envs",
|
||||||
Usage: "Pass envs",
|
Usage: "pass environment variable to shell script",
|
||||||
EnvVar: "PLUGIN_ENVS",
|
EnvVar: "PLUGIN_ENVS,INPUT_ENVS",
|
||||||
},
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "debug",
|
Name: "debug",
|
||||||
Usage: "debug mode",
|
Usage: "debug mode",
|
||||||
EnvVar: "PLUGIN_DEBUG,DEBUG",
|
EnvVar: "PLUGIN_DEBUG,DEBUG,INPUT_DEBUG",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,29 +225,41 @@ REPOSITORY:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func run(c *cli.Context) error {
|
func run(c *cli.Context) error {
|
||||||
|
scripts := c.StringSlice("script")
|
||||||
|
if s := c.String("script.string"); s != "" {
|
||||||
|
scripts = append(scripts, s)
|
||||||
|
}
|
||||||
plugin := Plugin{
|
plugin := Plugin{
|
||||||
Config: Config{
|
Config: Config{
|
||||||
Key: c.String("ssh-key"),
|
Key: c.String("ssh-key"),
|
||||||
KeyPath: c.String("key-path"),
|
KeyPath: c.String("key-path"),
|
||||||
Username: c.String("user"),
|
Username: c.String("user"),
|
||||||
Password: c.String("password"),
|
Password: c.String("password"),
|
||||||
Host: c.StringSlice("host"),
|
Passphrase: c.String("ssh-passphrase"),
|
||||||
Port: c.Int("port"),
|
Fingerprint: c.String("fingerprint"),
|
||||||
Timeout: c.Duration("timeout"),
|
Host: c.StringSlice("host"),
|
||||||
CommandTimeout: c.Duration("command.timeout"),
|
Port: c.Int("port"),
|
||||||
Script: c.StringSlice("script"),
|
Timeout: c.Duration("timeout"),
|
||||||
ScriptStop: c.Bool("script.stop"),
|
CommandTimeout: c.Duration("command.timeout"),
|
||||||
Envs: c.StringSlice("envs"),
|
Script: scripts,
|
||||||
Debug: c.Bool("debug"),
|
ScriptStop: c.Bool("script.stop"),
|
||||||
Sync: c.Bool("sync"),
|
Envs: c.StringSlice("envs"),
|
||||||
|
Debug: c.Bool("debug"),
|
||||||
|
Sync: c.Bool("sync"),
|
||||||
|
Ciphers: c.StringSlice("ciphers"),
|
||||||
|
UseInsecureCipher: c.Bool("useInsecureCipher"),
|
||||||
Proxy: easyssh.DefaultConfig{
|
Proxy: easyssh.DefaultConfig{
|
||||||
Key: c.String("proxy.ssh-key"),
|
Key: c.String("proxy.ssh-key"),
|
||||||
KeyPath: c.String("proxy.key-path"),
|
KeyPath: c.String("proxy.key-path"),
|
||||||
User: c.String("proxy.username"),
|
User: c.String("proxy.username"),
|
||||||
Password: c.String("proxy.password"),
|
Password: c.String("proxy.password"),
|
||||||
Server: c.String("proxy.host"),
|
Passphrase: c.String("proxy.ssh-passphrase"),
|
||||||
Port: c.String("proxy.port"),
|
Fingerprint: c.String("proxy.fingerprint"),
|
||||||
Timeout: c.Duration("proxy.timeout"),
|
Server: c.String("proxy.host"),
|
||||||
|
Port: c.String("proxy.port"),
|
||||||
|
Timeout: c.Duration("proxy.timeout"),
|
||||||
|
Ciphers: c.StringSlice("proxy.ciphers"),
|
||||||
|
UseInsecureCipher: c.Bool("proxy.useInsecureCipher"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Writer: os.Stdout,
|
Writer: os.Stdout,
|
||||||
|
|||||||
+8
-33
@@ -9,11 +9,8 @@
|
|||||||
steps: [
|
steps: [
|
||||||
{
|
{
|
||||||
name: 'vet',
|
name: 'vet',
|
||||||
image: 'golang:1.12',
|
image: 'golang:1.14',
|
||||||
pull: 'always',
|
pull: 'always',
|
||||||
environment: {
|
|
||||||
GO111MODULE: 'on',
|
|
||||||
},
|
|
||||||
commands: [
|
commands: [
|
||||||
'make vet',
|
'make vet',
|
||||||
],
|
],
|
||||||
@@ -26,11 +23,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'lint',
|
name: 'lint',
|
||||||
image: 'golang:1.12',
|
image: 'golang:1.14',
|
||||||
pull: 'always',
|
pull: 'always',
|
||||||
environment: {
|
|
||||||
GO111MODULE: 'on',
|
|
||||||
},
|
|
||||||
commands: [
|
commands: [
|
||||||
'make lint',
|
'make lint',
|
||||||
],
|
],
|
||||||
@@ -43,11 +37,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'misspell',
|
name: 'misspell',
|
||||||
image: 'golang:1.12',
|
image: 'golang:1.14',
|
||||||
pull: 'always',
|
pull: 'always',
|
||||||
environment: {
|
|
||||||
GO111MODULE: 'on',
|
|
||||||
},
|
|
||||||
commands: [
|
commands: [
|
||||||
'make misspell-check',
|
'make misspell-check',
|
||||||
],
|
],
|
||||||
@@ -60,11 +51,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'test',
|
name: 'test',
|
||||||
image: 'golang:1.12-alpine',
|
image: 'golang:1.14-alpine',
|
||||||
pull: 'always',
|
pull: 'always',
|
||||||
environment: {
|
|
||||||
GO111MODULE: 'on',
|
|
||||||
},
|
|
||||||
commands: [
|
commands: [
|
||||||
'apk add git make curl perl bash build-base zlib-dev ucl-dev',
|
'apk add git make curl perl bash build-base zlib-dev ucl-dev',
|
||||||
'make ssh-server',
|
'make ssh-server',
|
||||||
@@ -105,11 +93,10 @@
|
|||||||
steps: [
|
steps: [
|
||||||
{
|
{
|
||||||
name: 'build-push',
|
name: 'build-push',
|
||||||
image: 'golang:1.12',
|
image: 'golang:1.14',
|
||||||
pull: 'always',
|
pull: 'always',
|
||||||
environment: {
|
environment: {
|
||||||
CGO_ENABLED: '0',
|
CGO_ENABLED: '0',
|
||||||
GO111MODULE: 'on',
|
|
||||||
},
|
},
|
||||||
commands: [
|
commands: [
|
||||||
'go build -v -ldflags \'-X main.build=${DRONE_BUILD_NUMBER}\' -a -o release/' + os + '/' + arch + '/' + name,
|
'go build -v -ldflags \'-X main.build=${DRONE_BUILD_NUMBER}\' -a -o release/' + os + '/' + arch + '/' + name,
|
||||||
@@ -122,11 +109,10 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'build-tag',
|
name: 'build-tag',
|
||||||
image: 'golang:1.12',
|
image: 'golang:1.14',
|
||||||
pull: 'always',
|
pull: 'always',
|
||||||
environment: {
|
environment: {
|
||||||
CGO_ENABLED: '0',
|
CGO_ENABLED: '0',
|
||||||
GO111MODULE: 'on',
|
|
||||||
},
|
},
|
||||||
commands: [
|
commands: [
|
||||||
'go build -v -ldflags \'-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\' -a -o release/' + os + '/' + arch + '/' + name,
|
'go build -v -ldflags \'-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\' -a -o release/' + os + '/' + arch + '/' + name,
|
||||||
@@ -137,7 +123,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'executable',
|
name: 'executable',
|
||||||
image: 'golang:1.12',
|
image: 'golang:1.14',
|
||||||
pull: 'always',
|
pull: 'always',
|
||||||
commands: [
|
commands: [
|
||||||
'./release/' + os + '/' + arch + '/' + name + ' --help',
|
'./release/' + os + '/' + arch + '/' + name + ' --help',
|
||||||
@@ -202,11 +188,8 @@
|
|||||||
steps: [
|
steps: [
|
||||||
{
|
{
|
||||||
name: 'build-all-binary',
|
name: 'build-all-binary',
|
||||||
image: 'golang:1.12',
|
image: 'golang:1.14',
|
||||||
pull: 'always',
|
pull: 'always',
|
||||||
environment: {
|
|
||||||
GO111MODULE: 'on',
|
|
||||||
},
|
|
||||||
commands: [
|
commands: [
|
||||||
'make release'
|
'make release'
|
||||||
],
|
],
|
||||||
@@ -256,14 +239,6 @@
|
|||||||
ignore_missing: true,
|
ignore_missing: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: 'microbadger',
|
|
||||||
image: 'plugins/webhook:1',
|
|
||||||
pull: 'always',
|
|
||||||
settings: {
|
|
||||||
url: { 'from_secret': 'microbadger_url' },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
depends_on: depends_on,
|
depends_on: depends_on,
|
||||||
trigger: {
|
trigger: {
|
||||||
|
|||||||
@@ -23,20 +23,24 @@ var (
|
|||||||
type (
|
type (
|
||||||
// Config for the plugin.
|
// Config for the plugin.
|
||||||
Config struct {
|
Config struct {
|
||||||
Key string
|
Key string
|
||||||
KeyPath string
|
Passphrase string
|
||||||
Username string
|
KeyPath string
|
||||||
Password string
|
Username string
|
||||||
Host []string
|
Password string
|
||||||
Port int
|
Host []string
|
||||||
Timeout time.Duration
|
Port int
|
||||||
CommandTimeout time.Duration
|
Fingerprint string
|
||||||
Script []string
|
Timeout time.Duration
|
||||||
ScriptStop bool
|
CommandTimeout time.Duration
|
||||||
Envs []string
|
Script []string
|
||||||
Proxy easyssh.DefaultConfig
|
ScriptStop bool
|
||||||
Debug bool
|
Envs []string
|
||||||
Sync bool
|
Proxy easyssh.DefaultConfig
|
||||||
|
Debug bool
|
||||||
|
Sync bool
|
||||||
|
Ciphers []string
|
||||||
|
UseInsecureCipher bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Plugin structure
|
// Plugin structure
|
||||||
@@ -53,21 +57,29 @@ func escapeArg(arg string) string {
|
|||||||
func (p Plugin) exec(host string, wg *sync.WaitGroup, errChannel chan error) {
|
func (p Plugin) exec(host string, wg *sync.WaitGroup, errChannel chan error) {
|
||||||
// Create MakeConfig instance with remote username, server address and path to private key.
|
// Create MakeConfig instance with remote username, server address and path to private key.
|
||||||
ssh := &easyssh.MakeConfig{
|
ssh := &easyssh.MakeConfig{
|
||||||
Server: host,
|
Server: host,
|
||||||
User: p.Config.Username,
|
User: p.Config.Username,
|
||||||
Password: p.Config.Password,
|
Password: p.Config.Password,
|
||||||
Port: strconv.Itoa(p.Config.Port),
|
Port: strconv.Itoa(p.Config.Port),
|
||||||
Key: p.Config.Key,
|
Key: p.Config.Key,
|
||||||
KeyPath: p.Config.KeyPath,
|
KeyPath: p.Config.KeyPath,
|
||||||
Timeout: p.Config.Timeout,
|
Passphrase: p.Config.Passphrase,
|
||||||
|
Timeout: p.Config.Timeout,
|
||||||
|
Ciphers: p.Config.Ciphers,
|
||||||
|
Fingerprint: p.Config.Fingerprint,
|
||||||
|
UseInsecureCipher: p.Config.UseInsecureCipher,
|
||||||
Proxy: easyssh.DefaultConfig{
|
Proxy: easyssh.DefaultConfig{
|
||||||
Server: p.Config.Proxy.Server,
|
Server: p.Config.Proxy.Server,
|
||||||
User: p.Config.Proxy.User,
|
User: p.Config.Proxy.User,
|
||||||
Password: p.Config.Proxy.Password,
|
Password: p.Config.Proxy.Password,
|
||||||
Port: p.Config.Proxy.Port,
|
Port: p.Config.Proxy.Port,
|
||||||
Key: p.Config.Proxy.Key,
|
Key: p.Config.Proxy.Key,
|
||||||
KeyPath: p.Config.Proxy.KeyPath,
|
KeyPath: p.Config.Proxy.KeyPath,
|
||||||
Timeout: p.Config.Proxy.Timeout,
|
Passphrase: p.Config.Proxy.Passphrase,
|
||||||
|
Timeout: p.Config.Proxy.Timeout,
|
||||||
|
Ciphers: p.Config.Proxy.Ciphers,
|
||||||
|
Fingerprint: p.Config.Proxy.Fingerprint,
|
||||||
|
UseInsecureCipher: p.Config.Proxy.UseInsecureCipher,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,27 +186,34 @@ func (p Plugin) Exec() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("==========================================")
|
fmt.Println("==============================================")
|
||||||
fmt.Println("Successfully executed commands to all host.")
|
fmt.Println("✅ Successfully executed commands to all host.")
|
||||||
fmt.Println("==========================================")
|
fmt.Println("==============================================")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Plugin) scriptCommands() []string {
|
func (p Plugin) scriptCommands() []string {
|
||||||
numCommands := len(p.Config.Script)
|
scripts := []string{}
|
||||||
if p.Config.ScriptStop {
|
|
||||||
numCommands *= 2
|
|
||||||
}
|
|
||||||
|
|
||||||
commands := make([]string, numCommands)
|
|
||||||
|
|
||||||
for _, cmd := range p.Config.Script {
|
for _, cmd := range p.Config.Script {
|
||||||
|
if p.Config.ScriptStop {
|
||||||
|
scripts = append(scripts, strings.Split(cmd, "\n")...)
|
||||||
|
} else {
|
||||||
|
scripts = append(scripts, cmd)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
commands := make([]string, 0)
|
||||||
|
|
||||||
|
for _, cmd := range scripts {
|
||||||
|
if strings.TrimSpace(cmd) == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
commands = append(commands, cmd)
|
||||||
if p.Config.ScriptStop {
|
if p.Config.ScriptStop {
|
||||||
commands = append(commands, "DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;")
|
commands = append(commands, "DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;")
|
||||||
}
|
}
|
||||||
|
|
||||||
commands = append(commands, cmd)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return commands
|
return commands
|
||||||
|
|||||||
+183
-6
@@ -2,13 +2,17 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/appleboy/easyssh-proxy"
|
"github.com/appleboy/easyssh-proxy"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"golang.org/x/crypto/ssh"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMissingHostOrUser(t *testing.T) {
|
func TestMissingHostOrUser(t *testing.T) {
|
||||||
@@ -382,6 +386,80 @@ func TestCommandOutput(t *testing.T) {
|
|||||||
assert.Equal(t, unindent(expected), unindent(buffer.String()))
|
assert.Equal(t, unindent(expected), unindent(buffer.String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWrongFingerprint(t *testing.T) {
|
||||||
|
var (
|
||||||
|
buffer bytes.Buffer
|
||||||
|
)
|
||||||
|
|
||||||
|
plugin := Plugin{
|
||||||
|
Config: Config{
|
||||||
|
Host: []string{"localhost"},
|
||||||
|
Username: "drone-scp",
|
||||||
|
Port: 22,
|
||||||
|
KeyPath: "./tests/.ssh/id_rsa",
|
||||||
|
Script: []string{
|
||||||
|
"whoami",
|
||||||
|
},
|
||||||
|
Fingerprint: "wrong",
|
||||||
|
},
|
||||||
|
Writer: &buffer,
|
||||||
|
}
|
||||||
|
|
||||||
|
err := plugin.Exec()
|
||||||
|
assert.NotNil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getHostPublicKeyFile(keypath string) (ssh.PublicKey, error) {
|
||||||
|
var pubkey ssh.PublicKey
|
||||||
|
var err error
|
||||||
|
buf, err := ioutil.ReadFile(keypath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
pubkey, _, _, _, err = ssh.ParseAuthorizedKey(buf)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return pubkey, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFingerprint(t *testing.T) {
|
||||||
|
var (
|
||||||
|
buffer bytes.Buffer
|
||||||
|
expected = `
|
||||||
|
======CMD======
|
||||||
|
whoami
|
||||||
|
======END======
|
||||||
|
out: drone-scp
|
||||||
|
`
|
||||||
|
)
|
||||||
|
|
||||||
|
hostKey, err := getHostPublicKeyFile("/etc/ssh/ssh_host_rsa_key.pub")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
plugin := Plugin{
|
||||||
|
Config: Config{
|
||||||
|
Host: []string{"localhost"},
|
||||||
|
Username: "drone-scp",
|
||||||
|
Port: 22,
|
||||||
|
KeyPath: "./tests/.ssh/id_rsa",
|
||||||
|
Script: []string{
|
||||||
|
"whoami",
|
||||||
|
},
|
||||||
|
Fingerprint: ssh.FingerprintSHA256(hostKey),
|
||||||
|
CommandTimeout: 10 * time.Second,
|
||||||
|
},
|
||||||
|
Writer: &buffer,
|
||||||
|
}
|
||||||
|
|
||||||
|
err = plugin.Exec()
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Equal(t, unindent(expected), unindent(buffer.String()))
|
||||||
|
}
|
||||||
|
|
||||||
func TestScriptStop(t *testing.T) {
|
func TestScriptStop(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
buffer bytes.Buffer
|
buffer bytes.Buffer
|
||||||
@@ -492,12 +570,13 @@ func TestEnvOutput(t *testing.T) {
|
|||||||
|
|
||||||
plugin := Plugin{
|
plugin := Plugin{
|
||||||
Config: Config{
|
Config: Config{
|
||||||
Host: []string{"localhost"},
|
Host: []string{"localhost"},
|
||||||
Username: "drone-scp",
|
Username: "drone-scp",
|
||||||
Port: 22,
|
Port: 22,
|
||||||
KeyPath: "./tests/.ssh/id_rsa",
|
KeyPath: "./tests/.ssh/test",
|
||||||
Envs: []string{"env_1", "env_2", "env_3", "env_4", "env_5", "env_6", "env_7"},
|
Passphrase: "1234",
|
||||||
Debug: true,
|
Envs: []string{"env_1", "env_2", "env_3", "env_4", "env_5", "env_6", "env_7"},
|
||||||
|
Debug: true,
|
||||||
Script: []string{
|
Script: []string{
|
||||||
`echo "[${ENV_1}]"`,
|
`echo "[${ENV_1}]"`,
|
||||||
`echo "[${ENV_2}]"`,
|
`echo "[${ENV_2}]"`,
|
||||||
@@ -527,3 +606,101 @@ func TestEnvOutput(t *testing.T) {
|
|||||||
func unindent(text string) string {
|
func unindent(text string) string {
|
||||||
return strings.TrimSpace(strings.Replace(text, "\t", "", -1))
|
return strings.TrimSpace(strings.Replace(text, "\t", "", -1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPlugin_scriptCommands(t *testing.T) {
|
||||||
|
type fields struct {
|
||||||
|
Config Config
|
||||||
|
Writer io.Writer
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
fields fields
|
||||||
|
want []string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "normal testing",
|
||||||
|
fields: fields{
|
||||||
|
Config: Config{
|
||||||
|
Script: []string{"mkdir a", "mkdir b"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: []string{"mkdir a", "mkdir b"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "script stop",
|
||||||
|
fields: fields{
|
||||||
|
Config: Config{
|
||||||
|
Script: []string{"mkdir a", "mkdir b"},
|
||||||
|
ScriptStop: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: []string{"mkdir a", "DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;", "mkdir b", "DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "normal testing 2",
|
||||||
|
fields: fields{
|
||||||
|
Config: Config{
|
||||||
|
Script: []string{"mkdir a\nmkdir c", "mkdir b"},
|
||||||
|
ScriptStop: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: []string{"mkdir a", "DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;", "mkdir c", "DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;", "mkdir b", "DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "trim space",
|
||||||
|
fields: fields{
|
||||||
|
Config: Config{
|
||||||
|
Script: []string{"mkdir a", "mkdir b", "\t", " "},
|
||||||
|
ScriptStop: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: []string{"mkdir a", "mkdir b"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
p := Plugin{
|
||||||
|
Config: tt.fields.Config,
|
||||||
|
Writer: tt.fields.Writer,
|
||||||
|
}
|
||||||
|
if got := p.scriptCommands(); !reflect.DeepEqual(got, tt.want) {
|
||||||
|
t.Errorf("Plugin.scriptCommands() = %#v, want %#v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUseInsecureCipher(t *testing.T) {
|
||||||
|
var (
|
||||||
|
buffer bytes.Buffer
|
||||||
|
expected = `
|
||||||
|
======CMD======
|
||||||
|
mkdir a/b/c
|
||||||
|
mkdir d/e/f
|
||||||
|
======END======
|
||||||
|
err: mkdir: can't create directory 'a/b/c': No such file or directory
|
||||||
|
err: mkdir: can't create directory 'd/e/f': No such file or directory
|
||||||
|
`
|
||||||
|
)
|
||||||
|
|
||||||
|
plugin := Plugin{
|
||||||
|
Config: Config{
|
||||||
|
Host: []string{"localhost"},
|
||||||
|
Username: "drone-scp",
|
||||||
|
Port: 22,
|
||||||
|
KeyPath: "./tests/.ssh/id_rsa",
|
||||||
|
Script: []string{
|
||||||
|
"mkdir a/b/c",
|
||||||
|
"mkdir d/e/f",
|
||||||
|
},
|
||||||
|
CommandTimeout: 10 * time.Second,
|
||||||
|
UseInsecureCipher: true,
|
||||||
|
},
|
||||||
|
Writer: &buffer,
|
||||||
|
}
|
||||||
|
|
||||||
|
err := plugin.Exec()
|
||||||
|
assert.NotNil(t, err)
|
||||||
|
|
||||||
|
assert.Equal(t, unindent(expected), unindent(buffer.String()))
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
-----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HiUjJ0uXDL9cLMkcw6ElWz81mrD2VCkXUz+qFyjJ+G7aGWRtctZoOzKln4yfNfUmwW8/8ra3QnmrMZ2xW2Ylw3ZhO+tLi7jINHYFb54bAdLVPUU1ctIuJns2qkWnjJCxxMiynIqCif20/OU1n8CTJuOWiURmRdmvKOH4PE3JxC2Qnk/3tV3Cf8hp1CH5VjBZ9AjGj5MDMHXyu34VY2WvYo5QyzfS3ySPoT8kCO0G0xpvjwCMHOK+G2RP4kqb/KKZguiKdgintBXuskTlJmD7kcMQ== deploy@easyssh
|
||||||
Reference in New Issue
Block a user