Browse Source

Linting and dockerization.

tags/0.1
Stanislav Nikitin 6 months ago
parent
commit
355dac8ea3
Signed by: pztrn <pztrn@pztrn.name> GPG Key ID: 106900B32F8192EE
9 changed files with 56 additions and 12 deletions
  1. +15
    -0
      .drone.yml
  2. +18
    -0
      .golangci.yml
  3. +17
    -0
      Dockerfile
  4. +1
    -1
      cmd/giredorectl/main.go
  5. +1
    -1
      cmd/giredored/main.go
  6. +1
    -1
      domains/server/v1/packagesapi.go
  7. +1
    -3
      internal/configuration/exported.go
  8. +2
    -3
      internal/httpserver/exported.go
  9. +0
    -3
      internal/logger/exported.go

+ 15
- 0
.drone.yml View File

@@ -0,0 +1,15 @@
---
kind: pipeline
type: docker
name: build

steps:
- name: docker
image: plugins/docker
settings:
username:
from_secret: dockerhub_user
password:
from_secret: dockerhub_password
repo: pztrn/giredore
auto_tag: true

+ 18
- 0
.golangci.yml View File

@@ -0,0 +1,18 @@
run:
deadline: 5m
linters:
enable-all: true
disable:
# Because globals might exist, but according to our codestyle they
# should be lowercased and considered as unexported.
- gochecknoglobals
# While it might be useful it'll create more problems that will solve.
- gocritic
# Complains about main() lengths, which isn't an issue.
- funlen
linters-settings:
lll:
line-length: 420
gocyclo:
min-complexity: 40

+ 17
- 0
Dockerfile View File

@@ -0,0 +1,17 @@
FROM golang:1.13.1-alpine AS build

WORKDIR /go/src/sources.dev.pztrn.name/pztrn/giredore
COPY . .

WORKDIR /go/src/gitlab.com/pztrn/fastpastebin/cmd/fastpastebin

RUN cd /go/src/sources.dev.pztrn.name/pztrn/giredore/cmd/giredored && go build && cd ../giredorectl && go build

FROM alpine:latest
LABEL maintainer "Stanislav N. <pztrn@pztrn.name>"

COPY --from=build /go/src/sources.dev.pztrn.name/pztrn/giredore/cmd/giredored/giredored /usr/local/bin/giredored
COPY --from=build /go/src/sources.dev.pztrn.name/pztrn/giredore/cmd/giredorectl/giredorectl /usr/local/bin/giredorectl

EXPOSE 62222
ENTRYPOINT [ "/usr/local/bin/giredored" ]

+ 1
- 1
cmd/giredorectl/main.go View File

@@ -5,7 +5,7 @@ import (
"os"

// local
"sources.dev.pztrn.name/pztrn/giredore/domains/client/v1"
clientv1 "sources.dev.pztrn.name/pztrn/giredore/domains/client/v1"
"sources.dev.pztrn.name/pztrn/giredore/internal/logger"

// other


+ 1
- 1
cmd/giredored/main.go View File

@@ -7,7 +7,7 @@ import (
"syscall"

// local
"sources.dev.pztrn.name/pztrn/giredore/domains/server/v1"
serverv1 "sources.dev.pztrn.name/pztrn/giredore/domains/server/v1"
"sources.dev.pztrn.name/pztrn/giredore/internal/configuration"
"sources.dev.pztrn.name/pztrn/giredore/internal/httpserver"
"sources.dev.pztrn.name/pztrn/giredore/internal/logger"


+ 1
- 1
domains/server/v1/packagesapi.go View File

@@ -31,7 +31,7 @@ func packagesGET(ec echo.Context) error {
pkgs, errors = configuration.Cfg.GetPackagesInfo(req.PackageNames)
}

if errors != nil && len(errors) > 0 {
if len(errors) > 0 {
return ec.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: errors, Data: pkgs})
}



+ 1
- 3
internal/configuration/exported.go View File

@@ -9,8 +9,7 @@ import (
)

var (
log zerolog.Logger
loggerInitialized bool
log zerolog.Logger

envCfg *envConfig
Cfg *fileConfig
@@ -18,7 +17,6 @@ var (

func Initialize() {
log = logger.Logger.With().Str("type", "internal").Str("package", "configuration").Logger()
loggerInitialized = true
log.Info().Msg("Initializing...")

envCfg = &envConfig{}


+ 2
- 3
internal/httpserver/exported.go View File

@@ -49,7 +49,6 @@ func Shutdown() {
log.Fatal().Err(err).Msg("Failed to stop HTTP server")
}
log.Info().Msg("HTTP server shutted down")

}

// Start starts HTTP server and checks that server is ready to process
@@ -60,7 +59,7 @@ func Start() {
go func() {
err := Srv.Start(configuration.Cfg.HTTP.Listen)
if !strings.Contains(err.Error(), "Server closed") {
log.Fatal().Err(err).Msg("HTTP server critial error occured")
log.Fatal().Err(err).Msg("HTTP server critial error occurred")
}
}()

@@ -75,7 +74,7 @@ func Start() {
time.Sleep(time.Second * 1)
resp, err := httpc.Get("http://" + configuration.Cfg.HTTP.Listen + "/_internal/waitForOnline")
if err != nil {
log.Debug().Err(err).Msg("HTTP error occured, HTTP server isn't ready, waiting...")
log.Debug().Err(err).Msg("HTTP error occurred, HTTP server isn't ready, waiting...")
continue
}



+ 0
- 3
internal/logger/exported.go View File

@@ -14,8 +14,6 @@ import (
var (
Logger zerolog.Logger
SuperVerbosive bool

loggerInitialized bool
)

// Initialize initializes zerolog with proper formatting and log level.
@@ -72,5 +70,4 @@ func Initialize() {
}

Logger = zerolog.New(output).With().Timestamp().Logger()
loggerInitialized = true
}

Loading…
Cancel
Save