Skip to content

Commit e784118

Browse files
author
root
committed
add git action release
1 parent 56cdf84 commit e784118

File tree

7 files changed

+195
-24
lines changed

7 files changed

+195
-24
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Hades-agent
2+
3+
on:
4+
push:
5+
tags:
6+
- agent-v*
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
with:
14+
submodules: recursive
15+
16+
- name: go env
17+
uses: actions/setup-go@v2
18+
with:
19+
go-version: '1.20'
20+
21+
- name: make env
22+
run: |
23+
sudo apt-get install make
24+
shell: bash
25+
26+
- name: build version
27+
run:
28+
TAG = ${{ github.ref }}
29+
BUILD_VERSION=$(echo TAG | sed 's/agent-//')
30+
echo "BUILD_VERSION=$BUILD_VERSION" >> $GITHUB_ENV
31+
32+
- name: auth
33+
run: |
34+
gh auth login --with-token <<<'${{ secrets.GITHUB_TOKEN }}'
35+
36+
- name: build
37+
run: |
38+
cd agent/deploy
39+
BUILD_VERSION=${{ env.BUILD_VERSION }} sh build.sh
40+
cd ../..
41+
42+
- name: upload
43+
uses: actions/upload-artifact@v3
44+
with:
45+
path: /tmp/hades-agent-*
46+
name: hades-agent
47+
48+
release:
49+
runs-on: ubuntu-latest
50+
permissions: write-all
51+
steps:
52+
- name: create release
53+
id: create_release
54+
uses: actions/create-release@v1
55+
env:
56+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57+
with:
58+
# draft for testing!
59+
draft: true
60+
prerelease: false
61+
release_name: Release ${{github.ref}}
62+
tag_name: ${{github.ref}}
63+
- name: version env
64+
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
65+
- uses: actions/download-artifact@v3
66+
with:
67+
path: /tmp/hades-agent
68+
- name: release
69+
uses: actions/checkout@v2
70+
run: |
71+
for asset in /tmp/hades-agent/; do
72+
hub release create ${asset}
73+
echo ${asset}
74+
done
75+
needs:
76+
- build
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Hades-collector
2+
3+
on:
4+
push:
5+
tags:
6+
- collector-v*
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
with:
14+
submodules: recursive
15+
16+
- name: go env
17+
uses: actions/setup-go@v2
18+
with:
19+
go-version: '1.19'
20+
21+
- name: auth
22+
run: |
23+
gh auth login --with-token <<<'${{ secrets.GITHUB_TOKEN }}'
24+
25+
- name: build
26+
run: |
27+
cd plugins/collector
28+
make
29+
cd ../..
30+
31+
- name: upload
32+
uses: actions/upload-artifact@v3
33+
with:
34+
path: plugins/collector/collector
35+
name: collector
36+
37+
release:
38+
runs-on: ubuntu-latest
39+
permissions: write-all
40+
steps:
41+
- name: create release
42+
id: create_release
43+
uses: actions/create-release@v1
44+
env:
45+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
with:
47+
# draft for testing!
48+
draft: true
49+
prerelease: false
50+
release_name: Release ${{github.ref}}
51+
tag_name: ${{github.ref}}
52+
- name: version env
53+
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
54+
- uses: actions/download-artifact@v3
55+
with:
56+
path: /tmp/collector
57+
- name: package
58+
working-directory: /tmp/collector/collector
59+
run: |
60+
sha256sum collector >> checksum.txt
61+
tar zcvf /tmp/collector.tgz collector checksum.txt
62+
- name: upload
63+
id: upload
64+
uses: actions/upload-release-asset@v1
65+
env:
66+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
67+
with:
68+
asset_content_type: application/tar+gzip
69+
asset_name: ${{ env.RELEASE_VERSION }}.tgz
70+
asset_path: /tmp/collector.tgz
71+
upload_url: ${{steps.create_release.outputs.upload_url}}
72+
needs:
73+
- build

agent/Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
CMD_GO ?= go
2-
VERSION ?= v1.1.2
32

