Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the CI #30

Merged
merged 6 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 32 additions & 16 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,25 @@ jobs:
strategy:
matrix:
go:
- ^1.19
- ^1.20
- ^1.21
- ^1.22
- ^1.23
- ^1
steps:

- name: Set up Go 1.x
uses: actions/setup-go@v2
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}

- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get install -y libacl1-dev
GO111MODULE=off go get golang.org/x/lint/golint
go install golang.org/x/lint/golint@latest
go install github.com/goreleaser/nfpm/v2/cmd/[email protected]

- name: Test
run: |
Expand All @@ -46,8 +49,6 @@ jobs:
build:
name: Build packages
runs-on: ubuntu-latest
container:
image: ${{ github.repository }}:builder

outputs:
deb: ${{ steps.build.outputs.deb }}
Expand All @@ -56,8 +57,19 @@ jobs:
md5sum: ${{ steps.build.outputs.md5sum }}

steps:
- uses: actions/checkout@v2
name: Checkout
- name: Set up Go 1.x
uses: actions/setup-go@v5
with:
go-version: ^1

- name: Check out code into the Go module directory
uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get install -y libacl1-dev
go install github.com/goreleaser/nfpm/v2/cmd/[email protected]

- name: Build packages
id: build
run: |
Expand All @@ -67,7 +79,7 @@ jobs:
make packages
make github_artifact
- name: Upload artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: packages
path: artifact
Expand All @@ -77,7 +89,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
name: Checkout
- name: Build docker images
run: |
Expand All @@ -96,23 +108,27 @@ jobs:
strategy:
matrix:
os:
- debian:9
- debian:10
- ubuntu:18.04
- debian:11
- debian:12
- ubuntu:20.04
- centos:7
- ubuntu:22.04
- ubuntu:24.04
- centos:8
- fedora:40
- fedora:41
- fedora:42

steps:
- name: Download artifact
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: packages
- name: Test deb
if: ${{ contains(matrix.os, 'debian') || contains(matrix.os, 'ubuntu') }}
run: |
apt-get install libacl1; dpkg -i grafsy_0.0.0.1*deb
- name: Test rpm
if: ${{ contains(matrix.os, 'centos') }}
if: ${{ contains(matrix.os, 'centos') || contains(matrix.os, 'fedora') }}
run: |
rpm -i grafsy-0.0.0.1*rpm
18 changes: 13 additions & 5 deletions .github/workflows/upload-assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,31 @@ jobs:
name: Build
runs-on: ubuntu-latest

container:
image: ${{ github.repository }}:builder

outputs:
deb: ${{ steps.build.outputs.deb }}
rpm: ${{ steps.build.outputs.rpm }}
sha256sum: ${{ steps.build.outputs.sha256sum }}
md5sum: ${{ steps.build.outputs.md5sum }}

steps:
- uses: actions/checkout@v2
name: Checkout
- name: Set up Go 1.x
uses: actions/setup-go@v5
with:
go-version: ^1

- name: Check out code into the Go module directory
uses: actions/checkout@v4
with:
# Otherwise there's a risk to not get latest tag
# We hope, that the current commit at
# least 50 commits close to the latest release
fetch-depth: 50

- name: Install dependencies
run: |
sudo apt-get install -y libacl1-dev
go install github.com/goreleaser/nfpm/v2/cmd/[email protected]

- name: Build packages
id: build
run: |
Expand Down
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# Image which contains the binary artefacts
#
FROM golang:bookworm AS build


COPY . ./grafsy

WORKDIR ./grafsy

RUN apt update && \
apt install -y libacl1-dev && \
make clean test && \
make build

#
# Application image
#
FROM debian:stable-slim

RUN apt-get update && apt-get install libacl1 -y && apt-get clean && mkdir /etc/grafsy

WORKDIR /grafsy

COPY --from=build /go/grafsy/build/grafsy ./grafsy

COPY --from=build /go/grafsy/build/grafsy-client ./grafsy-client

COPY entrypoint.sh /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
CMD ["/grafsy/grafsy"]
36 changes: 10 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ endef
GO_FILES = $(shell find -name '*.go')
PKG_FILES = build/$(NAME)_$(VERSION)_amd64.deb build/$(NAME)-$(VERSION)-1.x86_64.rpm
SUM_FILES = build/sha256sum build/md5sum
GO_FLAGS =
GO_FLAGS = -trimpath
GO_BUILD = go build $(GO_FLAGS) -ldflags "-X 'main.version=$(VERSION)'" -o $@ $<

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

