Skip to content

Commit f4d3a0e

Browse files
authored
Merge pull request leoleovich#30 from leoleovich/update-ci
Update the CI
2 parents 02ae37b + 9c350ad commit f4d3a0e

File tree

15 files changed

+169
-111
lines changed

15 files changed

+169
-111
lines changed

.github/workflows/tests.yml

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,25 @@ jobs:
1414
strategy:
1515
matrix:
1616
go:
17-
- ^1.19
18-
- ^1.20
17+
- ^1.21
18+
- ^1.22
19+
- ^1.23
20+
- ^1
1921
steps:
2022

2123
- name: Set up Go 1.x
22-
uses: actions/setup-go@v2
24+
uses: actions/setup-go@v5
2325
with:
2426
go-version: ${{ matrix.go }}
2527

2628
- name: Check out code into the Go module directory
27-
uses: actions/checkout@v2
29+
uses: actions/checkout@v4
2830

2931
- name: Install dependencies
3032
run: |
3133
sudo apt-get install -y libacl1-dev
32-
GO111MODULE=off go get golang.org/x/lint/golint
34+
go install golang.org/x/lint/golint@latest
35+
go install github.com/goreleaser/nfpm/v2/cmd/nfpm@v2.40.0
3336
3437
- name: Test
3538
run: |
@@ -46,8 +49,6 @@ jobs:
4649
build:
4750
name: Build packages
4851
runs-on: ubuntu-latest
49-
container:
50-
image: ${{ github.repository }}:builder
5152

5253
outputs:
5354
deb: ${{ steps.build.outputs.deb }}
@@ -56,8 +57,19 @@ jobs:
5657
md5sum: ${{ steps.build.outputs.md5sum }}
5758

5859
steps:
59-
- uses: actions/checkout@v2
60-
name: Checkout
60+
- name: Set up Go 1.x
61+
uses: actions/setup-go@v5
62+
with:
63+
go-version: ^1
64+
65+
- name: Check out code into the Go module directory
66+
uses: actions/checkout@v4
67+
68+
- name: Install dependencies
69+
run: |
70+
sudo apt-get install -y libacl1-dev
71+
go install github.com/goreleaser/nfpm/v2/cmd/nfpm@v2.40.0
72+
6173
- name: Build packages
6274
id: build
6375
run: |
@@ -67,7 +79,7 @@ jobs:
6779
make packages
6880
make github_artifact
6981
- name: Upload artifact
70-
uses: actions/upload-artifact@v2
82+
uses: actions/upload-artifact@v4
7183
with:
7284
name: packages
7385
path: artifact
@@ -77,7 +89,7 @@ jobs:
7789
runs-on: ubuntu-latest
7890

7991
steps:
80-
- uses: actions/checkout@v2
92+
- uses: actions/checkout@v4
8193
name: Checkout
8294
- name: Build docker images
8395
run: |
@@ -96,23 +108,27 @@ jobs:
96108
strategy:
97109
matrix:
98110
os:
99-
- debian:9
100111
- debian:10
101-
- ubuntu:18.04
112+
- debian:11
113+
- debian:12
102114
- ubuntu:20.04
103-
- centos:7
115+
- ubuntu:22.04
116+
- ubuntu:24.04
104117
- centos:8
118+
- fedora:40
119+
- fedora:41
120+
- fedora:42
105121

106122
steps:
107123
- name: Download artifact
108-
uses: actions/download-artifact@v2
124+
uses: actions/download-artifact@v4
109125
with:
110126
name: packages
111127
- name: Test deb
112128
if: ${{ contains(matrix.os, 'debian') || contains(matrix.os, 'ubuntu') }}
113129
run: |
114130
apt-get install libacl1; dpkg -i grafsy_0.0.0.1*deb
115131
- name: Test rpm
116-
if: ${{ contains(matrix.os, 'centos') }}
132+
if: ${{ contains(matrix.os, 'centos') || contains(matrix.os, 'fedora') }}
117133
run: |
118134
rpm -i grafsy-0.0.0.1*rpm

