Skip to content

Commit

Permalink
NOISSUE - Fix CI (#35)
Browse files Browse the repository at this point in the history
* Fix CI

Signed-off-by: Dusan Borovcanin <[email protected]>

* Add temproary push test

Signed-off-by: Dusan Borovcanin <[email protected]>

---------

Signed-off-by: Dusan Borovcanin <[email protected]>
  • Loading branch information
dborovcanin authored Oct 7, 2024
1 parent 601c359 commit f0745c9
Show file tree
Hide file tree
Showing 34 changed files with 230 additions and 54 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ jobs:

- name: Build
run: make callhome

- name: Lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v6
with:
version: latest
args: --no-config --disable-all --enable gosimple --enable govet --enable unused --enable deadcode --timeout 3m
version: v1.59.1
args: --config .golangci.yml

- name: Run tests
run: make test
42 changes: 21 additions & 21 deletions .github/workflows/server-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@ on:


jobs:
push_to_registry:
name: Push Docker image to Docker Hub
build-and-push-image:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_SECRET }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
uses: docker/metadata-action@v5
with:
images: magistrala/callhome

- name: Build and push Docker image
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: docker/
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker images
run: |
make latest
84 changes: 84 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Copyright (c) Abstract Machines
# SPDX-License-Identifier: Apache-2.0

run:
timeout: 10m
build-tags:
- "nats"

issues:
max-issues-per-linter: 100
max-same-issues: 100
exclude:
- "string `Usage:\n` has (\\d+) occurrences, make it a constant"
- "string `For example:\n` has (\\d+) occurrences, make it a constant"
exclude-rules:
- path: cli/commands_test.go
linters:
- godot

linters-settings:
gocritic:
enabled-checks:
- importShadow
- httpNoBody
- paramTypeCombine
- emptyStringTest
- builtinShadow
- exposedSyncMutex
disabled-checks:
- appendAssign
enabled-tags:
- diagnostic
disabled-tags:
- performance
- style
- experimental
- opinionated
misspell:
ignore-words:
- "mosquitto"
stylecheck:
checks: ["-ST1000", "-ST1003", "-ST1020", "-ST1021", "-ST1022"]
goheader:
template: |-
Copyright (c) Abstract Machines
SPDX-License-Identifier: Apache-2.0
linters:
disable-all: true
enable:
- gocritic
- gosimple
- errcheck
- govet
- unused
- goconst
- godot
- godox
- ineffassign
- misspell
- stylecheck
- whitespace
- gci
- gofmt
- goimports
- loggercheck
- goheader
- asasalint
- asciicheck
- bidichk
- contextcheck
- decorder
- dogsled
- errchkjson
- errname
- ginkgolinter
- gocheckcompilerdirectives
- gofumpt
- goprintffuncname
- importas
- makezero
- mirror
- nakedret
- dupword
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ DOMAIN ?= deployments.magistrala.abstractmachines.fr

all: $(PROGRAM)

.PHONY: all clean $(PROGRAM)
.PHONY: all clean $(PROGRAM) latest

define make_docker
docker build \
Expand Down Expand Up @@ -47,6 +47,7 @@ clean:

docker-image:
$(call make_docker)

dev-cert:
$(call make_dev_cert)

Expand All @@ -55,3 +56,7 @@ run:

test:
go test -v --race -covermode=atomic -coverprofile cover.out ./...


latest: docker-image
docker push magistrala/callhome:latest
3 changes: 3 additions & 0 deletions api/endpoint.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Abstract Machines
// SPDX-License-Identifier: Apache-2.0

package api

