Functions.core.sh 3.18 KB
Newer Older
据说甜蜜呢 committed
1 2 3 4
#!/bin/bash

set -e

据说甜蜜呢 committed
5 6 7
# Import external functions
chmod +x ./devops/PipeLines/Functions.common.sh
source ./devops/PipeLines/Functions.common.sh
据说甜蜜呢 committed
8

9 10 11 12
# function GetServices()
# {
#	
# }
据说甜蜜呢 committed
13 14 15 16 17 18 19 20 21

function GetServiceCsProjFile()
{
    declare prefix=${1}
	declare name=${2}
	declare csprojFile="./src/Services/${prefix}/${name}/${name}.csproj"
	eval $3="${csprojFile}"
}

据说甜蜜呢 committed
22 23 24 25 26 27 28 29
function GetServiceDir()
{
    declare prefix=${1}
	declare name=${2}
	declare dir="./src/Services/${prefix}/${name}"
	eval $3="${dir}"
}

据说甜蜜呢 committed
30 31 32 33 34 35 36 37 38 39 40 41 42
function GetServiceName()
{
    declare prefix=${1}
	declare name=($(ls ./src/Services/${prefix}|head -n 1|xargs -d '/' echo))
	eval $2="${name}"
}

function GetAppName()
{
    declare name=($(grep -oP '(?<=AppName>)[^<]+' "./devops/app.props"))
	eval $1="${name}"
}

据说甜蜜呢 committed
43 44 45
function GetNameSpace()
{
    GetMajor major
46
	declare ns=($(grep -oP '(?<=NameSpace>)[^<]+' "./devops/app.props"))
47
	ToLower "${ns}-v${major}" nsOfK8s
48
	eval $1=${nsOfK8s}
据说甜蜜呢 committed
49 50
}

据说甜蜜呢 committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
function GetSolutionName()
{
    declare name=($(grep -oP '(?<=SolutionName>)[^<]+' "./devops/app.props"))
	eval $1="${name}"
}

function GetImageUserName()
{
    declare name=($(grep -oP '(?<=ImageUserName>)[^<]+' "devops/deploy.props"))
	eval $1="${name}"
}

function GetCiCdSettings()
{
    declare all=($(grep -oP '(?<=AllPublishable>)[^<]+' "/tmp/cicd.props"))
    declare no=($(grep -oP '(?<=NoPublishable>)[^<]+' "/tmp/cicd.props"))
	eval $1=${all}
	eval $2=${no}
}

function GetMajor()
{
    declare m=($(grep -oP '(?<=Major>)[^<]+' "./devops/version.props"))
	eval $1=${m}
}

function GetVersion()
{
    declare major=($(grep -oP '(?<=Major>)[^<]+' "./devops/version.props"))
	declare minor=($(grep -oP '(?<=Minor>)[^<]+' "./devops/version.props"))
	declare patch=($(grep -oP '(?<=Patch>)[^<]+' "./devops/version.props"))
	eval $1="${major}.${minor}.${patch}"
}

function GetImageRegistrySettings()
{
    declare host=($(grep -oP '(?<=ImageRegistryHost>)[^<]+' "devops/deploy.props"))
    declare username=($(grep -oP '(?<=ImageUserName>)[^<]+' "devops/deploy.props"))
	eval $1=${host}
	eval $2=${username}
}

93 94 95 96 97 98
function GetReplicas()
{
    declare count=($(grep -oP '(?<=Replicas>)[^<]+' "devops/deploy.props"))
	eval $1=${count}
}

99
function GetAccessToken()
据说甜蜜呢 committed
100
{
101 102
    ToLower ${Environment} environment
    declare token=($(grep -oP "(?<=AccessToken>)[^<]+" "devops/deploy.${environment}.props"))
据说甜蜜呢 committed
103 104 105
	eval $1="${token}"
}

106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
function GetRegistryHost()
{
    ToLower ${Environment} environment
    declare host=($(grep -oP "(?<=RegistryHost>)[^<]+" "devops/deploy.${environment}.props"))
	eval $1="${host}"
}

function GetK8sApiServer()
{
    ToLower ${Environment} environment
    declare host=($(grep -oP "(?<=K8sApiServer>)[^<]+" "devops/deploy.${environment}.props"))
	eval $1="${host}"
}

function GetKongApiServer()
{
    ToLower ${Environment} environment
    declare host=($(grep -oP "(?<=KongApiServer>)[^<]+" "devops/deploy.${environment}.props"))
	eval $1="${host}"
}

function GetKongRouteDomain()
{
    ToLower ${Environment} environment
    declare domain=($(grep -oP "(?<=KongRouteDomain>)[^<]+" "devops/deploy.${environment}.props"))
	eval $1="${domain}"
}

据说甜蜜呢 committed
134 135 136 137 138 139
function IsPublishableOf()
{
    declare prefix=$0
    declare isP=($(grep -oP "(?<=${prefix}Publishable>)[^<]+" "/tmp/cicd.props"))
	eval $1=isP
}