Skip to content

Commit 8fd8e5f

Browse files
committedOct 15, 2021
feat(update): update
update Signed-off-by: ysicing <i@ysicing.me>
1 parent 6b2876e commit 8fd8e5f

File tree

25 files changed

+431
-21
lines changed

25 files changed

+431
-21
lines changed
 

‎.github/ISSUE_TEMPLATE/bug_report.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behavior:
15+
1. Go to '...'
16+
2. Click on '....'
17+
3. Scroll down to '....'
18+
4. See error
19+
20+
**Expected behavior**
21+
A clear and concise description of what you expected to happen.
22+
23+
**Screenshots**
24+
If applicable, add screenshots to help explain your problem.
25+
26+
**Additional context**
27+
Add any other context about the problem here.
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for ErGo
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.

‎.github/dependabot.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "gomod" # See documentation for possible values
9+
directory: "/" # Location of package manifests
10+
schedule:
11+
interval: "daily"

‎.github/workflows/ci.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
name: build ergo tools
1+
name: pre-ci
22
on:
33
push:
44
branches:
55
- develop
6-
# schedule:
7-
#- cron: '0 */12 * * *'
86
jobs:
97
build:
108
name: build ergo tools
@@ -41,7 +39,7 @@ jobs:
4139
popd
4240
./gen.sh
4341
docker logout
44-
cat version.txt | grep -E '(beta|rc)' && (make pre-release) || (make release)
42+
cat version.txt | grep -E '(beta|rc)' && (make pre-release)
4543
env:
4644
GITHUB_RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
4745
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}

‎.github/workflows/codeql-analysis.yml

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: [ develop ]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: [ develop ]
20+
schedule:
21+
- cron: '39 19 * * 2'
22+
23+
jobs:
24+
analyze:
25+
name: Analyze
26+
runs-on: ubuntu-latest
27+
permissions:
28+
actions: read
29+
contents: read
30+
security-events: write
31+
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
language: [ 'go' ]
36+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
37+
# Learn more:
38+
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
39+
40+
steps:
41+
- name: Checkout repository
42+
uses: actions/checkout@v2
43+
44+
# Initializes the CodeQL tools for scanning.
45+
- name: Initialize CodeQL
46+
uses: github/codeql-action/init@v1
47+
with:
48+
languages: ${{ matrix.language }}
49+
# If you wish to specify custom queries, you can do so here or in a config file.
50+
# By default, queries listed here will override any specified in a config file.
51+
# Prefix the list here with "+" to use these queries and those in the config file.
52+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
53+
54+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
55+
# If this step fails, then you should remove it and run the build manually (see below)
56+
- name: Autobuild
57+
uses: github/codeql-action/autobuild@v1
58+
59+
# ℹ️ Command-line programs to run using the OS shell.
60+
# 📚 https://git.io/JvXDl
61+
62+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
63+
# and modify them (or add more) to build your code if your project
64+
# uses a compiled language
65+
66+
#- run: |
67+
# make bootstrap
68+
# make release
69+
70+
- name: Perform CodeQL Analysis
71+
uses: github/codeql-action/analyze@v1

