This commit is contained in:
Kirill 2023-06-22 11:38:29 +03:00
parent ef5bbf28c0
commit ffff284187
4 changed files with 292 additions and 0 deletions

101
.gitlab-ci.yml Normal file

@ -0,0 +1,101 @@
stages:
- lint
- test
- clean
- build
- deploy
lint:
image: golangci/golangci-lint:v1.52-alpine
stage: lint
allow_failure: true
before_script:
- go install github.com/vektra/mockery/v2@v2.26.0
- go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@v1.12.4
script:
- go generate ./...
- golangci-lint version
- golangci-lint run ./internal/...
test:
image: golang:1.20.3-alpine
stage: test
coverage: /\(statements\)(?:\s+)?(\d+(?:\.\d+)?%)/
script:
- CGO_ENABLED=0 go test ./internal/... -coverprofile=coverage.out
- go tool cover -html=coverage.out -o coverage.html
- go tool cover -func coverage.out
artifacts:
expire_in: "3 days"
paths:
- coverage.html
clean-old:
stage: clean
image:
name: docker/compose:1.28.0
entrypoint: [""]
allow_failure: true
variables:
PRODUCTION_BRANCH: main
STAGING_BRANCH: "staging"
DEPLOY_TO: "staging"
rules:
- if: $CI_COMMIT_BRANCH == $PRODUCTION_BRANCH || $CI_COMMIT_BRANCH == $STAGING_BRANCH
when: on_success
before_script:
- echo DEPLOY_TO = $DEPLOY_TO
script:
- docker-compose -f deployments/$DEPLOY_TO/docker-compose.yaml down --volumes --rmi local
build-app:
stage: build
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
variables:
DOCKER_BUILD_PATH: "./Dockerfile"
STAGING_BRANCH: "staging"
PRODUCTION_BRANCH: "main"
rules:
- if: $CI_COMMIT_BRANCH == $PRODUCTION_BRANCH || $CI_COMMIT_BRANCH == $STAGING_BRANCH
when: on_success
before_script:
- echo PRODUCTION_BRANCH = $PRODUCTION_BRANCH
- echo STAGING_BRANCH = $STAGING_BRANCH
- echo CI_REGISTRY = $CI_REGISTRY
- echo CI_REGISTRY_USER = $CI_REGISTRY_USER
- echo CI_PROJECT_DIR = $CI_PROJECT_DIR
- echo CI_REGISTRY_IMAGE = $CI_REGISTRY_IMAGE
- echo CI_COMMIT_REF_SLUG = $CI_COMMIT_REF_SLUG
- echo DOCKER_BUILD_PATH = $DOCKER_BUILD_PATH
- echo CI_PIPELINE_ID = $CI_PIPELINE_ID
script:
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- |
/kaniko/executor --context $CI_PROJECT_DIR \
--cache=true --cache-repo=$CI_REGISTRY_IMAGE \
--dockerfile $CI_PROJECT_DIR/$DOCKER_BUILD_PATH --target production \
--destination $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID
deploy-to-staging:
stage: deploy
image:
name: docker/compose:1.28.0
entrypoint: [""]
variables:
DEPLOY_TO: "staging"
BRANCH: "staging"
rules:
- if: $CI_COMMIT_BRANCH == $BRANCH
before_script:
- echo CI_PROJECT_NAME = $CI_PROJECT_NAME
- echo CI_REGISTRY = $CI_REGISTRY
- echo REGISTRY_USER = $REGISTRY_USER
- echo REGISTRY_TOKEN = $REGISTRY_TOKEN
- echo DEPLOY_TO = $DEPLOY_TO
- echo BRANCH = $BRANCH
script:
- docker login -u $REGISTRY_USER -p $REGISTRY_TOKEN $CI_REGISTRY
- docker-compose -f deployments/$DEPLOY_TO/docker-compose.yaml up -d

164
.golangci.yaml Normal file

