Signed-off-by: Luan Shengde luanshengde2@huawei.com --- container/send-mail/start | 92 +++++++++++++++------------------------ 1 file changed, 34 insertions(+), 58 deletions(-)
diff --git a/container/send-mail/start b/container/send-mail/start index 80be86a..95d797f 100755 --- a/container/send-mail/start +++ b/container/send-mail/start @@ -1,60 +1,36 @@ -#!/bin/bash +#!/usr/bin/env ruby # SPDX-License-Identifier: MulanPSL-2.0+ # Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. - -. $CCI_SRC/container/defconfig.sh - -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 -) - -"${cmd[@]}" - -cat<<EOF -port: 11311 ---- -data='{ -"from": "email_from_addr" # default: team@crystal.ci -"subject": "email subject", -"to": "email_to_addr", -"body": "email message" -}' - -or - -data=" -from: email_from_addr # default: team@crystal.ci -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" - ---- -data=" -From: email_from_addr # default: team@crystal.ci -To: email_to_addr -Subject: email_subject - -mail_msg_line1 -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 +# frozen_string_literal: true + +require 'set' +require_relative '../defconfig' + +docker_rm 'send-mail' + +names = Set.new %w[ + LOCAL_SEND_MAIL_PORT + LOCAL_ROBOT_EMAIL_ADDRESS +] + +defaults = relevant_defaults(names) + +cmd = %W[ + docker run + --restart=always + --name=send-mail + -u nobody + -d + -e CCI_SRC=/c/compass-ci + -e SEND_MAIL_PORT=#{defaults['LOCAL_SEND_MAIL_PORT']} + -e ROBOT_EMAIL_ADDRESS=#{defaults['LOCAL_ROBOT_EMAIL_ADDRESS']} + -p #{defaults['LOCAL_SEND_MAIL_PORT']}:#{defaults['LOCAL_SEND_MAIL_PORT']} + -v #{ENV['CCI_SRC']}:/c/compass-ci + -v /etc/localtime:/etc/localtime:ro + -w /c/compass-ci/container/send-mail + send-mail +] + +cmd += ['ruby', 'send-mail.rb'] + +system(*cmd)