43
# colors
54
INFO_COLOR = \033[34m[*]\033[0m
@@ -10,8 +9,8 @@ all: pre_show build_agent
109

1110
.PHONY: pre_show
1211
pre_show:
13-
@printf "$(INFO_COLOR) start to build hades-agent, version: $(VERSION)\n"
12+
@printf "$(INFO_COLOR) start to build hades-agent, version: $(BUILD_VERSION)\n"
1413

1514
.PHONY: build_agent
1615
build_agent:
17-
CGO_ENABLED=0 $(CMD_GO) build -ldflags "-X agent/agent.Version=$(VERSION)" -o hades-agent
16+
CGO_ENABLED=0 $(CMD_GO) build -ldflags "-X agent/agent.Version=$(BUILD_VERSION)" -o hades-agent

agent/deploy/build.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# install nfpm
5+
if ! nfpm -v > /dev/null 2>&1;then
6+
go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest
7+
fi
8+
9+
# release both arch
10+
for arch in amd64 arm64; do
11+
export GOARCH=${arch}
12+
sed -i 's/version:.*$/version: '${BUILD_VERSION}'/g' nfpm.yaml
13+
sed -i 's/arch:.*$/arch: '${arch}'/g' nfpm.yaml
14+
make deb
15+
make rpm
16+
done

agent/deploy/nfpm.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
# check https://nfpm.goreleaser.com/configuration for detailed usage
44
#
55
name: "hades-agent"
6-
arch: "amd64"
6+
arch: arm64
77
platform: "linux"
88
epoch: 3
9-
version: v1.2.0
9+
version: v1.1.3
1010
release: 1
1111
section: "default"
1212
priority: "extra"

agent/transport/transfer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ func (t *Transfer) resolveTask(cmd *proto.Command) (err error) {
165165
// crontab is used in sysvinit to keep the agent always available
166166
case config.TaskShutdown, config.TaskRestart:
167167
zap.S().Info("agent shutdown is called")
168+
TaskSuccess(cmd.Task.Token, "agent shutdown is called")
168169
agent.Cancel()
169170
return
170171
case config.TaskSetenv:

plugins/collector/event/systems/host.go

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,29 +74,35 @@ func (h *HostScanner) Run(s SDK.ISandbox, sig chan struct{}) (err error) {
7474
if len(availableAddrs) > 512 {
7575
rand.Shuffle(len(availableAddrs), func(i, j int) { availableAddrs[i], availableAddrs[j] = availableAddrs[j], availableAddrs[i] })
7676
}
77+
scan:
7778
for _, addr := range availableAddrs {
78-
pinger, err := ping.NewPinger(addr)
79-
if err != nil {
80-
continue
81-
}
82-
pinger.Count = 2
83-
pinger.Timeout = time.Duration(3 * time.Second)
84-
pinger.SetPrivileged(false)
85-
pinger.Run()
86-
if pinger.Statistics().PacketsRecv > 0 {
87-
rec := &protocol.Record{
88-
DataType: int32(h.DataType()),
89-
Timestamp: time.Now().Unix(),
90-
Data: &protocol.Payload{
91-
Fields: map[string]string{
92-
"addr": addr,
93-
"package_seq": hash,
79+
select {
80+
case <-sig:
81+
break scan
82+
default:
83+
pinger, err := ping.NewPinger(addr)
84+
if err != nil {
85+
continue
86+
}
87+
pinger.Count = 2
88+
pinger.Timeout = time.Duration(3 * time.Second)
89+
pinger.SetPrivileged(false)
90+
pinger.Run()
91+
if pinger.Statistics().PacketsRecv > 0 {
92+
rec := &protocol.Record{
93+
DataType: int32(h.DataType()),
94+
Timestamp: time.Now().Unix(),
95+
Data: &protocol.Payload{
96+
Fields: map[string]string{
97+
"addr": addr,
98+
"package_seq": hash,
99+
},
94100
},
95-
},
101+
}
102+
s.SendRecord(rec)
96103
}
97-
s.SendRecord(rec)
104+
time.Sleep(400 * time.Millisecond)
98105
}
99-
time.Sleep(400 * time.Millisecond)
100106
}
101107
}
102108
return

0 commit comments

Comments
 (0)