‎.github/workflows/tag.yml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: tag
2+
on:
3+
push:
4+
tags:
5+
- 'v*'
6+
jobs:
7+
build:
8+
name: build ergo tools
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Install Go
12+
uses: actions/setup-go@v1
13+
with:
14+
go-version: 1.17.x
15+
- name: install gox
16+
run: |
17+
echo "install gox"
18+
go get -u github.com/mitchellh/gox
19+
- name: install ghr
20+
run: |
21+
echo "install ghr"
22+
go get -u github.com/tcnksm/ghr
23+
- uses: actions/checkout@v1
24+
with:
25+
fetch-depth: 1
26+
- name: build ergo
27+
run: |
28+
export TZ='Asia/Shanghai'
29+
export PATH=$PATH:$(go env GOPATH)/bin
30+
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
31+
make dpush
32+
33+
pushd dist
34+
sha256sum ergo_darwin_amd64 > ergo_darwin_amd64.sha256sum
35+
sha256sum ergo_linux_amd64 > ergo_linux_amd64.sha256sum
36+
sha256sum ergo_windows_amd64.exe > ergo_windows_amd64.sha256sum
37+
sha256sum ergo_darwin_arm64 > ergo_darwin_arm64.sha256sum
38+
sha256sum ergo_linux_arm64 > ergo_linux_arm64.sha256sum
39+
popd
40+
./gen.sh
41+
docker logout
42+
make release
43+
make deb
44+
env:
45+
GITHUB_RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
46+
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
47+
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
48+
DEBTOKEN: ${{ secrets.APT }}

