add setup default variables update heredoc
Signed-off-by: Luan Shengde luanshengde2@huawei.com --- container/send-mail/start | 89 +++++++++++++++++++++++++++------------ 1 file changed, 62 insertions(+), 27 deletions(-)
diff --git a/container/send-mail/start b/container/send-mail/start index 80be86a..068fc1e 100755 --- a/container/send-mail/start +++ b/container/send-mail/start @@ -1,29 +1,68 @@ -#!/bin/bash +#!/usr/bin/env ruby # SPDX-License-Identifier: MulanPSL-2.0+ # Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true
-. $CCI_SRC/container/defconfig.sh +require 'set' +require_relative '../defconfig'
-docker_rm send-mail +docker_rm 'send-mail'
-cmd=( - docker run - --restart=always - --name=send-mail - -u nobody - -d - -p 11311:11311 - -v /etc/localtime:/etc/localtime:ro - send-mail -) +names = Set.new %w[ + EMAIL_PSWD + SEND_MAIL_PORT + SMTP_SERVER_ADDR + SMTP_SERVER_PORT + EMAIL_DOMAIN + EMAIL_ADDR + DEFAULT_EMAIL +]
-"${cmd[@]}" +defaults = relevant_defaults(names)
-cat<<EOF +EMAIL_PSWD = defaults['EMAIL_PSWD'] +SEND_MAIL_PORT = defaults['SEND_MAIL_PORT'] +SMTP_SERVER_ADDR = defaults['SMTP_SERVER_ADDR'] +SMTP_SERVER_PORT = defaults['SMTP_SERVER_PORT'] +EMAIL_DOMAIN = defaults['EMAIL_DOMAIN'] +EMAIL_ADDR = defaults['EMAIL_ADDR'] +DEFAULT_EMAIL = defaults['DEFAULT_EMAIL'] + +cmd = %W[ + docker run + --restart=always + --name=send-mail + -u nobody + -d + -e EMAIL_PSWD=#{EMAIL_PSWD} + -e SEND_MAIL_PORT=#{SEND_MAIL_PORT} + -e SMTP_SERVER_ADDR=#{SMTP_SERVER_ADDR} + -e SMTP_SERVER_PORT=#{SMTP_SERVER_PORT} + -e EMAIL_DOMAIN=#{EMAIL_DOMAIN} + -e EMAIL_ADDR=#{EMAIL_ADDR} + -e DEFAULT_EMAIL=#{DEFAULT_EMAIL} + -p #{SEND_MAIL_PORT}:#{SEND_MAIL_PORT} + -v /etc/localtime:/etc/localtime:ro + --log-driver json-file + send-mail +] + +cmd += ['bash', '-c', '/usr/local/bin/mail-post.rb'] + +system(*cmd) + +puts <<HEREDOC port: 11311 + +default from email: + when sending crystal.ci email. + team@crystal.ci if no from email appiontted + when sending to WAN email + compass-ci@qq.com in all cases + --- data='{ -"from": "email_from_addr" # default: team@crystal.ci +"from": "email_from_addr" "subject": "email subject", "to": "email_to_addr", "body": "email message" @@ -32,19 +71,17 @@ data='{ or
data=" -from: email_from_addr # default: team@crystal.ci +from: email_from_addr subject: email subject to: email_to_addr body: email message"
-when compass-ci: - curl -XPOST 'localhost:11311/send_mail_yaml' -d "$data" -when other server: - curl -XPOST '124.90.34.227:11311/send_mail_yaml' -d "$data" +Usage: + curl -XPOST '$send_mail_server:$send_mail_port/send_mail_yaml' -d "$data"
--- data=" -From: email_from_addr # default: team@crystal.ci +From: email_from_addr To: email_to_addr Subject: email_subject
@@ -53,8 +90,6 @@ mail_msg_line2 ... "
-when compass-ci: - curl -XPOST 'localhost:11311/send_mail_text' -d "$data" -when other server: - curl -XPOST '124.90.34.227:11311/send_mail_text' -d "$data" -EOF +Usage: + curl -XPOST '$send_mail_server:$send_mail_port/send_mail_text' -d "$data" +HEREDOC
On Fri, Oct 16, 2020 at 02:06:58PM +0800, Luan Shengde wrote:
add setup default variables update heredoc
Signed-off-by: Luan Shengde luanshengde2@huawei.com
container/send-mail/start | 89 +++++++++++++++++++++++++++------------ 1 file changed, 62 insertions(+), 27 deletions(-)
diff --git a/container/send-mail/start b/container/send-mail/start index 80be86a..068fc1e 100755 --- a/container/send-mail/start +++ b/container/send-mail/start @@ -1,29 +1,68 @@ -#!/bin/bash +#!/usr/bin/env ruby # SPDX-License-Identifier: MulanPSL-2.0+ # Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true
-. $CCI_SRC/container/defconfig.sh +require 'set' +require_relative '../defconfig'
-docker_rm send-mail +docker_rm 'send-mail'
-cmd=(
- docker run
- --restart=always
- --name=send-mail
- -u nobody
- -d
- -p 11311:11311
- -v /etc/localtime:/etc/localtime:ro
- send-mail
-) +names = Set.new %w[
- EMAIL_PSWD
- SEND_MAIL_PORT
- SMTP_SERVER_ADDR
- SMTP_SERVER_PORT
- EMAIL_DOMAIN
- EMAIL_ADDR
- DEFAULT_EMAIL
+]
-"${cmd[@]}" +defaults = relevant_defaults(names)
-cat<<EOF +EMAIL_PSWD = defaults['EMAIL_PSWD'] +SEND_MAIL_PORT = defaults['SEND_MAIL_PORT'] +SMTP_SERVER_ADDR = defaults['SMTP_SERVER_ADDR'] +SMTP_SERVER_PORT = defaults['SMTP_SERVER_PORT'] +EMAIL_DOMAIN = defaults['EMAIL_DOMAIN'] +EMAIL_ADDR = defaults['EMAIL_ADDR'] +DEFAULT_EMAIL = defaults['DEFAULT_EMAIL']
Perhaps can remove some use-once variables.
Thanks, Fengguang
+cmd = %W[
- docker run
- --restart=always
- --name=send-mail
- -u nobody
- -d
- -e EMAIL_PSWD=#{EMAIL_PSWD}
- -e SEND_MAIL_PORT=#{SEND_MAIL_PORT}
- -e SMTP_SERVER_ADDR=#{SMTP_SERVER_ADDR}
- -e SMTP_SERVER_PORT=#{SMTP_SERVER_PORT}
- -e EMAIL_DOMAIN=#{EMAIL_DOMAIN}
- -e EMAIL_ADDR=#{EMAIL_ADDR}
- -e DEFAULT_EMAIL=#{DEFAULT_EMAIL}
- -p #{SEND_MAIL_PORT}:#{SEND_MAIL_PORT}
- -v /etc/localtime:/etc/localtime:ro
- --log-driver json-file
- send-mail
+]
+cmd += ['bash', '-c', '/usr/local/bin/mail-post.rb']
+system(*cmd)
+puts <<HEREDOC port: 11311
+default from email:
- when sending crystal.ci email.
- team@crystal.ci if no from email appiontted
- when sending to WAN email
- compass-ci@qq.com in all cases
data='{ -"from": "email_from_addr" # default: team@crystal.ci +"from": "email_from_addr" "subject": "email subject", "to": "email_to_addr", "body": "email message" @@ -32,19 +71,17 @@ data='{ or
data=" -from: email_from_addr # default: team@crystal.ci +from: email_from_addr subject: email subject to: email_to_addr body: email message"
-when compass-ci:
- curl -XPOST 'localhost:11311/send_mail_yaml' -d "$data"
-when other server:
- curl -XPOST '124.90.34.227:11311/send_mail_yaml' -d "$data"
+Usage:
- curl -XPOST '$send_mail_server:$send_mail_port/send_mail_yaml' -d "$data"
data=" -From: email_from_addr # default: team@crystal.ci +From: email_from_addr To: email_to_addr Subject: email_subject
@@ -53,8 +90,6 @@ mail_msg_line2 ... "
-when compass-ci:
- curl -XPOST 'localhost:11311/send_mail_text' -d "$data"
-when other server:
- curl -XPOST '124.90.34.227:11311/send_mail_text' -d "$data"
-EOF +Usage:
- curl -XPOST '$send_mail_server:$send_mail_port/send_mail_text' -d "$data"
+HEREDOC
2.23.0