Compare commits

...

160 Commits

Author SHA1 Message Date
Bo-Yi Wu 2041794fd5 ci: update Go version and enhance GitHub Actions workflow
- Update Go version in GitHub Actions workflow from 1.21 to 1.22

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-07-14 15:42:01 +08:00
Bo-Yi Wu a2d37cbc1d chore: update dependencies and improve test coverage
- Update Go version from 1.18 to 1.22 in go.mod

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-07-14 15:35:48 +08:00
Bo-Yi Wu aa872a30be style: refactor import aliases for easyssh library
- Alias `github.com/appleboy/easyssh-proxy` import as `easyssh` in `main.go`
- Alias `github.com/appleboy/easyssh-proxy` import as `easyssh` in `plugin.go`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-07-14 15:30:53 +08:00
Bo-Yi Wu c049944302 chore: update Go dependencies to latest versions
- Update `golang.org/x/crypto` dependency from `v0.24.0` to `v0.25.0`
- Update `golang.org/x/sys` dependency from `v0.21.0` to `v0.22.0`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-07-14 15:25:54 +08:00
Bo-Yi Wu 0914cd212b test: enable comprehensive debugging in plugin execution (#278)
* test: enable comprehensive debugging in plugin execution

- Add debug logging to `exec` function in `plugin.go`
- Enable debug mode in `TestCommandOutput` and `TestSudoCommand` tests
- Remove redundant command blocks from multiple tests in `plugin_test.go`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* test: refactor codebase to improve performance and readability

- Remove debug command block from `TestSudoCommand` test

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* refactor: refactor test environment setup and command markers

- Add environment markers to `TestCommandOutput` for localhost and 127.0.0.1
- Remove command markers from `TestFingerprint`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* fix: improve environment variable handling in debug mode

- Add a check for non-empty environment variables when debug mode is enabled
- Remove redundant environment variable output in tests

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

---------

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-07-14 15:24:36 +08:00
Bo-Yi Wu e28acf4f3b ci: update Docker actions and remove ARM build step
- Remove `make build_linux_arm` step
- Update `docker/setup-qemu-action` from v2 to v3
- Update `docker/setup-buildx-action` from v2 to v3
- Update `docker/login-action` from v2 to v3
- Update `docker/metadata-action` from v4 to v5
- Update `docker/build-push-action` from v4 to v6
- Remove `linux/arm` from the platforms list

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-07-14 14:23:53 +08:00
Bo-Yi Wu c0e111cbef ci: update GoReleaser action to version 6
- Update GoReleaser action from version 5 to version 6

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-06-12 15:06:46 +08:00
Bo-Yi Wu 50e34882a3 chore: update Go dependencies to latest versions
- Update `golang.org/x/crypto` dependency from v0.23.0 to v0.24.0
- Update `golang.org/x/sys` dependency from v0.20.0 to v0.21.0

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-06-05 13:31:31 +08:00
appleboy 31607874dc chore: update dependencies to latest versions
- Update `github.com/urfave/cli/v2` to version `2.27.2`
- Update `golang.org/x/crypto` to version `0.23.0`
- Update `github.com/xrash/smetrics` to version `0.0.0-20240521201337-686a1a2994c1`
- Update `golang.org/x/sys` to version `0.20.0`

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-06-01 10:08:07 +08:00
appleboy 591c6c9f77 ci: update GitHub workflows and improve test configurations
- Update golangci-lint-action from v4 to v6 in GitHub workflow

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-06-01 09:54:06 +08:00
appleboy be0b134f0a ci: optimize CI/CD pipeline with Docker build cache
- Add Docker build cache configuration to GitHub Actions workflow

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-06-01 09:53:09 +08:00
Bo-Yi Wu dc026ac547 feat: refactor configuration handling in main function (#275)
- Add `FilePath` attribute with value `.host` to the configuration in `main` function

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-06-01 09:50:16 +08:00
Bo-Yi Wu 2e8030ff52 build: improve system compatibility and performance (#274)
- Add `tzdata` package to the Dockerfile

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-06-01 09:29:39 +08:00
Bo-Yi Wu 5401378058 chore: refine Changelog Generation Process
- Change the changelog generation from using git to using GitHub
- Add custom changelog sections for build process and documentation updates with specific regex patterns and order

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-04-19 10:27:48 +08:00
Bo-Yi Wu 046c21368d chore: update dependencies to latest versions
- Update `golang.org/x/crypto` from `v0.18.0` to `v0.22.0`
- Update `github.com/cpuguy83/go-md2man/v2` from `v2.0.3` to `v2.0.4`
- Update `github.com/xrash/smetrics` to a newer commit
- Update `golang.org/x/sys` from `v0.16.0` to `v0.19.0`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-04-18 08:22:08 +08:00
Bo-Yi Wu e8a39a16a6 chore: refactor release process configuration
- Change the changelog configuration in `.goreleaser.yaml` from using GitHub to using git.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-04-02 15:58:52 +08:00
Bo-Yi Wu f8b1db2997 chore: refine goreleaser configuration and output
- Change the name template in `.goreleaser.yaml` from single to double quotes
- Add a changelog configuration to `.goreleaser.yaml` with categorized groups for features, bug fixes, enhancements, refactor, and others

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-04-02 14:57:44 +08:00
Bo-Yi Wu f37c5b3557 ci: refactor CI workflows and update actions
- Update GitHub Actions to use newer versions (checkout to v4, codeql-action to v3, setup-go to v5, goreleaser-action to v5, golangci-lint-action to v4, codecov-action to v4)
- Remove specific Go version pinning in favor of using the version specified in go.mod
- Enable checking for the latest Go version in setup-go action
- Replace `release --rm-dist` argument with `release --clean` in goreleaser action
- Reorder steps and remove redundant checkout step in testing workflow

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-04-02 14:10:03 +08:00
appleboy 2c5e17dd2e docs: update badge
Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-03-16 13:00:11 +08:00
appleboy 42f9adb1b5 test: rename the workflow 2024-03-16 12:58:52 +08:00
Bo-Yi Wu cafc139713 test: enhance testing and internal API robustness (#269)
* test: support ipv6

* chore: update

Signed-off-by: appleboy <appleboy.tw@gmail.com>

* chore: update

Signed-off-by: appleboy <appleboy.tw@gmail.com>

---------

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-03-16 11:29:44 +08:00
appleboy 7d0a886109 refactor: remove unnecessary line setting FilePath field to .host
- Remove the line that sets the `FilePath` field to `.host`

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-01-27 11:22:04 +08:00
Bo-Yi Wu a83bebeafe refactor: refactor environment variable naming
- Rename environment variables to include `_PROXY_` in their names

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-01-21 09:35:37 +08:00
Bo-Yi Wu a41d4afc40 chore(protocol): improve IPv6 address. (#268)
* docs: improve documentation and configuration handling

- Clarify valid values for the IP protocol in usage messages for both main application and proxy settings

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* test: improve IPv6 command execution tests

- Add a new test function `TestCommandWithIPv6` to check command execution with an IPv6 address
- Initialize test variables and expected output for the IPv6 command test
- Set up a `Plugin` struct with IPv6 host, user, port, key path, script, and command timeout for testing
- Verify that `plugin.Exec()` returns `nil` (no error) in the IPv6 test
- Assert that the output of the command execution matches the expected output in the IPv6 test

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* test: enhance test suite and CI robustness

- Add support for IPv6 protocol in `TestCommandWithIPv6` test case in `plugin_test.go`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* update

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* update

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* update

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* update

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* update2

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* update3

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* update4

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* update5

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* update5

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* update5

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

---------

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-01-21 09:27:49 +08:00
Bo-Yi Wu 91fd4f8071 chore: update golang.org/x/crypto to v0.18.0 in go.mod file
- Update golang.org/x/crypto from v0.17.0 to v0.18.0 in the go.mod file

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-01-11 20:53:31 +08:00
Bo-Yi Wu b34fffdbd3 feat: update plugin functionality in main.go and plugin.go files
- Add a new flag to the main.go file
- Add a new field to the Plugin type in the plugin.go file
- Remove two lines from the plugin_test.go file

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-01-07 17:44:54 +08:00
Bo-Yi Wu d217773bac test: increase test coverage for SudoCommand function
- Add a test for the SudoCommand function

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-01-07 17:40:23 +08:00
Bo-Yi Wu ae023d7aa6 chore: update sudoers file for improved security and permissions management
- Add `requiretty` to the `Defaults` in sudoers
- Allow `drone-scp` to run commands without password prompt

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-01-07 17:21:59 +08:00
Bo-Yi Wu 222545746b chore: refactor build and deployment processes
- Add `sudo` to the apk add command in the lint workflow
- Add SSH server setup to the Makefile

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-01-07 17:13:16 +08:00
Bo-Yi Wu a5f89304fd chore: update golang.org/x/sys to v0.16.0 in go.mod file
- Update the version of `golang.org/x/sys` from `v0.15.0` to `v0.16.0` in the `go.mod` file

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-01-07 13:38:54 +08:00
Bo-Yi Wu a9cfc0c134 chore: update external dependencies to latest versions
- Update the version of `github.com/appleboy/easyssh-proxy` from `v1.4.1-0.20231106031702-5666e2ea5156` to `v1.5.0`
- Update the version of `github.com/urfave/cli/v2` from `v2.26.0` to `v2.27.1`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-01-01 13:53:45 +08:00
Bo-Yi Wu 13ba21acf6 chore: update dependencies to latest versions
- Update `github.com/urfave/cli` dependency from `v2.25.7` to `v2.26.0`
- Upgrade `golang.org/x/crypto` from `v0.14.0` to `v0.17.0`
- Bump `github.com/cpuguy83/go-md2man` from `v2.0.2` to `v2.0.3`
- Update `github.com/xrash/smetrics` to a newer commit
- Update `golang.org/x/sys` from `v0.14.0` to `v0.15.0`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2023-12-26 13:33:32 +08:00
Bo-Yi Wu e270b033d1 ci: update dependencies and workflows
- Update the Golang version in the lint workflow from `1.19-alpine` to `1.21-alpine`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2023-12-26 13:29:44 +08:00
Bo-Yi Wu aa9314a009 chore: add default user for enhanced security (#267)
- Add a new `.hadolint.yaml` configuration file with specific rule ignores
- Update the Dockerfile to install `ca-certificates` without a fixed version
- Add commands to create a `deploy` user and group with UID and GID `1000`, set home directory, and set ownership
- Set the Docker container to run as the `deploy` user with UID and GID `1000`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2023-12-26 13:29:22 +08:00
Bo-Yi Wu 037e0231ac chore: update dependencies to latest versions
- Update the `go-version` in the lint.yml file from `^1` to `^1.21`
- Update the version of `github.com/appleboy/easyssh-proxy` in the go.mod file from `v1.4.0` to `v1.4.1-0.20231106031702-5666e2ea5156`
- Update the version of `golang.org/x/crypto` in the go.mod file from `v0.10.0` to `v0.14.0`
- Update the version of `golang.org/x/sys` in the go.mod file from `v0.9.0` to `v0.14.0`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2023-11-06 11:20:51 +08:00
Bo-Yi Wu ddf1b161aa chore: refactor GitHub Actions workflows
- Fix a typo in the cron expression for the codeql.yml workflow
- Change the language specification from ['go'] to ['go'] in the codeql.yml workflow
- Change the version specification from 'v*' to 'v*' in the docker.yml workflow
- Change the branch specification from 'master' to 'master' in the docker.yml workflow
- Change the go-version specification from '^1' to '^1.21' in the docker.yml workflow
- Remove the name "Set up QEMU" in the docker.yml workflow
- Remove the name "Set up Docker Buildx" in the docker.yml workflow
- Remove the name "Login to Docker Hub" in the docker.yml workflow
- Remove the name "Login to GitHub Container Registry" in the docker.yml workflow
- Remove the name "Docker meta" in the docker.yml workflow
- Remove the name "Build and push" in the docker.yml workflow
- Change the version specification from '*' to '*' in the goreleaser.yml workflow
- Remove the name "Checkout" in the goreleaser.yml workflow
- Remove the name "Setup go" in the goreleaser.yml workflow
- Change the go-version specification from '^1' to '^1' in the goreleaser.yml workflow
- Remove the name "Run GoReleaser" in the goreleaser.yml workflow
- Change the go-version specification from '^1' to '^1' in the lint.yml workflow

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2023-10-25 10:52:46 +08:00
Bo-Yi Wu 32510c86bf feat: implement and test all environment variables functionality (#264)
- Add a new flag `allenvs` to pass all environment variables to the shell script
- Implement the `AllEnvs` functionality in the `exec` function
- Add a new function `findEnvs` to find all environment variables with specified prefixes
- Add tests for the `findEnvs` function and the `AllEnvs` functionality
2023-07-23 09:41:09 +08:00
appleboy 80cecf1ed3 refactor: improve code clarity and logging functionality
- Add a comment to clarify the purpose of the `format` function
- Add a comment to clarify the purpose of the `log` function
- Modify the `log` function to always print the message, removing the previous conditional statement

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2023-07-23 07:30:08 +08:00
appleboy c7dd9890fa chore: improve performance and test coverage across OSs
- Update easyssh-proxy dependency from v1.3.11 to v1.4.0

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2023-06-23 23:43:57 +08:00
Yoan Tournade 905bb4cb1a chore: allows to specify IP protocol (#261)
* Allows to specify IP protocol, including IPv4 only

* Add tests forcing IPv4 or IPv6
2023-06-23 16:45:44 +08:00
Bo-Yi Wu 066b72ac09 chore: update dependencies and improve test accuracy
- Update urfave/cli/v2 from v2.25.5 to v2.25.7
- Update golang.org/x/crypto from v0.9.0 to v0.10.0
- Update golang.org/x/sys from v0.8.0 to v0.9.0 (indirect)

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2023-06-21 16:25:15 +08:00
Bo-Yi Wu b33ad90151 chore: improve API efficiency and test robustness
- Update ca-certificates version from `20220614-r4` to `20230506-r0`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2023-06-04 16:46:53 +08:00
Bo-Yi Wu c4f4d0f112 chore: improve performance and update dependencies
- Add `bin` to .gitignore
- Change output path for the executable in Makefile
- Update `github.com/stretchr/testify` to v1.8.4
- Update `github.com/urfave/cli/v2` to v2.25.5

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2023-06-04 16:44:10 +08:00
appleboy 8b81da22bc chore: update dependencies and improve test tolerance
- Update `github.com/urfave/cli/v2` dependency from `v2.25.3` to `v2.25.4`
- Update `golang.org/x/crypto` dependency from `v0.8.0` to `v0.9.0`

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2023-05-29 21:07:06 +08:00
appleboy ba70ad67ca ci: improve release process and test robustness
- Add extra_files with .xz glob pattern to .goreleaser.yaml

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2023-05-06 08:16:02 +08:00
appleboy 73fa4739e3 chore: optimize codebase with latest library updates
- Update `github.com/urfave/cli/v2` from `v2.25.1` to `v2.25.3`
- Update `golang.org/x/sys` from `v0.7.0` to `v0.8.0` (indirect)

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2023-05-06 08:00:17 +08:00
appleboy 0a721bdfff build: optimize binary size and improve test accuracy
- Add a post-build hook to compress the generated binary with `xz` at level 9 compression

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2023-05-06 07:57:07 +08:00
appleboy a7c7568d70 feat: improve API usage and test coverage across platforms
- Add an option to include extra pre-existing files in the release with a specified file format (`.xz`)

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2023-05-06 07:51:54 +08:00
appleboy bc8c96633a chore: improve API usage and test accuracy
- Add "strconv" import
- Update app copyright to use the current year

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2023-05-01 11:56:09 +08:00
Bo-Yi.Wu 30b18520ed refactor(setting): reorder format. 2023-04-15 06:25:31 +08:00
Bo-Yi Wu 67a2631616 docs: improve clarity of Usage message in main.go
- Modify the `Usage` message in main.go

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2023-04-13 09:48:46 +08:00
Alexey Smirnov fdc4c8de43 fix: example with secrets (#178) 2023-04-13 09:39:43 +08:00
Bo-Yi Wu 49542638c6 refactor: set default environment variables format in plugin (#253)
- Add `INPUT_ENVS_FORMAT` to the list of environment variables in `main.go`
- Define `envsFormat` variable in `plugin.go`
- Add default value for `Config.EnvsFormat` in `plugin.go` `Exec()` function

fix https://github.com/appleboy/drone-ssh/pull/235
2023-04-13 09:32:31 +08:00
Vladimir Sigalkin 6464d9999f chore: flexible configuration of environment value transfer (#235)
**Reason:**
I have to use drone-ssh to work with Windows SSH. Initially, drone-ssh is written so that it transmits environment variables through the `export` command. Which makes it unsuitable for working with Power Shell.

**Solution:**
I have added a new option to configure environment variable commands formatting, with default value: `export {NAME}={VALUE}`. When I use drone-ssh with PowerShell I set this option like this: `$env:{NAME} = {VALUE}`.
2023-04-13 09:13:07 +08:00
Bo-Yi Wu 4aabfc90dd chore: upgrade Dependencies to Latest Versions
- Upgrade easyssh-proxy from v1.3.9 to v1.3.10
- Upgrade testify from v1.8.1 to v1.8.2
- Upgrade crypto from v0.7.0 to v0.8.0
- Upgrade sys from v0.6.0 to v0.7.0

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2023-04-13 09:09:37 +08:00
Bo-Yi Wu b9cfca60e9 refactor: standardize environment variables naming conventions (#252)
- Modify the `EnvVars` slice to include `INPUT_` prefix when needed
- Remove unused environment variables from the `EnvVars` slice
- Update the `EnvVars` slice to include `PROXY_` prefix when needed
- Modify the `EnvVars` slice to include `PLUGIN_SSH_CIPHERS` as `PROXY_SSH_CIPHERS`
- Modify the `EnvVars` slice to include `PLUGIN_PROXY_USE_INSECURE_CIPHER` as `PROXY_SSH_USE_INSECURE_CIPHER`
- Modify the `EnvVars` slice to include `PLUGIN_PROXY_FINGERPRINT` as `PROXY_SSH_FINGERPRINT`
- Remove the environment variable `PROXY_HOST`
- Modify the `EnvVars` slice to include `PLUGIN_DEBUG` as `INPUT_DEBUG`

* https://github.com/appleboy/ssh-action/issues/53#issuecomment-1184700432
* https://github.com/appleboy/ssh-action/issues/32#issuecomment-1184700363
* https://github.com/appleboy/ssh-action/issues/213
2023-04-13 09:08:12 +08:00
Bo-Yi Wu a8d30dc133 feat: refactor code for parallel execution on multiple hosts (#249)
- Add `trimValues` function for cleaning up slice values
- Remove unused `wg.Done()` call
- Modify `Exec` function to launch goroutines for each host in `Config.Host`
- Add test for `ScriptStop` with multiple hosts and sync mode

refer to: https://github.com/appleboy/ssh-action/issues/233
2023-04-04 16:56:50 +08:00
Bo-Yi.Wu f733bb5ebf chore: remove Hadolint configuration file
- Delete the `.hadolint.yaml` file.

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
2023-04-04 15:39:10 +08:00
Bo-Yi.Wu b0ddeb9413 chore: update container security measures
- Add Open Container Initiative labels for image source, description, and licenses
- Update `apk` command to include specific version of `ca-certificates`

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
2023-04-04 15:38:42 +08:00
Bo-Yi Wu 8c5d17d83d chore: refactor release process to use main.Version flag
- Change the `drone-ssh` version flag to `main.Version` in `.goreleaser.yaml`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2023-03-29 08:59:31 +08:00
Bo-Yi Wu 050e0e6efd docs: use ghcr.io/appleboy/drone-ssh image for SSH connections
- Update the `image` field to use `ghcr.io/appleboy/drone-ssh` in DOCS.md
- Update the `image` field to use `ghcr.io/appleboy/drone-ssh` in README.md

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2023-03-28 14:43:00 +08:00
Bo-Yi Wu f01d5d9454 chore(deps): update go.sum 2023-03-28 14:23:20 +08:00
Bo-Yi.Wu c004469746 ci: upgrade setup-go action and remove release binary action
- Remove release binary github action
- Upgrade setup-go action from v3 to v4 in docker, goreleaser, and lint github actions

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
2023-03-27 22:02:48 +08:00
Bo-Yi.Wu bc2dac669a chore: refactor installation command for drone-ssh using go install
- Update `drone-ssh` installation command to use `go install` instead of `go get`

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
2023-03-27 22:01:11 +08:00
Albert Wang 541508632d chore: remove dotenv autoloading (#243) 2023-03-27 21:56:04 +08:00
Bo-Yi.Wu 22cd751b47 chore: update third-party libraries for improved security and performance
- Update urfave/cli to version 2.25.1
- Update golang.org/x/crypto to version 0.7.0
- Update golang.org/x/sys to version 0.6.0 (indirect)

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
2023-03-27 21:52:44 +08:00
Bo-Yi.Wu 5a6a923356 build: configure cross-platform builds with Goreleaser
- Add a new file `.goreleaser.yaml`
- Configure builds for multiple operating systems and architectures
- Set flags and ldflags for the builds
- Add a binary name template for the builds
- Add an archive format
- Add a checksum template
- Add a snapshot template

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
2023-03-27 21:51:52 +08:00
Bo-Yi Wu 1a95b5f1b3 chore(auth): allow use password and key at same time (#240) 2023-02-28 17:04:39 +08:00
Bo-Yi Wu d0ed2bb2fb chore(docker): support multiple platform 2023-02-27 14:01:12 +08:00
Bo-Yi.Wu b2a60a2fec chore(CI): upgrade build push actions
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
2023-02-24 09:35:20 +08:00
Bo-Yi.Wu 7c7619ebbc chore(deps): upgrade dependency.
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
2023-02-24 09:33:41 +08:00
dependabot[bot] fc62fb377c chore(deps): bump hadolint/hadolint-action from 3.0.0 to 3.1.0 (#225)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-01 16:27:36 +08:00
Bo-Yi Wu 808373f717 docs: fix wrong link 2023-02-01 16:27:18 +08:00
Albert Wang 6d9d6acc6a Document configuration through dotenv variables (#224)
* Format parameter table

* Format parameter keys as code

* Add documentation of configuration overrides
2023-02-01 16:26:22 +08:00
dependabot[bot] 439ca59b8f chore(deps): bump github.com/urfave/cli/v2 from 2.23.7 to 2.24.2 (#229)
Bumps [github.com/urfave/cli/v2](https://github.com/urfave/cli) from 2.23.7 to 2.24.2.
- [Release notes](https://github.com/urfave/cli/releases)
- [Changelog](https://github.com/urfave/cli/blob/main/docs/CHANGELOG.md)
- [Commits](https://github.com/urfave/cli/compare/v2.23.7...v2.24.2)

---
updated-dependencies:
- dependency-name: github.com/urfave/cli/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-01 16:24:25 +08:00
Bo-Yi Wu d9493e4563 chore(deps): upgrade go 2023-01-10 13:36:56 +08:00
Prashant Shahi cc7a2d5983 fix(envs): 🐛 set environment variable instead of bash variable (#219) 2023-01-08 08:36:33 +08:00
Bo-Yi Wu 0a6e4de21c chore(CI): latest tag for linux and amd64 2023-01-03 11:10:09 +08:00
Bo-Yi.Wu 48f817effb chore(CI): add strategy in docker build
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
2023-01-01 15:16:29 +08:00
Bo-Yi Wu c8ecc03ef5 Revert "chore(scripts): disable SliceFlagSeparator" (#215) 2022-12-27 08:25:11 +08:00
Bo-Yi Wu ddf9ca3e6f chore(scripts): disable SliceFlagSeparator (#212) 2022-12-25 15:48:42 +08:00
Bo-Yi Wu a568d2e551 chore(cli): upgrade urfave/cli to v2 (#211) 2022-12-25 15:44:30 +08:00
Bo-Yi Wu d17a10dd0c Revert "chore(cli): upgrade urfave/cli to v2" (#210) 2022-12-25 15:15:55 +08:00
Bo-Yi Wu d83798f25b chore(cli): upgrade urfave/cli to v2 (#152) 2022-12-25 14:56:47 +08:00
Bo-Yi.Wu 59b08e1b4c chore(CI): Add Codecov
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
2022-12-25 14:32:58 +08:00
Bo-Yi.Wu 8d07792340 chore(CI): replace go get with go install
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
2022-12-25 14:27:10 +08:00
Bo-Yi.Wu 55bebcef3d chore(CI): add sshd service and testing
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
2022-12-25 14:21:18 +08:00
Bo-Yi.Wu dfa002a267 chore(CI): release binary
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
2022-12-25 11:12:32 +08:00
Bo-Yi.Wu 60da6458b5 docs(readme): remove drone badge
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
2022-12-25 10:02:55 +08:00
Bo-Yi.Wu fe2455ee6d chore(CI): rename
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
2022-12-25 10:01:25 +08:00
Bo-Yi.Wu d2cea88132 chore(CI): add hadolint checker
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
2022-12-25 09:51:48 +08:00
Bo-Yi.Wu 8da3787c97 chore(CI): add enable checker
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
2022-12-24 21:50:42 +08:00
Bo-Yi.Wu bf419cebf8 chore(CI): check push event
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
2022-12-24 21:41:20 +08:00
Bo-Yi.Wu 7b141b72ae chore(dockerfile): replace ADD with COPY
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
2022-12-24 21:34:09 +08:00
Bo-Yi.Wu 058dcd40d8 chore(CI): remove drone CI config
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
2022-12-24 21:31:52 +08:00
Bo-Yi.Wu 598a11a626 chore(CI): update setup-go version
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
2022-12-24 21:29:23 +08:00
Bo-Yi.Wu 31c298bb19 chore(CI): update version check.
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
2022-12-24 21:26:33 +08:00
Bo-Yi.Wu df6997a8e1 chore(CI): add build config
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
2022-12-24 21:16:51 +08:00
Bo-Yi.Wu 8c5823d726 chore(CI): rename
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
2022-12-24 21:15:56 +08:00
Bo-Yi.Wu c643b61b1b chore(CI): update golangci-lint to latest
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
2022-12-24 21:09:45 +08:00
Bo-Yi Wu 7c482e315d chore(deps): upgrade goreleaser 2022-12-20 11:24:55 +08:00
dependabot[bot] 07f8a59174 chore(deps): bump golang.org/x/crypto from 0.3.0 to 0.4.0 (#206)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-17 22:37:54 +08:00
Bo-Yi Wu f1ffd39895 chore(CI): disabled release binary 2022-12-08 17:23:51 +08:00
Bo-Yi Wu 040533909f chore(CI): disable build arm and arm64 2022-12-08 16:35:43 +08:00
Bo-Yi Wu 5be4214887 chore(CI): upgrade go version. 2022-12-08 09:21:50 +08:00
Bo-Yi Wu 906f6275a4 chore(CI): remove build step 2022-12-08 08:57:49 +08:00
Bo-Yi.Wu 4a05db1fe7 chore(CI): using container
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
2022-12-07 22:01:05 +08:00
Bo-Yi.Wu f1be0b3f99 chore(CI): disable windows
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
2022-12-07 21:47:03 +08:00
Bo-Yi.Wu d296797a6f chore(CI): enable build
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
2022-12-07 21:36:00 +08:00
Bo-Yi Wu 5525ed602f fix(lint): io/ioutil is deprecated 2022-12-07 13:47:02 +08:00
Bo-Yi Wu 836fd2d711 chore(dep): update go dependency 2022-12-07 13:44:49 +08:00
WangJun 307409651f remove empty string output (#198) 2022-12-07 13:35:59 +08:00
dependabot[bot] b937d64a58 chore(deps): bump github.com/stretchr/testify from 1.7.2 to 1.8.0 (#195)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-07-07 22:56:29 +08:00
Bo-Yi Wu 1dcc9acbe5 chore(release): support multiple platform 2022-06-16 10:50:33 +08:00
Bo-Yi Wu f11e2ed931 chore: remove testing 2022-06-15 23:16:34 +08:00
Bo-Yi Wu cf159c578b fix: missing installed version 2022-06-15 22:55:25 +08:00
Bo-Yi Wu c7df4b7f8c chore: bump golangci version 2022-06-15 22:52:24 +08:00
dependabot[bot] 4e6b85e4c7 chore(deps): bump github/codeql-action from 1 to 2 (#185)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-15 22:50:34 +08:00
dependabot[bot] 0dd29f2223 chore(deps): bump actions/checkout from 2 to 3 (#188)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-15 22:50:24 +08:00
dependabot[bot] bf697d7977 chore(deps): bump github.com/stretchr/testify from 1.6.1 to 1.7.2 (#191)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-15 22:50:06 +08:00
Bo-Yi Wu 1944689d90 chore: enable funding button 2022-06-15 22:26:03 +08:00
Bo-Yi Wu 7b035f27e3 chore: bump all dependecy 2022-06-15 22:25:29 +08:00
Bo-Yi Wu 492a5db6ae chore: update drone build flow 2022-06-15 22:24:28 +08:00
Bo-Yi Wu 2407d7a56b chore: update github plugin version 2022-06-15 22:21:51 +08:00
Bo-Yi Wu 642891be17 chore: add dependabot
fix https://github.com/appleboy/drone-ssh/pull/176
2022-06-15 22:19:33 +08:00
Bo-Yi Wu 471976f1d8 chore(go): upgrade to go1.17
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2022-02-06 13:02:24 +08:00
Bo-Yi Wu c4e24b1ab9 feat(CI): Enable GitHub Actions
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2022-02-06 13:00:22 +08:00
Bo-Yi Wu 9c88ecd501 chore: update go module
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2021-06-18 08:52:06 +08:00
Bo-Yi Wu b96b4db8cb chore: upgrade to go.16
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2021-06-18 08:48:29 +08:00
Bo-Yi Wu 6850ed1bff chore(makefile): change gofmt toll to gofumpt 2021-01-12 00:54:00 +08:00
Bo-Yi Wu 5750d46265 chore: update revive 2021-01-12 00:52:53 +08:00
Bo-Yi Wu 9edff25d7f chore(docs): fix typo 2020-11-18 06:33:33 +08:00
Bo-Yi Wu 79f4c2408b docs: add Multiple Hosts with differebt port
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-11-17 11:03:37 +08:00
Bo-Yi Wu 76fb630345 remove support i386
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-11-17 10:34:26 +08:00
Bo-Yi Wu e059b33708 chore: support multiple port (#168)
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-11-17 10:14:11 +08:00
Bo-Yi Wu bb733a53de chore: update docs
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-09-25 22:22:21 +08:00
Bo-Yi Wu f725d02d7b chore: add drone env
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-09-25 22:21:39 +08:00
Bo-Yi Wu ac47ca3480 chore: upgrade to go1.15
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-09-25 22:12:48 +08:00
Bo-Yi Wu 66bbf9b7cd chore: support Multiline SSH commands interpreted as single lines (#160)
https://github.com/appleboy/ssh-action/issues/75
2020-08-08 15:31:57 +08:00
Bo-Yi Wu 77a818a94d chore: update go module 2020-08-08 14:50:04 +08:00
Bo-Yi Wu 1d89d2d875 chore: load env from /run/drone/env path 2020-07-17 23:23:31 +08:00
Bo-Yi Wu b447da961e chore: remove auto load .env file
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-06-15 16:37:09 +08:00
Bo-Yi Wu 4d46a02d53 chore: bump easyssh to 1.3.7 2020-05-24 13:57:02 +08:00
Bo-Yi Wu 7994d5555e chore: update dependency 2020-05-24 12:43:43 +08:00
Bo-Yi Wu c7d8b0f2e9 chore: upgrade easy-ssh 2020-05-24 12:05:38 +08:00
Bo-Yi Wu 7755fdb39f chore: upgrade easy-ssh 2020-05-24 12:04:21 +08:00
Bo-Yi Wu 83417639b9 chore: clean up go module 2020-05-24 10:46:44 +08:00
Bo-Yi Wu 7344ac6529 chore: support UseInsecureCipher (#158) 2020-05-24 10:43:11 +08:00
Bo-Yi Wu 1288a4b20d docs: update fingerprint comment.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-05-19 14:11:26 +08:00
Bo-Yi Wu 11ec0bec7e update makefile
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-05-19 14:02:15 +08:00
Bo-Yi Wu a2c6be3c19 support Fingerprint (#157) 2020-05-19 14:01:28 +08:00
Bo-Yi Wu 923defc397 easyssh-proxy upgrade => v1.3.5
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-05-19 12:55:32 +08:00
Bo-Yi Wu ec9d02ec38 missing Ciphers config
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-04-30 15:49:00 +08:00
Bo-Yi Wu 9c9e7914ce support custom Ciphers value
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-04-30 15:38:46 +08:00
techknowlogick 9e205a756f Add option to use file for host info (#156) 2020-04-29 14:21:31 +08:00
Bo-Yi Wu 99f63aaaa8 upgrade easyssh-proxy
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-04-16 15:27:12 +08:00
Bo-Yi Wu 6bdace5138 update to go 1.14
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-02-27 09:58:32 +08:00
Bo-Yi Wu 54cdb693e4 update module
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-02-07 13:25:48 +08:00
Bo-Yi Wu 81d0430ffd chore(makefile): remove GOPACKAGE variable 2020-02-01 00:42:50 +08:00
Bo-Yi Wu a046be092b docs: add passphrase example
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-12-31 09:46:38 +08:00
29 changed files with 1431 additions and 1185 deletions
-16
View File
@@ -1,16 +0,0 @@
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',
]),
]
-365
View File
@@ -1,365 +0,0 @@
---
kind: pipeline
name: testing
platform:
os: linux
arch: amd64
steps:
- name: vet
pull: always
image: golang:1.13
commands:
- make vet
volumes:
- name: gopath
path: /go
- name: lint
pull: always
image: golang:1.13
commands:
- make lint
volumes:
- name: gopath
path: /go
- name: misspell
pull: always
image: golang:1.13
commands:
- make misspell-check
volumes:
- name: gopath
path: /go
- name: test
pull: always
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
volumes:
- name: gopath
path: /go
- name: codecov
pull: always
image: robertstettner/drone-codecov
settings:
token:
from_secret: codecov_token
volumes:
- name: gopath
temp: {}
---
kind: pipeline
name: linux-amd64
platform:
os: linux
arch: amd64
steps:
- name: build-push
pull: always
image: golang:1.13
commands:
- go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/amd64/drone-ssh
environment:
CGO_ENABLED: 0
when:
event:
exclude:
- tag
- name: build-tag
pull: always
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-ssh
environment:
CGO_ENABLED: 0
when:
event:
- tag
- name: executable
pull: always
image: golang:1.13
commands:
- ./release/linux/amd64/drone-ssh --help
- name: dryrun
pull: always
image: plugins/docker:linux-amd64
settings:
cache_from: appleboy/drone-ssh
dockerfile: docker/Dockerfile.linux.amd64
dry_run: true
repo: appleboy/drone-ssh
tags: linux-amd64
when:
event:
- pull_request
- name: publish
pull: always
image: plugins/docker:linux-amd64
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:
os: linux
arch: arm64
steps:
- name: build-push
pull: always
image: golang:1.13
commands:
- go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm64/drone-ssh
environment:
CGO_ENABLED: 0
when:
event:
exclude:
- tag
- name: build-tag
pull: always
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-ssh
environment:
CGO_ENABLED: 0
when:
event:
- tag
- name: executable
pull: always
image: golang:1.13
commands:
- ./release/linux/arm64/drone-ssh --help
- name: dryrun
pull: always
image: plugins/docker:linux-arm64
settings:
cache_from: appleboy/drone-ssh
dockerfile: docker/Dockerfile.linux.arm64
dry_run: true
repo: appleboy/drone-ssh
tags: linux-arm64
when:
event:
- pull_request
- name: publish
pull: always
image: plugins/docker:linux-arm64
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:
os: linux
arch: arm
steps:
- name: build-push
pull: always
image: golang:1.13
commands:
- go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm/drone-ssh
environment:
CGO_ENABLED: 0
when:
event:
exclude:
- tag
- name: build-tag
pull: always
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-ssh
environment:
CGO_ENABLED: 0
when:
event:
- tag
- name: executable
pull: always
image: golang:1.13
commands:
- ./release/linux/arm/drone-ssh --help
- name: dryrun
pull: always
image: plugins/docker:linux-arm
settings:
cache_from: appleboy/drone-ssh
dockerfile: docker/Dockerfile.linux.arm
dry_run: true
repo: appleboy/drone-ssh
tags: linux-arm
when:
event:
- pull_request
- name: publish
pull: always
image: plugins/docker:linux-arm
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:
os: linux
arch: amd64
steps:
- name: build-all-binary
pull: always
image: golang:1.13
commands:
- make release
when:
event:
- tag
- name: deploy-all-binary
pull: always
image: plugins/github-release
settings:
api_key:
from_secret: github_release_api_key
files:
- dist/release/*
when:
event:
- tag
trigger:
ref:
- refs/tags/**
depends_on:
- testing
---
kind: pipeline
name: notifications
platform:
os: linux
arch: amd64
steps:
- name: manifest
pull: always
image: plugins/manifest
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/**
depends_on:
- linux-amd64
- linux-arm64
- linux-arm
- release-binary
...
-42
View File
@@ -1,42 +0,0 @@
# unifying the coding style for different editors and IDEs => editorconfig.org
; indicate this is the root of the project
root = true
###########################################################
; common
###########################################################
[*]
charset = utf-8
end_of_line = LF
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 2
###########################################################
; make
###########################################################
[Makefile]
indent_style = tab
[makefile]
indent_style = tab
###########################################################
; markdown
###########################################################
[*.md]
trim_trailing_whitespace = false
###########################################################
; golang
###########################################################
[*.go]
indent_style = tab
+13
View File
@@ -0,0 +1,13 @@
# These are supported funding model platforms
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: ['https://www.paypal.me/appleboy46']
+10
View File
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
- package-ecosystem: gomod
directory: /
schedule:
interval: weekly
+54
View File
@@ -0,0 +1,54 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
on:
push:
branches: [master]
pull_request:
# The branches below must be a subset of the branches above
branches: [master]
schedule:
- cron: "41 23 * * 6"
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: ["go"]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# 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.
# 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
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
+73
View File
@@ -0,0 +1,73 @@
name: Docker Image
on:
push:
branches:
- master
tags:
- "v*"
pull_request:
branches:
- "master"
jobs:
build-docker:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
check-latest: true
- name: Build binary
run: |
make build_linux_amd64
make build_linux_arm64
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: docker-meta
uses: docker/metadata-action@v5
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@v6
with:
context: .
platforms: linux/amd64,linux/arm64
file: docker/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.docker-meta.outputs.tags }}
labels: ${{ steps.docker-meta.outputs.labels }}
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache
cache-to: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache,mode=max
+32
View File
@@ -0,0 +1,32 @@
name: Goreleaser
on:
push:
tags:
- "*"
permissions:
contents: write
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
check-latest: true
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+50
View File
@@ -0,0 +1,50 @@
name: Lint and Testing
on:
push:
pull_request:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
check-latest: true
- name: Setup golangci-lint
uses: golangci/golangci-lint-action@v6
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:
image: golang:1.22-alpine
options: --sysctl net.ipv6.conf.all.disable_ipv6=0
steps:
- name: Checkout repository
uses: actions/checkout@v4
- 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@v4
+2
View File
@@ -28,3 +28,5 @@ coverage.txt
release release
drone-ssh drone-ssh
.cover .cover
dist
bin
+123
View File
@@ -0,0 +1,123 @@
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
changelog:
use: github
groups:
- title: Features
regexp: "^.*feat[(\\w)]*:+.*$"
order: 0
- title: "Bug fixes"
regexp: "^.*fix[(\\w)]*:+.*$"
order: 1
- title: "Enhancements"
regexp: "^.*chore[(\\w)]*:+.*$"
order: 2
- title: "Refactor"
regexp: "^.*refactor[(\\w)]*:+.*$"
order: 3
- title: "Build process updates"
regexp: ^.*?(build|ci)(\(.+\))??!?:.+$
order: 4
- title: "Documentation updates"
regexp: ^.*?docs?(\(.+\))??!?:.+$
order: 4
- title: Others
order: 999
+3
View File
@@ -0,0 +1,3 @@
ignored:
- DL3018
- DL3008
-25
View File
@@ -1,25 +0,0 @@
ignoreGeneratedHeader = false
severity = "warning"
confidence = 0.8
errorCode = 1
warningCode = 1
[rule.blank-imports]
[rule.context-as-argument]
[rule.context-keys-type]
[rule.dot-imports]
[rule.error-return]
[rule.error-strings]
[rule.error-naming]
[rule.exported]
[rule.if-return]
[rule.increment-decrement]
[rule.var-naming]
[rule.var-declaration]
[rule.package-comments]
[rule.range]
[rule.receiver-naming]
[rule.time-naming]
[rule.unexported-return]
[rule.indent-error-flow]
[rule.errorf]
+98 -78
View File
@@ -5,14 +5,14 @@ author: appleboy
tags: [ deploy, publish, ssh ] tags: [ deploy, publish, ssh ]
repo: appleboy/drone-ssh repo: appleboy/drone-ssh
logo: term.svg logo: term.svg
image: appleboy/drone-ssh image: ghcr.io/appleboy/drone-ssh
--- ---
Use the SSH plugin to execute commands on a remote server. The below pipeline configuration demonstrates simple usage: Use the SSH plugin to execute commands on a remote server. The below pipeline configuration demonstrates simple usage:
```yaml ```yaml
- name: ssh commands - name: ssh commands
image: appleboy/drone-ssh image: ghcr.io/appleboy/drone-ssh
settings: settings:
host: foo.com host: foo.com
username: root username: root
@@ -27,7 +27,7 @@ Example configuration in your `.drone.yml` file for multiple hosts:
```diff ```diff
- name: ssh commands - name: ssh commands
image: appleboy/drone-ssh image: ghcr.io/appleboy/drone-ssh
settings: settings:
host: host:
+ - foo.com + - foo.com
@@ -40,11 +40,28 @@ Example configuration in your `.drone.yml` file for multiple hosts:
- echo world - echo world
``` ```
Example configuration for multiple hosts with different port:
```diff
- name: ssh commands
image: ghcr.io/appleboy/drone-ssh
settings:
host:
+ - foo.com:1234
+ - bar.com:5678
username: root
password: 1234
- port: 22
script:
- echo hello
- echo world
```
Example configuration for command timeout, default value is 60 seconds: Example configuration for command timeout, default value is 60 seconds:
```diff ```diff
- name: ssh commands - name: ssh commands
image: appleboy/drone-ssh image: ghcr.io/appleboy/drone-ssh
settings: settings:
host: foo.com host: foo.com
username: root username: root
@@ -60,7 +77,7 @@ Example configuration for execute commands on a remote server using SSHProxyC
```diff ```diff
- name: ssh commands - name: ssh commands
image: appleboy/drone-ssh image: ghcr.io/appleboy/drone-ssh
settings: settings:
host: foo.com host: foo.com
username: root username: root
@@ -79,7 +96,7 @@ Example configuration using password from secrets:
```diff ```diff
- name: ssh commands - name: ssh commands
image: appleboy/drone-ssh image: ghcr.io/appleboy/drone-ssh
settings: settings:
host: foo.com host: foo.com
username: root username: root
@@ -95,7 +112,7 @@ Example configuration using ssh key from secrets:
```diff ```diff
- name: ssh commands - name: ssh commands
image: appleboy/drone-ssh image: ghcr.io/appleboy/drone-ssh
settings: settings:
host: foo.com host: foo.com
username: root username: root
@@ -111,23 +128,28 @@ Example configuration for exporting custom secrets:
```diff ```diff
- name: ssh commands - name: ssh commands
image: appleboy/drone-ssh image: ghcr.io/appleboy/drone-ssh
environment:
# MUST BE in UPPERCASE
COMMIT:
from_secret: commit
settings: settings:
host: foo.com host: foo.com
username: root username: root
password: 1234 password: 1234
port: 22 port: 22
+ envs: + envs:
- aws_access_key_id # can be in lowercase (uppercased in code)
- commit
script: script:
- 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: appleboy/drone-ssh image: ghcr.io/appleboy/drone-ssh
settings: settings:
host: foo.com host: foo.com
username: root username: root
@@ -139,75 +161,73 @@ Example configuration for stoping script after first failure:
- echo "you can't see the steps." - echo "you can't see the steps."
``` ```
Example configuration for passphrase which protecting a private key:
```diff
- name: ssh commands
image: ghcr.io/appleboy/drone-ssh
settings:
host: foo.com
username: root
+ key:
+ from_secret: ssh_key
+ passphrase: 1234
port: 22
script:
- mkdir abc/def/efg
- echo "you can't see the steps."
```
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
ssh_username | Key | Description |
: account for target host user |-----|-------------|
| `ssh_username` | account for target host user |
ssh_password | `ssh_password` | password for target host user | |
: password for target host user | `ssh_passphrase` | The purpose of the passphrase is usually to encrypt the private key. |
| `ssh_key` | plain text of user private key |
ssh_key | `proxy_ssh_username` | account for user of proxy server |
: plain text of user private key | `proxy_ssh_password` | password for user of proxy server |
| `proxy_ssh_passphrase` | The purpose of the passphrase is usually to encrypt the private key. |
proxy_ssh_username | `proxy_ssh_key` | plain text of user private key for proxy server |
: account for user of proxy server
proxy_ssh_password
: password for user of proxy server
proxy_ssh_key
: plain text of user private key for proxy server
## Parameter Reference ## Parameter Reference
host | Key | Description |
: target hostname or IP |-----|-------------|
| `host` | target hostname or IP |
port | `port` | ssh port of target host |
: ssh port of target host | `protocol` | IP protocol to use: either tcp, tcp4 or tcp6 |
| `username` | account for target host user |
username | `password` | password for target host user |
: account for target host user | `key` | plain text of user private key |
| `key_path` | key path of user private key |
password | `envs` | custom secrets which are made available in the script section |
: password for target host user | `script` | execute commands on a remote server |
| `script_stop` | stop script after first failure |
key | `timeout` | Timeout is the maximum amount of time for the ssh connection to establish, default is 30 seconds. |
: plain text of user private key | `command_timeout` | Command timeout is the maximum amount of time for the execute commands, default is 10 minutes. |
| `proxy_host` | proxy hostname or IP |
key_path | `proxy_port` | ssh port of proxy host |
: key path of user private key | `proxy_protocol` | IP protocol to use for the proxy: either tcp, tcp4 or tcp6 |
| `proxy_username` | account for proxy host user |
envs | `proxy_password` | password for proxy host user |
: custom secrets which are made available in the script section | `proxy_key` | plain text of proxy private key |
| `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
+106 -71
View File
@@ -1,18 +1,19 @@
DIST := dist DIST := dist
EXECUTABLE := drone-ssh EXECUTABLE := drone-ssh
GOFMT ?= gofmt "-s" GOFMT ?= gofumpt -l
DIST := dist
DIST_DIRS := $(DIST)/binaries $(DIST)/release
GO ?= go GO ?= go
SHASUM ?= shasum -a 256
GOFILES := $(shell find . -name "*.go" -type f)
HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
XGO_VERSION := go-1.19.x
GXZ_PAGAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.11
# for dockerhub LINUX_ARCHS ?= linux/amd64,linux/arm64
DEPLOY_ACCOUNT := appleboy DARWIN_ARCHS ?= darwin-10.12/amd64,darwin-10.12/arm64
DEPLOY_IMAGE := $(EXECUTABLE) WINDOWS_ARCHS ?= windows/*
TARGETS ?= linux darwin windows
ARCHS ?= amd64 386
PACKAGES ?= $(shell $(GO) list ./...)
SOURCES ?= $(shell find . -name "*.go" -type f)
TAGS ?=
LDFLAGS ?= -X 'main.Version=$(VERSION)'
ifneq ($(shell uname), Darwin) ifneq ($(shell uname), Darwin)
EXTLDFLAGS = -extldflags "-static" $(null) EXTLDFLAGS = -extldflags "-static" $(null)
@@ -20,76 +21,67 @@ else
EXTLDFLAGS = EXTLDFLAGS =
endif endif
ifeq ($(HAS_GO), GO)
GOPATH ?= $(shell $(GO) env GOPATH)
export PATH := $(GOPATH)/bin:$(PATH)
CGO_EXTRA_CFLAGS := -DSQLITE_MAX_VARIABLE_NUMBER=32766
CGO_CFLAGS ?= $(shell $(GO) env CGO_CFLAGS) $(CGO_EXTRA_CFLAGS)
endif
ifeq ($(OS), Windows_NT)
GOFLAGS := -v -buildmode=exe
EXECUTABLE ?= $(EXECUTABLE).exe
else ifeq ($(OS), Windows)
GOFLAGS := -v -buildmode=exe
EXECUTABLE ?= $(EXECUTABLE).exe
else
GOFLAGS := -v
EXECUTABLE ?= $(EXECUTABLE)
endif
ifneq ($(DRONE_TAG),) ifneq ($(DRONE_TAG),)
VERSION ?= $(DRONE_TAG) VERSION ?= $(DRONE_TAG)
else else
VERSION ?= $(shell git describe --tags --always || git rev-parse --short HEAD) VERSION ?= $(shell git describe --tags --always || git rev-parse --short HEAD)
endif endif
TAGS ?=
LDFLAGS ?= -X 'main.Version=$(VERSION)'
all: build all: build
fmt: fmt:
$(GOFMT) -w $(SOURCES) @hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) install mvdan.cc/gofumpt; \
fi
$(GOFMT) -w $(GOFILES)
vet: vet:
$(GO) vet $(PACKAGES) $(GO) vet ./...
lint:
@hash revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/mgechev/revive; \
fi
revive -config .revive.toml ./... || exit 1
.PHONY: misspell-check
misspell-check:
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/client9/misspell/cmd/misspell; \
fi
misspell -error $(SOURCES)
.PHONY: misspell
misspell:
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/client9/misspell/cmd/misspell; \
fi
misspell -w $(SOURCES)
.PHONY: fmt-check .PHONY: fmt-check
fmt-check: fmt-check:
@diff=$$($(GOFMT) -d $(SOURCES)); \ @hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) install mvdan.cc/gofumpt; \
fi
@diff=$$($(GOFMT) -d $(GOFILES)); \
if [ -n "$$diff" ]; then \ if [ -n "$$diff" ]; then \
echo "Please run 'make fmt' and commit the result:"; \ echo "Please run 'make fmt' and commit the result:"; \
echo "$${diff}"; \ echo "$${diff}"; \
exit 1; \ exit 1; \
fi; fi;
test: fmt-check test:
@$(GO) test -v -cover -coverprofile coverage.txt $(PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1 @$(GO) test -v -cover -coverprofile coverage.txt ./... && echo "\n==>\033[32m Ok\033[m\n" || exit 1
install: $(SOURCES) install: $(GOFILES)
$(GO) install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' $(GO) install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)'
build: $(EXECUTABLE) build: $(EXECUTABLE)
$(EXECUTABLE): $(SOURCES) $(EXECUTABLE): $(GOFILES)
$(GO) build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o $@ $(GO) build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o bin/$@
release: release-dirs release-build release-copy release-check
release-dirs:
mkdir -p $(DIST)/binaries $(DIST)/release
release-build:
@which gox > /dev/null; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/mitchellh/gox; \
fi
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));)
release-check:
cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
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)
@@ -103,37 +95,80 @@ build_linux_arm64:
build_linux_arm: build_linux_arm:
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/arm/$(DEPLOY_IMAGE) CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/arm/$(DEPLOY_IMAGE)
docker_image:
docker build -t $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE) .
docker: docker_image
docker_deploy:
ifeq ($(tag),)
@echo "Usage: make $@ tag=<tag>"
@exit 1
endif
# deploy image
docker tag $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE):latest $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE):$(tag)
docker push $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE):$(tag)
ssh-server: ssh-server:
adduser -h /home/drone-scp -s /bin/bash -D -S drone-scp adduser -h /home/drone-scp -s /bin/sh -D -S drone-scp
echo drone-scp:1234 | chpasswd echo drone-scp:1234 | chpasswd
mkdir -p /home/drone-scp/.ssh mkdir -p /home/drone-scp/.ssh
chmod 700 /home/drone-scp/.ssh chmod 700 /home/drone-scp/.ssh
cat tests/.ssh/id_rsa.pub >> /home/drone-scp/.ssh/authorized_keys cat tests/.ssh/id_rsa.pub >> /home/drone-scp/.ssh/authorized_keys
cat tests/.ssh/test.pub >> /home/drone-scp/.ssh/authorized_keys cat tests/.ssh/test.pub >> /home/drone-scp/.ssh/authorized_keys
chmod 600 /home/drone-scp/.ssh/authorized_keys
chown -R drone-scp /home/drone-scp/.ssh chown -R drone-scp /home/drone-scp/.ssh
# 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 # install ssh and start server
apk add --update openssh openrc apk add --update openssh openrc
rm -rf /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_dsa_key rm -rf /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_dsa_key
sed -i 's/^#PubkeyAuthentication yes/PubkeyAuthentication yes/g' /etc/ssh/sshd_config
sed -i 's/AllowTcpForwarding no/AllowTcpForwarding yes/g' /etc/ssh/sshd_config sed -i 's/AllowTcpForwarding no/AllowTcpForwarding yes/g' /etc/ssh/sshd_config
sed -i 's/^#ListenAddress 0.0.0.0/ListenAddress 0.0.0.0/g' /etc/ssh/sshd_config
sed -i 's/^#ListenAddress ::/ListenAddress ::/g' /etc/ssh/sshd_config
./tests/entrypoint.sh /usr/sbin/sshd -D & ./tests/entrypoint.sh /usr/sbin/sshd -D &
coverage: coverage:
sed -i '/main.go/d' coverage.txt sed -i '/main.go/d' coverage.txt
.PHONY: deps-backend
deps-backend:
$(GO) mod download
$(GO) install $(GXZ_PAGAGE)
$(GO) install $(XGO_PACKAGE)
.PHONY: release
release: release-linux release-darwin release-windows release-copy release-compress release-check
$(DIST_DIRS):
mkdir -p $(DIST_DIRS)
.PHONY: release-windows
release-windows: | $(DIST_DIRS)
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) run $(XGO_PACKAGE) -go $(XGO_VERSION) -buildmode exe -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets '$(WINDOWS_ARCHS)' -out $(EXECUTABLE)-$(VERSION) .
ifeq ($(CI),true)
cp -r /build/* $(DIST)/binaries/
endif
.PHONY: release-linux
release-linux: | $(DIST_DIRS)
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) run $(XGO_PACKAGE) -go $(XGO_VERSION) -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets '$(LINUX_ARCHS)' -out $(EXECUTABLE)-$(VERSION) .
ifeq ($(CI),true)
cp -r /build/* $(DIST)/binaries/
endif
.PHONY: release-darwin
release-darwin: | $(DIST_DIRS)
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) run $(XGO_PACKAGE) -go $(XGO_VERSION) -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '$(LDFLAGS)' -targets '$(DARWIN_ARCHS)' -out $(EXECUTABLE)-$(VERSION) .
ifeq ($(CI),true)
cp -r /build/* $(DIST)/binaries/
endif
.PHONY: release-copy
release-copy: | $(DIST_DIRS)
cd $(DIST); for file in `find . -type f -name "*"`; do cp $${file} ./release/; done;
.PHONY: release-check
release-check: | $(DIST_DIRS)
cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "checksumming $${file}" && $(SHASUM) `echo $${file} | sed 's/^..//'` > $${file}.sha256; done;
.PHONY: release-compress
release-compress: | $(DIST_DIRS)
cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && $(GO) run $(GXZ_PAGAGE) -k -9 $${file}; done;
clean: clean:
$(GO) clean -x -i ./... $(GO) clean -x -i ./...
rm -rf coverage.txt $(EXECUTABLE) $(DIST) rm -rf coverage.txt $(EXECUTABLE) $(DIST)
+17 -6
View File
@@ -4,11 +4,10 @@
[![GitHub tag](https://img.shields.io/github/tag/appleboy/drone-ssh.svg)](https://github.com/appleboy/drone-ssh/releases) [![GitHub tag](https://img.shields.io/github/tag/appleboy/drone-ssh.svg)](https://github.com/appleboy/drone-ssh/releases)
[![GoDoc](https://godoc.org/github.com/appleboy/drone-ssh?status.svg)](https://godoc.org/github.com/appleboy/drone-ssh) [![GoDoc](https://godoc.org/github.com/appleboy/drone-ssh?status.svg)](https://godoc.org/github.com/appleboy/drone-ssh)
[![Build Status](https://cloud.drone.io/api/badges/appleboy/drone-ssh/status.svg)](https://cloud.drone.io/appleboy/drone-ssh) [![Lint and Testing](https://github.com/appleboy/drone-ssh/actions/workflows/testing.yml/badge.svg?branch=master)](https://github.com/appleboy/drone-ssh/actions/workflows/testing.yml)
[![codecov](https://codecov.io/gh/appleboy/drone-ssh/branch/master/graph/badge.svg)](https://codecov.io/gh/appleboy/drone-ssh) [![codecov](https://codecov.io/gh/appleboy/drone-ssh/branch/master/graph/badge.svg)](https://codecov.io/gh/appleboy/drone-ssh)
[![Go Report Card](https://goreportcard.com/badge/github.com/appleboy/drone-ssh)](https://goreportcard.com/report/github.com/appleboy/drone-ssh) [![Go Report Card](https://goreportcard.com/badge/github.com/appleboy/drone-ssh)](https://goreportcard.com/report/github.com/appleboy/drone-ssh)
[![Docker Pulls](https://img.shields.io/docker/pulls/appleboy/drone-ssh.svg)](https://hub.docker.com/r/appleboy/drone-ssh/) [![Docker Pulls](https://img.shields.io/docker/pulls/appleboy/drone-ssh.svg)](https://hub.docker.com/r/appleboy/drone-ssh/)
[![micro badger](https://images.microbadger.com/badges/image/appleboy/drone-ssh.svg)](https://microbadger.com/images/appleboy/drone-ssh "Get your own image badge on microbadger.com")
Drone plugin to execute commands on a remote host through SSH. For the usage Drone plugin to execute commands on a remote host through SSH. For the usage
information and a listing of the available options please take a look at [the docs](http://plugins.drone.io/appleboy/drone-ssh/). information and a listing of the available options please take a look at [the docs](http://plugins.drone.io/appleboy/drone-ssh/).
@@ -24,7 +23,7 @@ information and a listing of the available options please take a look at [the do
```diff ```diff
pipeline: pipeline:
scp: scp:
image: appleboy/drone-scp image: ghcr.io/appleboy/drone-ssh
settings: settings:
host: host:
- example1.com - example1.com
@@ -50,7 +49,7 @@ The pre-compiled binaries can be downloaded from [release page](https://github.c
With `Go` installed With `Go` installed
```sh ```sh
go get -u -v github.com/appleboy/drone-ssh go install github.com/appleboy/drone-ssh@latest
``` ```
or build the binary with the following command: or build the binary with the following command:
@@ -86,7 +85,7 @@ docker run --rm \
-e PLUGIN_SCRIPT=whoami \ -e PLUGIN_SCRIPT=whoami \
-v $(pwd):$(pwd) \ -v $(pwd):$(pwd) \
-w $(pwd) \ -w $(pwd) \
appleboy/drone-ssh ghcr.io/appleboy/drone-ssh
``` ```
## Mount key from file path ## Mount key from file path
@@ -100,7 +99,7 @@ Mount private key in `volumes` setting of `.drone.yml` config
```diff ```diff
pipeline: pipeline:
ssh: ssh:
image: appleboy/drone-ssh image: ghcr.io/appleboy/drone-ssh
host: xxxxx.com host: xxxxx.com
username: deploy username: deploy
+ volumes: + volumes:
@@ -111,3 +110,15 @@ pipeline:
``` ```
See the detail of [issue comment](https://github.com/appleboy/drone-ssh/issues/51#issuecomment-336732928). See the detail of [issue comment](https://github.com/appleboy/drone-ssh/issues/51#issuecomment-336732928).
## Configuration
See [DOCS.md](./DOCS.md) for examples and full configuration options
Configuration options are loaded from multiple sources:
0. Hardcoded drone-ssh defaults. See [main.go CLI Flags](https://github.com/appleboy/drone-ssh/blob/6d9d6acc6aef1f9166118c6ba8bd214d3a582bdb/main.go#L39) for more information.
1. From a dotenv file at a path specified by the `PLUGIN_ENV_FILE` environment variable.
2. From your `.drone.yml` Drone configuration.
Later sources override previous sources, i.e. if `PORT` is set in an `.env` file committed in the repository or created by previous test steps, it will override the default set `main.go`.
+37
View File
@@ -0,0 +1,37 @@
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 tzdata && \
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"]
-12
View File
@@ -1,12 +0,0 @@
FROM plugins/base:linux-amd64
LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
org.label-schema.name="Drone SSH" \
org.label-schema.vendor="Bo-Yi Wu" \
org.label-schema.schema-version="1.0"
RUN apk add --no-cache ca-certificates && \
rm -rf /var/cache/apk/*
ADD release/linux/amd64/drone-ssh /bin/
ENTRYPOINT ["/bin/drone-ssh"]
-12
View File
@@ -1,12 +0,0 @@
FROM plugins/base:linux-arm
LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
org.label-schema.name="Drone SSH" \
org.label-schema.vendor="Bo-Yi Wu" \
org.label-schema.schema-version="1.0"
RUN apk add --no-cache ca-certificates && \
rm -rf /var/cache/apk/*
ADD release/linux/arm/drone-ssh /bin/
ENTRYPOINT ["/bin/drone-ssh"]
-12
View File
@@ -1,12 +0,0 @@
FROM plugins/base:linux-arm64
LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
org.label-schema.name="Drone SSH" \
org.label-schema.vendor="Bo-Yi Wu" \
org.label-schema.schema-version="1.0"
RUN apk add --no-cache ca-certificates && \
rm -rf /var/cache/apk/*
ADD release/linux/arm64/drone-ssh /bin/
ENTRYPOINT ["/bin/drone-ssh"]
-9
View File
@@ -1,9 +0,0 @@
FROM microsoft/nanoserver:10.0.14393.1884
LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
org.label-schema.name="Drone SSH" \
org.label-schema.vendor="Bo-Yi Wu" \
org.label-schema.schema-version="1.0"
ADD drone-ssh.exe /drone-ssh.exe
ENTRYPOINT [ "\\drone-ssh.exe" ]
-25
View File
@@ -1,25 +0,0 @@
image: appleboy/drone-ssh:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}}
{{#if build.tags}}
tags:
{{#each build.tags}}
- {{this}}
{{/each}}
{{/if}}
manifests:
-
image: appleboy/drone-ssh:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64
platform:
architecture: amd64
os: linux
-
image: appleboy/drone-ssh:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64
platform:
architecture: arm64
os: linux
variant: v8
-
image: appleboy/drone-ssh:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm
platform:
architecture: arm
os: linux
variant: v7
+18 -5
View File
@@ -1,10 +1,23 @@
module github.com/appleboy/drone-ssh module github.com/appleboy/drone-ssh
go 1.13 go 1.22
require ( require (
github.com/appleboy/easyssh-proxy v1.3.0 github.com/appleboy/easyssh-proxy v1.5.0
github.com/joho/godotenv v1.3.0 github.com/joho/godotenv v1.5.1
github.com/stretchr/testify v1.4.0 github.com/stretchr/testify v1.8.4
github.com/urfave/cli v1.22.1 github.com/urfave/cli/v2 v2.27.2
golang.org/x/crypto v0.25.0
)
require (
github.com/ScaleFT/sshkeys v1.2.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
golang.org/x/sys v0.22.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
) )
+29 -24
View File
@@ -1,38 +1,43 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/ScaleFT/sshkeys v1.2.0 h1:5BRp6rTVIhJzXT3VcUQrKgXR8zWA3sOsNeuyW15WUA8=
github.com/ScaleFT/sshkeys v0.0.0-20181112160850-82451a803681 h1:JS2rl38kZmHgWa0xINSaSYH0Whtvem64/4+Ef0+Y5pE= github.com/ScaleFT/sshkeys v1.2.0/go.mod h1:gxOHeajFfvGQh/fxlC8oOKBe23xnnJTif00IFFbiT+o=
github.com/ScaleFT/sshkeys v0.0.0-20181112160850-82451a803681/go.mod h1:WfDateMPQ/55dPbZRp5Zxrux5WiEaHsjk9puUhz0KgY= github.com/appleboy/easyssh-proxy v1.5.0 h1:OYdSPvYQN3mhnsMH5I2OF1TgwSEcSq33kvjQfTwvZww=
github.com/appleboy/easyssh-proxy v1.3.0 h1:ToH+hZDPWP9/9E58lwxDLJQSHvgGgDAQ9ZVx6x5oofI= github.com/appleboy/easyssh-proxy v1.5.0/go.mod h1:zcEMrStH91/tcUn3gUGP0KpQwUYLm8tX/Ook1AH98uc=
github.com/appleboy/easyssh-proxy v1.3.0/go.mod h1:Kk57I3w7OCafOjp5kgZFvxk2fO8Tca5CriBTOsbSbjY= github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= github.com/cpuguy83/go-md2man/v2 v2.0.4/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/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.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.0.1/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 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/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/urfave/cli v1.22.1 h1:+mkCCcOFKPnCmVYVcURKps1Xe+3zP90gSYGNfRkjoIY= github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
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-20191227163750-53104e6ec876 h1:sKJQZMuxjOAR/Uo2LBfU90onWEf1dF4C+0hPJCc9Mpc= golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20191227163750-53104e6ec876/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
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 h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200219091948-cb0a6d8edb6c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk=
golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4=
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 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
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.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+208 -125
View File
@@ -3,12 +3,12 @@ package main
import ( import (
"log" "log"
"os" "os"
"strconv"
"time" "time"
"github.com/appleboy/easyssh-proxy" easyssh "github.com/appleboy/easyssh-proxy"
"github.com/joho/godotenv" "github.com/joho/godotenv"
_ "github.com/joho/godotenv/autoload" "github.com/urfave/cli/v2"
"github.com/urfave/cli"
) )
// Version set at compile-time // Version set at compile-time
@@ -20,11 +20,15 @@ func main() {
_ = godotenv.Load(filename) _ = godotenv.Load(filename)
} }
if _, err := os.Stat("/run/drone/env"); err == nil {
_ = godotenv.Overload("/run/drone/env")
}
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) 2019 Bo-Yi Wu" app.Copyright = "Copyright (c) " + strconv.Itoa(time.Now().Year()) + " 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",
@@ -33,126 +37,193 @@ func main() {
app.Action = run app.Action = run
app.Version = Version app.Version = Version
app.Flags = []cli.Flag{ app.Flags = []cli.Flag{
cli.StringFlag{ &cli.StringSliceFlag{
Name: "ssh-key", Name: "host",
Usage: "private ssh key", Aliases: []string{"H"},
EnvVar: "PLUGIN_SSH_KEY,PLUGIN_KEY,SSH_KEY,KEY,INPUT_KEY", Usage: "connect to host",
EnvVars: []string{"PLUGIN_HOST", "SSH_HOST", "INPUT_HOST"},
FilePath: ".host",
}, },
cli.StringFlag{ &cli.IntFlag{
Name: "ssh-passphrase", Name: "port",
Usage: "ssh passphrase", Aliases: []string{"p"},
EnvVar: "PLUGIN_SSH_PASSPHRASE,PLUGIN_PASSPHRASE,SSH_PASSPHRASE,PASSPHRASE,INPUT_PASSPHRASE", Usage: "connect to port",
EnvVars: []string{"PLUGIN_PORT", "SSH_PORT", "INPUT_PORT"},
Value: 22,
}, },
cli.StringFlag{ &cli.StringFlag{
Name: "key-path,i", Name: "protocol",
Usage: "ssh private key path", Usage: "The IP protocol to use. Valid values are \"tcp\". \"tcp4\" or \"tcp6\". Default to tcp.",
EnvVar: "PLUGIN_KEY_PATH,SSH_KEY_PATH,INPUT_KEY_PATH", EnvVars: []string{"PLUGIN_PROTOCOL", "SSH_PROTOCOL", "INPUT_PROTOCOL"},
Value: "tcp",
}, },
cli.StringFlag{ &cli.StringFlag{
Name: "username,user,u", Name: "username",
Usage: "connect as user", Aliases: []string{"user", "u"},
EnvVar: "PLUGIN_USERNAME,PLUGIN_USER,SSH_USERNAME,USERNAME,INPUT_USERNAME", Usage: "connect as user",
Value: "root", EnvVars: []string{"PLUGIN_USERNAME", "PLUGIN_USER", "SSH_USERNAME", "INPUT_USERNAME"},
Value: "root",
}, },
cli.StringFlag{ &cli.StringFlag{
Name: "password,P", Name: "password",
Usage: "user password", Aliases: []string{"P"},
EnvVar: "PLUGIN_PASSWORD,SSH_PASSWORD,PASSWORD,INPUT_PASSWORD", Usage: "user password",
EnvVars: []string{"PLUGIN_PASSWORD", "SSH_PASSWORD", "INPUT_PASSWORD"},
}, },
cli.StringSliceFlag{ &cli.DurationFlag{
Name: "host,H", Name: "timeout",
Usage: "connect to host", Aliases: []string{"t"},
EnvVar: "PLUGIN_HOST,SSH_HOST,HOST,INPUT_HOST", Usage: "connection timeout",
EnvVars: []string{"PLUGIN_TIMEOUT", "SSH_TIMEOUT", "INPUT_TIMEOUT"},
Value: 30 * time.Second,
}, },
cli.IntFlag{ &cli.StringFlag{
Name: "port,p", Name: "ssh-key",
Usage: "connect to port", Usage: "private ssh key",
EnvVar: "PLUGIN_PORT,SSH_PORT,PORT,INPUT_PORT", EnvVars: []string{"PLUGIN_SSH_KEY", "PLUGIN_KEY", "SSH_KEY", "INPUT_KEY"},
Value: 22,
}, },
cli.BoolFlag{ &cli.StringFlag{
Name: "sync", Name: "ssh-passphrase",
Usage: "sync mode", Usage: "The purpose of the passphrase is usually to encrypt the private key.",
EnvVar: "PLUGIN_SYNC,SYNC,INPUT_SYNC", EnvVars: []string{"PLUGIN_SSH_PASSPHRASE", "PLUGIN_PASSPHRASE", "SSH_PASSPHRASE", "INPUT_PASSPHRASE"},
}, },
cli.DurationFlag{ &cli.StringFlag{
Name: "timeout,t", Name: "key-path",
Usage: "connection timeout", Aliases: []string{"i"},
EnvVar: "PLUGIN_TIMEOUT,SSH_TIMEOUT,TIMEOUT,INPUT_TIMEOUT", Usage: "ssh private key path",
Value: 30 * time.Second, EnvVars: []string{"PLUGIN_KEY_PATH", "SSH_KEY_PATH", "INPUT_KEY_PATH"},
}, },
cli.DurationFlag{ &cli.StringSliceFlag{
Name: "command.timeout,T", Name: "ciphers",
Usage: "command timeout", Usage: "The allowed cipher algorithms. If unspecified then a sensible",
EnvVar: "PLUGIN_COMMAND_TIMEOUT,SSH_COMMAND_TIMEOUT,COMMAND_TIMEOUT,INPUT_COMMAND_TIMEOUT", EnvVars: []string{"PLUGIN_CIPHERS", "SSH_CIPHERS", "INPUT_CIPHERS"},
Value: 10 * time.Minute,
}, },
cli.StringSliceFlag{ &cli.BoolFlag{
Name: "script,s", Name: "useInsecureCipher",
Usage: "execute commands", Usage: "include more ciphers with use_insecure_cipher",
EnvVar: "PLUGIN_SCRIPT,SSH_SCRIPT,SCRIPT", EnvVars: []string{"PLUGIN_USE_INSECURE_CIPHER", "SSH_USE_INSECURE_CIPHER", "INPUT_USE_INSECURE_CIPHER"},
}, },
cli.StringFlag{ &cli.StringFlag{
Name: "script.string", Name: "fingerprint",
Usage: "execute single commands for github action", Usage: "fingerprint SHA256 of the host public key, default is to skip verification",
EnvVar: "INPUT_SCRIPT", EnvVars: []string{"PLUGIN_FINGERPRINT", "SSH_FINGERPRINT", "INPUT_FINGERPRINT"},
}, },
cli.BoolFlag{ &cli.BoolFlag{
Name: "script.stop", Name: "sync",
Usage: "stop script after first failure", Usage: "sync mode",
EnvVar: "PLUGIN_SCRIPT_STOP,STOP,INPUT_SCRIPT_STOP", EnvVars: []string{"PLUGIN_SYNC", "INPUT_SYNC"},
}, },
cli.StringFlag{ &cli.DurationFlag{
Name: "proxy.ssh-key", Name: "command.timeout",
Usage: "private ssh key of proxy", Aliases: []string{"T"},
EnvVar: "PLUGIN_PROXY_SSH_KEY,PLUGIN_PROXY_KEY,PROXY_SSH_KEY,INPUT_PROXY_KEY", Usage: "command timeout",
EnvVars: []string{"PLUGIN_COMMAND_TIMEOUT", "SSH_COMMAND_TIMEOUT", "INPUT_COMMAND_TIMEOUT"},
Value: 10 * time.Minute,
}, },
cli.StringFlag{ &cli.StringSliceFlag{
Name: "proxy.ssh-passphrase", Name: "script",
Usage: "proxy ssh passphrase", Aliases: []string{"s"},
EnvVar: "PLUGIN_PROXY_SSH_PASSPHRASE,PLUGIN_PROXY_PASSPHRASE,PROXY_SSH_PASSPHRASE,PROXY_PASSPHRASE,INPUT_PROXY_PASSPHRASE", Usage: "execute commands",
EnvVars: []string{"PLUGIN_SCRIPT", "SSH_SCRIPT"},
}, },
cli.StringFlag{ &cli.StringFlag{
Name: "proxy.key-path", Name: "script.string",
Usage: "ssh private key path of proxy", Usage: "execute single commands for github action",
EnvVar: "PLUGIN_PROXY_KEY_PATH,PROXY_SSH_KEY_PATH,INPUT_PROXY_KEY_PATH", EnvVars: []string{"INPUT_SCRIPT"},
}, },
cli.StringFlag{ &cli.BoolFlag{
Name: "proxy.username", Name: "script.stop",
Usage: "connect as user of proxy", Usage: "stop script after first failure",
EnvVar: "PLUGIN_PROXY_USERNAME,PLUGIN_PROXY_USER,PROXY_SSH_USERNAME,INPUT_PROXY_USERNAME", EnvVars: []string{"PLUGIN_SCRIPT_STOP", "INPUT_SCRIPT_STOP"},
Value: "root",
}, },
cli.StringFlag{ &cli.StringFlag{
Name: "proxy.password", Name: "proxy.host",
Usage: "user password of proxy", Usage: "connect to host of proxy",
EnvVar: "PLUGIN_PROXY_PASSWORD,PROXY_SSH_PASSWORD,INPUT_PROXY_PASSWORD", EnvVars: []string{"PLUGIN_PROXY_HOST", "PROXY_SSH_HOST", "INPUT_PROXY_HOST"},
}, },
cli.StringFlag{ &cli.StringFlag{
Name: "proxy.host", Name: "proxy.port",
Usage: "connect to host of proxy", Usage: "connect to port of proxy",
EnvVar: "PLUGIN_PROXY_HOST,PROXY_SSH_HOST,INPUT_PROXY_HOST", EnvVars: []string{"PLUGIN_PROXY_PORT", "PROXY_SSH_PORT", "INPUT_PROXY_PORT"},
Value: "22",
}, },
cli.StringFlag{ &cli.StringFlag{
Name: "proxy.port", Name: "proxy.protocol",
Usage: "connect to port of proxy", Usage: "The IP protocol to use for the proxy. Valid values are \"tcp\". \"tcp4\" or \"tcp6\". Default to tcp.",
EnvVar: "PLUGIN_PROXY_PORT,PROXY_SSH_PORT,INPUT_PROXY_PORT", EnvVars: []string{"PLUGIN_PROXY_PROTOCOL", "SSH_PROXY_PROTOCOL", "INPUT_PROXY_PROTOCOL"},
Value: "22", Value: "tcp",
}, },
cli.DurationFlag{ &cli.StringFlag{
Name: "proxy.timeout", Name: "proxy.username",
Usage: "proxy connection timeout", Usage: "connect as user of proxy",
EnvVar: "PLUGIN_PROXY_TIMEOUT,PROXY_SSH_TIMEOUT,INPUT_PROXY_TIMEOUT", EnvVars: []string{"PLUGIN_PROXY_USERNAME", "PLUGIN_PROXY_USER", "PROXY_SSH_USERNAME", "INPUT_PROXY_USERNAME"},
Value: "root",
}, },
cli.StringSliceFlag{ &cli.StringFlag{
Name: "envs", Name: "proxy.password",
Usage: "pass environment variable to shell script", Usage: "user password of proxy",
EnvVar: "PLUGIN_ENVS,INPUT_ENVS", EnvVars: []string{"PLUGIN_PROXY_PASSWORD", "PROXY_SSH_PASSWORD", "INPUT_PROXY_PASSWORD"},
}, },
cli.BoolFlag{ &cli.StringFlag{
Name: "debug", Name: "proxy.ssh-key",
Usage: "debug mode", Usage: "private ssh key of proxy",
EnvVar: "PLUGIN_DEBUG,DEBUG,INPUT_DEBUG", 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"},
}, },
} }
@@ -199,31 +270,43 @@ 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"),
KeyPath: c.String("key-path"), KeyPath: c.String("key-path"),
Username: c.String("user"), Username: c.String("user"),
Password: c.String("password"), Password: c.String("password"),
Passphrase: c.String("ssh-passphrase"), Passphrase: c.String("ssh-passphrase"),
Host: c.StringSlice("host"), Fingerprint: c.String("fingerprint"),
Port: c.Int("port"), Host: c.StringSlice("host"),
Timeout: c.Duration("timeout"), Port: c.Int("port"),
CommandTimeout: c.Duration("command.timeout"), Protocol: easyssh.Protocol(c.String("protocol")),
Script: scripts, Timeout: c.Duration("timeout"),
ScriptStop: c.Bool("script.stop"), CommandTimeout: c.Duration("command.timeout"),
Envs: c.StringSlice("envs"), Script: scripts,
Debug: c.Bool("debug"), ScriptStop: c.Bool("script.stop"),
Sync: c.Bool("sync"), Envs: c.StringSlice("envs"),
EnvsFormat: c.String("envs.format"),
Debug: c.Bool("debug"),
Sync: c.Bool("sync"),
Ciphers: c.StringSlice("ciphers"),
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"),
User: c.String("proxy.username"), User: c.String("proxy.username"),
Password: c.String("proxy.password"), Password: c.String("proxy.password"),
Passphrase: c.String("proxy.ssh-passphrase"), Passphrase: c.String("proxy.ssh-passphrase"),
Server: c.String("proxy.host"), Fingerprint: c.String("proxy.fingerprint"),
Port: c.String("proxy.port"), Server: c.String("proxy.host"),
Timeout: c.Duration("proxy.timeout"), Port: c.String("proxy.port"),
Protocol: easyssh.Protocol(c.String("proxy.protocol")),
Timeout: c.Duration("proxy.timeout"),
Ciphers: c.StringSlice("proxy.ciphers"),
UseInsecureCipher: c.Bool("proxy.useInsecureCipher"),
}, },
}, },
Writer: os.Stdout, Writer: os.Stdout,
-256
View File
@@ -1,256 +0,0 @@
{
test:: {
kind: 'pipeline',
name: 'testing',
platform: {
os: 'linux',
arch: 'amd64',
},
steps: [
{
name: 'vet',
image: 'golang:1.13',
pull: 'always',
commands: [
'make vet',
],
volumes: [
{
name: 'gopath',
path: '/go',
},
],
},
{
name: 'lint',
image: 'golang:1.13',
pull: 'always',
commands: [
'make lint',
],
volumes: [
{
name: 'gopath',
path: '/go',
},
],
},
{
name: 'misspell',
image: 'golang:1.13',
pull: 'always',
commands: [
'make misspell-check',
],
volumes: [
{
name: 'gopath',
path: '/go',
},
],
},
{
name: 'test',
image: 'golang:1.13-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.13',
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.13',
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.13',
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: 'golang:1.13',
pull: 'always',
commands: [
'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,
}
}
+154 -70
View File
@@ -10,34 +10,41 @@ import (
"sync" "sync"
"time" "time"
"github.com/appleboy/easyssh-proxy" easyssh "github.com/appleboy/easyssh-proxy"
) )
var ( var (
errMissingHost = errors.New("Error: missing server host") errMissingHost = errors.New("Error: missing server host")
errMissingPasswordOrKey = errors.New("Error: can't connect without a private SSH key or password") errMissingPasswordOrKey = errors.New("Error: can't connect without a private SSH key or password")
errCommandTimeOut = errors.New("Error: command timeout") errCommandTimeOut = errors.New("Error: command timeout")
errSetPasswordandKey = errors.New("can't set password and key at the same time") envsFormat = "export {NAME}={VALUE}"
) )
type ( type (
// Config for the plugin. // Config for the plugin.
Config struct { Config struct {
Key string Key string
Passphrase string Passphrase string
KeyPath string KeyPath string
Username string Username string
Password string Password string
Host []string Host []string
Port int Port int
Timeout time.Duration Protocol easyssh.Protocol
CommandTimeout time.Duration Fingerprint string
Script []string Timeout time.Duration
ScriptStop bool CommandTimeout time.Duration
Envs []string Script []string
Proxy easyssh.DefaultConfig ScriptStop bool
Debug bool Envs []string
Sync bool Proxy easyssh.DefaultConfig
Debug bool
Sync bool
Ciphers []string
UseInsecureCipher bool
EnvsFormat string
AllEnvs bool
RequireTty bool
} }
// Plugin structure // Plugin structure
@@ -51,44 +58,74 @@ func escapeArg(arg string) string {
return "'" + strings.Replace(arg, "'", `'\''`, -1) + "'" return "'" + strings.Replace(arg, "'", `'\''`, -1) + "'"
} }
func (p Plugin) hostPort(host string) (string, string) {
hosts := strings.Split(host, ":")
port := strconv.Itoa(p.Config.Port)
if len(hosts) > 1 &&
(p.Config.Protocol == easyssh.PROTOCOL_TCP ||
p.Config.Protocol == easyssh.PROTOCOL_TCP4) {
host = hosts[0]
port = hosts[1]
}
return host, port
}
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)
// Create MakeConfig instance with remote username, server address and path to private key. // Create MakeConfig instance with remote username, server address and path to private key.
ssh := &easyssh.MakeConfig{ ssh := &easyssh.MakeConfig{
Server: host, Server: host,
User: p.Config.Username, User: p.Config.Username,
Password: p.Config.Password, Password: p.Config.Password,
Port: strconv.Itoa(p.Config.Port), Port: port,
Key: p.Config.Key, Protocol: p.Config.Protocol,
KeyPath: p.Config.KeyPath, Key: p.Config.Key,
Passphrase: p.Config.Passphrase, KeyPath: p.Config.KeyPath,
Timeout: p.Config.Timeout, Passphrase: p.Config.Passphrase,
Timeout: p.Config.Timeout,
Ciphers: p.Config.Ciphers,
Fingerprint: p.Config.Fingerprint,
UseInsecureCipher: p.Config.UseInsecureCipher,
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,
Key: p.Config.Proxy.Key, Protocol: p.Config.Proxy.Protocol,
KeyPath: p.Config.Proxy.KeyPath, Key: p.Config.Proxy.Key,
Passphrase: p.Config.Proxy.Passphrase, KeyPath: p.Config.Proxy.KeyPath,
Timeout: p.Config.Proxy.Timeout, Passphrase: p.Config.Proxy.Passphrase,
Timeout: p.Config.Proxy.Timeout,
Ciphers: p.Config.Proxy.Ciphers,
Fingerprint: p.Config.Proxy.Fingerprint,
UseInsecureCipher: p.Config.Proxy.UseInsecureCipher,
}, },
} }
p.log(host, "======CMD======") if p.Config.Debug {
p.log(host, strings.Join(p.Config.Script, "\n")) p.log(host, "======CMD======")
p.log(host, "======END======") p.log(host, strings.Join(p.Config.Script, "\n"))
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, key+"="+escapeArg(val)) env = append(env, p.format(p.Config.EnvsFormat, "{NAME}", key, "{VALUE}", escapeArg(val)))
} }
} }
p.Config.Script = append(env, p.scriptCommands()...) p.Config.Script = append(env, p.scriptCommands()...)
if p.Config.Debug { if p.Config.Debug && len(env) > 0 {
p.log(host, "======ENV======") p.log(host, "======ENV======")
p.log(host, strings.Join(env, "\n")) p.log(host, strings.Join(env, "\n"))
p.log(host, "======END======") p.log(host, "======END======")
@@ -97,49 +134,61 @@ func (p Plugin) exec(host string, wg *sync.WaitGroup, errChannel chan error) {
stdoutChan, stderrChan, doneChan, errChan, err := ssh.Stream(strings.Join(p.Config.Script, "\n"), p.Config.CommandTimeout) stdoutChan, stderrChan, doneChan, errChan, err := ssh.Stream(strings.Join(p.Config.Script, "\n"), p.Config.CommandTimeout)
if err != nil { if err != nil {
errChannel <- err errChannel <- err
} else { return
// read from the output channel until the done signal is passed }
isTimeout := true // read from the output channel until the done signal is passed
loop: isTimeout := true
for { loop:
select { for {
case isTimeout = <-doneChan: select {
break loop case isTimeout = <-doneChan:
case outline := <-stdoutChan: break loop
case outline := <-stdoutChan:
if outline != "" {
p.log(host, "out:", outline) p.log(host, "out:", outline)
case errline := <-stderrChan:
p.log(host, "err:", errline)
case err = <-errChan:
} }
} case errline := <-stderrChan:
if errline != "" {
// get exit code or command error. p.log(host, "err:", errline)
if err != nil { }
errChannel <- err case err = <-errChan:
}
// command time out
if !isTimeout {
errChannel <- errCommandTimeOut
} }
} }
wg.Done() // get exit code or command error.
if err != nil {
errChannel <- err
}
// command time out
if !isTimeout {
errChannel <- errCommandTimeOut
}
} }
// 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...))
} else { return
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
} }
@@ -148,18 +197,22 @@ func (p Plugin) Exec() error {
return errMissingPasswordOrKey return errMissingPasswordOrKey
} }
if len(p.Config.Key) != 0 && len(p.Config.Password) != 0 { if p.Config.EnvsFormat == "" {
return errSetPasswordandKey p.Config.EnvsFormat = envsFormat
} }
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
wg.Add(len(p.Config.Host)) wg.Add(len(p.Config.Host))
errChannel := make(chan error) errChannel := make(chan error)
finished := make(chan struct{}) finished := make(chan struct{})
for _, host := range p.Config.Host { if p.Config.Sync {
if p.Config.Sync { go func() {
p.exec(host, &wg, errChannel) for _, host := range p.Config.Host {
} else { p.exec(host, &wg, errChannel)
}
}()
} else {
for _, host := range p.Config.Host {
go p.exec(host, &wg, errChannel) go p.exec(host, &wg, errChannel)
} }
} }
@@ -198,14 +251,45 @@ func (p Plugin) scriptCommands() []string {
commands := make([]string, 0) commands := make([]string, 0)
for _, cmd := range scripts { for _, cmd := range scripts {
cmd = strings.TrimSpace(cmd)
if strings.TrimSpace(cmd) == "" { if strings.TrimSpace(cmd) == "" {
continue continue
} }
commands = append(commands, cmd) commands = append(commands, cmd)
if p.Config.ScriptStop { if p.Config.ScriptStop && cmd[(len(cmd)-1):] != "\\" {
commands = append(commands, "DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;") commands = append(commands, "DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;")
} }
} }
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
}
+402 -32
View File
@@ -11,6 +11,7 @@ import (
"github.com/appleboy/easyssh-proxy" "github.com/appleboy/easyssh-proxy"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"golang.org/x/crypto/ssh"
) )
func TestMissingHostOrUser(t *testing.T) { func TestMissingHostOrUser(t *testing.T) {
@@ -37,23 +38,6 @@ func TestMissingKeyOrPassword(t *testing.T) {
assert.Equal(t, errMissingPasswordOrKey, err) assert.Equal(t, errMissingPasswordOrKey, err)
} }
func TestSetPasswordAndKey(t *testing.T) {
plugin := Plugin{
Config{
Host: []string{"localhost"},
Username: "ubuntu",
Password: "1234",
Key: "1234",
},
os.Stdout,
}
err := plugin.Exec()
assert.NotNil(t, err)
assert.Equal(t, errSetPasswordandKey, err)
}
func TestIncorrectPassword(t *testing.T) { func TestIncorrectPassword(t *testing.T) {
plugin := Plugin{ plugin := Plugin{
Config: Config{ Config: Config{
@@ -129,6 +113,40 @@ 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{
@@ -374,6 +392,7 @@ func TestCommandOutput(t *testing.T) {
}, },
CommandTimeout: 60 * time.Second, CommandTimeout: 60 * time.Second,
Sync: true, Sync: true,
Debug: true,
}, },
Writer: &buffer, Writer: &buffer,
} }
@@ -384,14 +403,109 @@ func TestCommandOutput(t *testing.T) {
assert.Equal(t, unindent(expected), unindent(buffer.String())) assert.Equal(t, unindent(expected), unindent(buffer.String()))
} }
func TestWrongFingerprint(t *testing.T) {
var buffer bytes.Buffer
plugin := Plugin{
Config: Config{
Host: []string{"localhost"},
Username: "drone-scp",
Port: 22,
KeyPath: "./tests/.ssh/id_rsa",
Script: []string{
"whoami",
},
Fingerprint: "wrong",
},
Writer: &buffer,
}
err := plugin.Exec()
assert.NotNil(t, err)
}
func getHostPublicKeyFile(keypath string) (ssh.PublicKey, error) {
var pubkey ssh.PublicKey
var err error
buf, err := os.ReadFile(keypath)
if err != nil {
return nil, err
}
pubkey, _, _, _, err = ssh.ParseAuthorizedKey(buf)
if err != nil {
return nil, err
}
return pubkey, nil
}
func TestFingerprint(t *testing.T) {
var (
buffer bytes.Buffer
expected = `
out: drone-scp
`
)
hostKey, err := getHostPublicKeyFile("/etc/ssh/ssh_host_rsa_key.pub")
assert.NoError(t, err)
plugin := Plugin{
Config: Config{
Host: []string{"localhost"},
Username: "drone-scp",
Port: 22,
KeyPath: "./tests/.ssh/id_rsa",
Script: []string{
"whoami",
},
Fingerprint: ssh.FingerprintSHA256(hostKey),
CommandTimeout: 10 * time.Second,
},
Writer: &buffer,
}
err = plugin.Exec()
assert.Nil(t, err)
assert.Equal(t, unindent(expected), unindent(buffer.String()))
}
func TestScriptStopWithMultipleHostAndSyncMode(t *testing.T) {
var (
buffer bytes.Buffer
expected = `
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
expected = ` expected = `
======CMD======
mkdir a/b/c
mkdir d/e/f
======END======
err: mkdir: can't create directory 'a/b/c': No such file or directory err: mkdir: can't create directory 'a/b/c': No such file or directory
` `
) )
@@ -422,10 +536,6 @@ func TestNoneScriptStop(t *testing.T) {
var ( var (
buffer bytes.Buffer buffer bytes.Buffer
expected = ` expected = `
======CMD======
mkdir a/b/c
mkdir d/e/f
======END======
err: mkdir: can't create directory 'a/b/c': No such file or directory err: mkdir: can't create directory 'a/b/c': No such file or directory
err: mkdir: can't create directory 'd/e/f': No such file or directory err: mkdir: can't create directory 'd/e/f': No such file or directory
` `
@@ -466,13 +576,13 @@ func TestEnvOutput(t *testing.T) {
echo "[${ENV_7}]" echo "[${ENV_7}]"
======END====== ======END======
======ENV====== ======ENV======
ENV_1='test' export ENV_1='test'
ENV_2='test test' export ENV_2='test test'
ENV_3='test ' export ENV_3='test '
ENV_4=' test test ' export ENV_4=' test test '
ENV_5='test'\''' export ENV_5='test'\'''
ENV_6='test"' export ENV_6='test"'
ENV_7='test,!#;?.@$~'\''"' export ENV_7='test,!#;?.@$~'\''"'
======END====== ======END======
out: [test] out: [test]
out: [test test] out: [test test]
@@ -570,6 +680,17 @@ func TestPlugin_scriptCommands(t *testing.T) {
}, },
want: []string{"mkdir a", "DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;", "mkdir c", "DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;", "mkdir b", "DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;"}, want: []string{"mkdir a", "DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;", "mkdir c", "DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;", "mkdir b", "DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;"},
}, },
// See: https://github.com/appleboy/ssh-action/issues/75#issuecomment-668314271
{
name: "Multiline SSH commands interpreted as single lines",
fields: fields{
Config: Config{
Script: []string{"ls \\ ", "-lah", "mkdir a"},
ScriptStop: true,
},
},
want: []string{"ls \\", "-lah", "DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;", "mkdir a", "DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;"},
},
{ {
name: "trim space", name: "trim space",
fields: fields{ fields: fields{
@@ -593,3 +714,252 @@ func TestPlugin_scriptCommands(t *testing.T) {
}) })
} }
} }
func TestUseInsecureCipher(t *testing.T) {
var (
buffer bytes.Buffer
expected = `
err: mkdir: can't create directory 'a/b/c': No such file or directory
err: mkdir: can't create directory 'd/e/f': No such file or directory
`
)
plugin := Plugin{
Config: Config{
Host: []string{"localhost"},
Username: "drone-scp",
Port: 22,
KeyPath: "./tests/.ssh/id_rsa",
Script: []string{
"mkdir a/b/c",
"mkdir d/e/f",
},
CommandTimeout: 10 * time.Second,
UseInsecureCipher: true,
},
Writer: &buffer,
}
err := plugin.Exec()
assert.NotNil(t, err)
assert.Equal(t, unindent(expected), unindent(buffer.String()))
}
func TestPlugin_hostPort(t *testing.T) {
type fields struct {
Config Config
Writer io.Writer
}
type args struct {
h string
}
tests := []struct {
name string
fields fields
args args
wantHost string
wantPort string
}{
{
name: "default host and port",
fields: fields{
Config: Config{
Port: 22,
},
},
args: args{
h: "localhost",
},
wantHost: "localhost",
wantPort: "22",
},
{
name: "different port",
fields: fields{
Config: Config{
Port: 22,
Protocol: easyssh.PROTOCOL_TCP4,
},
},
args: args{
h: "localhost:443",
},
wantHost: "localhost",
wantPort: "443",
},
{
name: "ipv6",
fields: fields{
Config: Config{
Port: 22,
Protocol: easyssh.PROTOCOL_TCP6,
},
},
args: args{
h: "::1",
},
wantHost: "::1",
wantPort: "22",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := Plugin{
Config: tt.fields.Config,
Writer: tt.fields.Writer,
}
gotHost, gotPort := p.hostPort(tt.args.h)
if gotHost != tt.wantHost {
t.Errorf("Plugin.hostPort() gotHost = %v, want %v", gotHost, tt.wantHost)
}
if gotPort != tt.wantPort {
t.Errorf("Plugin.hostPort() gotPort = %v, want %v", gotPort, tt.wantPort)
}
})
}
}
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 = `
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 = `
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()))
}
func TestCommandWithIPv6(t *testing.T) {
var (
buffer bytes.Buffer
expected = `
out: drone-scp
`
)
plugin := Plugin{
Config: Config{
Host: []string{"::1"},
Username: "drone-scp",
Port: 22,
KeyPath: "./tests/.ssh/id_rsa",
Script: []string{
"whoami",
},
Protocol: easyssh.PROTOCOL_TCP6,
CommandTimeout: 10 * time.Second,
},
Writer: &buffer,
}
assert.Nil(t, plugin.Exec())
assert.Equal(t, unindent(expected), unindent(buffer.String()))
}
+2
View File
@@ -0,0 +1,2 @@
Defaults requiretty
drone-scp ALL=(ALL) NOPASSWD:ALL