Compare commits

...

15 Commits

Author SHA1 Message Date
Bo-Yi Wu 531df19c8c docs: update drone docs. 2019-09-28 21:36:07 +08:00
Bo-Yi Wu df8214b645 chore: remove microbadge url 2019-09-28 17:33:25 +08:00
Bo-Yi Wu c85ca1ffd2 feat(tar): add Overwrite flag (#102)
* feat(tar): add Overwrite flag

* chore: remove

* chore: output

* chore: output
2019-09-28 16:59:01 +08:00
Ivo Nunes 933b45bc15 Add variable to set temporary tar upload path (#100) 2019-09-28 16:36:05 +08:00
Bo-Yi Wu 15344d67ae fix strip-components
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-09-28 16:30:07 +08:00
Bo-Yi Wu cf9e6f260d chore: debug command 2019-09-28 14:52:31 +08:00
Bo-Yi Wu cfa325a8c4 refactor: Add args command 2019-09-28 14:40:28 +08:00
Bo-Yi Wu c8dbddab25 chore: support -arch= 2019-09-28 14:14:15 +08:00
Bo-Yi Wu 1b27d28b27 chore: upgrade package 2019-09-28 12:52:08 +08:00
Bo-Yi Wu 8a0b0f3c0c chore(GitHub): support actions parameter. 2019-09-28 10:30:15 +08:00
Bo-Yi Wu ec489106f9 chore: upgrade to go1.13 2019-09-28 10:04:29 +08:00
Bo-Yi Wu 9ed20ee32d docs: fix markdown lint 2019-09-28 09:59:58 +08:00
Bo-Yi Wu 2aee5a3df1 docs: update 2019-08-03 23:51:16 +08:00
Bo-Yi Wu bc633e27cf docs: fix markdown lint 2019-08-03 18:55:27 +08:00
Bo-Yi Wu 9dad691d4f docs: update example 2019-08-03 18:55:02 +08:00
10 changed files with 273 additions and 171 deletions
+29 -52
View File
@@ -9,47 +9,39 @@ platform:
steps:
- name: vet
pull: always
image: golang:1.12
image: golang:1.13
commands:
- make vet
environment:
GO111MODULE: on
volumes:
- name: gopath
path: /go
- name: lint
pull: always
image: golang:1.12
image: golang:1.13
commands:
- make lint
environment:
GO111MODULE: on
volumes:
- name: gopath
path: /go
- name: misspell
pull: always
image: golang:1.12
image: golang:1.13
commands:
- make misspell-check
environment:
GO111MODULE: on
volumes:
- name: gopath
path: /go
- name: test
pull: always
image: golang:1.12-alpine
image: golang:1.13-alpine
commands:
- apk add git make curl perl bash build-base zlib-dev ucl-dev
- make ssh-server
- make test
- make coverage
environment:
GO111MODULE: on
volumes:
- name: gopath
path: /go
@@ -76,12 +68,11 @@ platform:
steps:
- name: build-push
pull: always
image: golang:1.12
image: golang:1.13
commands:
- "go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/amd64/drone-scp"
- go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/amd64/drone-scp
environment:
CGO_ENABLED: 0
GO111MODULE: on
when:
event:
exclude:
@@ -89,19 +80,18 @@ steps:
- name: build-tag
pull: always
image: golang:1.12
image: golang:1.13
commands:
- "go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/amd64/drone-scp"
- go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/amd64/drone-scp
environment:
CGO_ENABLED: 0
GO111MODULE: on
when:
event:
- tag
- name: executable
pull: always
image: golang:1.12
image: golang:1.13
commands:
- ./release/linux/amd64/drone-scp --help
@@ -140,8 +130,8 @@ steps:
trigger:
ref:
- refs/heads/master
- "refs/pull/**"
- "refs/tags/**"
- refs/pull/**
- refs/tags/**
depends_on:
- testing
@@ -157,12 +147,11 @@ platform:
steps:
- name: build-push
pull: always
image: golang:1.12
image: golang:1.13
commands:
- "go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm64/drone-scp"
- go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm64/drone-scp
environment:
CGO_ENABLED: 0
GO111MODULE: on
when:
event:
exclude:
@@ -170,19 +159,18 @@ steps:
- name: build-tag
pull: always
image: golang:1.12
image: golang:1.13
commands:
- "go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm64/drone-scp"
- go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm64/drone-scp
environment:
CGO_ENABLED: 0
GO111MODULE: on
when:
event:
- tag
- name: executable
pull: always
image: golang:1.12
image: golang:1.13
commands:
- ./release/linux/arm64/drone-scp --help
@@ -221,8 +209,8 @@ steps:
trigger:
ref:
- refs/heads/master
- "refs/pull/**"
- "refs/tags/**"
- refs/pull/**
- refs/tags/**
depends_on:
- testing
@@ -238,12 +226,11 @@ platform:
steps:
- name: build-push
pull: always
image: golang:1.12
image: golang:1.13
commands:
- "go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm/drone-scp"
- go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm/drone-scp
environment:
CGO_ENABLED: 0
GO111MODULE: on
when:
event:
exclude:
@@ -251,19 +238,18 @@ steps:
- name: build-tag
pull: always
image: golang:1.12
image: golang:1.13
commands:
- "go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm/drone-scp"
- go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm/drone-scp
environment:
CGO_ENABLED: 0
GO111MODULE: on
when:
event:
- tag
- name: executable
pull: always
image: golang:1.12
image: golang:1.13
commands:
- ./release/linux/arm/drone-scp --help
@@ -302,8 +288,8 @@ steps:
trigger:
ref:
- refs/heads/master
- "refs/pull/**"
- "refs/tags/**"
- refs/pull/**
- refs/tags/**
depends_on:
- testing
@@ -319,11 +305,9 @@ platform:
steps:
- name: build-all-binary
pull: always
image: golang:1.12
image: golang:1.13
commands:
- make release
environment:
GO111MODULE: on
when:
event:
- tag
@@ -335,14 +319,14 @@ steps:
api_key:
from_secret: github_release_api_key
files:
- "dist/release/*"
- dist/release/*
when:
event:
- tag
trigger:
ref:
- "refs/tags/**"
- refs/tags/**
depends_on:
- testing
@@ -367,17 +351,10 @@ steps:
username:
from_secret: docker_username
- name: microbadger
pull: always
image: plugins/webhook:1
settings:
url:
from_secret: microbadger_url
trigger:
ref:
- refs/heads/master
- "refs/tags/**"
- refs/tags/**
depends_on:
- linux-amd64
+12 -3
View File
@@ -140,7 +140,7 @@ pipeline:
port: 22
- password: 1234
+ password:
from_secret: ssh_password
+ from_secret: ssh_password
target: /home/deploy/web
source:
- release/*.tar.gz
@@ -188,7 +188,7 @@ pipeline:
- release/*
```
# Parameter Reference
## Parameter Reference
host
: target hostname or IP
@@ -223,6 +223,15 @@ command_timeout
strip_components
: remove the specified number of leading path elements
tar_tmp_path
: temporary path for tar file on the dest host
tar_exec
: alternative `tar` executable to on the dest host
overwrite
: use `--overwrite` flag with tar
proxy_host
: proxy hostname or IP
@@ -241,7 +250,7 @@ proxy_key
proxy_key_path
: key path of proxy private key
# Template Reference
## Template Reference
repo.owner
: repository owner
+2 -1
View File
@@ -8,6 +8,7 @@ DEPLOY_ACCOUNT := appleboy
DEPLOY_IMAGE := $(EXECUTABLE)
TARGETS ?= linux darwin windows
ARCHS ?= amd64 386
PACKAGES ?= $(shell $(GO) list ./...)
SOURCES ?= $(shell find . -name "*.go" -type f)
TAGS ?=
@@ -82,7 +83,7 @@ release-build:
@which gox > /dev/null; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/mitchellh/gox; \
fi
gox -os="$(TARGETS)" -tags="$(TAGS)" -ldflags="-s -w $(LDFLAGS)" -output="$(DIST)/binaries/$(EXECUTABLE)-$(VERSION)-{{.OS}}-{{.Arch}}"
gox -os="$(TARGETS)" -arch="$(ARCHS)" -tags="$(TAGS)" -ldflags="-s -w $(LDFLAGS)" -output="$(DIST)/binaries/$(EXECUTABLE)-$(VERSION)-{{.OS}}-{{.Arch}}"
release-copy:
$(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)
+36 -41
View File
@@ -1,11 +1,11 @@
# drone-scp
[![GoDoc](https://godoc.org/github.com/appleboy/drone-scp?status.svg)](https://godoc.org/github.com/appleboy/drone-scp)
[![GoDoc](https://godoc.org/github.com/appleboy/drone-scp?status.svg)](https://godoc.org/github.com/appleboy/drone-scp)
[![Build Status](https://cloud.drone.io/api/badges/appleboy/drone-scp/status.svg)](https://cloud.drone.io/appleboy/drone-scp)
[![codecov](https://codecov.io/gh/appleboy/drone-scp/branch/master/graph/badge.svg)](https://codecov.io/gh/appleboy/drone-scp)
[![Go Report Card](https://goreportcard.com/badge/github.com/appleboy/drone-scp)](https://goreportcard.com/report/github.com/appleboy/drone-scp)
[![Docker Pulls](https://img.shields.io/docker/pulls/appleboy/drone-scp.svg)](https://hub.docker.com/r/appleboy/drone-scp/)
[![](https://images.microbadger.com/badges/image/appleboy/drone-scp.svg)](https://microbadger.com/images/appleboy/drone-scp "Get your own image badge on microbadger.com")
[![codecov](https://codecov.io/gh/appleboy/drone-scp/branch/master/graph/badge.svg)](https://codecov.io/gh/appleboy/drone-scp)
[![Go Report Card](https://goreportcard.com/badge/github.com/appleboy/drone-scp)](https://goreportcard.com/report/github.com/appleboy/drone-scp)
[![Docker Pulls](https://img.shields.io/docker/pulls/appleboy/drone-scp.svg)](https://hub.docker.com/r/appleboy/drone-scp/)
[![micro badger](https://images.microbadger.com/badges/image/appleboy/drone-scp.svg)](https://microbadger.com/images/appleboy/drone-scp "Get your own image badge on microbadger.com")
Copy files and artifacts via SSH using a binary, docker or [Drone CI](http://docs.drone.io/).
@@ -18,17 +18,17 @@ Copy files and artifacts via SSH using a binary, docker or [Drone CI](http://doc
* [x] Support load ssh key from absolute path or raw body.
* [x] Support SSH ProxyCommand.
```
+--------+ +----------+ +-----------+
| Laptop | <--> | Jumphost | <--> | FooServer |
+--------+ +----------+ +-----------+
```sh
+--------+ +----------+ +-----------+
| Laptop | <--> | Jumphost | <--> | FooServer |
+--------+ +----------+ +-----------+
OR
OR
+--------+ +----------+ +-----------+
| Laptop | <--> | Firewall | <--> | FooServer |
+--------+ +----------+ +-----------+
192.168.1.5 121.1.2.3 10.10.29.68
+--------+ +----------+ +-----------+
| Laptop | <--> | Firewall | <--> | FooServer |
+--------+ +----------+ +-----------+
192.168.1.5 121.1.2.3 10.10.29.68
```
## Breaking changes
@@ -64,29 +64,29 @@ The pre-compiled binaries can be downloaded from [release page](https://github.c
With `Go` installed
```sh
go get -u -v github.com/appleboy/drone-scp
```
$ go get -u -v github.com/appleboy/drone-scp
```
or build the binary with the following command:
```
$ export GOOS=linux
$ export GOARCH=amd64
$ export CGO_ENABLED=0
$ export GO111MODULE=on
```sh
export GOOS=linux
export GOARCH=amd64
export CGO_ENABLED=0
export GO111MODULE=on
$ go test -cover ./...
go test -cover ./...
$ go build -v -a -tags netgo -o release/linux/amd64/drone-scp .
go build -v -a -tags netgo -o release/linux/amd64/drone-scp .
```
## Docker
Build the docker image with the following commands:
```
$ make docker
```sh
make docker
```
## Usage
@@ -97,7 +97,6 @@ There are three ways to send notification.
* [usage from docker](#usage-from-docker)
* [usage from drone ci](#usage-from-drone-ci)
<a name="usage-from-binary"></a>
### Usage from binary
#### Using public key
@@ -132,8 +131,8 @@ eval `ssh-agent -s`
Import your local public key `~/.ssh/id_rsa`
```bash
$ ssh-add
```sh
ssh-add
```
You don't need to add `--password` or `--key-path` arguments.
@@ -160,10 +159,9 @@ drone-scp --host example1.com \
+ --source your_local_folder_path_2
```
<a name="usage-from-docker"></a>
### Usage from docker
#### Using public key
Using public key
```bash
docker run --rm \
@@ -178,7 +176,7 @@ docker run --rm \
appleboy/drone-scp
```
#### Using password
Using password
```diff
docker run --rm \
@@ -193,9 +191,7 @@ docker run --rm \
appleboy/drone-scp
```
#### Using ssh-agent
Start your local ssh agent:
Using ssh-agent, start your local ssh agent:
```bash
eval `ssh-agent -s`
@@ -203,11 +199,11 @@ eval `ssh-agent -s`
Import your local public key `~/.ssh/id_rsa`
```bash
$ ssh-add
```sh
ssh-add
```
You don't need to add `SCP_PASSWORD` or `SCP_KEY_PATH ` arguments.
You don't need to add `SCP_PASSWORD` or `SCP_KEY_PATH` arguments.
```bash
docker run --rm \
@@ -221,7 +217,7 @@ docker run --rm \
appleboy/drone-scp
```
#### Send multiple source or target folder and hosts
Send multiple source or target folder and hosts
```bash
docker run --rm \
@@ -236,7 +232,6 @@ docker run --rm \
appleboy/drone-scp
```
<a name="usage-from-drone-ci"></a>
### Usage from drone ci
Execute from the working directory:
@@ -262,6 +257,6 @@ You can get more [information](http://plugins.drone.io/appleboy/drone-scp/) abou
Test the package with the following command:
```
$ make test
```sh
make test
```
+6 -6
View File
@@ -1,14 +1,14 @@
module github.com/appleboy/drone-scp
go 1.12
go 1.13
require (
github.com/appleboy/com v0.0.1
github.com/appleboy/com v0.0.2
github.com/appleboy/easyssh-proxy v1.2.0
github.com/fatih/color v1.7.0
github.com/joho/godotenv v1.3.0
github.com/mattn/go-colorable v0.1.1 // indirect
github.com/mattn/go-isatty v0.0.6 // indirect
github.com/stretchr/testify v1.3.0
github.com/urfave/cli v1.20.0
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/mattn/go-isatty v0.0.9 // indirect
github.com/stretchr/testify v1.4.0
github.com/urfave/cli v1.22.1
)
+25 -10
View File
@@ -1,26 +1,41 @@
github.com/appleboy/com v0.0.1 h1:SeP6J/YlZGWRwH7jdPYXXWA+qJy4GoQfcQFPda0ERYU=
github.com/appleboy/com v0.0.1/go.mod h1:rtwjPnHClMOJw4K5oW3ASx9BCPCJ1SDbFbzJjY4Ebqw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/appleboy/com v0.0.2 h1:sexcPX7gp7peXMlOJMxEYcRucW7DW0XHgFZqUB6PI6g=
github.com/appleboy/com v0.0.2/go.mod h1:jnufjIC3opMlReyPPPye+8JqNvUzLm25o7h6SOy8nv0=
github.com/appleboy/easyssh-proxy v1.2.0 h1:KvaUGC18WkBFet+N1oofQy03jkC5HaKFn2XGxFxCTtg=
github.com/appleboy/easyssh-proxy v1.2.0/go.mod h1:vHskChUNhxwW4dXMe2MNE/k+UBCkBagrQDm70UWZrS0=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/mattn/go-colorable v0.1.1 h1:G1f5SKeVxmagw/IyvzvtZE4Gybcc4Tr1tf7I8z0XgOg=
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.6 h1:SrwhHcpV4nWrMGdNcC2kXpMfcBVYGDuTArqyhocJgvA=
github.com/mattn/go-isatty v0.0.6/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.9 h1:d5US/mDsogSGW37IV293h//ZFaeajb69h+EHFsv2xGg=
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
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/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/urfave/cli v1.22.1 h1:+mkCCcOFKPnCmVYVcURKps1Xe+3zP90gSYGNfRkjoIY=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25 h1:jsG6UpNLt9iAsb0S2AGW28DveNzzgmbXR+ENoPjUeIU=
golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a h1:aYOabOQFp6Vj6W1F80affTUvO9UxmJRx8K0gsfABByQ=
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+33 -21
View File
@@ -34,59 +34,59 @@ func main() {
cli.StringSliceFlag{
Name: "host, H",
Usage: "Server host",
EnvVar: "PLUGIN_HOST,SCP_HOST,SSH_HOST,HOST",
EnvVar: "PLUGIN_HOST,SCP_HOST,SSH_HOST,HOST,INPUT_HOST",
},
cli.StringFlag{
Name: "port, P",
Value: "22",
Usage: "Server port, default to 22",
EnvVar: "PLUGIN_PORT,SCP_PORT,SSH_PORT,PORT",
EnvVar: "PLUGIN_PORT,SCP_PORT,SSH_PORT,PORT,INPUT_PORT",
},
cli.StringFlag{
Name: "username, u",
Usage: "Server username",
EnvVar: "PLUGIN_USERNAME,PLUGIN_USER,SCP_USERNAME,SSH_USERNAME,USERNAME",
EnvVar: "PLUGIN_USERNAME,PLUGIN_USER,SCP_USERNAME,SSH_USERNAME,USERNAME,INPUT_USERNAME",
},
cli.StringFlag{
Name: "password, p",
Usage: "Password for password-based authentication",
EnvVar: "PLUGIN_PASSWORD,SCP_PASSWORD,SSH_PASSWORD,PASSWORD",
EnvVar: "PLUGIN_PASSWORD,SCP_PASSWORD,SSH_PASSWORD,PASSWORD,INPUT_PASSWORD",
},
cli.DurationFlag{
Name: "timeout",
Usage: "connection timeout",
EnvVar: "PLUGIN_TIMEOUT,SCP_TIMEOUT",
EnvVar: "PLUGIN_TIMEOUT,SCP_TIMEOUT,INPUT_TIMEOUT",
},
cli.DurationFlag{
Name: "command.timeout,T",
Usage: "command timeout",
EnvVar: "PLUGIN_COMMAND_TIMEOUT,SSH_COMMAND_TIMEOUT",
EnvVar: "PLUGIN_COMMAND_TIMEOUT,SSH_COMMAND_TIMEOUT,INPUT_COMMAND_TIMEOUT",
Value: 60 * time.Second,
},
cli.StringFlag{
Name: "key, k",
Usage: "ssh private key",
EnvVar: "PLUGIN_KEY,SCP_KEY,SSH_KEY,KEY",
EnvVar: "PLUGIN_KEY,SCP_KEY,SSH_KEY,KEY,INPUT_KEY",
},
cli.StringFlag{
Name: "key-path, i",
Usage: "ssh private key path",
EnvVar: "PLUGIN_KEY_PATH,SCP_KEY_PATH,SSH_KEY_PATH",
EnvVar: "PLUGIN_KEY_PATH,SCP_KEY_PATH,SSH_KEY_PATH,INPUT_KEY_PATH",
},
cli.StringSliceFlag{
Name: "target, t",
Usage: "Target path on the server",
EnvVar: "PLUGIN_TARGET,SCP_TARGET,TARGET",
EnvVar: "PLUGIN_TARGET,SCP_TARGET,TARGET,INPUT_TARGET",
},
cli.StringSliceFlag{
Name: "source, s",
Usage: "scp file list",
EnvVar: "PLUGIN_SOURCE,SCP_SOURCE,SOURCE",
EnvVar: "PLUGIN_SOURCE,SCP_SOURCE,SOURCE,INPUT_SOURCE",
},
cli.BoolFlag{
Name: "rm, r",
Usage: "remove target folder before upload data",
EnvVar: "PLUGIN_RM,SCP_RM,RM",
EnvVar: "PLUGIN_RM,SCP_RM,RM,INPUT_RM",
},
cli.StringFlag{
Name: "repo.owner",
@@ -148,55 +148,65 @@ func main() {
cli.StringFlag{
Name: "proxy.ssh-key",
Usage: "private ssh key of proxy",
EnvVar: "PLUGIN_PROXY_SSH_KEY,PLUGIN_PROXY_KEY,PROXY_SSH_KEY,PROXY_KEY",
EnvVar: "PLUGIN_PROXY_SSH_KEY,PLUGIN_PROXY_KEY,PROXY_SSH_KEY,PROXY_KEY,INPUT_PROXY_SSH_KEY",
},
cli.StringFlag{
Name: "proxy.key-path",
Usage: "ssh private key path of proxy",
EnvVar: "PLUGIN_PROXY_KEY_PATH,PROXY_SSH_KEY_PATH",
EnvVar: "PLUGIN_PROXY_KEY_PATH,PROXY_SSH_KEY_PATH,INPUT_PROXY_SSH_KEY_PATH",
},
cli.StringFlag{
Name: "proxy.username",
Usage: "connect as user of proxy",
EnvVar: "PLUGIN_PROXY_USERNAME,PLUGIN_PROXY_USER,PROXY_SSH_USERNAME,PROXY_USERNAME",
EnvVar: "PLUGIN_PROXY_USERNAME,PLUGIN_PROXY_USER,PROXY_SSH_USERNAME,PROXY_USERNAME,INPUT_PROXY_USERNAME",
Value: "root",
},
cli.StringFlag{
Name: "proxy.password",
Usage: "user password of proxy",
EnvVar: "PLUGIN_PROXY_PASSWORD,PROXY_SSH_PASSWORD,PROXY_PASSWORD",
EnvVar: "PLUGIN_PROXY_PASSWORD,PROXY_SSH_PASSWORD,PROXY_PASSWORD,INPUT_PROXY_PASSWORD",
},
cli.StringFlag{
Name: "proxy.host",
Usage: "connect to host of proxy",
EnvVar: "PLUGIN_PROXY_HOST,PROXY_SSH_HOST,PROXY_HOST",
EnvVar: "PLUGIN_PROXY_HOST,PROXY_SSH_HOST,PROXY_HOST,INPUT_PROXY_HOST",
},
cli.StringFlag{
Name: "proxy.port",
Usage: "connect to port of proxy",
EnvVar: "PLUGIN_PROXY_PORT,PROXY_SSH_PORT,PROXY_PORT",
EnvVar: "PLUGIN_PROXY_PORT,PROXY_SSH_PORT,PROXY_PORT,INPUT_PROXY_PORT",
Value: "22",
},
cli.DurationFlag{
Name: "proxy.timeout",
Usage: "proxy connection timeout",
EnvVar: "PLUGIN_PROXY_TIMEOUT,PROXY_SSH_TIMEOUT",
EnvVar: "PLUGIN_PROXY_TIMEOUT,PROXY_SSH_TIMEOUT,INPUT_PROXY_TIMEOUT",
},
cli.IntFlag{
Name: "strip.components",
Usage: "Remove the specified number of leading path elements.",
EnvVar: "PLUGIN_STRIP_COMPONENTS,TAR_STRIP_COMPONENTS",
EnvVar: "PLUGIN_STRIP_COMPONENTS,TAR_STRIP_COMPONENTS,INPUT_STRIP_COMPONENTS",
},
cli.StringFlag{
Name: "tar.exec",
Usage: "Alternative `tar` executable to on the dest host",
EnvVar: "PLUGIN_TAR_EXEC,SCP_TAR_EXEC",
EnvVar: "PLUGIN_TAR_EXEC,SCP_TAR_EXEC,INPUT_TAR_EXEC",
Value: "tar",
},
cli.StringFlag{
Name: "tar.tmp-path",
Usage: "Temporary path for tar file on the dest host",
EnvVar: "PLUGIN_TAR_TMP_PATH,SCP_TAR_TMP_PATH",
},
cli.BoolFlag{
Name: "debug",
Usage: "remove target folder before upload data",
EnvVar: "PLUGIN_DEBUG,DEBUG",
EnvVar: "PLUGIN_DEBUG,DEBUG,INPUT_DEBUG",
},
cli.BoolFlag{
Name: "overwrite",
Usage: "use --overwrite flag with tar",
EnvVar: "PLUGIN_OVERWRITE,SCP_OVERWRITE,INPUT_OVERWRITE",
},
}
@@ -273,6 +283,8 @@ func run(c *cli.Context) error {
Debug: c.Bool("debug"),
StripComponents: c.Int("strip.components"),
TarExec: c.String("tar.exec"),
TarTmpPath: c.String("tar.tmp-path"),
Overwrite: c.Bool("overwrite"),
Proxy: easyssh.DefaultConfig{
Key: c.String("proxy.ssh-key"),
KeyPath: c.String("proxy.key-path"),
+8 -33
View File
@@ -9,11 +9,8 @@
steps: [
{
name: 'vet',
image: 'golang:1.12',
image: 'golang:1.13',
pull: 'always',
environment: {
GO111MODULE: 'on',
},
commands: [
'make vet',
],
@@ -26,11 +23,8 @@
},
{
name: 'lint',
image: 'golang:1.12',
image: 'golang:1.13',
pull: 'always',
environment: {
GO111MODULE: 'on',
},
commands: [
'make lint',
],
@@ -43,11 +37,8 @@
},
{
name: 'misspell',
image: 'golang:1.12',
image: 'golang:1.13',
pull: 'always',
environment: {
GO111MODULE: 'on',
},
commands: [
'make misspell-check',
],
@@ -60,11 +51,8 @@
},
{
name: 'test',
image: 'golang:1.12-alpine',
image: 'golang:1.13-alpine',
pull: 'always',
environment: {
GO111MODULE: 'on',
},
commands: [
'apk add git make curl perl bash build-base zlib-dev ucl-dev',
'make ssh-server',
@@ -105,11 +93,10 @@
steps: [
{
name: 'build-push',
image: 'golang:1.12',
image: 'golang:1.13',
pull: 'always',
environment: {
CGO_ENABLED: '0',
GO111MODULE: 'on',
},
commands: [
'go build -v -ldflags \'-X main.build=${DRONE_BUILD_NUMBER}\' -a -o release/' + os + '/' + arch + '/' + name,
@@ -122,11 +109,10 @@
},
{
name: 'build-tag',
image: 'golang:1.12',
image: 'golang:1.13',
pull: 'always',
environment: {
CGO_ENABLED: '0',
GO111MODULE: 'on',
},
commands: [
'go build -v -ldflags \'-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\' -a -o release/' + os + '/' + arch + '/' + name,
@@ -137,7 +123,7 @@
},
{
name: 'executable',
image: 'golang:1.12',
image: 'golang:1.13',
pull: 'always',
commands: [
'./release/' + os + '/' + arch + '/' + name + ' --help',
@@ -202,11 +188,8 @@
steps: [
{
name: 'build-all-binary',
image: 'golang:1.12',
image: 'golang:1.13',
pull: 'always',
environment: {
GO111MODULE: 'on',
},
commands: [
'make release'
],
@@ -256,14 +239,6 @@
ignore_missing: true,
},
},
{
name: 'microbadger',
image: 'plugins/webhook:1',
pull: 'always',
settings: {
url: { 'from_secret': 'microbadger_url' },
},
},
],
depends_on: depends_on,
trigger: {
+44 -4
View File
@@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
"sync"
"time"
@@ -57,8 +58,10 @@ type (
Remove bool
StripComponents int
TarExec string
TarTmpPath string
Proxy easyssh.DefaultConfig
Debug bool
Overwrite bool
}
// Plugin values.
@@ -194,6 +197,32 @@ type fileList struct {
Source []string
}
func (p *Plugin) buildArgs(target string) []string {
args := []string{}
args = append(args,
p.Config.TarExec,
"-xf",
p.DestFile,
)
if p.Config.StripComponents > 0 {
args = append(args, "--strip-components")
args = append(args, strconv.Itoa(p.Config.StripComponents))
}
if p.Config.Overwrite {
args = append(args, "--overwrite")
}
args = append(args,
"-C",
target,
)
return args
}
// Exec executes the plugin.
func (p *Plugin) Exec() error {
if len(p.Config.Host) == 0 {
@@ -261,6 +290,9 @@ func (p *Plugin) Exec() error {
},
}
// upload file to the tmp path
p.DestFile = fmt.Sprintf("%s%s", p.Config.TarTmpPath, p.DestFile)
// Call Scp method with file you want to upload to remote server.
p.log(host, "scp file to server.")
err := ssh.Scp(tar, p.DestFile)
@@ -298,10 +330,18 @@ func (p *Plugin) Exec() error {
// untar file
p.log(host, "untar file", p.DestFile)
if p.Config.StripComponents > 0 {
_, _, _, err = ssh.Run(fmt.Sprintf("%s -xf %s --strip-components=%d -C %s", p.Config.TarExec, p.DestFile, p.Config.StripComponents, target), p.Config.CommandTimeout)
} else {
_, _, _, err = ssh.Run(fmt.Sprintf("%s -xf %s -C %s", p.Config.TarExec, p.DestFile, target), p.Config.CommandTimeout)
commamd := strings.Join(p.buildArgs(target), " ")
if p.Config.Debug {
fmt.Println("$", commamd)
}
outStr, errStr, _, err := ssh.Run(commamd, p.Config.CommandTimeout)
if outStr != "" {
p.log(host, "output: ", outStr)
}
if errStr != "" {
p.log(host, "error: ", errStr)
}
if err != nil {
+78
View File
@@ -5,6 +5,7 @@ import (
"os/exec"
"os/user"
"path/filepath"
"reflect"
"testing"
"time"
@@ -267,6 +268,7 @@ func TestIgnoreList(t *testing.T) {
Target: []string{filepath.Join(u.HomeDir, "ignore")},
CommandTimeout: 60 * time.Second,
TarExec: "tar",
Debug: true,
},
}
@@ -456,3 +458,79 @@ func TestRemoveDestFile(t *testing.T) {
err = plugin.removeDestFile(ssh)
assert.Error(t, err)
}
func TestPlugin_buildArgs(t *testing.T) {
type fields struct {
Repo Repo
Build Build
Config Config
DestFile string
}
type args struct {
target string
}
tests := []struct {
name string
fields fields
args args
want []string
}{
{
name: "default command",
fields: fields{
Config: Config{
Overwrite: false,
TarExec: "tar",
},
DestFile: "foo.tar",
},
args: args{
target: "foo",
},
want: []string{"tar", "-xf", "foo.tar", "-C", "foo"},
},
{
name: "strip components",
fields: fields{
Config: Config{
Overwrite: false,
TarExec: "tar",
StripComponents: 2,
},
DestFile: "foo.tar",
},
args: args{
target: "foo",
},
want: []string{"tar", "-xf", "foo.tar", "--strip-components", "2", "-C", "foo"},
},
{
name: "overwrite",
fields: fields{
Config: Config{
TarExec: "tar",
StripComponents: 2,
Overwrite: true,
},
DestFile: "foo.tar",
},
args: args{
target: "foo",
},
want: []string{"tar", "-xf", "foo.tar", "--strip-components", "2", "--overwrite", "-C", "foo"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := &Plugin{
Repo: tt.fields.Repo,
Build: tt.fields.Build,
Config: tt.fields.Config,
DestFile: tt.fields.DestFile,
}
if got := p.buildArgs(tt.args.target); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Plugin.buildArgs() = %v, want %v", got, tt.want)
}
})
}
}