Two ruby services: web-backend git_mirror
Signed-off-by: Wu Zhende wuzhende666@163.com --- container/git-mirror/start | 12 +++++++++++- container/web-backend/start | 4 ++++ lib/constants.rb | 22 ++++++++++++++++++++++ lib/git_mirror.rb | 2 +- src/lib/web_backend.rb | 2 +- 5 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/container/git-mirror/start b/container/git-mirror/start index f01789c..9c9e3e2 100755 --- a/container/git-mirror/start +++ b/container/git-mirror/start @@ -3,8 +3,17 @@ # Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. # frozen_string_literal: true
+require 'set' require_relative '../defconfig.rb'
+names = Set.new %w[ + ES_USER + ES_PASSWORD +] + +service_authentication = relevant_service_authentication(names) +env = docker_env(service_authentication) + DOCKER_CCI = '/c/compass-ci' DOCKER_REPO = '/c/git-repos' docker_rm "git-mirror" @@ -12,10 +21,11 @@ docker_rm "git-mirror" lkp = %x(id -u lkp) group_id = %x(cat /etc/group | grep '^committer' | awk -F ':' '{print $3}')
-cmd = %W[ +cmd = %w[ docker run --restart=always --name git-mirror +] + env + %W[ -u #{lkp.to_i}:#{group_id.to_i} -d -e CCI_SRC=#{DOCKER_CCI} diff --git a/container/web-backend/start b/container/web-backend/start index cebf949..250c524 100755 --- a/container/web-backend/start +++ b/container/web-backend/start @@ -13,6 +13,8 @@ load_cci_defaults [[ $SRV_HTTP_RESULT_HOST ]] || SRV_HTTP_RESULT_HOST=$(curl ip.sb) [[ $SRV_HTTP_RESULT_PORT ]] || SRV_HTTP_RESULT_PORT=20007
+load_service_authentication + cmd=( docker run --name web-backend @@ -26,6 +28,8 @@ cmd=( -e CCI_SRC=/c/compass-ci -e LKP_SRC=/c/lkp-tests -e UPSTREAM_REPOS_PATH=/c/upstream-repos + -e ES_USER=$ES_USER + -e ES_PASSWORD=$ES_PASSWORD
-v $CCI_SRC:/c/compass-ci -v $LKP_SRC:/c/lkp-tests diff --git a/lib/constants.rb b/lib/constants.rb index 11927f9..c71c3de 100644 --- a/lib/constants.rb +++ b/lib/constants.rb @@ -5,9 +5,31 @@ require_relative '../container/defconfig.rb'
config = cci_defaults + +names = Set.new %w[ + ES_USER + ES_PASSWORD +] + ES_HOST ||= config['ES_HOST'] || '172.17.0.1' ES_PORT ||= config['ES_PORT'] || 9200
+if ENV['ES_USER'] + ES_USER = ENV['ES_USER'] + ES_PASSWORD = ENV['ES_PASSWORD'] +else + service_authentication = relevant_service_authentication(names) + ES_USER = service_authentication['ES_USER'] + ES_PASSWORD = service_authentication['ES_PASSWORD'] +end + +ES_HOSTS = [{ + host: ES_HOST, + port: ES_PORT, + user: ES_USER, + password: ES_PASSWORD +}] + SEND_MAIL_HOST ||= config['SEND_MAIL_HOST'] || '172.17.0.1' SEND_MAIL_PORT ||= config['SEND_MAIL_PORT'] || 10001
diff --git a/lib/git_mirror.rb b/lib/git_mirror.rb index 6100d6b..71d6956 100644 --- a/lib/git_mirror.rb +++ b/lib/git_mirror.rb @@ -125,7 +125,7 @@ class MirrorMain @defaults = {} @git_queue = Queue.new @log = JSONLogger.new - @es_client = Elasticsearch::Client.new(url: "http://#%7BES_HOST%7D:#%7BES_PORT%7D") + @es_client = Elasticsearch::Client.new(hosts: ES_HOSTS) clone_upstream_repo load_fork_info connection_init diff --git a/src/lib/web_backend.rb b/src/lib/web_backend.rb index 932d362..c4d4edd 100644 --- a/src/lib/web_backend.rb +++ b/src/lib/web_backend.rb @@ -34,7 +34,7 @@ NOT_SHOW_FIELDS = %w[result_root].freeze ALL_FIELDS = FIELDS + NOT_SHOW_FIELDS NOT_NEED_EXIST_FIELDS = %w[error_ids upstream_repo].freeze PREFIX_SEARCH_FIELDS = ['tbox_group'].freeze -ES_CLIENT = Elasticsearch::Client.new(url: "http://#%7BES_HOST%7D:#%7BES_PORT%7D") +ES_CLIENT = Elasticsearch::Client.new(hosts: ES_HOSTS) COMPARE_RECORDS_NUMBER = 100
def es_query(query)