Move to mirrorred images for Drone and Dockerfile, linting fixes.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Stanislav Nikitin 2022-06-29 15:04:57 +05:00
parent 899c406f09
commit 9e5f98a413
Signed by: pztrn
GPG Key ID: 1E944A0F0568B550
13 changed files with 44 additions and 40 deletions

View File

@ -5,7 +5,7 @@ name: build
steps:
- name: lint
image: golangci/golangci-lint:v1.43.0
image: code.pztrn.name/containers/mirror/golangci/golangci-lint:v1.46.2
environment:
CGO_ENABLED: 0
commands:
@ -19,15 +19,15 @@ steps:
- go test ./...
- name: docker
image: plugins/docker
image: code.pztrn.name/containers/mirror/plugins/docker:20.13.0
when:
branch: ["master"]
settings:
username:
from_secret: dockerhub_user
registry: code.pztrn.name
username: drone
password:
from_secret: dockerhub_password
repo: pztrn/giredore
from_secret: drone_secret
repo: code.pztrn.name/apps/giredore
auto_tag: true
depends_on:
- lint

View File

@ -12,6 +12,8 @@ linters:
- funlen
# Magic numbers might be everywhere. Disabled for now.
- gomnd
# Deprecated.
- exhaustivestruct
linters-settings:
lll:
line-length: 420

View File

@ -1,4 +1,4 @@
FROM golang:1.17.3-alpine AS build
FROM code.pztrn.name/containers/mirror/golang:1.18.3-alpine AS build
WORKDIR /go/src/sources.dev.pztrn.name/pztrn/giredore
COPY . .
@ -6,7 +6,7 @@ COPY . .
ENV CGO_ENABLED=0
RUN cd /go/src/sources.dev.pztrn.name/pztrn/giredore/cmd/giredored && go build -tags netgo -ldflags '-w -extldflags "-static"' && cd ../giredorectl && go build -tags netgo -ldflags '-w -extldflags "-static"'
FROM alpine:latest
FROM code.pztrn.name/containers/mirror/alpine:3.16.0
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

View File

@ -27,7 +27,7 @@ func DeletePackage(args []string, options map[string]string) {
func GetPackages(args []string, options map[string]string) {
pkgs := strings.Split(args[0], ",")
// nolint:exhaustivestruct
// nolint:exhaustruct
req := &structs.PackageGetRequest{}
if pkgs[0] == "all" {
req.All = true

View File

@ -15,11 +15,11 @@ func configurationGET(ec echo.Context) error {
}
func configurationAllowedIPsSET(ectx echo.Context) error {
// nolint:exhaustivestruct
// nolint:exhaustruct
req := &structs.AllowedIPsSetRequest{}
if err := ectx.Bind(req); err != nil {
log.Error().Err(err).Msg("Failed to parse allowed IPs set request")
// nolint:exhaustivestruct,wrapcheck
// nolint:exhaustruct,wrapcheck
return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrParsingAllowedIPsSetRequest}})
}
@ -27,6 +27,6 @@ func configurationAllowedIPsSET(ectx echo.Context) error {
configuration.Cfg.SetAllowedIPs(req.AllowedIPs)
// nolint:exhaustivestruct,wrapcheck
// nolint:exhaustruct,wrapcheck
return ectx.JSON(http.StatusOK, &structs.Reply{Status: structs.StatusSuccess})
}

View File

@ -20,18 +20,18 @@ func throwGoImports(ectx echo.Context) error {
if errs != nil {
log.Error().Str("package", packageNameRaw).Msgf("Failed to get package information: %+v", errs)
// nolint:exhaustivestruct,wrapcheck
// nolint:exhaustruct,wrapcheck
return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: errs})
}
if len(pkgs) == 0 {
// nolint:exhaustivestruct,wrapcheck
// nolint:exhaustruct,wrapcheck
return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrNoPackagesFound}})
}
pkg, found := pkgs[packageNameRaw]
if !found {
// nolint:exhaustivestruct,wrapcheck
// nolint:exhaustruct,wrapcheck
return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrNoPackagesFound}})
}

View File

