mirror of
https://github.com/appleboy/drone-ssh.git
synced 2026-06-16 14:49:25 +08:00
Compare commits
41 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 67a2631616 | |||
| fdc4c8de43 | |||
| 49542638c6 | |||
| 6464d9999f | |||
| 4aabfc90dd | |||
| b9cfca60e9 | |||
| a8d30dc133 | |||
| f733bb5ebf | |||
| b0ddeb9413 | |||
| 8c5d17d83d | |||
| 050e0e6efd | |||
| f01d5d9454 | |||
| c004469746 | |||
| bc2dac669a | |||
| 541508632d | |||
| 22cd751b47 | |||
| 5a6a923356 | |||
| 1a95b5f1b3 | |||
| d0ed2bb2fb | |||
| b2a60a2fec | |||
| 7c7619ebbc | |||
| fc62fb377c | |||
| 808373f717 | |||
| 6d9d6acc6a | |||
| 439ca59b8f | |||
| d9493e4563 | |||
| cc7a2d5983 | |||
| 0a6e4de21c | |||
| 48f817effb | |||
| c8ecc03ef5 | |||
| ddf9ca3e6f | |||
| a568d2e551 | |||
| d17a10dd0c | |||
| d83798f25b | |||
| 59b08e1b4c | |||
| 8d07792340 | |||
| 55bebcef3d | |||
| dfa002a267 | |||
| 60da6458b5 | |||
| fe2455ee6d | |||
| d2cea88132 |
@@ -1,138 +0,0 @@
|
|||||||
name: Release Binary
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
tags:
|
|
||||||
- 'v*'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Setup go
|
|
||||||
uses: actions/setup-go@v3
|
|
||||||
with:
|
|
||||||
go-version: '^1'
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Build binary
|
|
||||||
run : |
|
|
||||||
make build_linux_amd64
|
|
||||||
make build_linux_arm64
|
|
||||||
make build_linux_arm
|
|
||||||
|
|
||||||
- name: Check binary
|
|
||||||
run : |
|
|
||||||
./release/linux/amd64/drone-ssh --help
|
|
||||||
|
|
||||||
-
|
|
||||||
name: Set up QEMU
|
|
||||||
uses: docker/setup-qemu-action@v2
|
|
||||||
-
|
|
||||||
name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v2
|
|
||||||
|
|
||||||
-
|
|
||||||
name: Login to Docker Hub
|
|
||||||
uses: docker/login-action@v2
|
|
||||||
with:
|
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
||||||
|
|
||||||
-
|
|
||||||
name: Login to GitHub Container Registry
|
|
||||||
uses: docker/login-action@v2
|
|
||||||
with:
|
|
||||||
registry: ghcr.io
|
|
||||||
username: ${{ github.repository_owner }}
|
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
-
|
|
||||||
name: Docker meta for linux amd64
|
|
||||||
id: meta-linux-amd64
|
|
||||||
uses: docker/metadata-action@v4
|
|
||||||
with:
|
|
||||||
flavor: |
|
|
||||||
latest=false
|
|
||||||
suffix=linux-amd64
|
|
||||||
images: |
|
|
||||||
appleboy/drone-ssh
|
|
||||||
ghcr.io/appleboy/drone-ssh
|
|
||||||
tags: |
|
|
||||||
type=raw,value=,enable={{is_default_branch}}
|
|
||||||
type=raw,value=latest,suffix=,enable={{is_default_branch}}
|
|
||||||
type=semver,event=tag,pattern={{version}},suffix=-linux-amd64
|
|
||||||
type=semver,event=tag,pattern={{major}}.{{minor}},suffix=-linux-amd64
|
|
||||||
type=semver,event=tag,pattern={{major}},suffix=-linux-amd64
|
|
||||||
|
|
||||||
-
|
|
||||||
name: Build and push linux amd64
|
|
||||||
uses: docker/build-push-action@v3
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
file: docker/Dockerfile.linux.amd64
|
|
||||||
platforms: linux/amd64
|
|
||||||
push: true
|
|
||||||
tags: ${{ steps.meta-linux-amd64.outputs.tags }}
|
|
||||||
labels: ${{ steps.meta-linux-amd64.outputs.labels }}
|
|
||||||
|
|
||||||
-
|
|
||||||
name: Docker meta for linux arm64
|
|
||||||
id: meta-linux-arm64
|
|
||||||
uses: docker/metadata-action@v4
|
|
||||||
with:
|
|
||||||
flavor: |
|
|
||||||
latest=false
|
|
||||||
suffix=linux-arm64
|
|
||||||
images: |
|
|
||||||
appleboy/drone-ssh
|
|
||||||
ghcr.io/appleboy/drone-ssh
|
|
||||||
tags: |
|
|
||||||
type=raw,value=,enable={{is_default_branch}}
|
|
||||||
type=semver,event=tag,pattern={{version}},suffix=-linux-arm64
|
|
||||||
type=semver,event=tag,pattern={{major}}.{{minor}},suffix=-linux-arm64
|
|
||||||
type=semver,event=tag,pattern={{major}},suffix=-linux-arm64
|
|
||||||
|
|
||||||
-
|
|
||||||
name: Build and push linux arm64
|
|
||||||
uses: docker/build-push-action@v3
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
file: docker/Dockerfile.linux.arm64
|
|
||||||
platforms: linux/arm64
|
|
||||||
push: true
|
|
||||||
tags: ${{ steps.meta-linux-arm64.outputs.tags }}
|
|
||||||
labels: ${{ steps.meta-linux-arm64.outputs.labels }}
|
|
||||||
|
|
||||||
-
|
|
||||||
name: Docker meta for linux arm
|
|
||||||
id: meta-linux-arm
|
|
||||||
uses: docker/metadata-action@v4
|
|
||||||
with:
|
|
||||||
flavor: |
|
|
||||||
latest=false
|
|
||||||
suffix=linux-arm
|
|
||||||
images: |
|
|
||||||
appleboy/drone-ssh
|
|
||||||
ghcr.io/appleboy/drone-ssh
|
|
||||||
tags: |
|
|
||||||
type=raw,value=,enable={{is_default_branch}}
|
|
||||||
type=semver,event=tag,pattern={{version}},suffix=-linux-arm
|
|
||||||
type=semver,event=tag,pattern={{major}}.{{minor}},suffix=-linux-arm
|
|
||||||
type=semver,event=tag,pattern={{major}},suffix=-linux-arm
|
|
||||||
|
|
||||||
-
|
|
||||||
name: Build and push linux arm
|
|
||||||
uses: docker/build-push-action@v3
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
file: docker/Dockerfile.linux.arm
|
|
||||||
platforms: linux/arm
|
|
||||||
push: true
|
|
||||||
tags: ${{ steps.meta-linux-arm.outputs.tags }}
|
|
||||||
labels: ${{ steps.meta-linux-arm.outputs.labels }}
|
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
name: Docker Image
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- 'master'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-docker:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Setup go
|
||||||
|
uses: actions/setup-go@v4
|
||||||
|
with:
|
||||||
|
go-version: '^1'
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Build binary
|
||||||
|
run : |
|
||||||
|
make build_linux_amd64
|
||||||
|
make build_linux_arm
|
||||||
|
make build_linux_arm64
|
||||||
|
-
|
||||||
|
name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v2
|
||||||
|
|
||||||
|
-
|
||||||
|
name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
|
||||||
|
-
|
||||||
|
name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|
||||||
|
-
|
||||||
|
name: Login to GitHub Container Registry
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.repository_owner }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
-
|
||||||
|
name: Docker meta
|
||||||
|
id: docker-meta
|
||||||
|
uses: docker/metadata-action@v4
|
||||||
|
with:
|
||||||
|
images: |
|
||||||
|
${{ github.repository }}
|
||||||
|
ghcr.io/${{ github.repository }}
|
||||||
|
tags: |
|
||||||
|
type=raw,value=latest,enable={{is_default_branch}}
|
||||||
|
type=semver,pattern={{version}}
|
||||||
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
|
type=semver,pattern={{major}}
|
||||||
|
|
||||||
|
-
|
||||||
|
name: Build and push
|
||||||
|
uses: docker/build-push-action@v4
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
platforms: linux/amd64,linux/arm,linux/arm64
|
||||||
|
file: docker/Dockerfile
|
||||||
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
|
tags: ${{ steps.docker-meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.docker-meta.outputs.labels }}
|
||||||
@@ -19,7 +19,7 @@ jobs:
|
|||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
-
|
-
|
||||||
name: Setup go
|
name: Setup go
|
||||||
uses: actions/setup-go@v3
|
uses: actions/setup-go@v4
|
||||||
with:
|
with:
|
||||||
go-version: '^1'
|
go-version: '^1'
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,15 @@
|
|||||||
name: Run Lint
|
name: Lint and Testing
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint:
|
lint:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Setup go
|
- name: Setup go
|
||||||
uses: actions/setup-go@v3
|
uses: actions/setup-go@v4
|
||||||
with:
|
with:
|
||||||
go-version: '^1'
|
go-version: '^1'
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
@@ -23,3 +19,27 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
version: latest
|
version: latest
|
||||||
args: --verbose
|
args: --verbose
|
||||||
|
|
||||||
|
- uses: hadolint/hadolint-action@v3.1.0
|
||||||
|
name: hadolint for Dockerfile
|
||||||
|
with:
|
||||||
|
dockerfile: docker/Dockerfile
|
||||||
|
|
||||||
|
testing:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: golang:1.19-alpine
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: setup sshd server
|
||||||
|
run: |
|
||||||
|
apk add git make curl perl bash build-base zlib-dev ucl-dev
|
||||||
|
make ssh-server
|
||||||
|
|
||||||
|
- name: testing
|
||||||
|
run: |
|
||||||
|
make test
|
||||||
|
|
||||||
|
- name: Upload coverage to Codecov
|
||||||
|
uses: codecov/codecov-action@v3
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
before:
|
||||||
|
hooks:
|
||||||
|
- go mod tidy
|
||||||
|
|
||||||
|
builds:
|
||||||
|
- env:
|
||||||
|
- CGO_ENABLED=0
|
||||||
|
goos:
|
||||||
|
- darwin
|
||||||
|
- linux
|
||||||
|
- windows
|
||||||
|
- freebsd
|
||||||
|
goarch:
|
||||||
|
- amd64
|
||||||
|
- arm
|
||||||
|
- arm64
|
||||||
|
goarm:
|
||||||
|
- "5"
|
||||||
|
- "6"
|
||||||
|
- "7"
|
||||||
|
ignore:
|
||||||
|
- goos: darwin
|
||||||
|
goarch: arm
|
||||||
|
- goos: darwin
|
||||||
|
goarch: ppc64le
|
||||||
|
- goos: darwin
|
||||||
|
goarch: s390x
|
||||||
|
- goos: windows
|
||||||
|
goarch: ppc64le
|
||||||
|
- goos: windows
|
||||||
|
goarch: s390x
|
||||||
|
- goos: windows
|
||||||
|
goarch: arm
|
||||||
|
goarm: "5"
|
||||||
|
- goos: windows
|
||||||
|
goarch: arm
|
||||||
|
goarm: "6"
|
||||||
|
- goos: windows
|
||||||
|
goarch: arm
|
||||||
|
goarm: "7"
|
||||||
|
- goos: windows
|
||||||
|
goarch: arm64
|
||||||
|
- goos: freebsd
|
||||||
|
goarch: ppc64le
|
||||||
|
- goos: freebsd
|
||||||
|
goarch: s390x
|
||||||
|
- goos: freebsd
|
||||||
|
goarch: arm
|
||||||
|
goarm: "5"
|
||||||
|
- goos: freebsd
|
||||||
|
goarch: arm
|
||||||
|
goarm: "6"
|
||||||
|
- goos: freebsd
|
||||||
|
goarch: arm
|
||||||
|
goarm: "7"
|
||||||
|
- goos: freebsd
|
||||||
|
goarch: arm64
|
||||||
|
flags:
|
||||||
|
- -trimpath
|
||||||
|
ldflags:
|
||||||
|
- -s -w
|
||||||
|
- -X main.Version={{.Version}}
|
||||||
|
binary: >-
|
||||||
|
{{ .ProjectName }}-
|
||||||
|
{{- if .IsSnapshot }}{{ .Branch }}-
|
||||||
|
{{- else }}{{- .Version }}-{{ end }}
|
||||||
|
{{- .Os }}-
|
||||||
|
{{- if eq .Arch "amd64" }}amd64
|
||||||
|
{{- else if eq .Arch "amd64_v1" }}amd64
|
||||||
|
{{- else if eq .Arch "386" }}386
|
||||||
|
{{- else }}{{ .Arch }}{{ end }}
|
||||||
|
{{- if .Arm }}-{{ .Arm }}{{ end }}
|
||||||
|
no_unique_dist_dir: true
|
||||||
|
|
||||||
|
archives:
|
||||||
|
- format: binary
|
||||||
|
name_template: "{{ .Binary }}"
|
||||||
|
allow_different_binary_count: true
|
||||||
|
|
||||||
|
checksum:
|
||||||
|
name_template: 'checksums.txt'
|
||||||
|
|
||||||
|
snapshot:
|
||||||
|
name_template: "{{ incpatch .Version }}"
|
||||||
@@ -5,14 +5,14 @@ author: appleboy
|
|||||||
tags: [ deploy, 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: ghcr.io/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
|
||||||
- name: ssh commands
|
- name: ssh commands
|
||||||
image: appleboy/drone-ssh
|
image: ghcr.io/appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host: foo.com
|
host: foo.com
|
||||||
username: root
|
username: root
|
||||||
@@ -27,7 +27,7 @@ Example configuration in your `.drone.yml` file for multiple hosts:
|
|||||||
|
|
||||||
```diff
|
```diff
|
||||||
- name: ssh commands
|
- name: ssh commands
|
||||||
image: appleboy/drone-ssh
|
image: ghcr.io/appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host:
|
host:
|
||||||
+ - foo.com
|
+ - foo.com
|
||||||
@@ -44,7 +44,7 @@ Example configuration for multiple hosts with different port:
|
|||||||
|
|
||||||
```diff
|
```diff
|
||||||
- name: ssh commands
|
- name: ssh commands
|
||||||
image: appleboy/drone-ssh
|
image: ghcr.io/appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host:
|
host:
|
||||||
+ - foo.com:1234
|
+ - foo.com:1234
|
||||||
@@ -61,7 +61,7 @@ Example configuration for command timeout, default value is 60 seconds:
|
|||||||
|
|
||||||
```diff
|
```diff
|
||||||
- name: ssh commands
|
- name: ssh commands
|
||||||
image: appleboy/drone-ssh
|
image: ghcr.io/appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host: foo.com
|
host: foo.com
|
||||||
username: root
|
username: root
|
||||||
@@ -77,7 +77,7 @@ Example configuration for execute commands on a remote server using `SSHProxyC
|
|||||||
|
|
||||||
```diff
|
```diff
|
||||||
- name: ssh commands
|
- name: ssh commands
|
||||||
image: appleboy/drone-ssh
|
image: ghcr.io/appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host: foo.com
|
host: foo.com
|
||||||
username: root
|
username: root
|
||||||
@@ -96,7 +96,7 @@ Example configuration using password from secrets:
|
|||||||
|
|
||||||
```diff
|
```diff
|
||||||
- name: ssh commands
|
- name: ssh commands
|
||||||
image: appleboy/drone-ssh
|
image: ghcr.io/appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host: foo.com
|
host: foo.com
|
||||||
username: root
|
username: root
|
||||||
@@ -112,7 +112,7 @@ Example configuration using ssh key from secrets:
|
|||||||
|
|
||||||
```diff
|
```diff
|
||||||
- name: ssh commands
|
- name: ssh commands
|
||||||
image: appleboy/drone-ssh
|
image: ghcr.io/appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host: foo.com
|
host: foo.com
|
||||||
username: root
|
username: root
|
||||||
@@ -128,27 +128,28 @@ Example configuration for exporting custom secrets:
|
|||||||
|
|
||||||
```diff
|
```diff
|
||||||
- name: ssh commands
|
- name: ssh commands
|
||||||
image: appleboy/drone-ssh
|
image: ghcr.io/appleboy/drone-ssh
|
||||||
environment:
|
environment:
|
||||||
commit: ${DRONE_BUILD_NUMBER}
|
# MUST BE in UPPERCASE
|
||||||
|
COMMIT:
|
||||||
|
from_secret: commit
|
||||||
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
|
# can be in lowercase (uppercased in code)
|
||||||
- commit
|
- commit
|
||||||
script:
|
script:
|
||||||
- export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
|
- echo $COMMIT
|
||||||
- echo $commit
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Example configuration for stoping script after first failure:
|
Example configuration for stoping script after first failure:
|
||||||
|
|
||||||
```diff
|
```diff
|
||||||
- name: ssh commands
|
- name: ssh commands
|
||||||
image: appleboy/drone-ssh
|
image: ghcr.io/appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host: foo.com
|
host: foo.com
|
||||||
username: root
|
username: root
|
||||||
@@ -164,7 +165,7 @@ Example configuration for passphrase which protecting a private key:
|
|||||||
|
|
||||||
```diff
|
```diff
|
||||||
- name: ssh commands
|
- name: ssh commands
|
||||||
image: appleboy/drone-ssh
|
image: ghcr.io/appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host: foo.com
|
host: foo.com
|
||||||
username: root
|
username: root
|
||||||
@@ -179,79 +180,35 @@ Example configuration for passphrase which protecting a private key:
|
|||||||
|
|
||||||
## Secret Reference
|
## Secret Reference
|
||||||
|
|
||||||
ssh_username
|
| Key | Description |
|
||||||
: account for target host user
|
|-----|-------------|
|
||||||
|
| `ssh_username` | account for target host user |
|
||||||
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` | plain text of user private key |
|
||||||
ssh_passphrase
|
| `proxy_ssh_username` | account for user of proxy server |
|
||||||
: The purpose of the passphrase is usually to encrypt the private key.
|
| `proxy_ssh_password` | password for user of proxy server |
|
||||||
|
| `proxy_ssh_passphrase` | The purpose of the passphrase is usually to encrypt the private key. |
|
||||||
ssh_key
|
| `proxy_ssh_key` | plain text of user private key for proxy server |
|
||||||
: plain text of user private key
|
|
||||||
|
|
||||||
proxy_ssh_username
|
|
||||||
: account for user of proxy server
|
|
||||||
|
|
||||||
proxy_ssh_password
|
|
||||||
: password for user of proxy server
|
|
||||||
|
|
||||||
proxy_ssh_passphrase
|
|
||||||
: The purpose of the passphrase is usually to encrypt the private key.
|
|
||||||
|
|
||||||
proxy_ssh_key
|
|
||||||
: plain text of user private key for proxy server
|
|
||||||
|
|
||||||
## Parameter Reference
|
## Parameter Reference
|
||||||
|
|
||||||
host
|
| Key | Description |
|
||||||
: target hostname or IP
|
|-----|-------------|
|
||||||
|
| `host` | target hostname or IP |
|
||||||
port
|
| `port` | ssh port of target host |
|
||||||
: ssh port of target host
|
| `username` | account for target host user |
|
||||||
|
| `password` | password for target host user |
|
||||||
username
|
| `key` | plain text of user private key |
|
||||||
: account for target host user
|
| `key_path` | key path of user private key |
|
||||||
|
| `envs` | custom secrets which are made available in the script section |
|
||||||
password
|
| `script` | execute commands on a remote server |
|
||||||
: password for target host user
|
| `script_stop` | stop script after first failure |
|
||||||
|
| `timeout` | Timeout is the maximum amount of time for the ssh connection to establish, default is 30 seconds. |
|
||||||
key
|
| `command_timeout` | Command timeout is the maximum amount of time for the execute commands, default is 10 minutes. |
|
||||||
: plain text of user private key
|
| `proxy_host` | proxy hostname or IP |
|
||||||
|
| `proxy_port` | ssh port of proxy host |
|
||||||
key_path
|
| `proxy_username` | account for proxy host user |
|
||||||
: key path of user private key
|
| `proxy_password` | password for proxy host user |
|
||||||
|
| `proxy_key` | plain text of proxy private key |
|
||||||
envs
|
| `proxy_key_path` | key path of proxy private key |
|
||||||
: custom secrets which are made available in the script section
|
|
||||||
|
|
||||||
script
|
|
||||||
: execute commands on a remote server
|
|
||||||
|
|
||||||
script_stop
|
|
||||||
: stop script after first failure
|
|
||||||
|
|
||||||
timeout
|
|
||||||
: Timeout is the maximum amount of time for the ssh connection to establish, default is 30 seconds.
|
|
||||||
|
|
||||||
command_timeout
|
|
||||||
: Command timeout is the maximum amount of time for the execute commands, default is 10 minutes.
|
|
||||||
|
|
||||||
proxy_host
|
|
||||||
: proxy hostname or IP
|
|
||||||
|
|
||||||
proxy_port
|
|
||||||
: ssh port of proxy host
|
|
||||||
|
|
||||||
proxy_username
|
|
||||||
: account for proxy host user
|
|
||||||
|
|
||||||
proxy_password
|
|
||||||
: password for proxy host user
|
|
||||||
|
|
||||||
proxy_key
|
|
||||||
: plain text of proxy private key
|
|
||||||
|
|
||||||
proxy_key_path
|
|
||||||
: key path of proxy private key
|
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
DIST := dist
|
DIST := dist
|
||||||
EXECUTABLE := drone-ssh
|
EXECUTABLE := drone-ssh
|
||||||
GOFMT ?= gofumpt -l -s
|
GOFMT ?= gofumpt -l
|
||||||
DIST := dist
|
DIST := dist
|
||||||
DIST_DIRS := $(DIST)/binaries $(DIST)/release
|
DIST_DIRS := $(DIST)/binaries $(DIST)/release
|
||||||
GO ?= go
|
GO ?= go
|
||||||
SHASUM ?= shasum -a 256
|
SHASUM ?= shasum -a 256
|
||||||
|
GOFILES := $(shell find . -name "*.go" -type f)
|
||||||
HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
|
HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
|
||||||
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
|
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
|
||||||
XGO_VERSION := go-1.18.x
|
XGO_VERSION := go-1.19.x
|
||||||
GXZ_PAGAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.10
|
GXZ_PAGAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.11
|
||||||
|
|
||||||
LINUX_ARCHS ?= linux/amd64,linux/arm64
|
LINUX_ARCHS ?= linux/amd64,linux/arm64
|
||||||
DARWIN_ARCHS ?= darwin-12/amd64,darwin-12/arm64
|
DARWIN_ARCHS ?= darwin-10.12/amd64,darwin-10.12/arm64
|
||||||
WINDOWS_ARCHS ?= windows/amd64
|
WINDOWS_ARCHS ?= windows/*
|
||||||
|
|
||||||
ifneq ($(shell uname), Darwin)
|
ifneq ($(shell uname), Darwin)
|
||||||
EXTLDFLAGS = -extldflags "-static" $(null)
|
EXTLDFLAGS = -extldflags "-static" $(null)
|
||||||
@@ -52,9 +53,9 @@ all: build
|
|||||||
|
|
||||||
fmt:
|
fmt:
|
||||||
@hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
@hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
||||||
$(GO) get -u mvdan.cc/gofumpt; \
|
$(GO) install mvdan.cc/gofumpt; \
|
||||||
fi
|
fi
|
||||||
$(GOFMT) -w $(SOURCES)
|
$(GOFMT) -w $(GOFILES)
|
||||||
|
|
||||||
vet:
|
vet:
|
||||||
$(GO) vet ./...
|
$(GO) vet ./...
|
||||||
@@ -62,24 +63,24 @@ vet:
|
|||||||
.PHONY: fmt-check
|
.PHONY: fmt-check
|
||||||
fmt-check:
|
fmt-check:
|
||||||
@hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
@hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
||||||
$(GO) get -u mvdan.cc/gofumpt; \
|
$(GO) install mvdan.cc/gofumpt; \
|
||||||
fi
|
fi
|
||||||
@diff=$$($(GOFMT) -d $(SOURCES)); \
|
@diff=$$($(GOFMT) -d $(GOFILES)); \
|
||||||
if [ -n "$$diff" ]; then \
|
if [ -n "$$diff" ]; then \
|
||||||
echo "Please run 'make fmt' and commit the result:"; \
|
echo "Please run 'make fmt' and commit the result:"; \
|
||||||
echo "$${diff}"; \
|
echo "$${diff}"; \
|
||||||
exit 1; \
|
exit 1; \
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
test: fmt-check
|
test:
|
||||||
@$(GO) test -v -cover -coverprofile coverage.txt ./... && 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: $(GOFILES)
|
||||||
$(GO) install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)'
|
$(GO) install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)'
|
||||||
|
|
||||||
build: $(EXECUTABLE)
|
build: $(EXECUTABLE)
|
||||||
|
|
||||||
$(EXECUTABLE): $(SOURCES)
|
$(EXECUTABLE): $(GOFILES)
|
||||||
$(GO) build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o $@
|
$(GO) build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o $@
|
||||||
|
|
||||||
build_linux_amd64:
|
build_linux_amd64:
|
||||||
@@ -119,7 +120,7 @@ deps-backend:
|
|||||||
$(GO) install $(XGO_PACKAGE)
|
$(GO) install $(XGO_PACKAGE)
|
||||||
|
|
||||||
.PHONY: release
|
.PHONY: release
|
||||||
release: release-linux release-copy release-compress release-check
|
release: release-linux release-darwin release-windows release-copy release-compress release-check
|
||||||
|
|
||||||
$(DIST_DIRS):
|
$(DIST_DIRS):
|
||||||
mkdir -p $(DIST_DIRS)
|
mkdir -p $(DIST_DIRS)
|
||||||
|
|||||||
@@ -4,11 +4,10 @@
|
|||||||
|
|
||||||
[](https://github.com/appleboy/drone-ssh/releases)
|
[](https://github.com/appleboy/drone-ssh/releases)
|
||||||
[](https://godoc.org/github.com/appleboy/drone-ssh)
|
[](https://godoc.org/github.com/appleboy/drone-ssh)
|
||||||
[](https://cloud.drone.io/appleboy/drone-ssh)
|
[](https://github.com/appleboy/drone-ssh/actions/workflows/lint.yml)
|
||||||
[](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")
|
|
||||||
|
|
||||||
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/).
|
||||||
@@ -24,7 +23,7 @@ information and a listing of the available options please take a look at [the do
|
|||||||
```diff
|
```diff
|
||||||
pipeline:
|
pipeline:
|
||||||
scp:
|
scp:
|
||||||
image: appleboy/drone-scp
|
image: ghcr.io/appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host:
|
host:
|
||||||
- example1.com
|
- example1.com
|
||||||
@@ -50,7 +49,7 @@ The pre-compiled binaries can be downloaded from [release page](https://github.c
|
|||||||
With `Go` installed
|
With `Go` installed
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
go get -u -v github.com/appleboy/drone-ssh
|
go install github.com/appleboy/drone-ssh@latest
|
||||||
```
|
```
|
||||||
|
|
||||||
or build the binary with the following command:
|
or build the binary with the following command:
|
||||||
@@ -86,7 +85,7 @@ docker run --rm \
|
|||||||
-e PLUGIN_SCRIPT=whoami \
|
-e PLUGIN_SCRIPT=whoami \
|
||||||
-v $(pwd):$(pwd) \
|
-v $(pwd):$(pwd) \
|
||||||
-w $(pwd) \
|
-w $(pwd) \
|
||||||
appleboy/drone-ssh
|
ghcr.io/appleboy/drone-ssh
|
||||||
```
|
```
|
||||||
|
|
||||||
## Mount key from file path
|
## Mount key from file path
|
||||||
@@ -100,7 +99,7 @@ Mount private key in `volumes` setting of `.drone.yml` config
|
|||||||
```diff
|
```diff
|
||||||
pipeline:
|
pipeline:
|
||||||
ssh:
|
ssh:
|
||||||
image: appleboy/drone-ssh
|
image: ghcr.io/appleboy/drone-ssh
|
||||||
host: xxxxx.com
|
host: xxxxx.com
|
||||||
username: deploy
|
username: deploy
|
||||||
+ volumes:
|
+ volumes:
|
||||||
@@ -111,3 +110,15 @@ pipeline:
|
|||||||
```
|
```
|
||||||
|
|
||||||
See the detail of [issue comment](https://github.com/appleboy/drone-ssh/issues/51#issuecomment-336732928).
|
See the detail of [issue comment](https://github.com/appleboy/drone-ssh/issues/51#issuecomment-336732928).
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
See [DOCS.md](./DOCS.md) for examples and full configuration options
|
||||||
|
|
||||||
|
Configuration options are loaded from multiple sources:
|
||||||
|
|
||||||
|
0. Hardcoded drone-ssh defaults. See [main.go CLI Flags](https://github.com/appleboy/drone-ssh/blob/6d9d6acc6aef1f9166118c6ba8bd214d3a582bdb/main.go#L39) for more information.
|
||||||
|
1. From a dotenv file at a path specified by the `PLUGIN_ENV_FILE` environment variable.
|
||||||
|
2. From your `.drone.yml` Drone configuration.
|
||||||
|
|
||||||
|
Later sources override previous sources, i.e. if `PORT` is set in an `.env` file committed in the repository or created by previous test steps, it will override the default set `main.go`.
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
FROM alpine:3.17
|
||||||
|
|
||||||
|
ARG TARGETOS
|
||||||
|
ARG TARGETARCH
|
||||||
|
|
||||||
|
LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
|
||||||
|
org.label-schema.name="SSH Plugin" \
|
||||||
|
org.label-schema.vendor="Bo-Yi Wu" \
|
||||||
|
org.label-schema.schema-version="1.0"
|
||||||
|
|
||||||
|
LABEL org.opencontainers.image.source=https://github.com/appleboy/drone-ssh
|
||||||
|
LABEL org.opencontainers.image.description="Execute commands on a remote host through SSH"
|
||||||
|
LABEL org.opencontainers.image.licenses=MIT
|
||||||
|
|
||||||
|
RUN apk add --no-cache ca-certificates=20220614-r4 && \
|
||||||
|
rm -rf /var/cache/apk/*
|
||||||
|
|
||||||
|
COPY release/${TARGETOS}/${TARGETARCH}/drone-ssh /bin/
|
||||||
|
|
||||||
|
ENTRYPOINT ["/bin/drone-ssh"]
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
FROM plugins/base:linux-amd64
|
|
||||||
|
|
||||||
LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
|
|
||||||
org.label-schema.name="Drone SSH" \
|
|
||||||
org.label-schema.vendor="Bo-Yi Wu" \
|
|
||||||
org.label-schema.schema-version="1.0"
|
|
||||||
|
|
||||||
RUN apk add --no-cache ca-certificates && \
|
|
||||||
rm -rf /var/cache/apk/*
|
|
||||||
|
|
||||||
COPY release/linux/amd64/drone-ssh /bin/
|
|
||||||
|
|
||||||
ENTRYPOINT ["/bin/drone-ssh"]
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
FROM plugins/base:linux-arm
|
|
||||||
|
|
||||||
LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
|
|
||||||
org.label-schema.name="Drone SSH" \
|
|
||||||
org.label-schema.vendor="Bo-Yi Wu" \
|
|
||||||
org.label-schema.schema-version="1.0"
|
|
||||||
|
|
||||||
RUN apk add --no-cache ca-certificates && \
|
|
||||||
rm -rf /var/cache/apk/*
|
|
||||||
|
|
||||||
COPY release/linux/arm/drone-ssh /bin/
|
|
||||||
|
|
||||||
ENTRYPOINT ["/bin/drone-ssh"]
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
FROM plugins/base:linux-arm64
|
|
||||||
|
|
||||||
LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
|
|
||||||
org.label-schema.name="Drone SSH" \
|
|
||||||
org.label-schema.vendor="Bo-Yi Wu" \
|
|
||||||
org.label-schema.schema-version="1.0"
|
|
||||||
|
|
||||||
RUN apk add --no-cache ca-certificates && \
|
|
||||||
rm -rf /var/cache/apk/*
|
|
||||||
|
|
||||||
COPY release/linux/arm64/drone-ssh /bin/
|
|
||||||
|
|
||||||
ENTRYPOINT ["/bin/drone-ssh"]
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
FROM microsoft/nanoserver:10.0.14393.1884
|
|
||||||
|
|
||||||
LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
|
|
||||||
org.label-schema.name="Drone SSH" \
|
|
||||||
org.label-schema.vendor="Bo-Yi Wu" \
|
|
||||||
org.label-schema.schema-version="1.0"
|
|
||||||
|
|
||||||
ADD drone-ssh.exe /drone-ssh.exe
|
|
||||||
ENTRYPOINT [ "\\drone-ssh.exe" ]
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
image: appleboy/drone-ssh:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}}
|
|
||||||
{{#if build.tags}}
|
|
||||||
tags:
|
|
||||||
{{#each build.tags}}
|
|
||||||
- {{this}}
|
|
||||||
{{/each}}
|
|
||||||
{{/if}}
|
|
||||||
manifests:
|
|
||||||
-
|
|
||||||
image: appleboy/drone-ssh:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64
|
|
||||||
platform:
|
|
||||||
architecture: amd64
|
|
||||||
os: linux
|
|
||||||
-
|
|
||||||
image: appleboy/drone-ssh:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64
|
|
||||||
platform:
|
|
||||||
architecture: arm64
|
|
||||||
os: linux
|
|
||||||
variant: v8
|
|
||||||
-
|
|
||||||
image: appleboy/drone-ssh:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm
|
|
||||||
platform:
|
|
||||||
architecture: arm
|
|
||||||
os: linux
|
|
||||||
variant: v7
|
|
||||||
@@ -3,11 +3,11 @@ module github.com/appleboy/drone-ssh
|
|||||||
go 1.18
|
go 1.18
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/appleboy/easyssh-proxy v1.3.9
|
github.com/appleboy/easyssh-proxy v1.3.10
|
||||||
github.com/joho/godotenv v1.4.0
|
github.com/joho/godotenv v1.5.1
|
||||||
github.com/stretchr/testify v1.8.1
|
github.com/stretchr/testify v1.8.2
|
||||||
github.com/urfave/cli v1.22.10
|
github.com/urfave/cli/v2 v2.25.1
|
||||||
golang.org/x/crypto v0.4.0
|
golang.org/x/crypto v0.8.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
@@ -17,6 +17,7 @@ require (
|
|||||||
github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a // indirect
|
github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||||
golang.org/x/sys v0.3.0 // indirect
|
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
|
||||||
|
golang.org/x/sys v0.7.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
|
||||||
github.com/ScaleFT/sshkeys v0.0.0-20200327173127-6142f742bca5/go.mod h1:gxOHeajFfvGQh/fxlC8oOKBe23xnnJTif00IFFbiT+o=
|
|
||||||
github.com/ScaleFT/sshkeys v1.2.0 h1:5BRp6rTVIhJzXT3VcUQrKgXR8zWA3sOsNeuyW15WUA8=
|
github.com/ScaleFT/sshkeys v1.2.0 h1:5BRp6rTVIhJzXT3VcUQrKgXR8zWA3sOsNeuyW15WUA8=
|
||||||
github.com/ScaleFT/sshkeys v1.2.0/go.mod h1:gxOHeajFfvGQh/fxlC8oOKBe23xnnJTif00IFFbiT+o=
|
github.com/ScaleFT/sshkeys v1.2.0/go.mod h1:gxOHeajFfvGQh/fxlC8oOKBe23xnnJTif00IFFbiT+o=
|
||||||
github.com/appleboy/easyssh-proxy v1.3.9 h1:b+sVSTz+cVFvfA23HQywMMpm0s5g3gH7jYdBcQqaCQI=
|
github.com/appleboy/easyssh-proxy v1.3.10 h1:iriF68tlrYoxgWhS7t7Wyr0FA+hJlOem5tMfm+RDlx4=
|
||||||
github.com/appleboy/easyssh-proxy v1.3.9/go.mod h1:G1eQomBEME7NWKA3hE49s5HsT44S5fn0aBxX7k9Yjug=
|
github.com/appleboy/easyssh-proxy v1.3.10/go.mod h1:T81pu/Cxx/zf/7YXhFCFiucBa4xeQ81ci5b0PFnMRJc=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
|
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||||
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=
|
||||||
@@ -12,39 +9,35 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
|||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/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 h1:saTgr5tMLFnmy/yg3qDTft4rE5DY2uJ/cCxCe3q0XTU=
|
||||||
github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a/go.mod h1:Bw9BbhOJVNR+t0jCqx2GC6zv0TGBsShs56Y3gfSCvl0=
|
github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a/go.mod h1:Bw9BbhOJVNR+t0jCqx2GC6zv0TGBsShs56Y3gfSCvl0=
|
||||||
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
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/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
|
||||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
|
||||||
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/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
|
||||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
|
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
|
||||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||||
github.com/urfave/cli v1.22.10 h1:p8Fspmz3iTctJstry1PYS3HVdllxnEzTEsgIgtxTrCk=
|
github.com/urfave/cli/v2 v2.25.1 h1:zw8dSP7ghX0Gmm8vugrs6q9Ku0wzweqPyshy+syu9Gw=
|
||||||
github.com/urfave/cli v1.22.10/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
github.com/urfave/cli/v2 v2.25.1/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
|
||||||
|
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
|
||||||
|
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
golang.org/x/crypto v0.8.0 h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ=
|
||||||
golang.org/x/crypto v0.4.0 h1:UVQgzMY87xqpKNgb+kDsll2Igd33HszWHFLmpaRMq/8=
|
golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE=
|
||||||
golang.org/x/crypto v0.4.0/go.mod h1:3quD/ATkf6oY+rnes5c3ExXTbLc8mueNue5/DoinL80=
|
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
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/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200219091948-cb0a6d8edb6c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200219091948-cb0a6d8edb6c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
|
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
|
||||||
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
golang.org/x/term v0.7.0 h1:BEvjmm5fURWqcfbSKTdpkDXYBrUS1c0m8agp14W48vQ=
|
||||||
golang.org/x/term v0.3.0 h1:qoo4akIqOcDME5bhc/NgxUdovd6BSS2uMsVjB56q1xI=
|
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
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 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
"github.com/appleboy/easyssh-proxy"
|
"github.com/appleboy/easyssh-proxy"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Version set at compile-time
|
// Version set at compile-time
|
||||||
@@ -27,7 +27,7 @@ func main() {
|
|||||||
app.Name = "Drone SSH"
|
app.Name = "Drone SSH"
|
||||||
app.Usage = "Executing remote ssh commands"
|
app.Usage = "Executing remote ssh commands"
|
||||||
app.Copyright = "Copyright (c) 2019 Bo-Yi Wu"
|
app.Copyright = "Copyright (c) 2019 Bo-Yi Wu"
|
||||||
app.Authors = []cli.Author{
|
app.Authors = []*cli.Author{
|
||||||
{
|
{
|
||||||
Name: "Bo-Yi Wu",
|
Name: "Bo-Yi Wu",
|
||||||
Email: "appleboy.tw@gmail.com",
|
Email: "appleboy.tw@gmail.com",
|
||||||
@@ -36,157 +36,171 @@ func main() {
|
|||||||
app.Action = run
|
app.Action = run
|
||||||
app.Version = Version
|
app.Version = Version
|
||||||
app.Flags = []cli.Flag{
|
app.Flags = []cli.Flag{
|
||||||
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,INPUT_KEY",
|
EnvVars: []string{"PLUGIN_SSH_KEY", "PLUGIN_KEY", "SSH_KEY", "INPUT_KEY"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "ssh-passphrase",
|
Name: "ssh-passphrase",
|
||||||
Usage: "The purpose of the passphrase is usually to encrypt the private key.",
|
Usage: "The purpose of the passphrase is usually to encrypt the private key.",
|
||||||
EnvVar: "PLUGIN_SSH_PASSPHRASE,PLUGIN_PASSPHRASE,SSH_PASSPHRASE,PASSPHRASE,INPUT_PASSPHRASE",
|
EnvVars: []string{"PLUGIN_SSH_PASSPHRASE", "PLUGIN_PASSPHRASE", "SSH_PASSPHRASE", "INPUT_PASSPHRASE"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "key-path,i",
|
Name: "key-path",
|
||||||
Usage: "ssh private key path",
|
Aliases: []string{"i"},
|
||||||
EnvVar: "PLUGIN_KEY_PATH,SSH_KEY_PATH,INPUT_KEY_PATH",
|
Usage: "ssh private key path",
|
||||||
|
EnvVars: []string{"PLUGIN_KEY_PATH", "SSH_KEY_PATH", "INPUT_KEY_PATH"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "username,user,u",
|
Name: "username",
|
||||||
Usage: "connect as user",
|
Aliases: []string{"user", "u"},
|
||||||
EnvVar: "PLUGIN_USERNAME,PLUGIN_USER,SSH_USERNAME,USERNAME,INPUT_USERNAME",
|
Usage: "connect as user",
|
||||||
Value: "root",
|
EnvVars: []string{"PLUGIN_USERNAME", "PLUGIN_USER", "SSH_USERNAME", "INPUT_USERNAME"},
|
||||||
|
Value: "root",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "password,P",
|
Name: "password",
|
||||||
Usage: "user password",
|
Aliases: []string{"P"},
|
||||||
EnvVar: "PLUGIN_PASSWORD,SSH_PASSWORD,PASSWORD,INPUT_PASSWORD",
|
Usage: "user password",
|
||||||
|
EnvVars: []string{"PLUGIN_PASSWORD", "SSH_PASSWORD", "INPUT_PASSWORD"},
|
||||||
},
|
},
|
||||||
cli.StringSliceFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "ciphers",
|
Name: "ciphers",
|
||||||
Usage: "The allowed cipher algorithms. If unspecified then a sensible",
|
Usage: "The allowed cipher algorithms. If unspecified then a sensible",
|
||||||
EnvVar: "PLUGIN_CIPHERS,SSH_CIPHERS,CIPHERS,INPUT_CIPHERS",
|
EnvVars: []string{"PLUGIN_CIPHERS", "SSH_CIPHERS", "INPUT_CIPHERS"},
|
||||||
},
|
},
|
||||||
cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "useInsecureCipher",
|
Name: "useInsecureCipher",
|
||||||
Usage: "include more ciphers with use_insecure_cipher",
|
Usage: "include more ciphers with use_insecure_cipher",
|
||||||
EnvVar: "PLUGIN_USE_INSECURE_CIPHER,SSH_USE_INSECURE_CIPHER,USE_INSECURE_CIPHER,INPUT_USE_INSECURE_CIPHER",
|
EnvVars: []string{"PLUGIN_USE_INSECURE_CIPHER", "SSH_USE_INSECURE_CIPHER", "INPUT_USE_INSECURE_CIPHER"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "fingerprint",
|
Name: "fingerprint",
|
||||||
Usage: "fingerprint SHA256 of the host public key, default is to skip verification",
|
Usage: "fingerprint SHA256 of the host public key, default is to skip verification",
|
||||||
EnvVar: "PLUGIN_FINGERPRINT,SSH_FINGERPRINT,FINGERPRINT,INPUT_FINGERPRINT",
|
EnvVars: []string{"PLUGIN_FINGERPRINT", "SSH_FINGERPRINT", "INPUT_FINGERPRINT"},
|
||||||
},
|
},
|
||||||
cli.StringSliceFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "host,H",
|
Name: "host",
|
||||||
|
Aliases: []string{"H"},
|
||||||
Usage: "connect to host",
|
Usage: "connect to host",
|
||||||
EnvVar: "PLUGIN_HOST,SSH_HOST,HOST,INPUT_HOST",
|
EnvVars: []string{"PLUGIN_HOST", "SSH_HOST", "INPUT_HOST"},
|
||||||
FilePath: ".host",
|
FilePath: ".host",
|
||||||
},
|
},
|
||||||
cli.IntFlag{
|
&cli.IntFlag{
|
||||||
Name: "port,p",
|
Name: "port",
|
||||||
Usage: "connect to port",
|
Aliases: []string{"p"},
|
||||||
EnvVar: "PLUGIN_PORT,SSH_PORT,PORT,INPUT_PORT",
|
Usage: "connect to port",
|
||||||
Value: 22,
|
EnvVars: []string{"PLUGIN_PORT", "SSH_PORT", "INPUT_PORT"},
|
||||||
|
Value: 22,
|
||||||
},
|
},
|
||||||
cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "sync",
|
Name: "sync",
|
||||||
Usage: "sync mode",
|
Usage: "sync mode",
|
||||||
EnvVar: "PLUGIN_SYNC,SYNC,INPUT_SYNC",
|
EnvVars: []string{"PLUGIN_SYNC", "INPUT_SYNC"},
|
||||||
},
|
},
|
||||||
cli.DurationFlag{
|
&cli.DurationFlag{
|
||||||
Name: "timeout,t",
|
Name: "timeout",
|
||||||
Usage: "connection timeout",
|
Aliases: []string{"t"},
|
||||||
EnvVar: "PLUGIN_TIMEOUT,SSH_TIMEOUT,TIMEOUT,INPUT_TIMEOUT",
|
Usage: "connection timeout",
|
||||||
Value: 30 * time.Second,
|
EnvVars: []string{"PLUGIN_TIMEOUT", "SSH_TIMEOUT", "INPUT_TIMEOUT"},
|
||||||
|
Value: 30 * time.Second,
|
||||||
},
|
},
|
||||||
cli.DurationFlag{
|
&cli.DurationFlag{
|
||||||
Name: "command.timeout,T",
|
Name: "command.timeout",
|
||||||
Usage: "command timeout",
|
Aliases: []string{"T"},
|
||||||
EnvVar: "PLUGIN_COMMAND_TIMEOUT,SSH_COMMAND_TIMEOUT,COMMAND_TIMEOUT,INPUT_COMMAND_TIMEOUT",
|
Usage: "command timeout",
|
||||||
Value: 10 * time.Minute,
|
EnvVars: []string{"PLUGIN_COMMAND_TIMEOUT", "SSH_COMMAND_TIMEOUT", "INPUT_COMMAND_TIMEOUT"},
|
||||||
|
Value: 10 * time.Minute,
|
||||||
},
|
},
|
||||||
cli.StringSliceFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "script,s",
|
Name: "script",
|
||||||
Usage: "execute commands",
|
Aliases: []string{"s"},
|
||||||
EnvVar: "PLUGIN_SCRIPT,SSH_SCRIPT,SCRIPT",
|
Usage: "execute commands",
|
||||||
|
EnvVars: []string{"PLUGIN_SCRIPT", "SSH_SCRIPT"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "script.string",
|
Name: "script.string",
|
||||||
Usage: "execute single commands for github action",
|
Usage: "execute single commands for github action",
|
||||||
EnvVar: "INPUT_SCRIPT",
|
EnvVars: []string{"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,INPUT_SCRIPT_STOP",
|
EnvVars: []string{"PLUGIN_SCRIPT_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,INPUT_PROXY_KEY",
|
EnvVars: []string{"PLUGIN_PROXY_SSH_KEY", "PLUGIN_PROXY_KEY", "PROXY_SSH_KEY", "INPUT_PROXY_KEY"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "proxy.ssh-passphrase",
|
Name: "proxy.ssh-passphrase",
|
||||||
Usage: "The purpose of the passphrase is usually to encrypt the private key.",
|
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",
|
EnvVars: []string{"PLUGIN_PROXY_SSH_PASSPHRASE", "PLUGIN_PROXY_PASSPHRASE", "PROXY_SSH_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,INPUT_PROXY_KEY_PATH",
|
EnvVars: []string{"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,INPUT_PROXY_USERNAME",
|
EnvVars: []string{"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,INPUT_PROXY_PASSWORD",
|
EnvVars: []string{"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,INPUT_PROXY_HOST",
|
EnvVars: []string{"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,INPUT_PROXY_PORT",
|
EnvVars: []string{"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,INPUT_PROXY_TIMEOUT",
|
EnvVars: []string{"PLUGIN_PROXY_TIMEOUT", "PROXY_SSH_TIMEOUT", "INPUT_PROXY_TIMEOUT"},
|
||||||
},
|
},
|
||||||
cli.StringSliceFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "proxy.ciphers",
|
Name: "proxy.ciphers",
|
||||||
Usage: "The allowed cipher algorithms. If unspecified then a sensible",
|
Usage: "The allowed cipher algorithms. If unspecified then a sensible",
|
||||||
EnvVar: "PLUGIN_PROXY_CIPHERS,SSH_PROXY_CIPHERS,PROXY_CIPHERS,INPUT_PROXY_CIPHERS",
|
EnvVars: []string{"PLUGIN_PROXY_CIPHERS", "PROXY_SSH_CIPHERS", "INPUT_PROXY_CIPHERS"},
|
||||||
},
|
},
|
||||||
cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "proxy.useInsecureCipher",
|
Name: "proxy.useInsecureCipher",
|
||||||
Usage: "include more ciphers with use_insecure_cipher",
|
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",
|
EnvVars: []string{"PLUGIN_PROXY_USE_INSECURE_CIPHER", "PROXY_SSH_USE_INSECURE_CIPHER", "INPUT_PROXY_USE_INSECURE_CIPHER"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "proxy.fingerprint",
|
Name: "proxy.fingerprint",
|
||||||
Usage: "fingerprint SHA256 of the host public key, default is to skip verification",
|
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",
|
EnvVars: []string{"PLUGIN_PROXY_FINGERPRINT", "PROXY_SSH_FINGERPRINT", "PROXY_FINGERPRINT", "INPUT_PROXY_FINGERPRINT"},
|
||||||
},
|
},
|
||||||
cli.StringSliceFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "envs",
|
Name: "envs",
|
||||||
Usage: "pass environment variable to shell script",
|
Usage: "pass environment variable to shell script",
|
||||||
EnvVar: "PLUGIN_ENVS,INPUT_ENVS",
|
EnvVars: []string{"PLUGIN_ENVS", "INPUT_ENVS"},
|
||||||
},
|
},
|
||||||
cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "debug",
|
Name: "debug",
|
||||||
Usage: "debug mode",
|
Usage: "debug mode",
|
||||||
EnvVar: "PLUGIN_DEBUG,DEBUG,INPUT_DEBUG",
|
EnvVars: []string{"PLUGIN_DEBUG", "INPUT_DEBUG"},
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "envs.format",
|
||||||
|
Usage: "flexible configuration of environment value transfer",
|
||||||
|
EnvVars: []string{"PLUGIN_ENVS_FORMAT", "INPUT_ENVS_FORMAT"},
|
||||||
|
Value: envsFormat,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,6 +247,7 @@ func run(c *cli.Context) error {
|
|||||||
if s := c.String("script.string"); s != "" {
|
if s := c.String("script.string"); s != "" {
|
||||||
scripts = append(scripts, s)
|
scripts = append(scripts, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin := Plugin{
|
plugin := Plugin{
|
||||||
Config: Config{
|
Config: Config{
|
||||||
Key: c.String("ssh-key"),
|
Key: c.String("ssh-key"),
|
||||||
@@ -248,6 +263,7 @@ func run(c *cli.Context) error {
|
|||||||
Script: scripts,
|
Script: scripts,
|
||||||
ScriptStop: c.Bool("script.stop"),
|
ScriptStop: c.Bool("script.stop"),
|
||||||
Envs: c.StringSlice("envs"),
|
Envs: c.StringSlice("envs"),
|
||||||
|
EnvsFormat: c.String("envs.format"),
|
||||||
Debug: c.Bool("debug"),
|
Debug: c.Bool("debug"),
|
||||||
Sync: c.Bool("sync"),
|
Sync: c.Bool("sync"),
|
||||||
Ciphers: c.StringSlice("ciphers"),
|
Ciphers: c.StringSlice("ciphers"),
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ var (
|
|||||||
errMissingHost = errors.New("Error: missing server host")
|
errMissingHost = errors.New("Error: missing server host")
|
||||||
errMissingPasswordOrKey = errors.New("Error: can't connect without a private SSH key or password")
|
errMissingPasswordOrKey = errors.New("Error: can't connect without a private SSH key or password")
|
||||||
errCommandTimeOut = errors.New("Error: command timeout")
|
errCommandTimeOut = errors.New("Error: command timeout")
|
||||||
errSetPasswordandKey = errors.New("can't set password and key at the same time")
|
envsFormat = "export {NAME}={VALUE}"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@@ -41,6 +41,7 @@ type (
|
|||||||
Sync bool
|
Sync bool
|
||||||
Ciphers []string
|
Ciphers []string
|
||||||
UseInsecureCipher bool
|
UseInsecureCipher bool
|
||||||
|
EnvsFormat string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Plugin structure
|
// Plugin structure
|
||||||
@@ -66,6 +67,7 @@ func (p Plugin) hostPort(host string) (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) {
|
||||||
|
defer wg.Done()
|
||||||
host, port := p.hostPort(host)
|
host, port := p.hostPort(host)
|
||||||
// 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{
|
||||||
@@ -103,7 +105,7 @@ func (p Plugin) exec(host string, wg *sync.WaitGroup, errChannel chan error) {
|
|||||||
for _, key := range p.Config.Envs {
|
for _, key := range p.Config.Envs {
|
||||||
key = strings.ToUpper(key)
|
key = strings.ToUpper(key)
|
||||||
if val, found := os.LookupEnv(key); found {
|
if val, found := os.LookupEnv(key); found {
|
||||||
env = append(env, key+"="+escapeArg(val))
|
env = append(env, p.format(p.Config.EnvsFormat, "{NAME}", key, "{VALUE}", escapeArg(val)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,38 +120,41 @@ func (p Plugin) exec(host string, wg *sync.WaitGroup, errChannel chan error) {
|
|||||||
stdoutChan, stderrChan, doneChan, errChan, err := ssh.Stream(strings.Join(p.Config.Script, "\n"), p.Config.CommandTimeout)
|
stdoutChan, stderrChan, doneChan, errChan, err := ssh.Stream(strings.Join(p.Config.Script, "\n"), p.Config.CommandTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errChannel <- err
|
errChannel <- err
|
||||||
} else {
|
return
|
||||||
// read from the output channel until the done signal is passed
|
}
|
||||||
isTimeout := true
|
// read from the output channel until the done signal is passed
|
||||||
loop:
|
isTimeout := true
|
||||||
for {
|
loop:
|
||||||
select {
|
for {
|
||||||
case isTimeout = <-doneChan:
|
select {
|
||||||
break loop
|
case isTimeout = <-doneChan:
|
||||||
case outline := <-stdoutChan:
|
break loop
|
||||||
if outline != "" {
|
case outline := <-stdoutChan:
|
||||||
p.log(host, "out:", outline)
|
if outline != "" {
|
||||||
}
|
p.log(host, "out:", outline)
|
||||||
case errline := <-stderrChan:
|
|
||||||
if errline != "" {
|
|
||||||
p.log(host, "err:", errline)
|
|
||||||
}
|
|
||||||
case err = <-errChan:
|
|
||||||
}
|
}
|
||||||
}
|
case errline := <-stderrChan:
|
||||||
|
if errline != "" {
|
||||||
// get exit code or command error.
|
p.log(host, "err:", errline)
|
||||||
if err != nil {
|
}
|
||||||
errChannel <- err
|
case err = <-errChan:
|
||||||
}
|
|
||||||
|
|
||||||
// command time out
|
|
||||||
if !isTimeout {
|
|
||||||
errChannel <- errCommandTimeOut
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wg.Done()
|
// get exit code or command error.
|
||||||
|
if err != nil {
|
||||||
|
errChannel <- err
|
||||||
|
}
|
||||||
|
|
||||||
|
// command time out
|
||||||
|
if !isTimeout {
|
||||||
|
errChannel <- errCommandTimeOut
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Plugin) format(format string, args ...string) string {
|
||||||
|
r := strings.NewReplacer(args...)
|
||||||
|
return r.Replace(format)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Plugin) log(host string, message ...interface{}) {
|
func (p Plugin) log(host string, message ...interface{}) {
|
||||||
@@ -165,6 +170,8 @@ func (p Plugin) log(host string, message ...interface{}) {
|
|||||||
|
|
||||||
// Exec executes the plugin.
|
// Exec executes the plugin.
|
||||||
func (p Plugin) Exec() error {
|
func (p Plugin) Exec() error {
|
||||||
|
p.Config.Host = trimValues(p.Config.Host)
|
||||||
|
|
||||||
if len(p.Config.Host) == 0 {
|
if len(p.Config.Host) == 0 {
|
||||||
return errMissingHost
|
return errMissingHost
|
||||||
}
|
}
|
||||||
@@ -173,18 +180,22 @@ func (p Plugin) Exec() error {
|
|||||||
return errMissingPasswordOrKey
|
return errMissingPasswordOrKey
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(p.Config.Key) != 0 && len(p.Config.Password) != 0 {
|
if p.Config.EnvsFormat == "" {
|
||||||
return errSetPasswordandKey
|
p.Config.EnvsFormat = envsFormat
|
||||||
}
|
}
|
||||||
|
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
wg.Add(len(p.Config.Host))
|
wg.Add(len(p.Config.Host))
|
||||||
errChannel := make(chan error)
|
errChannel := make(chan error)
|
||||||
finished := make(chan struct{})
|
finished := make(chan struct{})
|
||||||
for _, host := range p.Config.Host {
|
if p.Config.Sync {
|
||||||
if p.Config.Sync {
|
go func() {
|
||||||
p.exec(host, &wg, errChannel)
|
for _, host := range p.Config.Host {
|
||||||
} else {
|
p.exec(host, &wg, errChannel)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
} else {
|
||||||
|
for _, host := range p.Config.Host {
|
||||||
go p.exec(host, &wg, errChannel)
|
go p.exec(host, &wg, errChannel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -235,3 +246,18 @@ func (p Plugin) scriptCommands() []string {
|
|||||||
|
|
||||||
return commands
|
return commands
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func trimValues(keys []string) []string {
|
||||||
|
var newKeys []string
|
||||||
|
|
||||||
|
for _, value := range keys {
|
||||||
|
value = strings.TrimSpace(value)
|
||||||
|
if len(value) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
newKeys = append(newKeys, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
return newKeys
|
||||||
|
}
|
||||||
|
|||||||
+42
-24
@@ -38,23 +38,6 @@ func TestMissingKeyOrPassword(t *testing.T) {
|
|||||||
assert.Equal(t, errMissingPasswordOrKey, err)
|
assert.Equal(t, errMissingPasswordOrKey, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetPasswordAndKey(t *testing.T) {
|
|
||||||
plugin := Plugin{
|
|
||||||
Config{
|
|
||||||
Host: []string{"localhost"},
|
|
||||||
Username: "ubuntu",
|
|
||||||
Password: "1234",
|
|
||||||
Key: "1234",
|
|
||||||
},
|
|
||||||
os.Stdout,
|
|
||||||
}
|
|
||||||
|
|
||||||
err := plugin.Exec()
|
|
||||||
|
|
||||||
assert.NotNil(t, err)
|
|
||||||
assert.Equal(t, errSetPasswordandKey, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestIncorrectPassword(t *testing.T) {
|
func TestIncorrectPassword(t *testing.T) {
|
||||||
plugin := Plugin{
|
plugin := Plugin{
|
||||||
Config: Config{
|
Config: Config{
|
||||||
@@ -457,6 +440,41 @@ func TestFingerprint(t *testing.T) {
|
|||||||
assert.Equal(t, unindent(expected), unindent(buffer.String()))
|
assert.Equal(t, unindent(expected), unindent(buffer.String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestScriptStopWithMultipleHostAndSyncMode(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
|
||||||
|
`
|
||||||
|
)
|
||||||
|
|
||||||
|
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,
|
||||||
|
ScriptStop: true,
|
||||||
|
Sync: true,
|
||||||
|
},
|
||||||
|
Writer: &buffer,
|
||||||
|
}
|
||||||
|
|
||||||
|
err := plugin.Exec()
|
||||||
|
assert.NotNil(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
|
||||||
@@ -539,13 +557,13 @@ func TestEnvOutput(t *testing.T) {
|
|||||||
echo "[${ENV_7}]"
|
echo "[${ENV_7}]"
|
||||||
======END======
|
======END======
|
||||||
======ENV======
|
======ENV======
|
||||||
ENV_1='test'
|
export ENV_1='test'
|
||||||
ENV_2='test test'
|
export ENV_2='test test'
|
||||||
ENV_3='test '
|
export ENV_3='test '
|
||||||
ENV_4=' test test '
|
export ENV_4=' test test '
|
||||||
ENV_5='test'\'''
|
export ENV_5='test'\'''
|
||||||
ENV_6='test"'
|
export ENV_6='test"'
|
||||||
ENV_7='test,!#;?.@$~'\''"'
|
export ENV_7='test,!#;?.@$~'\''"'
|
||||||
======END======
|
======END======
|
||||||
out: [test]
|
out: [test]
|
||||||
out: [test test]
|
out: [test test]
|
||||||
|
|||||||
Reference in New Issue
Block a user