Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bd3a52e7f3 | ||
|
|
bb02ef25ab | ||
|
|
bd633d1599 |
No files matched your search
+23
-3
@@ -1,3 +1,23 @@
|
|||||||
include:
|
docker-build:
|
||||||
- project: '$CI_PROJECT_PATH'
|
image: docker:20.10.16
|
||||||
file: '/ci-isp-go-service.yml'
|
stage: build
|
||||||
|
services:
|
||||||
|
- docker:20.10.16-dind
|
||||||
|
before_script:
|
||||||
|
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
|
||||||
|
- export VERSION=`cat .version `
|
||||||
|
- echo $VERSION
|
||||||
|
- echo $CI_DOCKER_FILE
|
||||||
|
- echo $CI_REGISTRY
|
||||||
|
script:
|
||||||
|
- set
|
||||||
|
- mkdir -p migrations
|
||||||
|
- docker build -f Dockerfile.dit --force-rm --build-arg="version=$VERSION" --build-arg="app_name=$CI_PROJECT_NAME" --pull -t "$CI_REGISTRY/$CI_PROJECT_NAME:$VERSION" .
|
||||||
|
- |
|
||||||
|
docker tag "$CI_REGISTRY/$CI_PROJECT_NAME:$VERSION" "$CI_REGISTRY/$CI_PROJECT_NAME:latest"
|
||||||
|
docker push "$CI_REGISTRY/$CI_PROJECT_NAME:$VERSION"
|
||||||
|
docker push "$CI_REGISTRY/$CI_PROJECT_NAME:latest"
|
||||||
|
docker rmi -f "$CI_REGISTRY/$CI_PROJECT_NAME:$VERSION"
|
||||||
|
docker rmi -f "$CI_REGISTRY/$CI_PROJECT_NAME:latest"
|
||||||
|
- docker logout $CI_REGISTRY
|
||||||
|
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
FROM dockerhub.mos.ru/mosos/arbat:15.5 as builder
|
||||||
|
RUN zypper --no-gpg-checks update -y && zypper --no-gpg-checks install -y go1.25 git
|
||||||
|
WORKDIR /build
|
||||||
|
ARG version
|
||||||
|
ENV version_env=$version
|
||||||
|
ARG app_name
|
||||||
|
ENV app_name_env=$app_name
|
||||||
|
COPY . .
|
||||||
|
ENV GOPROXY=https://repo-mirror.mos.ru/repository/go-public
|
||||||
|
RUN go build -ldflags="-X 'main.version=$version_env'" -o /main .
|
||||||
|
WORKDIR cmd/migrate
|
||||||
|
RUN CGO_ENABLED=1 go build -o /migrate .
|
||||||
|
|
||||||
|
FROM dockerhub.mos.ru/mosos/arbat:15.5
|
||||||
|
|
||||||
|
RUN cp /usr/share/zoneinfo/Europe/Moscow /etc/localtime
|
||||||
|
RUN echo "Europe/Moscow" > /etc/timezone
|
||||||
|
|
||||||
|
COPY --from=builder migrate /migrate/migrate
|
||||||
|
COPY cmd/migrate/config.yml /migrate/config.yml
|
||||||
|
RUN chmod 666 /migrate/config.yml
|
||||||
|
|
||||||
|
ARG UID=10001
|
||||||
|
RUN useradd \
|
||||||
|
--home "/nonexistent" \
|
||||||
|
--shell "/sbin/nologin" \
|
||||||
|
--no-create-home \
|
||||||
|
--uid "${UID}" \
|
||||||
|
--user-group \
|
||||||
|
appuser
|
||||||
|
|
||||||
|
RUN mkdir -p /app/data
|
||||||
|
RUN chown appuser:appuser /app/data
|
||||||
|
VOLUME /app/data
|
||||||
|
|
||||||
|
USER appuser
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
ARG app_name
|
||||||
|
ENV app_name_env=$app_name
|
||||||
|
COPY --from=builder main /app/$app_name_env
|
||||||
|
COPY /conf/config.yml /app/config.yml
|
||||||
|
COPY /conf/default_remote_config.json* /app/default_remote_config.json
|
||||||
|
COPY /migrations /app/migrations
|
||||||
|
ENTRYPOINT /app/$app_name_env
|
||||||
|
|
||||||
|
COPY /conf/config.yml /app/config.yml
|
||||||
|
COPY /conf/default_remote_config.json* /app/default_remote_config.json
|
||||||
|
COPY /migrations /app/migrations
|
||||||
|
|
||||||
|
ENTRYPOINT /app/$app_name_env
|
||||||
+1
-1
@@ -156,7 +156,7 @@ func (l Locator) Config() *Config {
|
|||||||
)
|
)
|
||||||
configApiController := api.NewConfig(configApiService)
|
configApiController := api.NewConfig(configApiService)
|
||||||
|
|
||||||
configSchemaApiService := apisvs.NewConfigSchema(configSchemaRepo)
|
configSchemaApiService := apisvs.NewConfigSchema(configSchemaRepo, moduleRepo)
|
||||||
configSchemaController := api.NewConfigSchema(configSchemaApiService)
|
configSchemaController := api.NewConfigSchema(configSchemaApiService)
|
||||||
|
|
||||||
controllers := routes.Controllers{
|
controllers := routes.Controllers{
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
### v3.8.0
|
||||||
|
* Добавлен новый endpoint `config/schema/update_by_module_name` для обновления схемы модуля по его названию
|
||||||
## v3.7.0
|
## v3.7.0
|
||||||
* добавлены rqlite-автобэкапы и прокси-эндпоинт `/backup` для создания резервных копий
|
* добавлены rqlite-автобэкапы и прокси-эндпоинт `/backup` для создания резервных копий
|
||||||
* изменен таймаут ожидания лидера с 30 до 180 секунд
|
* изменен таймаут ожидания лидера с 30 до 180 секунд
|
||||||
|
|||||||
@@ -3,14 +3,16 @@ package api
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/txix-open/isp-kit/grpc/apierrors"
|
|
||||||
"isp-config-service/domain"
|
"isp-config-service/domain"
|
||||||
"isp-config-service/entity"
|
"isp-config-service/entity"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/txix-open/isp-kit/grpc/apierrors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ConfigSchemaService interface {
|
type ConfigSchemaService interface {
|
||||||
SchemaByModuleId(ctx context.Context, moduleId string) (*domain.ConfigSchema, error)
|
SchemaByModuleId(ctx context.Context, moduleId string) (*domain.ConfigSchema, error)
|
||||||
|
UpdateSchemaByModuleName(ctx context.Context, request domain.UpdateSchemaRequest) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConfigSchema struct {
|
type ConfigSchema struct {
|
||||||
@@ -49,3 +51,30 @@ func (c ConfigSchema) SchemaByModuleId(ctx context.Context, request domain.GetBy
|
|||||||
return schema, nil
|
return schema, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateSchemaByModuleName
|
||||||
|
// @Summary Метод обновления схемы конфигурации модуля
|
||||||
|
// @Description Меняет схему конфигурации модуля на переданную
|
||||||
|
// @Tags Схема
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param body body domain.UpdateSchemaRequest true "название модуля и схема конфига"
|
||||||
|
// @Success 200 {object} any
|
||||||
|
// @Failure 400 {object} apierrors.Error "`errorCode: 2001` - модуль не найден"
|
||||||
|
// @Failure 500 {object} apierrors.Error
|
||||||
|
// @Router /schema/update_by_module_name [POST]
|
||||||
|
func (c ConfigSchema) UpdateSchemaByModuleName(ctx context.Context, request domain.UpdateSchemaRequest) error {
|
||||||
|
err := c.service.UpdateSchemaByModuleName(ctx, request)
|
||||||
|
switch {
|
||||||
|
case errors.Is(err, entity.ErrModuleNotFound):
|
||||||
|
return apierrors.NewBusinessError(
|
||||||
|
domain.ErrorCodeModuleNotFound,
|
||||||
|
"module not found",
|
||||||
|
err,
|
||||||
|
)
|
||||||
|
case err != nil:
|
||||||
|
return apierrors.NewInternalServiceError(err)
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -235,6 +235,16 @@ definitions:
|
|||||||
- id
|
- id
|
||||||
- newConfigName
|
- newConfigName
|
||||||
type: object
|
type: object
|
||||||
|
domain.UpdateSchemaRequest:
|
||||||
|
properties:
|
||||||
|
moduleName:
|
||||||
|
type: string
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- moduleName
|
||||||
|
- schema
|
||||||
|
type: object
|
||||||
domain.UpdateVariableRequest:
|
domain.UpdateVariableRequest:
|
||||||
properties:
|
properties:
|
||||||
description:
|
description:
|
||||||
@@ -784,6 +794,35 @@ paths:
|
|||||||
summary: Метод получения схемы конфигурации модуля
|
summary: Метод получения схемы конфигурации модуля
|
||||||
tags:
|
tags:
|
||||||
- Схема
|
- Схема
|
||||||
|
/schema/update_by_module_name:
|
||||||
|
post:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Меняет схему конфигурации модуля на переданную
|
||||||
|
parameters:
|
||||||
|
- description: название модуля и схема конфига
|
||||||
|
in: body
|
||||||
|
name: body
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/domain.UpdateSchemaRequest'
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema: {}
|
||||||
|
"400":
|
||||||
|
description: '`errorCode: 2001` - модуль не найден'
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||||
|
summary: Метод обновления схемы конфигурации модуля
|
||||||
|
tags:
|
||||||
|
- Схема
|
||||||
/variable/all:
|
/variable/all:
|
||||||
post:
|
post:
|
||||||
consumes:
|
consumes:
|
||||||
|
|||||||
@@ -21,6 +21,11 @@ type GetByModuleNameRequest struct {
|
|||||||
ModuleName string `validate:"required"`
|
ModuleName string `validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UpdateSchemaRequest struct {
|
||||||
|
ModuleName string `validate:"required"`
|
||||||
|
Schema json.RawMessage `validate:"required" swaggertype:"object"`
|
||||||
|
}
|
||||||
|
|
||||||
type CreateUpdateConfigRequest struct {
|
type CreateUpdateConfigRequest struct {
|
||||||
Id string
|
Id string
|
||||||
Name string `validate:"required"`
|
Name string `validate:"required"`
|
||||||
|
|||||||
@@ -69,6 +69,24 @@ func (r ConfigSchema) GetByModuleId(ctx context.Context, moduleId string) (*enti
|
|||||||
return selectRow[entity.ConfigSchema](ctx, r.db, query, args...)
|
return selectRow[entity.ConfigSchema](ctx, r.db, query, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r ConfigSchema) UpdateByModuleId(ctx context.Context, moduleId string, data []byte) error {
|
||||||
|
ctx = sql_metrics.OperationLabelToContext(ctx, "ConfigSchema.UpdateByModuleId")
|
||||||
|
query, args, err := squirrel.Update(Table("config_schema")).
|
||||||
|
Set("data", data).
|
||||||
|
Set("updated_at", squirrel.Expr("unixepoch()")).
|
||||||
|
Where(squirrel.Eq{"module_id": moduleId}).
|
||||||
|
ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "build query")
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = r.db.Exec(ctx, query, args...)
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessagef(err, "exec: %s", query)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
//nolint:nilnil
|
//nolint:nilnil
|
||||||
func selectRow[T any](ctx context.Context, db db.DB, query string, args ...interface{}) (*T, error) {
|
func selectRow[T any](ctx context.Context, db db.DB, query string, args ...interface{}) (*T, error) {
|
||||||
var result T
|
var result T
|
||||||
|
|||||||
@@ -133,6 +133,10 @@ func endpointDescriptors(c Controllers) []cluster.EndpointDescriptor {
|
|||||||
Path: "config/schema/get_by_module_id",
|
Path: "config/schema/get_by_module_id",
|
||||||
Inner: true,
|
Inner: true,
|
||||||
Handler: c.ConfigSchemaApi.SchemaByModuleId,
|
Handler: c.ConfigSchemaApi.SchemaByModuleId,
|
||||||
|
}, {
|
||||||
|
Path: "config/schema/update_by_module_name",
|
||||||
|
Inner: true,
|
||||||
|
Handler: c.ConfigSchemaApi.UpdateSchemaByModuleName,
|
||||||
},
|
},
|
||||||
// variables
|
// variables
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,18 +4,21 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"isp-config-service/domain"
|
"isp-config-service/domain"
|
||||||
"isp-config-service/entity"
|
"isp-config-service/entity"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ConfigSchema struct {
|
type ConfigSchema struct {
|
||||||
schemaRepo SchemaRepo
|
schemaRepo SchemaRepo
|
||||||
|
moduleRepo ModuleRepo
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfigSchema(schemaRepo SchemaRepo) ConfigSchema {
|
func NewConfigSchema(schemaRepo SchemaRepo, moduleRepo ModuleRepo) ConfigSchema {
|
||||||
return ConfigSchema{
|
return ConfigSchema{
|
||||||
schemaRepo: schemaRepo,
|
schemaRepo: schemaRepo,
|
||||||
|
moduleRepo: moduleRepo,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,3 +42,20 @@ func (s ConfigSchema) SchemaByModuleId(ctx context.Context, moduleId string) (*d
|
|||||||
|
|
||||||
return &result, nil
|
return &result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s ConfigSchema) UpdateSchemaByModuleName(ctx context.Context, request domain.UpdateSchemaRequest) error {
|
||||||
|
modules, err := s.moduleRepo.GetByNames(ctx, []string{request.ModuleName})
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "get modules by name")
|
||||||
|
}
|
||||||
|
if len(modules) == 0 {
|
||||||
|
return entity.ErrModuleNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
err = s.schemaRepo.UpdateByModuleId(ctx, modules[0].Id, request.Schema)
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "update schema by module id")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -27,6 +27,7 @@ type BackendsRepo interface {
|
|||||||
type SchemaRepo interface {
|
type SchemaRepo interface {
|
||||||
All(ctx context.Context) ([]entity.ConfigSchema, error)
|
All(ctx context.Context) ([]entity.ConfigSchema, error)
|
||||||
GetByModuleId(ctx context.Context, moduleId string) (*entity.ConfigSchema, error)
|
GetByModuleId(ctx context.Context, moduleId string) (*entity.ConfigSchema, error)
|
||||||
|
UpdateByModuleId(ctx context.Context, moduleId string, data []byte) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type Module struct {
|
type Module struct {
|
||||||
|
|||||||
Reference in new issue
Block a user