Skip to content

Commit

Permalink
add git action release
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Mar 27, 2023
1 parent 56cdf84 commit e784118
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 24 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/release-agent.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Hades-agent

on:
push:
tags:
- agent-v*

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: recursive

- name: go env
uses: actions/setup-go@v2
with:
go-version: '1.20'

- name: make env
run: |
sudo apt-get install make
shell: bash

- name: build version
run:
TAG = ${{ github.ref }}
BUILD_VERSION=$(echo TAG | sed 's/agent-//')
echo "BUILD_VERSION=$BUILD_VERSION" >> $GITHUB_ENV

- name: auth
run: |
gh auth login --with-token <<<'${{ secrets.GITHUB_TOKEN }}'
- name: build
run: |
cd agent/deploy
BUILD_VERSION=${{ env.BUILD_VERSION }} sh build.sh
cd ../..
- name: upload
uses: actions/upload-artifact@v3
with:
path: /tmp/hades-agent-*
name: hades-agent

release:
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: create release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# draft for testing!
draft: true
prerelease: false
release_name: Release ${{github.ref}}
tag_name: ${{github.ref}}
- name: version env
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- uses: actions/download-artifact@v3
with:
path: /tmp/hades-agent
- name: release
uses: actions/checkout@v2
run: |
for asset in /tmp/hades-agent/; do
hub release create ${asset}
echo ${asset}
done
needs:
- build
73 changes: 73 additions & 0 deletions .github/workflows/release-collector.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Hades-collector

on:
push:
tags:
- collector-v*

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: recursive

- name: go env
uses: actions/setup-go@v2
with:
go-version: '1.19'

- name: auth
run: |
gh auth login --with-token <<<'${{ secrets.GITHUB_TOKEN }}'
- name: build
run: |
cd plugins/collector
make
cd ../..
- name: upload
uses: actions/upload-artifact@v3
with:
path: plugins/collector/collector
name: collector

release:
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: create release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# draft for testing!
draft: true
prerelease: false
release_name: Release ${{github.ref}}
tag_name: ${{github.ref}}
- name: version env
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- uses: actions/download-artifact@v3
with:
path: /tmp/collector
- name: package
working-directory: /tmp/collector/collector
run: |
sha256sum collector >> checksum.txt
tar zcvf /tmp/collector.tgz collector checksum.txt
- name: upload
id: upload
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
asset_content_type: application/tar+gzip
asset_name: ${{ env.RELEASE_VERSION }}.tgz
asset_path: /tmp/collector.tgz
upload_url: ${{steps.create_release.outputs.upload_url}}
needs:
- build
5 changes: 2 additions & 3 deletions agent/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
CMD_GO ?= go
VERSION ?= v1.1.2

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

.PHONY: pre_show
pre_show:
@printf "$(INFO_COLOR) start to build hades-agent, version: $(VERSION)\n"
@printf "$(INFO_COLOR) start to build hades-agent, version: $(BUILD_VERSION)\n"

.PHONY: build_agent
build_agent:
CGO_ENABLED=0 $(CMD_GO) build -ldflags "-X agent/agent.Version=$(VERSION)" -o hades-agent
CGO_ENABLED=0 $(CMD_GO) build -ldflags "-X agent/agent.Version=$(BUILD_VERSION)" -o hades-agent
16 changes: 16 additions & 0 deletions agent/deploy/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -e

# install nfpm
if ! nfpm -v > /dev/null 2>&1;then
go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest
fi

# release both arch
for arch in amd64 arm64; do
export GOARCH=${arch}
sed -i 's/version:.*$/version: '${BUILD_VERSION}'/g' nfpm.yaml
sed -i 's/arch:.*$/arch: '${arch}'/g' nfpm.yaml
make deb
make rpm
done
4 changes: 2 additions & 2 deletions agent/deploy/nfpm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# check https://nfpm.goreleaser.com/configuration for detailed usage
#
name: "hades-agent"
arch: "amd64"
arch: arm64
platform: "linux"
epoch: 3
version: v1.2.0
version: v1.1.3
release: 1
section: "default"
priority: "extra"
Expand Down
1 change: 1 addition & 0 deletions agent/transport/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ func (t *Transfer) resolveTask(cmd *proto.Command) (err error) {
// crontab is used in sysvinit to keep the agent always available
case config.TaskShutdown, config.TaskRestart:
zap.S().Info("agent shutdown is called")
TaskSuccess(cmd.Task.Token, "agent shutdown is called")
agent.Cancel()
return
case config.TaskSetenv:
Expand Down
44 changes: 25 additions & 19 deletions plugins/collector/event/systems/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,29 +74,35 @@ func (h *HostScanner) Run(s SDK.ISandbox, sig chan struct{}) (err error) {
if len(availableAddrs) > 512 {
rand.Shuffle(len(availableAddrs), func(i, j int) { availableAddrs[i], availableAddrs[j] = availableAddrs[j], availableAddrs[i] })
}
scan:
for _, addr := range availableAddrs {
pinger, err := ping.NewPinger(addr)
if err != nil {
continue
}
pinger.Count = 2
pinger.Timeout = time.Duration(3 * time.Second)
pinger.SetPrivileged(false)
pinger.Run()
if pinger.Statistics().PacketsRecv > 0 {
rec := &protocol.Record{
DataType: int32(h.DataType()),
Timestamp: time.Now().Unix(),
Data: &protocol.Payload{
Fields: map[string]string{
"addr": addr,
"package_seq": hash,
select {
case <-sig:
break scan
default:
pinger, err := ping.NewPinger(addr)
if err != nil {
continue
}
pinger.Count = 2
pinger.Timeout = time.Duration(3 * time.Second)
pinger.SetPrivileged(false)
pinger.Run()
if pinger.Statistics().PacketsRecv > 0 {
rec := &protocol.Record{
DataType: int32(h.DataType()),
Timestamp: time.Now().Unix(),
Data: &protocol.Payload{
Fields: map[string]string{
"addr": addr,
"package_seq": hash,
},
},
},
}
s.SendRecord(rec)
}
s.SendRecord(rec)
time.Sleep(400 * time.Millisecond)
}
time.Sleep(400 * time.Millisecond)
}
}
return
Expand Down

0 comments on commit e784118

Please sign in to comment.