Linting and dockerization.

This commit is contained in:
Stanislav Nikitin 2019-10-07 21:51:45 +05:00
parent cd6e739dc2
commit 355dac8ea3
No known key found for this signature in database
GPG Key ID: 106900B32F8192EE
9 changed files with 56 additions and 12 deletions

15
.drone.yml Normal file
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
.golangci.yml Normal file
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
Dockerfile Normal file
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" ]

View File

@ -5,7 +5,7 @@ import (
"os" "os"
// local // 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" "sources.dev.pztrn.name/pztrn/giredore/internal/logger"
// other // other

View File

@ -7,7 +7,7 @@ import (
"syscall" "syscall"
// local // 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/configuration"
"sources.dev.pztrn.name/pztrn/giredore/internal/httpserver" "sources.dev.pztrn.name/pztrn/giredore/internal/httpserver"
"sources.dev.pztrn.name/pztrn/giredore/internal/logger" "sources.dev.pztrn.name/pztrn/giredore/internal/logger"

View File

@ -31,7 +31,7 @@ func packagesGET(ec echo.Context) error {
pkgs, errors = configuration.Cfg.GetPackagesInfo(req.PackageNames) 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}) return ec.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: errors, Data: pkgs})
} }

View File

@ -9,8 +9,7 @@ import (
) )
var ( var (
log zerolog.Logger log zerolog.Logger
loggerInitialized bool
envCfg *envConfig envCfg *envConfig
Cfg *fileConfig Cfg *fileConfig
@ -18,7 +17,6 @@ var (
func Initialize() { func Initialize() {
log = logger.Logger.With().Str("type", "internal").Str("package", "configuration").Logger() log = logger.Logger.With().Str("type", "internal").Str("package", "configuration").Logger()
loggerInitialized = true
log.Info().Msg("Initializing...") log.Info().Msg("Initializing...")
envCfg = &envConfig{} envCfg = &envConfig{}

View File

@ -49,7 +49,6 @@ func Shutdown() {
log.Fatal().Err(err).Msg("Failed to stop HTTP server") log.Fatal().Err(err).Msg("Failed to stop HTTP server")
} }
log.Info().Msg("HTTP server shutted down") log.Info().Msg("HTTP server shutted down")
} }
// Start starts HTTP server and checks that server is ready to process // Start starts HTTP server and checks that server is ready to process
@ -60,7 +59,7 @@ func Start() {
go func() { go func() {
err := Srv.Start(configuration.Cfg.HTTP.Listen) err := Srv.Start(configuration.Cfg.HTTP.Listen)
if !strings.Contains(err.Error(), "Server closed") { 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) time.Sleep(time.Second * 1)
resp, err := httpc.Get("http://" + configuration.Cfg.HTTP.Listen + "/_internal/waitForOnline") resp, err := httpc.Get("http://" + configuration.Cfg.HTTP.Listen + "/_internal/waitForOnline")
if err != nil { 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 continue
} }

View File

@ -14,8 +14,6 @@ import (
var ( var (
Logger zerolog.Logger Logger zerolog.Logger
SuperVerbosive bool SuperVerbosive bool
loggerInitialized bool
) )
// Initialize initializes zerolog with proper formatting and log level. // Initialize initializes zerolog with proper formatting and log level.
@ -72,5 +70,4 @@ func Initialize() {
} }
Logger = zerolog.New(output).With().Timestamp().Logger() Logger = zerolog.New(output).With().Timestamp().Logger()
loggerInitialized = true
} }