diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..1a83a18 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +store +builds + +.env +.env.example + +Makefile +README.md + +docker-*.yml +Dockerfile +.dockerignore \ No newline at end of file diff --git a/.gitignore b/.gitignore index b463ea6..52bf3a0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ builds store -.env \ No newline at end of file +.env + +*.tar \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml index fe617bb..e508c20 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,133 +1,100 @@ -linters-settings: - # depguard: // Specific for golangci repository - # list-type: blacklist - # packages: - # # logging is allowed only by logutils.Log, logrus - # # is allowed to use only in logutils package - # - github.com/sirupsen/logrus - # packages-with-error-message: - # - github.com/sirupsen/logrus: 'logging is allowed only by logutils.Log' - dupl: - threshold: 100 - funlen: - lines: 100 - statements: 50 - gci: - sections: - prefix(fetchsysd) - goconst: - min-len: 2 - min-occurrences: 2 - gocritic: - enabled-tags: - - diagnostic - - experimental - - opinionated - - performance - - style - disabled-checks: - - dupImport # https://github.com/go-critic/go-critic/issues/845 - - ifElseChain - - octalLiteral - # - whyNoLint - - wrapperFunc - gocyclo: - min-complexity: 15 - goimports: - local-prefixes: localenv - mnd: - # don't include the "operation" and "assign" - checks: - - argument - - case - - condition - - return - govet: - shadow: true - # settings: // Specific for golangci repository - # printf: - # funcs: - # - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof - # - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf - # - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf - # - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf - lll: - line-length: 200 - maligned: - suggest-new: true - misspell: - locale: US - nolintlint: - allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space) - allow-unused: false # report any unused nolint directives - require-explanation: false # don't require an explanation for nolint directives - require-specific: false # don't require nolint directives to be specific about which linter is being skipped - errcheck: - check-blank: true - exclude-functions: - - '(*github.com/gin-gonic/gin.Error).SetType' - - '(*github.com/gin-gonic/gin.Context).Error' - +version: "2" linters: - disable-all: true + default: none enable: - bodyclose - # - deadcode # deprecated (since v1.49.0) - # - depguard + - copyloopvar - dogsled - dupl - errcheck - - copyloopvar - exhaustive - funlen - gochecknoinits - goconst - gocritic - gocyclo - - gofmt - - goimports - - mnd - goprintffuncname - gosec - - gosimple - govet - ineffassign - lll - misspell + - mnd - nakedret - noctx - nolintlint - # - rowserrcheck # https://github.com/golangci/golangci-lint/issues/2649 - staticcheck - # - structcheck # https://github.com/golangci/golangci-lint/issues/2649 - - stylecheck - - typecheck - unconvert - unparam - unused - # - varcheck # deprecated (since v1.49.0) - whitespace - # - gochecknoglobals # too many global in ds9 - - # don't enable: - # - asciicheck - # - scopelint - # - gocognit - # - godot - # - godox - # - goerr113 - # - interfacer - # - maligned - # - nestif - # - prealloc - # - testpackage - # - revive - # - wsl - -# issues: -# Excluding configuration per-path, per-linter, per-text and per-source -# fix: true - -run: - timeout: 5m - skip-dirs: [] + settings: + dupl: + threshold: 100 + errcheck: + check-blank: true + exclude-functions: + - (*github.com/gin-gonic/gin.Error).SetType + - (*github.com/gin-gonic/gin.Context).Error + funlen: + lines: 100 + statements: 50 + goconst: + min-len: 2 + min-occurrences: 2 + gocritic: + disabled-checks: + - dupImport + - ifElseChain + - octalLiteral + - wrapperFunc + enabled-tags: + - diagnostic + - experimental + - opinionated + - performance + - style + gocyclo: + min-complexity: 15 + lll: + line-length: 200 + misspell: + locale: US + mnd: + checks: + - argument + - case + - condition + - return + nolintlint: + require-explanation: false + require-specific: false + allow-unused: false + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gofmt + - goimports + settings: + gci: + sections: + - prefix(fetchsysd) + goimports: + local-prefixes: + - localenv + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2a71218 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ + +FROM golang:1.22 AS builder + +WORKDIR /app + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +RUN GOOS=linux go build -o librapi main.go + + +FROM debian:bookworm-slim + +WORKDIR /app + +COPY --from=builder /app/librapi . +RUN chmod +x /app/librapi +RUN mkdir -p /app/store + +CMD ["./librapi"] \ No newline at end of file diff --git a/Makefile b/Makefile index 0f018a9..9b6d91d 100644 --- a/Makefile +++ b/Makefile @@ -8,5 +8,5 @@ build: lint lint: golangci-lint run --fix -run: lint - go run main.go \ No newline at end of file +run: lint build + docker compose up \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..123efc9 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,16 @@ +services: + librapi: + image: librapi:local + container_name: librapi + env_file: + - .env + ports: + - "8080:8080" + networks: + - librapi_network + volumes: + - ./store:/app/store:rw + +networks: + librapi_network: + driver: bridge