import (
Expand Down
3 changes: 3 additions & 0 deletions api/endpoint_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Abstract Machines
// SPDX-License-Identifier: Apache-2.0

package api

import (
Expand Down
5 changes: 4 additions & 1 deletion api/logging.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Abstract Machines
// SPDX-License-Identifier: Apache-2.0

package api

import (
Expand Down Expand Up @@ -62,7 +65,7 @@ func (lm *loggingMiddleware) RetrieveSummary(ctx context.Context, filters callho
return lm.svc.RetrieveSummary(ctx, filters)
}

// ServeUI implements callhome.Service
// ServeUI implements callhome.Service.
func (lm *loggingMiddleware) ServeUI(ctx context.Context, filters callhome.TelemetryFilters) (res []byte, err error) {
defer func(begin time.Time) {
message := fmt.Sprintf("Method serve ui event took %s to complete", time.Since(begin))
Expand Down
5 changes: 4 additions & 1 deletion api/metrics.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Abstract Machines
// SPDX-License-Identifier: Apache-2.0

package api

import (
Expand Down Expand Up @@ -54,7 +57,7 @@ func (mm *metricsMiddleware) RetrieveSummary(ctx context.Context, filters callho
return mm.svc.RetrieveSummary(ctx, filters)
}

// ServeUI implements callhome.Service
// ServeUI implements callhome.Service.
func (mm *metricsMiddleware) ServeUI(ctx context.Context, filters callhome.TelemetryFilters) ([]byte, error) {
defer func(begin time.Time) {
mm.counter.With("method", "serve-ui").Add(1)
Expand Down
3 changes: 3 additions & 0 deletions api/requests.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Abstract Machines
// SPDX-License-Identifier: Apache-2.0

package api

import (
Expand Down
15 changes: 9 additions & 6 deletions api/responses.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Abstract Machines
// SPDX-License-Identifier: Apache-2.0

package api

import (
Expand Down Expand Up @@ -67,7 +70,7 @@ type uiRes struct {
html []byte
}

// Code implements magistrala.Response
// Code implements magistrala.Response.
func (res uiRes) Code() int {
if res.code == 0 {
return http.StatusCreated
Expand All @@ -76,12 +79,12 @@ func (res uiRes) Code() int {
return res.code
}

// Empty implements magistrala.Response
// Empty implements magistrala.Response.
func (res uiRes) Empty() bool {
return res.html == nil
}

// Headers implements magistrala.Response
// Headers implements magistrala.Response.
func (res uiRes) Headers() map[string]string {
if res.headers == nil {
return map[string]string{}
Expand All @@ -97,17 +100,17 @@ type telemetrySummaryRes struct {
TotalDeployments int `json:"total_deployments,omitempty"`
}

// Code implements magistrala.Response
// Code implements magistrala.Response.
func (*telemetrySummaryRes) Code() int {
return http.StatusOK
}

// Empty implements magistrala.Response
// Empty implements magistrala.Response.
func (*telemetrySummaryRes) Empty() bool {
return false
}

// Headers implements magistrala.Response
// Headers implements magistrala.Response.
func (res *telemetrySummaryRes) Headers() map[string]string {
return map[string]string{}
}
4 changes: 3 additions & 1 deletion api/transport.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Abstract Machines
// SPDX-License-Identifier: Apache-2.0

package api

import (
Expand All @@ -15,7 +18,6 @@ import (
"github.com/absmach/magistrala/pkg/uuid"
kithttp "github.com/go-kit/kit/transport/http"
"github.com/go-zoo/bone"

"github.com/prometheus/client_golang/prometheus/promhttp"
"go.opentelemetry.io/contrib/instrumentation/github.com/go-kit/kit/otelkit"
"go.opentelemetry.io/otel/trace"
Expand Down
7 changes: 5 additions & 2 deletions api/utils.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Abstract Machines
// SPDX-License-Identifier: Apache-2.0

package api

import (
Expand Down Expand Up @@ -29,7 +32,7 @@ func LoggingErrorEncoder(logger *slog.Logger, enc kithttp.ErrorEncoder) kithttp.
}
}

// ReadUintQuery reads the value of uint64 http query parameters for a given key
// ReadUintQuery reads the value of uint64 http query parameters for a given key.
func ReadUintQuery(r *http.Request, key string, def uint64) (uint64, error) {
vals := bone.GetQuery(r, key)
if len(vals) > 1 {
Expand All @@ -46,7 +49,7 @@ func ReadUintQuery(r *http.Request, key string, def uint64) (uint64, error) {
return val, nil
}

// ReadStringQuery reads the value of string http query parameters for a given key
// ReadStringQuery reads the value of string http query parameters for a given key.
func ReadStringQuery(r *http.Request, key string, def string) (string, error) {
vals := bone.GetQuery(r, key)
if len(vals) > 1 {
Expand Down
16 changes: 9 additions & 7 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Abstract Machines
// SPDX-License-Identifier: Apache-2.0

package main

import (
Expand Down Expand Up @@ -49,7 +52,7 @@ func main() {

logger, err := newLogger(os.Stdout, cfg.LogLevel)
if err != nil {
log.Fatalf(fmt.Sprintf("failed to init logger: %s", err.Error()))
log.Fatalf("failed to init logger: %s", err.Error())
}
timescaleDB, err := postgres.Setup(envPrefix, timescale.Migration())
if err != nil {
Expand All @@ -60,18 +63,17 @@ func main() {
if err != nil {
log.Fatalf("Failed to init Jaeger: %s", err)
}
defer func() {
if err := tp.Shutdown(context.Background()); err != nil {
log.Fatalf("Error shutting down tracer provider: %v", err)
}
}()
tracer := tp.Tracer(svcName)

svc, err := newService(ctx, logger, cfg.IPDatabaseFile, timescaleDB, tracer)
if err != nil {
log.Fatalf("failed to initialize service: %s", err)
return
}
defer func() {
if err := tp.Shutdown(context.Background()); err != nil {
log.Fatalf("Error shutting down tracer provider: %v", err)
}
}()

httpServerConfig := server.Config{Port: defSvcHttpPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil {
Expand Down
9 changes: 6 additions & 3 deletions internal/clients/postgres/postgres.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Abstract Machines
// SPDX-License-Identifier: Apache-2.0

package postgres

import (
Expand All @@ -16,7 +19,7 @@ var (
errMigration = errors.New("failed to apply migrations")
)

// Config defines the options that are used when connecting to a TimescaleSQL instance
// Config defines the options that are used when connecting to a TimescaleSQL instance.
type Config struct {
Host string `env:"TIMESCALE_HOST" envDefault:"localhost"`
Port string `env:"TIMESCALE_PORT" envDefault:"5432"`
Expand Down Expand Up @@ -58,7 +61,7 @@ func SetupDB(cfg Config, migrations migrate.MemoryMigrationSource) (*sqlx.DB, er
return db, nil
}

// Connect creates a connection to the PostgreSQL instance
// Connect creates a connection to the PostgreSQL instance.
func Connect(cfg Config) (*sqlx.DB, error) {
url := fmt.Sprintf("host=%s port=%s user=%s dbname=%s password=%s sslmode=%s sslcert=%s sslkey=%s sslrootcert=%s", cfg.Host, cfg.Port, cfg.User, cfg.Name, cfg.Pass, cfg.SSLMode, cfg.SSLCert, cfg.SSLKey, cfg.SSLRootCert)

Expand All @@ -70,7 +73,7 @@ func Connect(cfg Config) (*sqlx.DB, error) {
return db, nil
}

// MigrateDB applies any unapplied database migrations
// MigrateDB applies any unapplied database migrations.
func MigrateDB(db *sqlx.DB, migrations migrate.MemoryMigrationSource) error {
_, err := migrate.Exec(db.DB, "postgres", migrations, migrate.Up)
if err != nil {
Expand Down
Loading

0 comments on commit f0745c9

Please sign in to comment.