.github/workflows/upload-assets.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,31 @@ jobs:
1010
name: Build
1111
runs-on: ubuntu-latest
1212

13-
container:
14-
image: ${{ github.repository }}:builder
15-
1613
outputs:
1714
deb: ${{ steps.build.outputs.deb }}
1815
rpm: ${{ steps.build.outputs.rpm }}
1916
sha256sum: ${{ steps.build.outputs.sha256sum }}
2017
md5sum: ${{ steps.build.outputs.md5sum }}
2118

2219
steps:
23-
- uses: actions/checkout@v2
24-
name: Checkout
20+
- name: Set up Go 1.x
21+
uses: actions/setup-go@v5
22+
with:
23+
go-version: ^1
24+
25+
- name: Check out code into the Go module directory
26+
uses: actions/checkout@v4
2527
with:
2628
# Otherwise there's a risk to not get latest tag
2729
# We hope, that the current commit at
2830
# least 50 commits close to the latest release
2931
fetch-depth: 50
32+
33+
- name: Install dependencies
34+
run: |
35+
sudo apt-get install -y libacl1-dev
36+
go install github.com/goreleaser/nfpm/v2/cmd/nfpm@v2.40.0
37+
3038
- name: Build packages
3139
id: build
3240
run: |

Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#
2+
# Image which contains the binary artefacts
3+
#
4+
FROM golang:bookworm AS build
5+
6+
7+
COPY . ./grafsy
8+
9+
WORKDIR ./grafsy
10+
11+
RUN apt update && \
12+
apt install -y libacl1-dev && \
13+
make clean test && \
14+
make build
15+
16+
#
17+
# Application image
18+
#
19+
FROM debian:stable-slim
20+
21+
RUN apt-get update && apt-get install libacl1 -y && apt-get clean && mkdir /etc/grafsy
22+
23+
WORKDIR /grafsy
24+
25+
COPY --from=build /go/grafsy/build/grafsy ./grafsy
26+
27+
COPY --from=build /go/grafsy/build/grafsy-client ./grafsy-client
28+
29+
COPY entrypoint.sh /entrypoint.sh
30+
31+
ENTRYPOINT ["/entrypoint.sh"]
32+
CMD ["/grafsy/grafsy"]

Makefile

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ endef
1414
GO_FILES = $(shell find -name '*.go')
1515
PKG_FILES = build/$(NAME)_$(VERSION)_amd64.deb build/$(NAME)-$(VERSION)-1.x86_64.rpm
1616
SUM_FILES = build/sha256sum build/md5sum
17-
GO_FLAGS =
17+
GO_FLAGS = -trimpath
1818
GO_BUILD = go build $(GO_FLAGS) -ldflags "-X 'main.version=$(VERSION)'" -o $@ $<
1919

2020
export GO111MODULE=on
@@ -40,8 +40,7 @@ test:
4040
build: build/$(NAME) build/$(NAME)-client
4141

4242
docker:
43-
docker build -t $(ORG_NAME)/$(NAME):builder -f docker/builder/Dockerfile .
44-
docker build --build-arg IMAGE=$(ORG_NAME)/$(NAME) -t $(ORG_NAME)/$(NAME):latest -f docker/$(NAME)/Dockerfile .
43+
docker build --build-arg IMAGE=$(ORG_NAME)/$(NAME) -t $(ORG_NAME)/$(NAME):latest -f Dockerfile .
4544

4645
build/$(NAME): $(NAME)/main.go
4746
$(GO_BUILD)
@@ -94,7 +93,6 @@ build/$(NAME)_linux_x64: $(NAME)/main.go
9493
build/$(NAME)-client_linux_x64: $(NAME)-client/main.go
9594
GOOS=linux GOARCH=amd64 $(GO_BUILD)
9695

97-
packages: $(PKG_FILES) $(SUM_FILES)
9896

9997
# md5 and sha256 sum-files for packages
10098
$(SUM_FILES): COMMAND = $(notdir $@)
@@ -104,30 +102,16 @@ $(SUM_FILES): $(PKG_FILES)
104102
cd build
105103
$(COMMAND) $(PKG_FILES_NAME) > $(COMMAND)
106104