@ -11,12 +11,12 @@ import (
// This function responsible for getting packages configuration.
func packagesGET(ectx echo.Context) error {
// nolint:exhaustivestruct
// nolint:exhaustruct
req := &structs.PackageGetRequest{}
if err := ectx.Bind(req); err != nil {
log.Error().Err(err).Msg("Failed to parse package get request")
// nolint:exhaustivestruct,wrapcheck
// nolint:exhaustruct,wrapcheck
return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrParsingPackagesGetRequest}})
}
@ -37,18 +37,18 @@ func packagesGET(ectx echo.Context) error {
return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: errors, Data: pkgs})
}
// nolint:exhaustivestruct,wrapcheck
// nolint:exhaustruct,wrapcheck
return ectx.JSON(http.StatusOK, &structs.Reply{Status: structs.StatusSuccess, Data: pkgs})
}
// This function responsible for deleting package.
func packagesDELETE(ectx echo.Context) error {
// nolint:exhaustivestruct
// nolint:exhaustruct
req := &structs.PackageDeleteRequest{}
if err := ectx.Bind(req); err != nil {
log.Error().Err(err).Msg("Failed to parse package delete request")
// nolint:exhaustivestruct,wrapcheck
// nolint:exhaustruct,wrapcheck
return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrParsingDeleteRequest}})
}
@ -57,17 +57,17 @@ func packagesDELETE(ectx echo.Context) error {
errs := configuration.Cfg.DeletePackage(req)
if len(errs) > 0 {
// nolint:exhaustivestruct,wrapcheck
// nolint:exhaustruct,wrapcheck
return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: errs})
}
// nolint:exhaustivestruct,wrapcheck
// nolint:exhaustruct,wrapcheck
return ectx.JSON(http.StatusOK, &structs.Reply{Status: structs.StatusSuccess})
}
// This function responsible for setting or updating packages.
func packagesSET(ectx echo.Context) error {
// nolint:exhaustivestruct
// nolint:exhaustruct
req := &structs.Package{}
if err := ectx.Bind(req); err != nil {
log.Error().Err(err).Msg("Failed to parse package data")
@ -80,12 +80,12 @@ func packagesSET(ectx echo.Context) error {
// Validate passed package data.
if !strings.HasPrefix(req.OriginalPath, "/") {
// nolint:exhaustivestruct,wrapcheck
// nolint:exhaustruct,wrapcheck
return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrPackageOrigPathShouldStartWithSlash}})
}
configuration.Cfg.AddOrUpdatePackage(req)
// nolint:exhaustivestruct,wrapcheck
// nolint:exhaustruct,wrapcheck
return ectx.JSON(http.StatusOK, &structs.Reply{Status: structs.StatusSuccess})
}

View File

@ -16,11 +16,11 @@ func Initialize() {
log = logger.Logger.With().Str("type", "internal").Str("package", "configuration").Logger()
log.Info().Msg("Initializing...")
// nolint:exhaustivestruct
// nolint:exhaustruct
envCfg = &envConfig{}
envCfg.Initialize()
// nolint:exhaustivestruct
// nolint:exhaustruct
Cfg = &fileConfig{}
Cfg.Initialize()

View File

@ -35,7 +35,7 @@ func checkAllowedIPs() echo.MiddlewareFunc {
if err != nil {
log.Error().Err(err).Str("subnet", ipToParse).Msg("Failed to parse CIDR. /_api/ endpoint won't be accessible, this should be fixed manually in configuration file!")
// nolint:exhaustivestruct,wrapcheck
// nolint:exhaustruct,wrapcheck
return ectx.JSON(http.StatusInternalServerError, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrInvalidAllowedIPDefined}})
}
@ -60,7 +60,7 @@ func checkAllowedIPs() echo.MiddlewareFunc {
return next(ectx)
}
// nolint:exhaustivestruct,wrapcheck
// nolint:exhaustruct,wrapcheck
return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrIPAddressNotAllowed}})
}
}

View File

@ -62,7 +62,7 @@ func Start() {
}()
// Check that HTTP server was started.
// nolint:exhaustivestruct
// nolint:exhaustruct
httpc := &http.Client{Timeout: time.Second * 1}
checks := 0

View File

@ -44,32 +44,32 @@ func Initialize() {
zerolog.SetGlobalLevel(zerolog.InfoLevel)
}
// nolint:exhaustivestruct
// nolint:exhaustruct
output := zerolog.ConsoleWriter{Out: os.Stdout, NoColor: false, TimeFormat: time.RFC3339}
output.FormatLevel = func(lvlRaw interface{}) string {
var v string
var formattedLvl string
if lvl, ok := lvlRaw.(string); ok {
lvl = strings.ToUpper(lvl)
switch lvl {
case "DEBUG":
v = fmt.Sprintf("\x1b[30m%-5s\x1b[0m", lvl)
formattedLvl = fmt.Sprintf("\x1b[30m%-5s\x1b[0m", lvl)
case "ERROR":
v = fmt.Sprintf("\x1b[31m%-5s\x1b[0m", lvl)
formattedLvl = fmt.Sprintf("\x1b[31m%-5s\x1b[0m", lvl)
case "FATAL":
v = fmt.Sprintf("\x1b[35m%-5s\x1b[0m", lvl)
formattedLvl = fmt.Sprintf("\x1b[35m%-5s\x1b[0m", lvl)
case "INFO":
v = fmt.Sprintf("\x1b[32m%-5s\x1b[0m", lvl)
formattedLvl = fmt.Sprintf("\x1b[32m%-5s\x1b[0m", lvl)
case "PANIC":
v = fmt.Sprintf("\x1b[36m%-5s\x1b[0m", lvl)
formattedLvl = fmt.Sprintf("\x1b[36m%-5s\x1b[0m", lvl)
case "WARN":
v = fmt.Sprintf("\x1b[33m%-5s\x1b[0m", lvl)
formattedLvl = fmt.Sprintf("\x1b[33m%-5s\x1b[0m", lvl)
default:
v = lvl
formattedLvl = lvl
}
}
return fmt.Sprintf("| %s |", v)
return fmt.Sprintf("| %s |", formattedLvl)
}
Logger = zerolog.New(output).With().Timestamp().Logger()

View File

@ -30,6 +30,7 @@ func execRequest(method string, url string, data interface{}) ([]byte, error) {
var dataToSend []byte
if data != nil {
// nolint:errchkjson
dataToSend, _ = json.Marshal(data)
}

View File

@ -8,6 +8,7 @@ import (
// nolint:exhaustivestruct
func getHTTPClient() *http.Client {
// nolint:exhaustruct
client := &http.Client{
Transport: &http.Transport{
ExpectContinueTimeout: time.Second * 5,