@ -0,0 +1,164 @@
run:
timeout: 5m
skip-files:
- \.pb\.go$
- \.pb\.validate\.go$
- \.pb\.gw\.go$
- \.gen\.go$
skip-dirs:
- mocks
- proto
linters:
disable-all: true
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- containedctx
- depguard
- dogsled
- dupword
- durationcheck
- errcheck
- errchkjson
- exportloopref
- goconst
- gocritic
- godot
- gofmt
- gci
- goprintffuncname
- gosec
- gosimple
- govet
- importas
- ineffassign
- misspell
- nakedret
- nilerr
- noctx
- nolintlint
- nosprintfhostport
- prealloc
- predeclared
- revive
- rowserrcheck
- staticcheck
- stylecheck
- thelper
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- whitespace
linters-settings:
errcheck:
exclude-functions:
- (io.Closer).Close
govet:
check-shadowing: true
gci:
custom-order: false
section-separators:
- newLine
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- blank # Blank section: contains all blank imports. This section is not present unless explicitly enabled.
- dot # Dot section: contains all dot imports. This section is not present unless explicitly enabled.
importas:
no-unaliased: true
alias:
# Foundation libraries
- pkg: git.sbercloud.tech/products/paas/shared/foundation/management-server
alias: mgmtserver
maligned:
suggest-new: true
goconst:
min-len: 2
min-occurrences: 2
lll:
line-length: 140
revive:
rules:
# The following rules are recommended https://github.com/mgechev/revive#recommended-configuration
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
# - name: exported
- name: if-return
- name: increment-decrement
- name: var-naming
- name: var-declaration
# - name: package-comments
- name: range
- name: receiver-naming
- name: time-naming
- name: unexported-return
- name: indent-error-flow
- name: errorf
- name: empty-block
- name: superfluous-else
- name: unused-parameter
- name: unreachable-code
- name: redefines-builtin-id
#
# Rules in addition to the recommended configuration above.
#
- name: bool-literal-in-expr
- name: constant-logical-expr
gosec:
excludes:
- G307 # Deferring unsafe method "Close" on type "\*os.File"
- G108 # Profiling endpoint is automatically exposed on /debug/pprof
gocritic:
enabled-tags:
- diagnostic
- experimental
- performance
disabled-checks:
- appendAssign
- dupImport # https://github.com/go-critic/go-critic/issues/845
- evalOrder
- ifElseChain
- octalLiteral
- regexpSimplify
- sloppyReassign
- truncateCmp
- typeDefFirst
- unnamedResult
- unnecessaryDefer
- whyNoLint
- wrapperFunc
- rangeValCopy
- hugeParam
issues:
exclude-rules:
- text: "at least one file in a package should have a package comment"
linters:
- stylecheck
- text: "should have a package comment, unless it's in another file for this package"
linters:
- golint
- text: "should have comment or be unexported"
linters:
- golint
- path: _test\.go
linters:
- gosec
- dupl
exclude-use-default: false
output:
# colored-line-number|line-number|json|tab|checkstyle, default is "colored-line-number"
format: colored-line-number
print-linter-name: true

6
.mockery.yaml Normal file

@ -0,0 +1,6 @@
exported: True
inpackage: False
keeptree: True
case: underscore
with-expecter: True
inpackage-suffix: True

21
README.md Normal file

@ -0,0 +1,21 @@
# cbrfworker
Сервис CBRF
| Branch | Pipeline | Code coverage |
| ------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| master | [![pipeline status](https://penahub.gitlab.yandexcloud.net/external/cbrfworker/badges/master/pipeline.svg)](https://penahub.gitlab.yandexcloud.net/external/cbrfworker/-/pipelines) | [![coverage report](https://penahub.gitlab.yandexcloud.net/external/cbrfworker/badges/master/coverage.svg?job=test)](https://penahub.gitlab.yandexcloud.net/external/cbrfworker/-/pipelines) |
| staging | [![pipeline status](https://penahub.gitlab.yandexcloud.net/external/cbrfworker/badges/staging/pipeline.svg)](https://penahub.gitlab.yandexcloud.net/external/cbrfworker/-/pipelines) | [![coverage report](https://penahub.gitlab.yandexcloud.net/external/cbrfworker/badges/staging/coverage.svg?job=test)](https://penahub.gitlab.yandexcloud.net/external/cbrfworker/-/pipelines) |
| dev | [![pipeline status](https://penahub.gitlab.yandexcloud.net/external/cbrfworker/badges/dev/pipeline.svg)](https://penahub.gitlab.yandexcloud.net/external/cbrfworker/-/pipelines) | [![coverage report](https://penahub.gitlab.yandexcloud.net/external/cbrfworker/badges/dev/coverage.svg?job=test)](https://penahub.gitlab.yandexcloud.net/external/cbrfworker/-/pipelines) |
## Переменные окружения приложения
```
IS_PRODUCTION - флаг, который помечает статус приложения: в production или нет (boolean)
DEVELOPMENT - флаг, который помечает статус приложени: в разработке или нет (boolean)
APP_NAME - название приложения (string)
APP_ADDR - адрес на котором будет запущено приложение (string)
DATABASE_URI - полная ссылка к базе данных (string)
DATABASE_TABLE - название таблицы (string)
COLLECTION_NAME - название коллекции (string)
```