Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ad505b8f3c | ||
|
|
9600f7ef1e | ||
|
|
0db03de171 |
No files matched your search
@@ -0,0 +1,23 @@
|
||||
docker-build:
|
||||
image: docker:latest
|
||||
stage: build
|
||||
services:
|
||||
- docker: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 "$CI_DOCKER_FILE" --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
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
### v3.1.3
|
||||
* Замена в конфигурации одного массива скриптов на кастомные и остальные
|
||||
* Добавлена новая ошибка с дупликатами id
|
||||
### v3.1.1
|
||||
* Обновлены зависимости
|
||||
* Замена `integration-system` на `txix-open`
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
FROM dockerhub.mos.ru/mosos/arbat:15.5 as builder
|
||||
RUN zypper --no-gpg-checks update -y && zypper --no-gpg-checks install -y go1.23 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 .
|
||||
|
||||
FROM dockerhub.mos.ru/mosos/arbat:15.5
|
||||
|
||||
RUN cp /usr/share/zoneinfo/Europe/Moscow /etc/localtime
|
||||
RUN echo "Europe/Moscow" > /etc/timezone
|
||||
|
||||
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
|
||||
@@ -48,7 +48,10 @@ func (a *Assembly) ReceiveConfig(ctx context.Context, remoteConfig []byte) error
|
||||
a.logger.SetLevel(newCfg.LogLevel)
|
||||
|
||||
locator := NewLocator(a.logger, a.router)
|
||||
handler := locator.Handler(newCfg)
|
||||
handler, err := locator.Handler(newCfg)
|
||||
if err != nil {
|
||||
a.logger.Fatal(ctx, errors.WithMessage(err, "new handler"))
|
||||
}
|
||||
|
||||
a.server.Upgrade(handler)
|
||||
|
||||
|
||||
+35
-3
@@ -2,12 +2,14 @@
|
||||
package assembly
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/grpc"
|
||||
"github.com/txix-open/isp-kit/grpc/client"
|
||||
"github.com/txix-open/isp-kit/grpc/endpoint"
|
||||
"github.com/txix-open/isp-kit/log"
|
||||
"isp-script-service/conf"
|
||||
"isp-script-service/controller"
|
||||
"isp-script-service/domain"
|
||||
"isp-script-service/repository"
|
||||
"isp-script-service/routes"
|
||||
"isp-script-service/service"
|
||||
@@ -25,9 +27,14 @@ func NewLocator(logger log.Logger, grpcCli *client.Client) Locator {
|
||||
}
|
||||
}
|
||||
|
||||
func (l Locator) Handler(cfg conf.Remote) *grpc.Mux {
|
||||
func (l Locator) Handler(cfg conf.Remote) (*grpc.Mux, error) {
|
||||
scripts, err := MergeScripts(cfg.Scripts, cfg.CustomScripts)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "merge scripts")
|
||||
}
|
||||
|
||||
router := repository.NewRouter(l.grpcCli)
|
||||
scriptService := service.NewScript(router, l.logger, cfg.Scripts, cfg.SharedScript, cfg.ScriptExecutionTimeoutMs)
|
||||
scriptService := service.NewScript(router, l.logger, scripts, cfg.SharedScript, cfg.ScriptExecutionTimeoutMs)
|
||||
scriptController := controller.NewScript(scriptService)
|
||||
|
||||
c := routes.Controllers{
|
||||
@@ -35,5 +42,30 @@ func (l Locator) Handler(cfg conf.Remote) *grpc.Mux {
|
||||
}
|
||||
mapper := endpoint.DefaultWrapper(l.logger, endpoint.BodyLogger(l.logger))
|
||||
handler := routes.Handler(mapper, c)
|
||||
return handler
|
||||
return handler, nil
|
||||
}
|
||||
|
||||
func MergeScripts(scripts []conf.ScriptDefinition, customScripts []conf.ScriptDefinition) ([]conf.ScriptDefinition, error) {
|
||||
uniqueScripts := make(map[string]conf.ScriptDefinition)
|
||||
|
||||
for _, script := range scripts {
|
||||
if _, exists := uniqueScripts[script.Id]; exists {
|
||||
return nil, domain.ErrDuplicateScriptId
|
||||
}
|
||||
uniqueScripts[script.Id] = script
|
||||
}
|
||||
|
||||
for _, customScript := range customScripts {
|
||||
if _, exists := uniqueScripts[customScript.Id]; exists {
|
||||
return nil, domain.ErrDuplicateScriptId
|
||||
}
|
||||
uniqueScripts[customScript.Id] = customScript
|
||||
}
|
||||
|
||||
mergedScripts := make([]conf.ScriptDefinition, 0, len(uniqueScripts))
|
||||
for _, script := range uniqueScripts {
|
||||
mergedScripts = append(mergedScripts, script)
|
||||
}
|
||||
|
||||
return mergedScripts, nil
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"logLevel": "debug",
|
||||
"scripts": [
|
||||
],
|
||||
"scripts": [],
|
||||
"customScripts": [],
|
||||
"sharedScript": "",
|
||||
"scriptExecutionTimeoutMs": 1000
|
||||
}
|
||||
+5
-4
@@ -17,10 +17,11 @@ func init() {
|
||||
}
|
||||
|
||||
type Remote struct {
|
||||
LogLevel log.Level `schemaGen:"logLevel" schema:"Уровень логирования"`
|
||||
Scripts []ScriptDefinition
|
||||
SharedScript string
|
||||
ScriptExecutionTimeoutMs int `validate:"required"`
|
||||
LogLevel log.Level `schemaGen:"logLevel" schema:"Уровень логирования"`
|
||||
Scripts []ScriptDefinition `schema:"Скрипты"`
|
||||
CustomScripts []ScriptDefinition `schema:"Кастомные скрипты"`
|
||||
SharedScript string `schema:"Общий скрипт"`
|
||||
ScriptExecutionTimeoutMs int `validate:"required" schema:"Время выполнения скрипта"`
|
||||
}
|
||||
|
||||
type ScriptDefinition struct {
|
||||
|
||||
+4
-1
@@ -4,4 +4,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var ErrScriptNotFound = errors.New("script not found")
|
||||
var (
|
||||
ErrScriptNotFound = errors.New("script not found")
|
||||
ErrDuplicateScriptId = errors.New("duplicate script id")
|
||||
)
|
||||
@@ -45,10 +45,11 @@ func (s *ApiScript) SetupSuite() {
|
||||
Script: "return false",
|
||||
},
|
||||
},
|
||||
CustomScripts: []conf.ScriptDefinition{},
|
||||
}
|
||||
|
||||
locator := assembly.NewLocator(s.test.Logger(), cli)
|
||||
handler := locator.Handler(cfg)
|
||||
handler, _ := locator.Handler(cfg)
|
||||
|
||||
_, s.apiCli = grpct.TestServer(s.test, handler)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
package tests_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/txix-open/isp-kit/grpc/client"
|
||||
"github.com/txix-open/isp-kit/test"
|
||||
"github.com/txix-open/isp-kit/test/grpct"
|
||||
"isp-script-service/assembly"
|
||||
"isp-script-service/conf"
|
||||
)
|
||||
|
||||
func TestMergeScriptTestSuite(t *testing.T) {
|
||||
t.Parallel()
|
||||
suite.Run(t, &MergeScript{})
|
||||
}
|
||||
|
||||
type MergeScript struct {
|
||||
suite.Suite
|
||||
test *test.Test
|
||||
require *require.Assertions
|
||||
}
|
||||
|
||||
func (s *MergeScript) TestMergeScriptsDuplicateId() {
|
||||
s.test, s.require = test.New(s.T())
|
||||
|
||||
cli := s.initMockServer()
|
||||
|
||||
cfg := conf.Remote{
|
||||
ScriptExecutionTimeoutMs: 10000,
|
||||
Scripts: []conf.ScriptDefinition{
|
||||
{
|
||||
Id: "1",
|
||||
Script: "return true",
|
||||
},
|
||||
},
|
||||
CustomScripts: []conf.ScriptDefinition{
|
||||
{
|
||||
Id: "1",
|
||||
Script: "return false",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
locator := assembly.NewLocator(s.test.Logger(), cli)
|
||||
_, err := locator.Handler(cfg)
|
||||
|
||||
s.Require().Error(err)
|
||||
}
|
||||
|
||||
func (s *MergeScript) TestMergeScriptsHappyPath() {
|
||||
s.test, s.require = test.New(s.T())
|
||||
|
||||
cli := s.initMockServer()
|
||||
|
||||
cfg := conf.Remote{
|
||||
ScriptExecutionTimeoutMs: 10000,
|
||||
Scripts: []conf.ScriptDefinition{
|
||||
{
|
||||
Id: "1",
|
||||
Script: "return true",
|
||||
},
|
||||
{
|
||||
Id: "2",
|
||||
Script: "return true",
|
||||
},
|
||||
},
|
||||
CustomScripts: []conf.ScriptDefinition{
|
||||
{
|
||||
Id: "3",
|
||||
Script: "return false",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
locator := assembly.NewLocator(s.test.Logger(), cli)
|
||||
_, err := locator.Handler(cfg)
|
||||
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
func (s *MergeScript) initMockServer() *client.Client {
|
||||
server, cli := grpct.NewMock(s.test)
|
||||
server.Mock("mock", func(req bool) bool {
|
||||
return req
|
||||
})
|
||||
|
||||
return cli
|
||||
}
|
||||
Reference in new issue
Block a user