mirror of
https://github.com/appleboy/drone-ssh.git
synced 2026-06-16 14:49:25 +08:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1efc71c743 |
@@ -0,0 +1,16 @@
|
|||||||
|
local pipeline = import 'pipeline.libsonnet';
|
||||||
|
local name = 'drone-ssh';
|
||||||
|
|
||||||
|
[
|
||||||
|
pipeline.test,
|
||||||
|
pipeline.build(name, 'linux', 'amd64'),
|
||||||
|
pipeline.build(name, 'linux', 'arm64'),
|
||||||
|
pipeline.build(name, 'linux', 'arm'),
|
||||||
|
pipeline.release,
|
||||||
|
pipeline.notifications(depends_on=[
|
||||||
|
'linux-amd64',
|
||||||
|
'linux-arm64',
|
||||||
|
'linux-arm',
|
||||||
|
'release-binary',
|
||||||
|
]),
|
||||||
|
]
|
||||||
+298
@@ -0,0 +1,298 @@
|
|||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
name: testing
|
||||||
|
platform:
|
||||||
|
arch: amd64
|
||||||
|
os: linux
|
||||||
|
steps:
|
||||||
|
- commands:
|
||||||
|
- make vet
|
||||||
|
image: golang:1.18
|
||||||
|
name: vet
|
||||||
|
pull: always
|
||||||
|
volumes:
|
||||||
|
- name: gopath
|
||||||
|
path: /go
|
||||||
|
- image: robertstettner/drone-codecov
|
||||||
|
name: codecov
|
||||||
|
pull: always
|
||||||
|
settings:
|
||||||
|
token:
|
||||||
|
from_secret: codecov_token
|
||||||
|
volumes:
|
||||||
|
- name: gopath
|
||||||
|
temp: {}
|
||||||
|
---
|
||||||
|
depends_on:
|
||||||
|
- testing
|
||||||
|
kind: pipeline
|
||||||
|
name: linux-amd64
|
||||||
|
platform:
|
||||||
|
arch: amd64
|
||||||
|
os: linux
|
||||||
|
steps:
|
||||||
|
- commands:
|
||||||
|
- go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/amd64/drone-ssh
|
||||||
|
environment:
|
||||||
|
CGO_ENABLED: "0"
|
||||||
|
image: golang:1.18
|
||||||
|
name: build-push
|
||||||
|
pull: always
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
exclude:
|
||||||
|
- tag
|
||||||
|
- commands:
|
||||||
|
- go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}'
|
||||||
|
-a -o release/linux/amd64/drone-ssh
|
||||||
|
environment:
|
||||||
|
CGO_ENABLED: "0"
|
||||||
|
image: golang:1.18
|
||||||
|
name: build-tag
|
||||||
|
pull: always
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- tag
|
||||||
|
- commands:
|
||||||
|
- ./release/linux/amd64/drone-ssh --help
|
||||||
|
image: golang:1.18
|
||||||
|
name: executable
|
||||||
|
pull: always
|
||||||
|
- image: plugins/docker:linux-amd64
|
||||||
|
name: dryrun
|
||||||
|
pull: always
|
||||||
|
settings:
|
||||||
|
cache_from: appleboy/drone-ssh
|
||||||
|
daemon_off: false
|
||||||
|
dockerfile: docker/Dockerfile.linux.amd64
|
||||||
|
dry_run: true
|
||||||
|
repo: appleboy/drone-ssh
|
||||||
|
tags: linux-amd64
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- pull_request
|
||||||
|
- image: plugins/docker:linux-amd64
|
||||||
|
name: publish
|
||||||
|
pull: always
|
||||||
|
settings:
|
||||||
|
auto_tag: true
|
||||||
|
auto_tag_suffix: linux-amd64
|
||||||
|
cache_from: appleboy/drone-ssh
|
||||||
|
daemon_off: "false"
|
||||||
|
dockerfile: docker/Dockerfile.linux.amd64
|
||||||
|
password:
|
||||||
|
from_secret: docker_password
|
||||||
|
repo: appleboy/drone-ssh
|
||||||
|
username:
|
||||||
|
from_secret: docker_username
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
exclude:
|
||||||
|
- pull_request
|
||||||
|
trigger:
|
||||||
|
ref:
|
||||||
|
- refs/heads/master
|
||||||
|
- refs/pull/**
|
||||||
|
- refs/tags/**
|
||||||
|
---
|
||||||
|
depends_on:
|
||||||
|
- testing
|
||||||
|
kind: pipeline
|
||||||
|
name: linux-arm64
|
||||||
|
platform:
|
||||||
|
arch: arm64
|
||||||
|
os: linux
|
||||||
|
steps:
|
||||||
|
- commands:
|
||||||
|
- go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm64/drone-ssh
|
||||||
|
environment:
|
||||||
|
CGO_ENABLED: "0"
|
||||||
|
image: golang:1.18
|
||||||
|
name: build-push
|
||||||
|
pull: always
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
exclude:
|
||||||
|
- tag
|
||||||
|
- commands:
|
||||||
|
- go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}'
|
||||||
|
-a -o release/linux/arm64/drone-ssh
|
||||||
|
environment:
|
||||||
|
CGO_ENABLED: "0"
|
||||||
|
image: golang:1.18
|
||||||
|
name: build-tag
|
||||||
|
pull: always
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- tag
|
||||||
|
- commands:
|
||||||
|
- ./release/linux/arm64/drone-ssh --help
|
||||||
|
image: golang:1.18
|
||||||
|
name: executable
|
||||||
|
pull: always
|
||||||
|
- image: plugins/docker:linux-arm64
|
||||||
|
name: dryrun
|
||||||
|
pull: always
|
||||||
|
settings:
|
||||||
|
cache_from: appleboy/drone-ssh
|
||||||
|
daemon_off: false
|
||||||
|
dockerfile: docker/Dockerfile.linux.arm64
|
||||||
|
dry_run: true
|
||||||
|
repo: appleboy/drone-ssh
|
||||||
|
tags: linux-arm64
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- pull_request
|
||||||
|
- image: plugins/docker:linux-arm64
|
||||||
|
name: publish
|
||||||
|
pull: always
|
||||||
|
settings:
|
||||||
|
auto_tag: true
|
||||||
|
auto_tag_suffix: linux-arm64
|
||||||
|
cache_from: appleboy/drone-ssh
|
||||||
|
daemon_off: "false"
|
||||||
|
dockerfile: docker/Dockerfile.linux.arm64
|
||||||
|
password:
|
||||||
|
from_secret: docker_password
|
||||||
|
repo: appleboy/drone-ssh
|
||||||
|
username:
|
||||||
|
from_secret: docker_username
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
exclude:
|
||||||
|
- pull_request
|
||||||
|
trigger:
|
||||||
|
ref:
|
||||||
|
- refs/heads/master
|
||||||
|
- refs/pull/**
|
||||||
|
- refs/tags/**
|
||||||
|
---
|
||||||
|
depends_on:
|
||||||
|
- testing
|
||||||
|
kind: pipeline
|
||||||
|
name: linux-arm
|
||||||
|
platform:
|
||||||
|
arch: arm
|
||||||
|
os: linux
|
||||||
|
steps:
|
||||||
|
- commands:
|
||||||
|
- go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm/drone-ssh
|
||||||
|
environment:
|
||||||
|
CGO_ENABLED: "0"
|
||||||
|
image: golang:1.18
|
||||||
|
name: build-push
|
||||||
|
pull: always
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
exclude:
|
||||||
|
- tag
|
||||||
|
- commands:
|
||||||
|
- go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}'
|
||||||
|
-a -o release/linux/arm/drone-ssh
|
||||||
|
environment:
|
||||||
|
CGO_ENABLED: "0"
|
||||||
|
image: golang:1.18
|
||||||
|
name: build-tag
|
||||||
|
pull: always
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- tag
|
||||||
|
- commands:
|
||||||
|
- ./release/linux/arm/drone-ssh --help
|
||||||
|
image: golang:1.18
|
||||||
|
name: executable
|
||||||
|
pull: always
|
||||||
|
- image: plugins/docker:linux-arm
|
||||||
|
name: dryrun
|
||||||
|
pull: always
|
||||||
|
settings:
|
||||||
|
cache_from: appleboy/drone-ssh
|
||||||
|
daemon_off: false
|
||||||
|
dockerfile: docker/Dockerfile.linux.arm
|
||||||
|
dry_run: true
|
||||||
|
repo: appleboy/drone-ssh
|
||||||
|
tags: linux-arm
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- pull_request
|
||||||
|
- image: plugins/docker:linux-arm
|
||||||
|
name: publish
|
||||||
|
pull: always
|
||||||
|
settings:
|
||||||
|
auto_tag: true
|
||||||
|
auto_tag_suffix: linux-arm
|
||||||
|
cache_from: appleboy/drone-ssh
|
||||||
|
daemon_off: "false"
|
||||||
|
dockerfile: docker/Dockerfile.linux.arm
|
||||||
|
password:
|
||||||
|
from_secret: docker_password
|
||||||
|
repo: appleboy/drone-ssh
|
||||||
|
username:
|
||||||
|
from_secret: docker_username
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
exclude:
|
||||||
|
- pull_request
|
||||||
|
trigger:
|
||||||
|
ref:
|
||||||
|
- refs/heads/master
|
||||||
|
- refs/pull/**
|
||||||
|
- refs/tags/**
|
||||||
|
---
|
||||||
|
depends_on:
|
||||||
|
- testing
|
||||||
|
kind: pipeline
|
||||||
|
name: release-binary
|
||||||
|
platform:
|
||||||
|
arch: amd64
|
||||||
|
os: linux
|
||||||
|
steps:
|
||||||
|
- commands:
|
||||||
|
- export PATH=$PATH:$GOPATH/bin
|
||||||
|
- make release
|
||||||
|
image: techknowlogick/xgo:go-1.18.x
|
||||||
|
name: build-all-binary
|
||||||
|
pull: always
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- tag
|
||||||
|
- image: plugins/github-release
|
||||||
|
name: deploy-all-binary
|
||||||
|
pull: always
|
||||||
|
settings:
|
||||||
|
api_key:
|
||||||
|
from_secret: github_release_api_key
|
||||||
|
files:
|
||||||
|
- dist/release/*
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- tag
|
||||||
|
trigger:
|
||||||
|
ref:
|
||||||
|
- refs/tags/**
|
||||||
|
---
|
||||||
|
depends_on:
|
||||||
|
- linux-amd64
|
||||||
|
- linux-arm64
|
||||||
|
- linux-arm
|
||||||
|
- release-binary
|
||||||
|
kind: pipeline
|
||||||
|
name: notifications
|
||||||
|
platform:
|
||||||
|
arch: amd64
|
||||||
|
os: linux
|
||||||
|
steps:
|
||||||
|
- image: plugins/manifest
|
||||||
|
name: manifest
|
||||||
|
pull: always
|
||||||
|
settings:
|
||||||
|
ignore_missing: true
|
||||||
|
password:
|
||||||
|
from_secret: docker_password
|
||||||
|
spec: docker/manifest.tmpl
|
||||||
|
username:
|
||||||
|
from_secret: docker_username
|
||||||
|
trigger:
|
||||||
|
ref:
|
||||||
|
- refs/heads/master
|
||||||
|
- refs/tags/**
|
||||||
@@ -13,12 +13,12 @@ name: "CodeQL"
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [master]
|
branches: [ master ]
|
||||||
pull_request:
|
pull_request:
|
||||||
# The branches below must be a subset of the branches above
|
# The branches below must be a subset of the branches above
|
||||||
branches: [master]
|
branches: [ master ]
|
||||||
schedule:
|
schedule:
|
||||||
- cron: "41 23 * * 6"
|
- cron: '41 23 * * 6'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
analyze:
|
analyze:
|
||||||
@@ -32,23 +32,23 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
language: ["go"]
|
language: [ 'go' ]
|
||||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
||||||
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@v2
|
uses: github/codeql-action/init@v2
|
||||||
with:
|
with:
|
||||||
languages: ${{ matrix.language }}
|
languages: ${{ matrix.language }}
|
||||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||||
# By default, queries listed here will override any specified in a config file.
|
# By default, queries listed here will override any specified in a config file.
|
||||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||||
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@v2
|
uses: github/codeql-action/analyze@v2
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
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.21"
|
|
||||||
- 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 }}
|
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
name: Run Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lint:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Setup go
|
||||||
|
uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: '^1'
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Setup golangci-lint
|
||||||
|
uses: golangci/golangci-lint-action@v3
|
||||||
|
with:
|
||||||
|
version: v1.46.2
|
||||||
|
args: --verbose
|
||||||
|
|
||||||
|
# build:
|
||||||
|
# strategy:
|
||||||
|
# matrix:
|
||||||
|
# os: [ubuntu-latest]
|
||||||
|
# go: [ 1.18]
|
||||||
|
# include:
|
||||||
|
# - os: ubuntu-latest
|
||||||
|
# go-build: ~/.cache/go-build
|
||||||
|
# name: ${{ matrix.os }} @ Go ${{ matrix.go }}
|
||||||
|
# runs-on: ${{ matrix.os }}
|
||||||
|
# env:
|
||||||
|
# GO111MODULE: on
|
||||||
|
# GOPROXY: https://proxy.golang.org
|
||||||
|
# steps:
|
||||||
|
# - name: Set up Go ${{ matrix.go }}
|
||||||
|
# uses: actions/setup-go@v3
|
||||||
|
# with:
|
||||||
|
# go-version: ${{ matrix.go }}
|
||||||
|
|
||||||
|
# - name: Checkout Code
|
||||||
|
# uses: actions/checkout@v3
|
||||||
|
# with:
|
||||||
|
# ref: ${{ github.ref }}
|
||||||
|
|
||||||
|
# - uses: actions/cache@v3
|
||||||
|
# with:
|
||||||
|
# path: |
|
||||||
|
# ${{ matrix.go-build }}
|
||||||
|
# ~/go/pkg/mod
|
||||||
|
# key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||||
|
# restore-keys: |
|
||||||
|
# ${{ runner.os }}-go-
|
||||||
|
# - name: initial docker
|
||||||
|
# uses: docker-practice/actions-setup-docker@master
|
||||||
|
# - name: build all binaries
|
||||||
|
# run: |
|
||||||
|
# set -x
|
||||||
|
# make release
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
name: Goreleaser
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- "*"
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
goreleaser:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
- name: Setup go
|
|
||||||
uses: actions/setup-go@v4
|
|
||||||
with:
|
|
||||||
go-version: "^1"
|
|
||||||
|
|
||||||
- name: Run GoReleaser
|
|
||||||
uses: goreleaser/goreleaser-action@v4
|
|
||||||
with:
|
|
||||||
# either 'goreleaser' (default) or 'goreleaser-pro'
|
|
||||||
distribution: goreleaser
|
|
||||||
version: latest
|
|
||||||
args: release --rm-dist
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
name: Lint and Testing
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
pull_request:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
lint:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Setup go
|
|
||||||
uses: actions/setup-go@v4
|
|
||||||
with:
|
|
||||||
go-version: "^1.21"
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: Setup golangci-lint
|
|
||||||
uses: golangci/golangci-lint-action@v3
|
|
||||||
with:
|
|
||||||
version: latest
|
|
||||||
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.21-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 sudo
|
|
||||||
make ssh-server
|
|
||||||
|
|
||||||
- name: testing
|
|
||||||
run: |
|
|
||||||
make test
|
|
||||||
|
|
||||||
- name: Upload coverage to Codecov
|
|
||||||
uses: codecov/codecov-action@v3
|
|
||||||
@@ -29,4 +29,3 @@ release
|
|||||||
drone-ssh
|
drone-ssh
|
||||||
.cover
|
.cover
|
||||||
dist
|
dist
|
||||||
bin
|
|
||||||
|
|||||||
@@ -1,99 +0,0 @@
|
|||||||
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
|
|
||||||
hooks:
|
|
||||||
post:
|
|
||||||
- cmd: xz -k -9 {{ .Path }}
|
|
||||||
dir: ./dist/
|
|
||||||
|
|
||||||
archives:
|
|
||||||
- format: binary
|
|
||||||
name_template: "{{ .Binary }}"
|
|
||||||
allow_different_binary_count: true
|
|
||||||
|
|
||||||
checksum:
|
|
||||||
name_template: 'checksums.txt'
|
|
||||||
extra_files:
|
|
||||||
- glob: ./**.xz
|
|
||||||
|
|
||||||
snapshot:
|
|
||||||
name_template: "{{ incpatch .Version }}"
|
|
||||||
|
|
||||||
release:
|
|
||||||
# You can add extra pre-existing files to the release.
|
|
||||||
# The filename on the release will be the last part of the path (base).
|
|
||||||
# If another file with the same name exists, the last one found will be used.
|
|
||||||
#
|
|
||||||
# Templates: allowed
|
|
||||||
extra_files:
|
|
||||||
- glob: ./**.xz
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
ignored:
|
|
||||||
- DL3018
|
|
||||||
- DL3008
|
|
||||||
@@ -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: ghcr.io/appleboy/drone-ssh
|
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
|
||||||
- name: ssh commands
|
- name: ssh commands
|
||||||
image: ghcr.io/appleboy/drone-ssh
|
image: 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: ghcr.io/appleboy/drone-ssh
|
image: 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: ghcr.io/appleboy/drone-ssh
|
image: 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: ghcr.io/appleboy/drone-ssh
|
image: 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: ghcr.io/appleboy/drone-ssh
|
image: 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: ghcr.io/appleboy/drone-ssh
|
image: 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: ghcr.io/appleboy/drone-ssh
|
image: appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host: foo.com
|
host: foo.com
|
||||||
username: root
|
username: root
|
||||||
@@ -128,28 +128,27 @@ Example configuration for exporting custom secrets:
|
|||||||
|
|
||||||
```diff
|
```diff
|
||||||
- name: ssh commands
|
- name: ssh commands
|
||||||
image: ghcr.io/appleboy/drone-ssh
|
image: appleboy/drone-ssh
|
||||||
environment:
|
environment:
|
||||||
# MUST BE in UPPERCASE
|
commit: ${DRONE_BUILD_NUMBER}
|
||||||
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:
|
||||||
# can be in lowercase (uppercased in code)
|
- aws_access_key_id
|
||||||
- commit
|
- commit
|
||||||
script:
|
script:
|
||||||
- echo $COMMIT
|
- export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
|
||||||
|
- 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: ghcr.io/appleboy/drone-ssh
|
image: appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host: foo.com
|
host: foo.com
|
||||||
username: root
|
username: root
|
||||||
@@ -165,7 +164,7 @@ Example configuration for passphrase which protecting a private key:
|
|||||||
|
|
||||||
```diff
|
```diff
|
||||||
- name: ssh commands
|
- name: ssh commands
|
||||||
image: ghcr.io/appleboy/drone-ssh
|
image: appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host: foo.com
|
host: foo.com
|
||||||
username: root
|
username: root
|
||||||
@@ -178,56 +177,81 @@ Example configuration for passphrase which protecting a private key:
|
|||||||
- echo "you can't see the steps."
|
- echo "you can't see the steps."
|
||||||
```
|
```
|
||||||
|
|
||||||
Example configuration for forcing protocol to IPv4 only:
|
|
||||||
|
|
||||||
```diff
|
|
||||||
- name: ssh commands
|
|
||||||
image: ghcr.io/appleboy/drone-ssh
|
|
||||||
settings:
|
|
||||||
host: foo.com
|
|
||||||
username: root
|
|
||||||
password: 1234
|
|
||||||
port: 22
|
|
||||||
+ protocol: tcp4
|
|
||||||
script:
|
|
||||||
- echo hello
|
|
||||||
- echo world
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## Secret Reference
|
## Secret Reference
|
||||||
|
|
||||||
| Key | Description |
|
ssh_username
|
||||||
|-----|-------------|
|
: account for target host user
|
||||||
| `ssh_username` | account for target host user |
|
|
||||||
| `ssh_password` | password for target host user | |
|
ssh_password
|
||||||
| `ssh_passphrase` | The purpose of the passphrase is usually to encrypt the private key. |
|
: password for target host user
|
||||||
| `ssh_key` | plain text of user private key |
|
|
||||||
| `proxy_ssh_username` | account for user of proxy server |
|
ssh_passphrase
|
||||||
| `proxy_ssh_password` | password for user of proxy server |
|
: The purpose of the passphrase is usually to encrypt the private key.
|
||||||
| `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 |
|
ssh_key
|
||||||
|
: 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
|
||||||
|
|
||||||
| Key | Description |
|
host
|
||||||
|-----|-------------|
|
: target hostname or IP
|
||||||
| `host` | target hostname or IP |
|
|
||||||
| `port` | ssh port of target host |
|
port
|
||||||
| `protocol` | IP protocol to use: either tcp, tcp4 or tcp6 |
|
: 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_protocol` | IP protocol to use for the proxy: either tcp, tcp4 or tcp6 |
|
: key path of user private key
|
||||||
| `proxy_username` | account for proxy host user |
|
|
||||||
| `proxy_password` | password for proxy host user |
|
envs
|
||||||
| `proxy_key` | plain text of proxy private key |
|
: custom secrets which are made available in the script section
|
||||||
| `proxy_key_path` | key path of proxy private key |
|
|
||||||
|
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,19 +1,18 @@
|
|||||||
DIST := dist
|
DIST := dist
|
||||||
EXECUTABLE := drone-ssh
|
EXECUTABLE := drone-ssh
|
||||||
GOFMT ?= gofumpt -l
|
GOFMT ?= gofumpt -l -s
|
||||||
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.19.x
|
XGO_VERSION := go-1.18.x
|
||||||
GXZ_PAGAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.11
|
GXZ_PAGAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.10
|
||||||
|
|
||||||
LINUX_ARCHS ?= linux/amd64,linux/arm64
|
LINUX_ARCHS ?= linux/amd64,linux/arm64
|
||||||
DARWIN_ARCHS ?= darwin-10.12/amd64,darwin-10.12/arm64
|
DARWIN_ARCHS ?= darwin-12/amd64,darwin-12/arm64
|
||||||
WINDOWS_ARCHS ?= windows/*
|
WINDOWS_ARCHS ?= windows/amd64
|
||||||
|
|
||||||
ifneq ($(shell uname), Darwin)
|
ifneq ($(shell uname), Darwin)
|
||||||
EXTLDFLAGS = -extldflags "-static" $(null)
|
EXTLDFLAGS = -extldflags "-static" $(null)
|
||||||
@@ -40,10 +39,24 @@ else
|
|||||||
EXECUTABLE ?= $(EXECUTABLE)
|
EXECUTABLE ?= $(EXECUTABLE)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
STORED_VERSION_FILE := VERSION
|
||||||
|
|
||||||
ifneq ($(DRONE_TAG),)
|
ifneq ($(DRONE_TAG),)
|
||||||
VERSION ?= $(DRONE_TAG)
|
VERSION ?= $(subst v,,$(DRONE_TAG))
|
||||||
|
RELASE_VERSION ?= $(VERSION)
|
||||||
else
|
else
|
||||||
VERSION ?= $(shell git describe --tags --always || git rev-parse --short HEAD)
|
ifneq ($(DRONE_BRANCH),)
|
||||||
|
VERSION ?= $(subst release/v,,$(DRONE_BRANCH))
|
||||||
|
else
|
||||||
|
VERSION ?= master
|
||||||
|
endif
|
||||||
|
|
||||||
|
STORED_VERSION=$(shell cat $(STORED_VERSION_FILE) 2>/dev/null)
|
||||||
|
ifneq ($(STORED_VERSION),)
|
||||||
|
RELASE_VERSION ?= $(STORED_VERSION)
|
||||||
|
else
|
||||||
|
RELASE_VERSION ?= $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
TAGS ?=
|
TAGS ?=
|
||||||
@@ -53,9 +66,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) install mvdan.cc/gofumpt; \
|
$(GO) get -u mvdan.cc/gofumpt; \
|
||||||
fi
|
fi
|
||||||
$(GOFMT) -w $(GOFILES)
|
$(GOFMT) -w $(SOURCES)
|
||||||
|
|
||||||
vet:
|
vet:
|
||||||
$(GO) vet ./...
|
$(GO) vet ./...
|
||||||
@@ -63,25 +76,25 @@ 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) install mvdan.cc/gofumpt; \
|
$(GO) get -u mvdan.cc/gofumpt; \
|
||||||
fi
|
fi
|
||||||
@diff=$$($(GOFMT) -d $(GOFILES)); \
|
@diff=$$($(GOFMT) -d $(SOURCES)); \
|
||||||
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:
|
test: fmt-check
|
||||||
@$(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: $(GOFILES)
|
install: $(SOURCES)
|
||||||
$(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): $(GOFILES)
|
$(EXECUTABLE): $(SOURCES)
|
||||||
$(GO) build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o bin/$@
|
$(GO) build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o $@
|
||||||
|
|
||||||
build_linux_amd64:
|
build_linux_amd64:
|
||||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/amd64/$(DEPLOY_IMAGE)
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/amd64/$(DEPLOY_IMAGE)
|
||||||
@@ -104,15 +117,6 @@ ssh-server:
|
|||||||
cat tests/.ssh/test.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
|
chmod 600 /home/drone-scp/.ssh/authorized_keys
|
||||||
chown -R drone-scp /home/drone-scp/.ssh
|
chown -R drone-scp /home/drone-scp/.ssh
|
||||||
# add public key to root user
|
|
||||||
mkdir -p /root/.ssh
|
|
||||||
chmod 700 /root/.ssh
|
|
||||||
cat tests/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
|
|
||||||
cat tests/.ssh/test.pub >> /root/.ssh/authorized_keys
|
|
||||||
chmod 600 /root/.ssh/authorized_keys
|
|
||||||
# Append the following entry to run ALL command without a password for a user named drone-scp:
|
|
||||||
cat tests/sudoers >> /etc/sudoers.d/sudoers
|
|
||||||
# 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/^#PubkeyAuthentication yes/PubkeyAuthentication yes/g' /etc/ssh/sshd_config
|
||||||
@@ -129,7 +133,7 @@ deps-backend:
|
|||||||
$(GO) install $(XGO_PACKAGE)
|
$(GO) install $(XGO_PACKAGE)
|
||||||
|
|
||||||
.PHONY: release
|
.PHONY: release
|
||||||
release: release-linux release-darwin release-windows release-copy release-compress release-check
|
release: release-windows release-linux release-darwin release-copy release-compress release-check
|
||||||
|
|
||||||
$(DIST_DIRS):
|
$(DIST_DIRS):
|
||||||
mkdir -p $(DIST_DIRS)
|
mkdir -p $(DIST_DIRS)
|
||||||
|
|||||||
@@ -4,10 +4,11 @@
|
|||||||
|
|
||||||
[](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://github.com/appleboy/drone-ssh/actions/workflows/lint.yml)
|
[](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")
|
||||||
|
|
||||||
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/).
|
||||||
@@ -23,7 +24,7 @@ information and a listing of the available options please take a look at [the do
|
|||||||
```diff
|
```diff
|
||||||
pipeline:
|
pipeline:
|
||||||
scp:
|
scp:
|
||||||
image: ghcr.io/appleboy/drone-ssh
|
image: appleboy/drone-scp
|
||||||
settings:
|
settings:
|
||||||
host:
|
host:
|
||||||
- example1.com
|
- example1.com
|
||||||
@@ -49,7 +50,7 @@ The pre-compiled binaries can be downloaded from [release page](https://github.c
|
|||||||
With `Go` installed
|
With `Go` installed
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
go install github.com/appleboy/drone-ssh@latest
|
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:
|
||||||
@@ -85,7 +86,7 @@ docker run --rm \
|
|||||||
-e PLUGIN_SCRIPT=whoami \
|
-e PLUGIN_SCRIPT=whoami \
|
||||||
-v $(pwd):$(pwd) \
|
-v $(pwd):$(pwd) \
|
||||||
-w $(pwd) \
|
-w $(pwd) \
|
||||||
ghcr.io/appleboy/drone-ssh
|
appleboy/drone-ssh
|
||||||
```
|
```
|
||||||
|
|
||||||
## Mount key from file path
|
## Mount key from file path
|
||||||
@@ -99,7 +100,7 @@ Mount private key in `volumes` setting of `.drone.yml` config
|
|||||||
```diff
|
```diff
|
||||||
pipeline:
|
pipeline:
|
||||||
ssh:
|
ssh:
|
||||||
image: ghcr.io/appleboy/drone-ssh
|
image: appleboy/drone-ssh
|
||||||
host: xxxxx.com
|
host: xxxxx.com
|
||||||
username: deploy
|
username: deploy
|
||||||
+ volumes:
|
+ volumes:
|
||||||
@@ -110,15 +111,3 @@ 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`.
|
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
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 && \
|
|
||||||
rm -rf /var/cache/apk/*
|
|
||||||
|
|
||||||
RUN addgroup \
|
|
||||||
-S -g 1000 \
|
|
||||||
deploy && \
|
|
||||||
adduser \
|
|
||||||
-S -H -D \
|
|
||||||
-h /home/deploy \
|
|
||||||
-s /bin/sh \
|
|
||||||
-u 1000 \
|
|
||||||
-G deploy \
|
|
||||||
deploy
|
|
||||||
|
|
||||||
RUN mkdir -p /home/deploy && \
|
|
||||||
chown deploy:deploy /home/deploy
|
|
||||||
|
|
||||||
# deploy:deploy
|
|
||||||
USER 1000:1000
|
|
||||||
|
|
||||||
COPY release/${TARGETOS}/${TARGETARCH}/drone-ssh /bin/
|
|
||||||
|
|
||||||
ENTRYPOINT ["/bin/drone-ssh"]
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
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/*
|
||||||
|
|
||||||
|
ADD release/linux/amd64/drone-ssh /bin/
|
||||||
|
ENTRYPOINT ["/bin/drone-ssh"]
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
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/*
|
||||||
|
|
||||||
|
ADD release/linux/arm/drone-ssh /bin/
|
||||||
|
ENTRYPOINT ["/bin/drone-ssh"]
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
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/*
|
||||||
|
|
||||||
|
ADD release/linux/arm64/drone-ssh /bin/
|
||||||
|
ENTRYPOINT ["/bin/drone-ssh"]
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
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" ]
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
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,21 +3,20 @@ module github.com/appleboy/drone-ssh
|
|||||||
go 1.18
|
go 1.18
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/appleboy/easyssh-proxy v1.5.0
|
github.com/appleboy/easyssh-proxy v1.3.9
|
||||||
github.com/joho/godotenv v1.5.1
|
github.com/joho/godotenv v1.4.0
|
||||||
github.com/stretchr/testify v1.8.4
|
github.com/stretchr/testify v1.7.2
|
||||||
github.com/urfave/cli/v2 v2.27.1
|
github.com/urfave/cli v1.22.9
|
||||||
golang.org/x/crypto v0.17.0
|
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/ScaleFT/sshkeys v1.2.0 // indirect
|
github.com/ScaleFT/sshkeys v0.0.0-20200327173127-6142f742bca5 // indirect
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
|
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.0 // indirect
|
||||||
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
|
||||||
github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e // indirect
|
golang.org/x/sys v0.0.0-20220614162138-6c1b26c55098 // indirect
|
||||||
golang.org/x/sys v0.16.0 // indirect
|
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,42 +1,48 @@
|
|||||||
github.com/ScaleFT/sshkeys v1.2.0 h1:5BRp6rTVIhJzXT3VcUQrKgXR8zWA3sOsNeuyW15WUA8=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/ScaleFT/sshkeys v1.2.0/go.mod h1:gxOHeajFfvGQh/fxlC8oOKBe23xnnJTif00IFFbiT+o=
|
github.com/ScaleFT/sshkeys v0.0.0-20200327173127-6142f742bca5 h1:VauE2GcJNZFun2Och6tIT2zJZK1v6jxALQDA9BIji/E=
|
||||||
github.com/appleboy/easyssh-proxy v1.5.0 h1:OYdSPvYQN3mhnsMH5I2OF1TgwSEcSq33kvjQfTwvZww=
|
github.com/ScaleFT/sshkeys v0.0.0-20200327173127-6142f742bca5/go.mod h1:gxOHeajFfvGQh/fxlC8oOKBe23xnnJTif00IFFbiT+o=
|
||||||
github.com/appleboy/easyssh-proxy v1.5.0/go.mod h1:zcEMrStH91/tcUn3gUGP0KpQwUYLm8tX/Ook1AH98uc=
|
github.com/appleboy/easyssh-proxy v1.3.9 h1:b+sVSTz+cVFvfA23HQywMMpm0s5g3gH7jYdBcQqaCQI=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM=
|
github.com/appleboy/easyssh-proxy v1.3.9/go.mod h1:G1eQomBEME7NWKA3hE49s5HsT44S5fn0aBxX7k9Yjug=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
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/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||||
|
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/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/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.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
|
||||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
github.com/joho/godotenv v1.4.0/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/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.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
|
||||||
github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho=
|
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
|
||||||
github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
|
github.com/urfave/cli v1.22.9 h1:cv3/KhXGBGjEXLC4bH0sLuJ9BewaAbpk5oyMOveu4pw=
|
||||||
github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e h1:+SOyEddqYF09QP7vr7CgJ1eti3pY9Fn3LHO1M1r/0sI=
|
github.com/urfave/cli v1.22.9/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
||||||
github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e/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.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
|
golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||||
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
|
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e h1:T8NU3HyQ8ClP4SEE+KbFlg6n0NhuTsN4MyznaarGsZM=
|
||||||
|
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||||
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.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
|
golang.org/x/sys v0.0.0-20220614162138-6c1b26c55098 h1:PgOr27OhUx2IRqGJ2RxAWI4dJQ7bi9cSrB82uzFzfUA=
|
||||||
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.0.0-20220614162138-6c1b26c55098/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
|
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||||
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
|
||||||
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=
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|||||||
@@ -3,12 +3,11 @@ package main
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/appleboy/easyssh-proxy"
|
"github.com/appleboy/easyssh-proxy"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Version set at compile-time
|
// Version set at compile-time
|
||||||
@@ -27,8 +26,8 @@ func main() {
|
|||||||
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"
|
||||||
app.Copyright = "Copyright (c) " + strconv.Itoa(time.Now().Year()) + " 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",
|
||||||
@@ -37,193 +36,157 @@ func main() {
|
|||||||
app.Action = run
|
app.Action = run
|
||||||
app.Version = Version
|
app.Version = Version
|
||||||
app.Flags = []cli.Flag{
|
app.Flags = []cli.Flag{
|
||||||
&cli.StringSliceFlag{
|
cli.StringFlag{
|
||||||
Name: "host",
|
Name: "ssh-key",
|
||||||
Aliases: []string{"H"},
|
Usage: "private ssh 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{
|
||||||
|
Name: "key-path,i",
|
||||||
|
Usage: "ssh private key path",
|
||||||
|
EnvVar: "PLUGIN_KEY_PATH,SSH_KEY_PATH,INPUT_KEY_PATH",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "username,user,u",
|
||||||
|
Usage: "connect as user",
|
||||||
|
EnvVar: "PLUGIN_USERNAME,PLUGIN_USER,SSH_USERNAME,USERNAME,INPUT_USERNAME",
|
||||||
|
Value: "root",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "password,P",
|
||||||
|
Usage: "user password",
|
||||||
|
EnvVar: "PLUGIN_PASSWORD,SSH_PASSWORD,PASSWORD,INPUT_PASSWORD",
|
||||||
|
},
|
||||||
|
cli.StringSliceFlag{
|
||||||
|
Name: "ciphers",
|
||||||
|
Usage: "The allowed cipher algorithms. If unspecified then a sensible",
|
||||||
|
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",
|
Usage: "connect to host",
|
||||||
EnvVars: []string{"PLUGIN_HOST", "SSH_HOST", "INPUT_HOST"},
|
EnvVar: "PLUGIN_HOST,SSH_HOST,HOST,INPUT_HOST",
|
||||||
FilePath: ".host",
|
FilePath: ".host",
|
||||||
},
|
},
|
||||||
&cli.IntFlag{
|
cli.IntFlag{
|
||||||
Name: "port",
|
Name: "port,p",
|
||||||
Aliases: []string{"p"},
|
Usage: "connect to port",
|
||||||
Usage: "connect to port",
|
EnvVar: "PLUGIN_PORT,SSH_PORT,PORT,INPUT_PORT",
|
||||||
EnvVars: []string{"PLUGIN_PORT", "SSH_PORT", "INPUT_PORT"},
|
Value: 22,
|
||||||
Value: 22,
|
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
cli.BoolFlag{
|
||||||
Name: "protocol",
|
Name: "sync",
|
||||||
Usage: "The IP protocol to use. Default to tcp (both IPv4 and IPv6).",
|
Usage: "sync mode",
|
||||||
EnvVars: []string{"PLUGIN_PROTOCOL", "SSH_PROTOCOL", "INPUT_PROTOCOL"},
|
EnvVar: "PLUGIN_SYNC,SYNC,INPUT_SYNC",
|
||||||
Value: "tcp",
|
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
cli.DurationFlag{
|
||||||
Name: "username",
|
Name: "timeout,t",
|
||||||
Aliases: []string{"user", "u"},
|
Usage: "connection timeout",
|
||||||
Usage: "connect as user",
|
EnvVar: "PLUGIN_TIMEOUT,SSH_TIMEOUT,TIMEOUT,INPUT_TIMEOUT",
|
||||||
EnvVars: []string{"PLUGIN_USERNAME", "PLUGIN_USER", "SSH_USERNAME", "INPUT_USERNAME"},
|
Value: 30 * time.Second,
|
||||||
Value: "root",
|
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
cli.DurationFlag{
|
||||||
Name: "password",
|
Name: "command.timeout,T",
|
||||||
Aliases: []string{"P"},
|
Usage: "command timeout",
|
||||||
Usage: "user password",
|
EnvVar: "PLUGIN_COMMAND_TIMEOUT,SSH_COMMAND_TIMEOUT,COMMAND_TIMEOUT,INPUT_COMMAND_TIMEOUT",
|
||||||
EnvVars: []string{"PLUGIN_PASSWORD", "SSH_PASSWORD", "INPUT_PASSWORD"},
|
Value: 10 * time.Minute,
|
||||||
},
|
},
|
||||||
&cli.DurationFlag{
|
cli.StringSliceFlag{
|
||||||
Name: "timeout",
|
Name: "script,s",
|
||||||
Aliases: []string{"t"},
|
Usage: "execute commands",
|
||||||
Usage: "connection timeout",
|
EnvVar: "PLUGIN_SCRIPT,SSH_SCRIPT,SCRIPT",
|
||||||
EnvVars: []string{"PLUGIN_TIMEOUT", "SSH_TIMEOUT", "INPUT_TIMEOUT"},
|
|
||||||
Value: 30 * time.Second,
|
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "ssh-key",
|
Name: "script.string",
|
||||||
Usage: "private ssh key",
|
Usage: "execute single commands for github action",
|
||||||
EnvVars: []string{"PLUGIN_SSH_KEY", "PLUGIN_KEY", "SSH_KEY", "INPUT_KEY"},
|
EnvVar: "INPUT_SCRIPT",
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
cli.BoolFlag{
|
||||||
Name: "ssh-passphrase",
|
Name: "script.stop",
|
||||||
Usage: "The purpose of the passphrase is usually to encrypt the private key.",
|
Usage: "stop script after first failure",
|
||||||
EnvVars: []string{"PLUGIN_SSH_PASSPHRASE", "PLUGIN_PASSPHRASE", "SSH_PASSPHRASE", "INPUT_PASSPHRASE"},
|
EnvVar: "PLUGIN_SCRIPT_STOP,STOP,INPUT_SCRIPT_STOP",
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "key-path",
|
Name: "proxy.ssh-key",
|
||||||
Aliases: []string{"i"},
|
Usage: "private ssh key of proxy",
|
||||||
Usage: "ssh private key path",
|
EnvVar: "PLUGIN_PROXY_SSH_KEY,PLUGIN_PROXY_KEY,PROXY_SSH_KEY,INPUT_PROXY_KEY",
|
||||||
EnvVars: []string{"PLUGIN_KEY_PATH", "SSH_KEY_PATH", "INPUT_KEY_PATH"},
|
|
||||||
},
|
},
|
||||||
&cli.StringSliceFlag{
|
cli.StringFlag{
|
||||||
Name: "ciphers",
|
Name: "proxy.ssh-passphrase",
|
||||||
Usage: "The allowed cipher algorithms. If unspecified then a sensible",
|
Usage: "The purpose of the passphrase is usually to encrypt the private key.",
|
||||||
EnvVars: []string{"PLUGIN_CIPHERS", "SSH_CIPHERS", "INPUT_CIPHERS"},
|
EnvVar: "PLUGIN_PROXY_SSH_PASSPHRASE,PLUGIN_PROXY_PASSPHRASE,PROXY_SSH_PASSPHRASE,PROXY_PASSPHRASE,INPUT_PROXY_PASSPHRASE",
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
cli.StringFlag{
|
||||||
Name: "useInsecureCipher",
|
Name: "proxy.key-path",
|
||||||
Usage: "include more ciphers with use_insecure_cipher",
|
Usage: "ssh private key path of proxy",
|
||||||
EnvVars: []string{"PLUGIN_USE_INSECURE_CIPHER", "SSH_USE_INSECURE_CIPHER", "INPUT_USE_INSECURE_CIPHER"},
|
EnvVar: "PLUGIN_PROXY_KEY_PATH,PROXY_SSH_KEY_PATH,INPUT_PROXY_KEY_PATH",
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "fingerprint",
|
Name: "proxy.username",
|
||||||
Usage: "fingerprint SHA256 of the host public key, default is to skip verification",
|
Usage: "connect as user of proxy",
|
||||||
EnvVars: []string{"PLUGIN_FINGERPRINT", "SSH_FINGERPRINT", "INPUT_FINGERPRINT"},
|
EnvVar: "PLUGIN_PROXY_USERNAME,PLUGIN_PROXY_USER,PROXY_SSH_USERNAME,INPUT_PROXY_USERNAME",
|
||||||
|
Value: "root",
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
cli.StringFlag{
|
||||||
Name: "sync",
|
Name: "proxy.password",
|
||||||
Usage: "sync mode",
|
Usage: "user password of proxy",
|
||||||
EnvVars: []string{"PLUGIN_SYNC", "INPUT_SYNC"},
|
EnvVar: "PLUGIN_PROXY_PASSWORD,PROXY_SSH_PASSWORD,INPUT_PROXY_PASSWORD",
|
||||||
},
|
},
|
||||||
&cli.DurationFlag{
|
cli.StringFlag{
|
||||||
Name: "command.timeout",
|
Name: "proxy.host",
|
||||||
Aliases: []string{"T"},
|
Usage: "connect to host of proxy",
|
||||||
Usage: "command timeout",
|
EnvVar: "PLUGIN_PROXY_HOST,PROXY_SSH_HOST,INPUT_PROXY_HOST",
|
||||||
EnvVars: []string{"PLUGIN_COMMAND_TIMEOUT", "SSH_COMMAND_TIMEOUT", "INPUT_COMMAND_TIMEOUT"},
|
|
||||||
Value: 10 * time.Minute,
|
|
||||||
},
|
},
|
||||||
&cli.StringSliceFlag{
|
cli.StringFlag{
|
||||||
Name: "script",
|
Name: "proxy.port",
|
||||||
Aliases: []string{"s"},
|
Usage: "connect to port of proxy",
|
||||||
Usage: "execute commands",
|
EnvVar: "PLUGIN_PROXY_PORT,PROXY_SSH_PORT,INPUT_PROXY_PORT",
|
||||||
EnvVars: []string{"PLUGIN_SCRIPT", "SSH_SCRIPT"},
|
Value: "22",
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
cli.DurationFlag{
|
||||||
Name: "script.string",
|
Name: "proxy.timeout",
|
||||||
Usage: "execute single commands for github action",
|
Usage: "proxy connection timeout",
|
||||||
EnvVars: []string{"INPUT_SCRIPT"},
|
EnvVar: "PLUGIN_PROXY_TIMEOUT,PROXY_SSH_TIMEOUT,INPUT_PROXY_TIMEOUT",
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
cli.StringSliceFlag{
|
||||||
Name: "script.stop",
|
Name: "proxy.ciphers",
|
||||||
Usage: "stop script after first failure",
|
Usage: "The allowed cipher algorithms. If unspecified then a sensible",
|
||||||
EnvVars: []string{"PLUGIN_SCRIPT_STOP", "INPUT_SCRIPT_STOP"},
|
EnvVar: "PLUGIN_PROXY_CIPHERS,SSH_PROXY_CIPHERS,PROXY_CIPHERS,INPUT_PROXY_CIPHERS",
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
cli.BoolFlag{
|
||||||
Name: "proxy.host",
|
Name: "proxy.useInsecureCipher",
|
||||||
Usage: "connect to host of proxy",
|
Usage: "include more ciphers with use_insecure_cipher",
|
||||||
EnvVars: []string{"PLUGIN_PROXY_HOST", "PROXY_SSH_HOST", "INPUT_PROXY_HOST"},
|
EnvVar: "PLUGIN_PROXY_USE_INSECURE_CIPHER,SSH_PROXY_USE_INSECURE_CIPHER,PROXY_USE_INSECURE_CIPHER,INPUT_PROXY_USE_INSECURE_CIPHER",
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "proxy.port",
|
Name: "proxy.fingerprint",
|
||||||
Usage: "connect to port of proxy",
|
Usage: "fingerprint SHA256 of the host public key, default is to skip verification",
|
||||||
EnvVars: []string{"PLUGIN_PROXY_PORT", "PROXY_SSH_PORT", "INPUT_PROXY_PORT"},
|
EnvVar: "PLUGIN_PROXY_FINGERPRINT,SSH_PROXY_FINGERPRINT,PROXY_FINGERPRINT,INPUT_PROXY_FINGERPRINT",
|
||||||
Value: "22",
|
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
cli.StringSliceFlag{
|
||||||
Name: "proxy.protocol",
|
Name: "envs",
|
||||||
Usage: "The IP protocol to use for the proxy. Default to tcp (both IPv4 and IPv6).",
|
Usage: "pass environment variable to shell script",
|
||||||
EnvVars: []string{"PLUGIN_PROTOCOL", "SSH_PROTOCOL", "INPUT_PROTOCOL"},
|
EnvVar: "PLUGIN_ENVS,INPUT_ENVS",
|
||||||
Value: "tcp",
|
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
cli.BoolFlag{
|
||||||
Name: "proxy.username",
|
Name: "debug",
|
||||||
Usage: "connect as user of proxy",
|
Usage: "debug mode",
|
||||||
EnvVars: []string{"PLUGIN_PROXY_USERNAME", "PLUGIN_PROXY_USER", "PROXY_SSH_USERNAME", "INPUT_PROXY_USERNAME"},
|
EnvVar: "PLUGIN_DEBUG,DEBUG,INPUT_DEBUG",
|
||||||
Value: "root",
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "proxy.password",
|
|
||||||
Usage: "user password of proxy",
|
|
||||||
EnvVars: []string{"PLUGIN_PROXY_PASSWORD", "PROXY_SSH_PASSWORD", "INPUT_PROXY_PASSWORD"},
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "proxy.ssh-key",
|
|
||||||
Usage: "private ssh key of proxy",
|
|
||||||
EnvVars: []string{"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.",
|
|
||||||
EnvVars: []string{"PLUGIN_PROXY_SSH_PASSPHRASE", "PLUGIN_PROXY_PASSPHRASE", "PROXY_SSH_PASSPHRASE", "INPUT_PROXY_PASSPHRASE"},
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "proxy.key-path",
|
|
||||||
Usage: "ssh private key path of proxy",
|
|
||||||
EnvVars: []string{"PLUGIN_PROXY_KEY_PATH", "PROXY_SSH_KEY_PATH", "INPUT_PROXY_KEY_PATH"},
|
|
||||||
},
|
|
||||||
&cli.DurationFlag{
|
|
||||||
Name: "proxy.timeout",
|
|
||||||
Usage: "proxy connection timeout",
|
|
||||||
EnvVars: []string{"PLUGIN_PROXY_TIMEOUT", "PROXY_SSH_TIMEOUT", "INPUT_PROXY_TIMEOUT"},
|
|
||||||
},
|
|
||||||
&cli.StringSliceFlag{
|
|
||||||
Name: "proxy.ciphers",
|
|
||||||
Usage: "The allowed cipher algorithms. If unspecified then a sensible",
|
|
||||||
EnvVars: []string{"PLUGIN_PROXY_CIPHERS", "PROXY_SSH_CIPHERS", "INPUT_PROXY_CIPHERS"},
|
|
||||||
},
|
|
||||||
&cli.BoolFlag{
|
|
||||||
Name: "proxy.useInsecureCipher",
|
|
||||||
Usage: "include more ciphers with use_insecure_cipher",
|
|
||||||
EnvVars: []string{"PLUGIN_PROXY_USE_INSECURE_CIPHER", "PROXY_SSH_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",
|
|
||||||
EnvVars: []string{"PLUGIN_PROXY_FINGERPRINT", "PROXY_SSH_FINGERPRINT", "PROXY_FINGERPRINT", "INPUT_PROXY_FINGERPRINT"},
|
|
||||||
},
|
|
||||||
&cli.StringSliceFlag{
|
|
||||||
Name: "envs",
|
|
||||||
Usage: "pass environment variable to shell script",
|
|
||||||
EnvVars: []string{"PLUGIN_ENVS", "INPUT_ENVS"},
|
|
||||||
},
|
|
||||||
&cli.BoolFlag{
|
|
||||||
Name: "debug",
|
|
||||||
Usage: "debug mode",
|
|
||||||
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,
|
|
||||||
},
|
|
||||||
&cli.BoolFlag{
|
|
||||||
Name: "allenvs",
|
|
||||||
Usage: "pass all environment variable to shell script",
|
|
||||||
EnvVars: []string{"PLUGIN_ALLENVS", "INPUT_ALLENVS"},
|
|
||||||
},
|
|
||||||
&cli.BoolFlag{
|
|
||||||
Name: "request-pty",
|
|
||||||
Usage: "request a pseudo-terminal from the server",
|
|
||||||
EnvVars: []string{"PLUGIN_REQUEST_PTY", "INPUT_REQUEST_PTY"},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,7 +233,6 @@ 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"),
|
||||||
@@ -281,19 +243,15 @@ func run(c *cli.Context) error {
|
|||||||
Fingerprint: c.String("fingerprint"),
|
Fingerprint: c.String("fingerprint"),
|
||||||
Host: c.StringSlice("host"),
|
Host: c.StringSlice("host"),
|
||||||
Port: c.Int("port"),
|
Port: c.Int("port"),
|
||||||
Protocol: easyssh.Protocol(c.String("protocol")),
|
|
||||||
Timeout: c.Duration("timeout"),
|
Timeout: c.Duration("timeout"),
|
||||||
CommandTimeout: c.Duration("command.timeout"),
|
CommandTimeout: c.Duration("command.timeout"),
|
||||||
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"),
|
||||||
UseInsecureCipher: c.Bool("useInsecureCipher"),
|
UseInsecureCipher: c.Bool("useInsecureCipher"),
|
||||||
AllEnvs: c.Bool("allenvs"),
|
|
||||||
RequireTty: c.Bool("request-pty"),
|
|
||||||
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"),
|
||||||
@@ -303,7 +261,6 @@ func run(c *cli.Context) error {
|
|||||||
Fingerprint: c.String("proxy.fingerprint"),
|
Fingerprint: c.String("proxy.fingerprint"),
|
||||||
Server: c.String("proxy.host"),
|
Server: c.String("proxy.host"),
|
||||||
Port: c.String("proxy.port"),
|
Port: c.String("proxy.port"),
|
||||||
Protocol: easyssh.Protocol(c.String("proxy.protocol")),
|
|
||||||
Timeout: c.Duration("proxy.timeout"),
|
Timeout: c.Duration("proxy.timeout"),
|
||||||
Ciphers: c.StringSlice("proxy.ciphers"),
|
Ciphers: c.StringSlice("proxy.ciphers"),
|
||||||
UseInsecureCipher: c.Bool("proxy.useInsecureCipher"),
|
UseInsecureCipher: c.Bool("proxy.useInsecureCipher"),
|
||||||
|
|||||||
@@ -0,0 +1,229 @@
|
|||||||
|
{
|
||||||
|
test:: {
|
||||||
|
kind: 'pipeline',
|
||||||
|
name: 'testing',
|
||||||
|
platform: {
|
||||||
|
os: 'linux',
|
||||||
|
arch: 'amd64',
|
||||||
|
},
|
||||||
|
steps: [
|
||||||
|
{
|
||||||
|
name: 'vet',
|
||||||
|
image: 'golang:1.18',
|
||||||
|
pull: 'always',
|
||||||
|
commands: [
|
||||||
|
'make vet',
|
||||||
|
],
|
||||||
|
volumes: [
|
||||||
|
{
|
||||||
|
name: 'gopath',
|
||||||
|
path: '/go',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
// {
|
||||||
|
// name: 'test',
|
||||||
|
// image: 'golang:1.18-alpine',
|
||||||
|
// pull: 'always',
|
||||||
|
// commands: [
|
||||||
|
// 'apk add git make curl perl bash build-base zlib-dev ucl-dev',
|
||||||
|
// 'make ssh-server',
|
||||||
|
// 'make test',
|
||||||
|
// 'make coverage',
|
||||||
|
// ],
|
||||||
|
// volumes: [
|
||||||
|
// {
|
||||||
|
// name: 'gopath',
|
||||||
|
// path: '/go',
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
// },
|
||||||
|
{
|
||||||
|
name: 'codecov',
|
||||||
|
image: 'robertstettner/drone-codecov',
|
||||||
|
pull: 'always',
|
||||||
|
settings: {
|
||||||
|
token: { 'from_secret': 'codecov_token' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
volumes: [
|
||||||
|
{
|
||||||
|
name: 'gopath',
|
||||||
|
temp: {},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
|
build(name, os='linux', arch='amd64'):: {
|
||||||
|
kind: 'pipeline',
|
||||||
|
name: os + '-' + arch,
|
||||||
|
platform: {
|
||||||
|
os: os,
|
||||||
|
arch: arch,
|
||||||
|
},
|
||||||
|
steps: [
|
||||||
|
{
|
||||||
|
name: 'build-push',
|
||||||
|
image: 'golang:1.18',
|
||||||
|
pull: 'always',
|
||||||
|
environment: {
|
||||||
|
CGO_ENABLED: '0',
|
||||||
|
},
|
||||||
|
commands: [
|
||||||
|
'go build -v -ldflags \'-X main.build=${DRONE_BUILD_NUMBER}\' -a -o release/' + os + '/' + arch + '/' + name,
|
||||||
|
],
|
||||||
|
when: {
|
||||||
|
event: {
|
||||||
|
exclude: [ 'tag' ],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'build-tag',
|
||||||
|
image: 'golang:1.18',
|
||||||
|
pull: 'always',
|
||||||
|
environment: {
|
||||||
|
CGO_ENABLED: '0',
|
||||||
|
},
|
||||||
|
commands: [
|
||||||
|
'go build -v -ldflags \'-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\' -a -o release/' + os + '/' + arch + '/' + name,
|
||||||
|
],
|
||||||
|
when: {
|
||||||
|
event: [ 'tag' ],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'executable',
|
||||||
|
image: 'golang:1.18',
|
||||||
|
pull: 'always',
|
||||||
|
commands: [
|
||||||
|
'./release/' + os + '/' + arch + '/' + name + ' --help',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'dryrun',
|
||||||
|
image: 'plugins/docker:' + os + '-' + arch,
|
||||||
|
pull: 'always',
|
||||||
|
settings: {
|
||||||
|
daemon_off: false,
|
||||||
|
dry_run: true,
|
||||||
|
tags: os + '-' + arch,
|
||||||
|
dockerfile: 'docker/Dockerfile.' + os + '.' + arch,
|
||||||
|
repo: 'appleboy/' + name,
|
||||||
|
cache_from: 'appleboy/' + name,
|
||||||
|
},
|
||||||
|
when: {
|
||||||
|
event: [ 'pull_request' ],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'publish',
|
||||||
|
image: 'plugins/docker:' + os + '-' + arch,
|
||||||
|
pull: 'always',
|
||||||
|
settings: {
|
||||||
|
daemon_off: 'false',
|
||||||
|
auto_tag: true,
|
||||||
|
auto_tag_suffix: os + '-' + arch,
|
||||||
|
dockerfile: 'docker/Dockerfile.' + os + '.' + arch,
|
||||||
|
repo: 'appleboy/' + name,
|
||||||
|
cache_from: 'appleboy/' + name,
|
||||||
|
username: { 'from_secret': 'docker_username' },
|
||||||
|
password: { 'from_secret': 'docker_password' },
|
||||||
|
},
|
||||||
|
when: {
|
||||||
|
event: {
|
||||||
|
exclude: [ 'pull_request' ],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
depends_on: [
|
||||||
|
'testing',
|
||||||
|
],
|
||||||
|
trigger: {
|
||||||
|
ref: [
|
||||||
|
'refs/heads/master',
|
||||||
|
'refs/pull/**',
|
||||||
|
'refs/tags/**',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
release:: {
|
||||||
|
kind: 'pipeline',
|
||||||
|
name: 'release-binary',
|
||||||
|
platform: {
|
||||||
|
os: 'linux',
|
||||||
|
arch: 'amd64',
|
||||||
|
},
|
||||||
|
steps: [
|
||||||
|
{
|
||||||
|
name: 'build-all-binary',
|
||||||
|
image: 'techknowlogick/xgo:go-1.18.x',
|
||||||
|
pull: 'always',
|
||||||
|
commands: [
|
||||||
|
'export PATH=$PATH:$GOPATH/bin',
|
||||||
|
'make release'
|
||||||
|
],
|
||||||
|
when: {
|
||||||
|
event: [ 'tag' ],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'deploy-all-binary',
|
||||||
|
image: 'plugins/github-release',
|
||||||
|
pull: 'always',
|
||||||
|
settings: {
|
||||||
|
files: [ 'dist/release/*' ],
|
||||||
|
api_key: { 'from_secret': 'github_release_api_key' },
|
||||||
|
},
|
||||||
|
when: {
|
||||||
|
event: [ 'tag' ],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
depends_on: [
|
||||||
|
'testing',
|
||||||
|
],
|
||||||
|
trigger: {
|
||||||
|
ref: [
|
||||||
|
'refs/tags/**',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
notifications(os='linux', arch='amd64', depends_on=[]):: {
|
||||||
|
kind: 'pipeline',
|
||||||
|
name: 'notifications',
|
||||||
|
platform: {
|
||||||
|
os: os,
|
||||||
|
arch: arch,
|
||||||
|
},
|
||||||
|
steps: [
|
||||||
|
{
|
||||||
|
name: 'manifest',
|
||||||
|
image: 'plugins/manifest',
|
||||||
|
pull: 'always',
|
||||||
|
settings: {
|
||||||
|
username: { from_secret: 'docker_username' },
|
||||||
|
password: { from_secret: 'docker_password' },
|
||||||
|
spec: 'docker/manifest.tmpl',
|
||||||
|
ignore_missing: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
depends_on: depends_on,
|
||||||
|
trigger: {
|
||||||
|
ref: [
|
||||||
|
'refs/heads/master',
|
||||||
|
'refs/tags/**',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
signature(key):: {
|
||||||
|
kind: 'signature',
|
||||||
|
hmac: key,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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")
|
||||||
envsFormat = "export {NAME}={VALUE}"
|
errSetPasswordandKey = errors.New("can't set password and key at the same time")
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@@ -30,7 +30,6 @@ type (
|
|||||||
Password string
|
Password string
|
||||||
Host []string
|
Host []string
|
||||||
Port int
|
Port int
|
||||||
Protocol easyssh.Protocol
|
|
||||||
Fingerprint string
|
Fingerprint string
|
||||||
Timeout time.Duration
|
Timeout time.Duration
|
||||||
CommandTimeout time.Duration
|
CommandTimeout time.Duration
|
||||||
@@ -42,9 +41,6 @@ type (
|
|||||||
Sync bool
|
Sync bool
|
||||||
Ciphers []string
|
Ciphers []string
|
||||||
UseInsecureCipher bool
|
UseInsecureCipher bool
|
||||||
EnvsFormat string
|
|
||||||
AllEnvs bool
|
|
||||||
RequireTty bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Plugin structure
|
// Plugin structure
|
||||||
@@ -70,7 +66,6 @@ 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{
|
||||||
@@ -78,7 +73,6 @@ func (p Plugin) exec(host string, wg *sync.WaitGroup, errChannel chan error) {
|
|||||||
User: p.Config.Username,
|
User: p.Config.Username,
|
||||||
Password: p.Config.Password,
|
Password: p.Config.Password,
|
||||||
Port: port,
|
Port: port,
|
||||||
Protocol: p.Config.Protocol,
|
|
||||||
Key: p.Config.Key,
|
Key: p.Config.Key,
|
||||||
KeyPath: p.Config.KeyPath,
|
KeyPath: p.Config.KeyPath,
|
||||||
Passphrase: p.Config.Passphrase,
|
Passphrase: p.Config.Passphrase,
|
||||||
@@ -86,13 +80,11 @@ func (p Plugin) exec(host string, wg *sync.WaitGroup, errChannel chan error) {
|
|||||||
Ciphers: p.Config.Ciphers,
|
Ciphers: p.Config.Ciphers,
|
||||||
Fingerprint: p.Config.Fingerprint,
|
Fingerprint: p.Config.Fingerprint,
|
||||||
UseInsecureCipher: p.Config.UseInsecureCipher,
|
UseInsecureCipher: p.Config.UseInsecureCipher,
|
||||||
RequestPty: p.Config.RequireTty,
|
|
||||||
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,
|
||||||
Protocol: p.Config.Proxy.Protocol,
|
|
||||||
Key: p.Config.Proxy.Key,
|
Key: p.Config.Proxy.Key,
|
||||||
KeyPath: p.Config.Proxy.KeyPath,
|
KeyPath: p.Config.Proxy.KeyPath,
|
||||||
Passphrase: p.Config.Proxy.Passphrase,
|
Passphrase: p.Config.Proxy.Passphrase,
|
||||||
@@ -108,14 +100,10 @@ func (p Plugin) exec(host string, wg *sync.WaitGroup, errChannel chan error) {
|
|||||||
p.log(host, "======END======")
|
p.log(host, "======END======")
|
||||||
|
|
||||||
env := []string{}
|
env := []string{}
|
||||||
if p.Config.AllEnvs {
|
|
||||||
allenvs := findEnvs("DRONE_", "PLUGIN_", "INPUT_", "GITHUB_")
|
|
||||||
p.Config.Envs = append(p.Config.Envs, allenvs...)
|
|
||||||
}
|
|
||||||
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, p.format(p.Config.EnvsFormat, "{NAME}", key, "{VALUE}", escapeArg(val)))
|
env = append(env, key+"="+escapeArg(val))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,61 +118,49 @@ 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
|
||||||
return
|
} else {
|
||||||
}
|
// read from the output channel until the done signal is passed
|
||||||
// read from the output channel until the done signal is passed
|
isTimeout := true
|
||||||
isTimeout := true
|
loop:
|
||||||
loop:
|
for {
|
||||||
for {
|
select {
|
||||||
select {
|
case isTimeout = <-doneChan:
|
||||||
case isTimeout = <-doneChan:
|
break loop
|
||||||
break loop
|
case outline := <-stdoutChan:
|
||||||
case outline := <-stdoutChan:
|
|
||||||
if outline != "" {
|
|
||||||
p.log(host, "out:", outline)
|
p.log(host, "out:", outline)
|
||||||
}
|
case errline := <-stderrChan:
|
||||||
case errline := <-stderrChan:
|
|
||||||
if errline != "" {
|
|
||||||
p.log(host, "err:", errline)
|
p.log(host, "err:", errline)
|
||||||
|
case err = <-errChan:
|
||||||
}
|
}
|
||||||
case err = <-errChan:
|
}
|
||||||
|
|
||||||
|
// get exit code or command error.
|
||||||
|
if err != nil {
|
||||||
|
errChannel <- err
|
||||||
|
}
|
||||||
|
|
||||||
|
// command time out
|
||||||
|
if !isTimeout {
|
||||||
|
errChannel <- errCommandTimeOut
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get exit code or command error.
|
wg.Done()
|
||||||
if err != nil {
|
|
||||||
errChannel <- err
|
|
||||||
}
|
|
||||||
|
|
||||||
// command time out
|
|
||||||
if !isTimeout {
|
|
||||||
errChannel <- errCommandTimeOut
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// format string
|
|
||||||
func (p Plugin) format(format string, args ...string) string {
|
|
||||||
r := strings.NewReplacer(args...)
|
|
||||||
return r.Replace(format)
|
|
||||||
}
|
|
||||||
|
|
||||||
// log output to console
|
|
||||||
func (p Plugin) log(host string, message ...interface{}) {
|
func (p Plugin) log(host string, message ...interface{}) {
|
||||||
if p.Writer == nil {
|
if p.Writer == nil {
|
||||||
p.Writer = os.Stdout
|
p.Writer = os.Stdout
|
||||||
}
|
}
|
||||||
if count := len(p.Config.Host); count == 1 {
|
if count := len(p.Config.Host); count == 1 {
|
||||||
fmt.Fprintf(p.Writer, "%s", fmt.Sprintln(message...))
|
fmt.Fprintf(p.Writer, "%s", fmt.Sprintln(message...))
|
||||||
return
|
} else {
|
||||||
|
fmt.Fprintf(p.Writer, "%s: %s", host, fmt.Sprintln(message...))
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(p.Writer, "%s: %s", host, fmt.Sprintln(message...))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
}
|
}
|
||||||
@@ -193,22 +169,18 @@ func (p Plugin) Exec() error {
|
|||||||
return errMissingPasswordOrKey
|
return errMissingPasswordOrKey
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.Config.EnvsFormat == "" {
|
if len(p.Config.Key) != 0 && len(p.Config.Password) != 0 {
|
||||||
p.Config.EnvsFormat = envsFormat
|
return errSetPasswordandKey
|
||||||
}
|
}
|
||||||
|
|
||||||
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{})
|
||||||
if p.Config.Sync {
|
for _, host := range p.Config.Host {
|
||||||
go func() {
|
if p.Config.Sync {
|
||||||
for _, host := range p.Config.Host {
|
p.exec(host, &wg, errChannel)
|
||||||
p.exec(host, &wg, errChannel)
|
} else {
|
||||||
}
|
|
||||||
}()
|
|
||||||
} else {
|
|
||||||
for _, host := range p.Config.Host {
|
|
||||||
go p.exec(host, &wg, errChannel)
|
go p.exec(host, &wg, errChannel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -259,33 +231,3 @@ 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
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find all envs from specified prefix
|
|
||||||
func findEnvs(prefix ...string) []string {
|
|
||||||
envs := []string{}
|
|
||||||
for _, e := range os.Environ() {
|
|
||||||
for _, p := range prefix {
|
|
||||||
if strings.HasPrefix(e, p) {
|
|
||||||
e = strings.Split(e, "=")[0]
|
|
||||||
envs = append(envs, e)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return envs
|
|
||||||
}
|
|
||||||
|
|||||||
+26
-203
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -38,6 +39,23 @@ 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{
|
||||||
@@ -113,40 +131,6 @@ func TestSSHScriptFromKeyFile(t *testing.T) {
|
|||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSSHIPv4Only(t *testing.T) {
|
|
||||||
plugin := Plugin{
|
|
||||||
Config: Config{
|
|
||||||
Host: []string{"localhost", "127.0.0.1"},
|
|
||||||
Username: "drone-scp",
|
|
||||||
Port: 22,
|
|
||||||
Protocol: easyssh.PROTOCOL_TCP4,
|
|
||||||
KeyPath: "./tests/.ssh/id_rsa",
|
|
||||||
Script: []string{"whoami", "ls -al"},
|
|
||||||
CommandTimeout: 60 * time.Second,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
err := plugin.Exec()
|
|
||||||
assert.Nil(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSSHIPv6OnlyError(t *testing.T) {
|
|
||||||
plugin := Plugin{
|
|
||||||
Config: Config{
|
|
||||||
Host: []string{"127.0.0.1"},
|
|
||||||
Username: "drone-scp",
|
|
||||||
Port: 22,
|
|
||||||
Protocol: easyssh.PROTOCOL_TCP6,
|
|
||||||
KeyPath: "./tests/.ssh/id_rsa",
|
|
||||||
Script: []string{"whoami", "ls -al"},
|
|
||||||
CommandTimeout: 60 * time.Second,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
err := plugin.Exec()
|
|
||||||
assert.NotNil(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestStreamFromSSHCommand(t *testing.T) {
|
func TestStreamFromSSHCommand(t *testing.T) {
|
||||||
plugin := Plugin{
|
plugin := Plugin{
|
||||||
Config: Config{
|
Config: Config{
|
||||||
@@ -426,7 +410,7 @@ func TestWrongFingerprint(t *testing.T) {
|
|||||||
func getHostPublicKeyFile(keypath string) (ssh.PublicKey, error) {
|
func getHostPublicKeyFile(keypath string) (ssh.PublicKey, error) {
|
||||||
var pubkey ssh.PublicKey
|
var pubkey ssh.PublicKey
|
||||||
var err error
|
var err error
|
||||||
buf, err := os.ReadFile(keypath)
|
buf, err := ioutil.ReadFile(keypath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -474,41 +458,6 @@ 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
|
||||||
@@ -591,13 +540,13 @@ func TestEnvOutput(t *testing.T) {
|
|||||||
echo "[${ENV_7}]"
|
echo "[${ENV_7}]"
|
||||||
======END======
|
======END======
|
||||||
======ENV======
|
======ENV======
|
||||||
export ENV_1='test'
|
ENV_1='test'
|
||||||
export ENV_2='test test'
|
ENV_2='test test'
|
||||||
export ENV_3='test '
|
ENV_3='test '
|
||||||
export ENV_4=' test test '
|
ENV_4=' test test '
|
||||||
export ENV_5='test'\'''
|
ENV_5='test'\'''
|
||||||
export ENV_6='test"'
|
ENV_6='test"'
|
||||||
export ENV_7='test,!#;?.@$~'\''"'
|
ENV_7='test,!#;?.@$~'\''"'
|
||||||
======END======
|
======END======
|
||||||
out: [test]
|
out: [test]
|
||||||
out: [test test]
|
out: [test test]
|
||||||
@@ -823,129 +772,3 @@ func TestPlugin_hostPort(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFindEnvs(t *testing.T) {
|
|
||||||
testEnvs := []string{
|
|
||||||
"INPUT_FOO",
|
|
||||||
"INPUT_BAR",
|
|
||||||
"NO_PREFIX",
|
|
||||||
"INPUT_FOOBAR",
|
|
||||||
}
|
|
||||||
|
|
||||||
origEnviron := os.Environ()
|
|
||||||
os.Clearenv()
|
|
||||||
for _, env := range testEnvs {
|
|
||||||
os.Setenv(env, "dummyValue")
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
os.Clearenv()
|
|
||||||
for _, env := range origEnviron {
|
|
||||||
pair := strings.SplitN(env, "=", 2)
|
|
||||||
os.Setenv(pair[0], pair[1])
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
t.Run("Find single prefix", func(t *testing.T) {
|
|
||||||
expected := []string{"INPUT_FOO", "INPUT_BAR", "INPUT_FOOBAR"}
|
|
||||||
result := findEnvs("INPUT_")
|
|
||||||
if !reflect.DeepEqual(result, expected) {
|
|
||||||
t.Errorf("Expected %v, but got %v", expected, result)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("Find multiple prefixes", func(t *testing.T) {
|
|
||||||
expected := []string{"INPUT_FOO", "INPUT_BAR", "NO_PREFIX", "INPUT_FOOBAR"}
|
|
||||||
result := findEnvs("INPUT_", "NO_PREFIX")
|
|
||||||
if !reflect.DeepEqual(result, expected) {
|
|
||||||
t.Errorf("Expected %v, but got %v", expected, result)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("Find non-existing prefix", func(t *testing.T) {
|
|
||||||
expected := []string{}
|
|
||||||
result := findEnvs("NON_EXISTING_")
|
|
||||||
if !reflect.DeepEqual(result, expected) {
|
|
||||||
t.Errorf("Expected %v, but got %v", expected, result)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAllEnvs(t *testing.T) {
|
|
||||||
var (
|
|
||||||
buffer bytes.Buffer
|
|
||||||
expected = `
|
|
||||||
======CMD======
|
|
||||||
echo "[${INPUT_1}]"
|
|
||||||
echo "[${GITHUB_2}]"
|
|
||||||
echo "[${PLUGIN_3}]"
|
|
||||||
======END======
|
|
||||||
out: [foobar]
|
|
||||||
out: [foobar]
|
|
||||||
out: [foobar]
|
|
||||||
`
|
|
||||||
)
|
|
||||||
|
|
||||||
os.Setenv("INPUT_1", `foobar`)
|
|
||||||
os.Setenv("GITHUB_2", `foobar`)
|
|
||||||
os.Setenv("PLUGIN_3", `foobar`)
|
|
||||||
|
|
||||||
plugin := Plugin{
|
|
||||||
Config: Config{
|
|
||||||
Host: []string{"localhost"},
|
|
||||||
Username: "drone-scp",
|
|
||||||
Port: 22,
|
|
||||||
KeyPath: "./tests/.ssh/test",
|
|
||||||
Passphrase: "1234",
|
|
||||||
AllEnvs: true,
|
|
||||||
Script: []string{
|
|
||||||
`echo "[${INPUT_1}]"`,
|
|
||||||
`echo "[${GITHUB_2}]"`,
|
|
||||||
`echo "[${PLUGIN_3}]"`,
|
|
||||||
},
|
|
||||||
CommandTimeout: 10 * time.Second,
|
|
||||||
Proxy: easyssh.DefaultConfig{
|
|
||||||
Server: "localhost",
|
|
||||||
User: "drone-scp",
|
|
||||||
Port: "22",
|
|
||||||
KeyPath: "./tests/.ssh/id_rsa",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Writer: &buffer,
|
|
||||||
}
|
|
||||||
|
|
||||||
err := plugin.Exec()
|
|
||||||
assert.Nil(t, err)
|
|
||||||
|
|
||||||
assert.Equal(t, unindent(expected), unindent(buffer.String()))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSudoCommand(t *testing.T) {
|
|
||||||
var (
|
|
||||||
buffer bytes.Buffer
|
|
||||||
expected = `
|
|
||||||
======CMD======
|
|
||||||
sudo su - -c "whoami"
|
|
||||||
======END======
|
|
||||||
out: root
|
|
||||||
`
|
|
||||||
)
|
|
||||||
|
|
||||||
plugin := Plugin{
|
|
||||||
Config: Config{
|
|
||||||
Host: []string{"localhost"},
|
|
||||||
Username: "drone-scp",
|
|
||||||
Port: 22,
|
|
||||||
KeyPath: "./tests/.ssh/id_rsa",
|
|
||||||
Script: []string{
|
|
||||||
`sudo su - -c "whoami"`,
|
|
||||||
},
|
|
||||||
CommandTimeout: 10 * time.Second,
|
|
||||||
RequireTty: true,
|
|
||||||
},
|
|
||||||
Writer: &buffer,
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.Nil(t, plugin.Exec())
|
|
||||||
assert.Equal(t, unindent(expected), unindent(buffer.String()))
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
Defaults requiretty
|
|
||||||
drone-scp ALL=(ALL) NOPASSWD:ALL
|
|
||||||
Reference in New Issue
Block a user