‎.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ gen
1010
dist
1111
.githubtoken
1212
release.sh
13-
ergo.rb
13+
ergo.rb
14+
15+
hack/deb/*.deb

‎CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
## Ergo CHANGELOG
22

3+
- v2.0.6
4+
- ops添加ping子命令
5+
6+
- v2.0.5
7+
- 修复默认ergo插件库
8+
9+
- v2.0.4
10+
- 增强plugin子命令
11+
312
- v2.0.3
413
- 新增code命令,支持初始化crds/go项目
514
- plugin增强, 参考helm repo

‎Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ install: clean ## install
6363
-X 'github.com/ysicing/ergo/cmd.BuildDate=${BUILD_DATE}' \
6464
-X 'github.com/ysicing/ergo/cmd.CommitID=${COMMIT_SHA1}'"
6565

66+
deb: build ## build deb
67+
./deb.sh
68+
6669
.PHONY : build release clean install
6770

6871
.EXPORT_ALL_VARIABLES:

‎README.md

+35-8
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,57 @@
11
[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=ysicing_ergo&metric=ncloc)](https://sonarcloud.io/dashboard?id=ysicing_ergo)
2+
![GitHub Workflow Status (event)](https://img.shields.io/github/workflow/status/ysicing/ergo/ci?style=flat-square)
3+
![GitHub go.mod Go version (subdirectory of monorepo)](https://img.shields.io/github/go-mod/go-version/ysicing/ergo?filename=go.mod&style=flat-square)
4+
![GitHub commit activity](https://img.shields.io/github/commit-activity/w/ysicing/ergo?style=flat-square)
5+
![GitHub all releases](https://img.shields.io/github/downloads/ysicing/ergo/total?style=flat-square)
6+
![GitHub](https://img.shields.io/github/license/ysicing/ergo?style=flat-square)
7+
28

39
## ergo
410

5-
> 一个使用 Go 编写运维工具,尽量减少重复工作,同时降低维护脚本的成本
11+
> 一款使用 Go 编写的轻量运维工具集,尽量减少重复工作,同时降低维护脚本的成本
612
7-
### 镜像使用
13+
兼容性:
814

9-
```bash
10-
ysicing/ergo
11-
```
15+
- [x] 100%兼容`Debian 9+`
16+
- [ ] macOS部分功能可用
17+
18+
## 安装使用
1219

1320
### 二进制安装
1421

15-
可直接从 [release](https://github.com/ysicing/ergo/releases) 页下载预编译的二进制文件
22+
可直接从 [release](https://github.com/ysicing/ergo/releases) 下载预编译的二进制文件
1623

17-
### Mac OS安装
24+
### macOS安装
1825

1926
```bash
2027
brew tap ysicing/tap
2128
brew install ergo
2229
```
2330

24-
### Mac OS升级
31+
### macOS升级
2532

2633
```bash
2734
brew upgrade
2835
或者
2936
ergo upgrade
3037
```
3138

39+
### 镜像使用
40+
41+
```bash
42+
ysicing/ergo
43+
```
44+
45+
### Debian使用
46+
47+
```bash
48+
echo "deb [trusted=yes] https://debian.ysicing.me/ /" | sudo tee /etc/apt/sources.list.d/ergo.list
49+
apt update
50+
# 避免与源里其他ergo混淆,deb包为opsergo
51+
apt-get install -y opsergo
52+
ergo version
53+
```
54+
3255
## 命令支持
3356

3457
- [x] code 初始化项目
@@ -40,6 +63,7 @@ ergo upgrade
4063
- [x] `ps` 进程
4164
- [x] `nc` nc
4265
- [x] `exec` 执行命令
66+
- [x] `ping`
4367
- [x] plugin
4468
- [x] `install` 安装插件
4569
- [x] `list` 列出ergo插件
@@ -55,6 +79,9 @@ ergo upgrade
5579
- [x] `containerd`
5680
- [x] `mysql`
5781
- [x] `dump` dump安装脚本
82+
- [x] sec
83+
- [ ] `deny` 封禁sm
84+
- [ ] `banip` 封禁ip
5885
- [x] upgrade
5986
- [x] version
6087

‎cmd/ops.go

+21
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import (
88
"github.com/ysicing/ergo/cmd/flags"
99
"github.com/ysicing/ergo/pkg/ergo/ops/exec"
1010
"github.com/ysicing/ergo/pkg/ergo/ops/nc"
11+
"github.com/ysicing/ergo/pkg/ergo/ops/ping"
1112
"github.com/ysicing/ergo/pkg/ergo/ops/ps"
1213
"github.com/ysicing/ergo/pkg/util/factory"
1314
"github.com/ysicing/ergo/pkg/util/log"
1415
sshutil "github.com/ysicing/ergo/pkg/util/ssh"
16+
"helm.sh/helm/v3/cmd/helm/require"
1517
"strings"
1618
"sync"
1719
)
@@ -48,6 +50,7 @@ type InstallCmd struct {
4850

4951
// newOPSCmd ergo ops
5052
func newOPSCmd(f factory.Factory) *cobra.Command {
53+
var pingcount int
5154
cmd := OPSCmd{
5255
GlobalFlags: globalFlags,
5356
log: f.GetLog(),
@@ -68,16 +71,34 @@ func newOPSCmd(f factory.Factory) *cobra.Command {
6871
},
6972
}
7073

74+
pingcmd := &cobra.Command{
75+
Use: "ping",
76+
Short: "ping",
77+
Version: "2.0.6",
78+
Args: require.MinimumNArgs(1),
79+
RunE: func(cobraCmd *cobra.Command, args []string) error {
80+
return cmd.ping(args[0], pingcount)
81+
},
82+
}
83+
84+
pingcmd.PersistentFlags().IntVar(&pingcount, "c", 4, "ping count")
85+
86+
7187
ops.AddCommand(pscmd)
7288
ops.AddCommand(ncCmd(cmd))
7389
ops.AddCommand(execCmd(cmd))
90+
ops.AddCommand(pingcmd)
7491
return ops
7592
}
7693

7794
func (cmd *OPSCmd) ps() error {
7895
return ps.RunPS()
7996
}
8097

98+
func (cmd *OPSCmd) ping(target string, count int) error {
99+
return ping.DoPing(target, count)
100+
}
101+
81102
func ncCmd(supercmd OPSCmd) *cobra.Command {
82103
cmd := NCCmd{
83104
OPSCmd: supercmd,

‎cmd/root.go

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func BuildRoot(f factory.Factory) *cobra.Command {
6262
rootCmd.AddCommand(newPluginCmd(f))
6363
rootCmd.AddCommand(newCodeGenCmd(f))
6464
rootCmd.AddCommand(newCloudCommand(f))
65+
rootCmd.AddCommand(newSecCmd(f))
6566
// Add plugin commands
6667

6768
args := os.Args

0 commit comments

Comments
 (0)
Please sign in to comment.