docker:
docker build -t $(ORG_NAME)/$(NAME):builder -f docker/builder/Dockerfile .
docker build --build-arg IMAGE=$(ORG_NAME)/$(NAME) -t $(ORG_NAME)/$(NAME):latest -f docker/$(NAME)/Dockerfile .
docker build --build-arg IMAGE=$(ORG_NAME)/$(NAME) -t $(ORG_NAME)/$(NAME):latest -f Dockerfile .

build/$(NAME): $(NAME)/main.go
$(GO_BUILD)
Expand Down Expand Up @@ -94,7 +93,6 @@ build/$(NAME)_linux_x64: $(NAME)/main.go
build/$(NAME)-client_linux_x64: $(NAME)-client/main.go
GOOS=linux GOARCH=amd64 $(GO_BUILD)

packages: $(PKG_FILES) $(SUM_FILES)

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

deb: $(word 1, $(PKG_FILES))
packages: nfpm $(SUM_FILES)
deb: nfpm
rpm: nfpm
nfpm: build build/pkg
$(MAKE) $(PKG_FILES) ARCH=amd64

rpm: $(word 2, $(PKG_FILES))

# Set TYPE to package suffix w/o dot
.ONESHELL:
$(PKG_FILES): TYPE = $(subst .,,$(suffix $@))
$(PKG_FILES): build/pkg
fpm --verbose \
-s dir \
-a x86_64 \
-t $(TYPE) \
--vendor $(VENDOR) \
-m $(VENDOR) \
--url $(URL) \
--description $(DESC) \
--license Apache \
-n $(NAME) \
-v $(VERSION) \
--after-install packaging/postinst \
--before-remove packaging/prerm \
-p build \
build/pkg/=/ \
packaging/$(NAME).service=/lib/systemd/system/$(NAME).service

$(PKG_FILES): nfpm.yaml
NAME=$(NAME) VENDOR=$(VENDOR) DESCRIPTION=$(DESCRIPTION) ARCH=$(ARCH) VERSION_STRING=$(VERSION) nfpm package --packager $(TYPE) --target build/
#######
# END #
#######
10 changes: 5 additions & 5 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"
)

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

// Run go routine per carbon server to:
// 1) Send data from retryFile to a carbon
// 2) Send metrics from monitoring channel to a carbon
// 3) Send metrics from the main channel to carbon
// 1. Send data from retryFile to a carbon
// 2. Send metrics from monitoring channel to a carbon
// 3. Send metrics from the main channel to carbon
//
// And save everything to the retryFile on any error
func (c Client) runBackend(carbonAddr string) {
Expand Down Expand Up @@ -235,7 +235,7 @@ func (c Client) runBackend(carbonAddr string) {
}
}

//Run a client, which:
// Run a client, which:
// 1) Make monitoring and main channels per carbon server
// 2) Launchs go routine per carbon server
// 3) Copy metrics from monitoring and main channels to the carbon server specific
Expand Down
13 changes: 10 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"regexp"
"strings"

"github.com/BurntSushi/toml"
"github.com/pelletier/go-toml/v2"
"github.com/pkg/errors"
)

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

if _, err := toml.DecodeFile(configFile, conf); err != nil {
return errors.New("Failed to parse config file: " + err.Error())
// Read the file content
data, err := os.ReadFile(configFile)
if err != nil {
return fmt.Errorf("failed to read config file: %s", err)
}

// Unmarshal the data into 'conf'
if err := toml.Unmarshal(data, conf); err != nil {
return fmt.Errorf("failed to parse config file: %s", err)
}

if conf.ClientSendInterval < 1 || conf.AggrInterval < 1 || conf.AggrPerSecond < 1 ||
Expand Down
2 changes: 1 addition & 1 deletion config_linux.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !noacl
//go:build !noacl

package grafsy

Expand Down
10 changes: 0 additions & 10 deletions docker/builder/Dockerfile

This file was deleted.

34 changes: 0 additions & 34 deletions docker/grafsy/Dockerfile

This file was deleted.

File renamed without changes.
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
module github.com/leoleovich/grafsy

go 1.14
go 1.21.0

toolchain go1.23.3

require (
github.com/BurntSushi/toml v0.3.1
github.com/naegelejd/go-acl v0.0.0-20200406162857-ebe394c522e5
github.com/pelletier/go-toml/v2 v2.2.3
github.com/pkg/errors v0.9.1
)
12 changes: 10 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
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/naegelejd/go-acl v0.0.0-20200406162857-ebe394c522e5 h1:R10+S1Knv6udBjyDYU84+zD5R8qLWg7wSH/ddhJSzX4=
github.com/naegelejd/go-acl v0.0.0-20200406162857-ebe394c522e5/go.mod h1:nMzsOoQWESVMF6s+hAF8Qnc14fUIpL7pfmGm6MV8B2g=
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
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/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading
Loading