107-
deb: $(word 1, $(PKG_FILES))
105+
packages: nfpm $(SUM_FILES)
106+
deb: nfpm
107+
rpm: nfpm
108+
nfpm: build build/pkg
109+
$(MAKE) $(PKG_FILES) ARCH=amd64
108110

109-
rpm: $(word 2, $(PKG_FILES))
110-
111-
# Set TYPE to package suffix w/o dot
111+
.ONESHELL:
112112
$(PKG_FILES): TYPE = $(subst .,,$(suffix $@))
113-
$(PKG_FILES): build/pkg
114-
fpm --verbose \
115-
-s dir \
116-
-a x86_64 \
117-
-t $(TYPE) \
118-
--vendor $(VENDOR) \
119-
-m $(VENDOR) \
120-
--url $(URL) \
121-
--description $(DESC) \
122-
--license Apache \
123-
-n $(NAME) \
124-
-v $(VERSION) \
125-
--after-install packaging/postinst \
126-
--before-remove packaging/prerm \
127-
-p build \
128-
build/pkg/=/ \
129-
packaging/$(NAME).service=/lib/systemd/system/$(NAME).service
130-
113+
$(PKG_FILES): nfpm.yaml
114+
NAME=$(NAME) VENDOR=$(VENDOR) DESCRIPTION=$(DESCRIPTION) ARCH=$(ARCH) VERSION_STRING=$(VERSION) nfpm package --packager $(TYPE) --target build/
131115
#######
132116
# END #
133117
#######

client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"time"
1111
)
1212

13-
// Client is a class wich sends metrics to the carbon receivers
13+
// Client is a class which sends metrics to the carbon receivers
1414
type Client struct {
1515
// User config.
1616
Conf *Config
@@ -137,9 +137,9 @@ func (c *Client) tryToSendToGraphite(metric string, carbonAddr string, conn net.
137137
}
138138

139139
// Run go routine per carbon server to:
140-
// 1) Send data from retryFile to a carbon
141-
// 2) Send metrics from monitoring channel to a carbon
142-
// 3) Send metrics from the main channel to carbon
140+
// 1. Send data from retryFile to a carbon
141+
// 2. Send metrics from monitoring channel to a carbon
142+
// 3. Send metrics from the main channel to carbon
143143
//
144144
// And save everything to the retryFile on any error
145145
func (c Client) runBackend(carbonAddr string) {
@@ -235,7 +235,7 @@ func (c Client) runBackend(carbonAddr string) {
235235
}
236236
}
237237

238-
//Run a client, which:
238+
// Run a client, which:
239239
// 1) Make monitoring and main channels per carbon server
240240
// 2) Launchs go routine per carbon server
241241
// 3) Copy metrics from monitoring and main channels to the carbon server specific

config.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"regexp"
1010
"strings"
1111

12-
"github.com/BurntSushi/toml"
12+
"github.com/pelletier/go-toml/v2"
1313
"github.com/pkg/errors"
1414
)
1515

@@ -141,8 +141,15 @@ type LocalConfig struct {
141141
// LoadConfig loads a configFile to a Config structure.
142142
func (conf *Config) LoadConfig(configFile string) error {
143143

144-
if _, err := toml.DecodeFile(configFile, conf); err != nil {
145-
return errors.New("Failed to parse config file: " + err.Error())
144+
// Read the file content
145+
data, err := os.ReadFile(configFile)
146+
if err != nil {
147+
return fmt.Errorf("failed to read config file: %s", err)
148+
}
149+
150+
// Unmarshal the data into 'conf'
151+
if err := toml.Unmarshal(data, conf); err != nil {
152+
return fmt.Errorf("failed to parse config file: %s", err)
146153
}
147154

148155
if conf.ClientSendInterval < 1 || conf.AggrInterval < 1 || conf.AggrPerSecond < 1 ||

config_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build !noacl
1+
//go:build !noacl
22

33
package grafsy
44

docker/builder/Dockerfile

Lines changed: 0 additions & 10 deletions
This file was deleted.

docker/grafsy/Dockerfile

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)