Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
microservice-autodevopspipelines
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李春生
microservice-autodevopspipelines
Commits
e237127b
Commit
e237127b
authored
Jan 09, 2019
by
据说甜蜜呢
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加文件
parent
21efb2e6
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
205 additions
and
0 deletions
+205
-0
devops/PipeLines/Creation/002_CreateConfig.sh
+71
-0
devops/PipeLines/Creation/003_ReleaseMajor.sh
+42
-0
devops/PipeLines/Creation/Gateways/Kong/004_CreateGatewayRoute.sh
+92
-0
No files found.
devops/PipeLines/Creation/002_CreateConfig.sh
0 → 100644
View file @
e237127b
#!/bin/bash
set
-e
IFS
=
$'
\n\n
'
declare
appName
=(
$(
grep
-oP
'(?<=AppName>)[^<]+'
"devops/app.props"
)
)
echo
"Begin creating
${
appName
}
's settings to the configmap of k8s..."
function
Create
()
{
declare
createUrl
=
"
$3
/api/v1/namespaces/
$2
/configmaps?pretty=true"
echo
"[environment:
$1
, namespace:
$2
]"
function
send
()
{
set
+e
declare
deleteUrl
=
"
${
3
}
/api/v1/namespaces/
${
2
}
/configmaps/
$5
"
curl
-X
DELETE
$deleteUrl
-k
\
--connect-timeout
$2
--max-time
$3
--retry
$4
\
-H
'Authorization: Bearer '
${
AccessToken
}
''
set
-e
declare
configInfo
=
$(
cat
$1
| jq tostring
)
curl
-X
POST
$createUrl
-k
\
--connect-timeout
$2
--max-time
$3
--retry
$4
\
-H
'Content-Type: application/json'
\
-H
'cache-control: no-cache'
\
-H
'Authorization: Bearer '
${
AccessToken
}
''
\
-d
'{
"kind": "ConfigMap",
"apiVersion": "v1",
"metadata": {
"name": "'
$5
'",
"namespace": "'
${
namespace
}
'"
},
"data": {
"'
$6
'":'
"
$configInfo
"
'
}
}'
}
declare
maxTime
=
30
declare
maxConnectTime
=
20
declare
retryCount
=
5
send
"
$4
/appsettings.json"
$maxConnectTime
$maxTime
$retryCount
"
$5
.appsettings.json"
"appsettings.json"
send
"
$4
/appsettings.
$1
.json"
$maxConnectTime
$maxTime
$retryCount
"
$(
echo
$5
.appsettings.
$1
.json | tr
'A-Z'
'a-z'
)
"
"appsettings.
$1
.json"
}
declare
major
=(
$(
grep
-oP
'(?<=VersionMajor>)[^<]+'
"devops/version.props"
)
)
declare
namespace
=(
$(
grep
-oP
'(?<=Namespace>)[^<]+'
"devops/app.props"
)
)
declare
namespaceOfK8s
=
$(
echo
"
${
namespace
}
-v
${
major
}
"
| tr
'A-Z'
'a-z'
)
declare
k8sApiServer
=(
$(
grep
-oP
'(?<=K8sApiServer>)[^<]+'
"devops/deploy.props"
)
)
kubectl create namespace
${
namespaceOfK8s
}
declare
services
=
$(
ls
-l
src/services | awk
'NR>1'
)
declare
servicePrefix
=
""
for
service
in
${
services
}
do
servicePrefix
=(
$(
echo
${
service
}
| awk
'{print $9}'
)
)
Create
${
Environment
}
${
namespaceOfK8s
}
${
k8sApiServer
}
"./src/
${
servicePrefix
}
.API"
"
${
servicePrefix
}
"
done
echo
""
echo
"End creating app settings to the configmap of k8s..."
\ No newline at end of file
devops/PipeLines/Creation/003_ReleaseMajor.sh
0 → 100644
View file @
e237127b
#!/bin/bash
set
-e
IFS
=
$'
\n\n
'
declare
appName
=(
$(
grep
-oP
'(?<=AppName>)[^<]+'
"devops/app.props"
)
)
echo
"Release for
${
appName
}
starting, dynamicly creating k8s environment..."
declare
major
=(
$(
grep
-oP
'(?<=Major>)[^<]+'
"devops/version.props"
)
)
declare
minor
=(
$(
grep
-oP
'(?<=Minor>)[^<]+'
"devops/version.props"
)
)
declare
patch
=(
$(
grep
-oP
'(?<=Patch>)[^<]+'
"devops/version.props"
)
)
declare
namespace
=(
$(
grep
-oP
'(?<=Namespace>)[^<]+'
"devops/app.props"
)
)
declare
version
=
${
major
}
.
${
minor
}
.
${
patch
}
declare
namespaceOfK8s
=
$(
echo
"
${
namespace
}
-v
${
major
}
"
| tr
'A-Z'
'a-z'
)
declare
releaseName
=
"
${
appName
}
-v
${
major
}
"
echo
""
echo
"Please check the image version of each microservice carefully !!!"
echo
"kubernetes's namespace:
${
namespaceOfK8s
}
"
declare
services
=
$(
ls
-l
src/services | awk
'NR>1'
)
declare
servicePrefix
=
""
for
service
in
${
services
}
do
servicePrefix
=(
$(
echo
${
service
}
| awk
'{print $9}'
)
)
echo
"
${
servicePrefix
}
:
${
version
}
"
done
echo
""
declare
replicas
=(
$(
grep
-oP
'(?<=Replicas>)[^<]+'
"devops/app.props"
)
)
helm install /root/AutoDevOpsPipeLinesCharts
\
--name
=
${
releaseName
}
\
--set
environment.upper
=
${
Environment
}
\
--set
environment.lower
=
$(
echo
${
Environment
}
| tr
'A-Z'
'a-z'
)
\
--set
namespace
=
${
namespaceOfK8s
}
\
--set
image.version
=
${
version
}
\
--set
replicas
=
${
replicas
}
echo
""
echo
"Dynamicly creating k8s environment Successfully !!!"
\ No newline at end of file
devops/PipeLines/Creation/Gateways/Kong/004_CreateGatewayRoute.sh
0 → 100644
View file @
e237127b
#!/bin/bash
set
-e
IFS
=
$'
\n\n
'
declare
appName
=(
$(
grep
-oP
'(?<=AppName>)[^<]+'
"devops/app.props"
)
)
echo
"Start building the gateway for
${
appName
}
route dynamically..."
declare
namespace
=(
$(
grep
-oP
'(?<=Namespace>)[^<]+'
"devops/app.props"
)
)
declare
namespaceOfK8s
=
$(
echo
"
${
appName
}
-v
${
major
}
"
| tr
'A-Z'
'a-z'
)
declare
fdnOfK8s
=
"
${
namespaceOfK8s
}
.svc.cluster.local"
declare
kongServiceUrl
=(
$(
grep
-oP
'(?<=Namespace>)[^<]+'
"devops/app.props"
)
)
declare
major
=(
$(
grep
-oP
'(?<=Major>)[^<]+'
"devops/version.props"
)
)
declare
releaseVersion
=
"v
${
major
}
"
# resilience handle
# Maximum time in seconds that you allow the whole operation to take.
declare
maxTime
=
5
# Maximum time in seconds that you allow the connection to the server to take.
declare
maxConnectTime
=
2
declare
retryCount
=
5
## add services
function
createService
()
{
curl
-X
POST
$1
\
--connect-timeout
$2
\
--max-time
$3
\
--retry
$4
\
-H
"accept: application/json"
\
-H
"Content-Type: application/json"
\
-d
"{
\"
name
\"
:
\"
$5
\"
,
\"
url
\"
:
\"
$6
\"
}"
;
}
## add routes
function
createRoute
()
{
declare
svcResponse
=
$(
curl
-X
GET
${
kongServiceBaseUrl
}
/
$5
--connect-timeout
$2
--max-time
$3
--retry
$4
)
declare
JQ_EXEC
=
`
which jq
`
declare
svcId
=
$(
echo
$svcResponse
|
${
JQ_EXEC
}
.id | sed
's/\"//g'
)
declare
defMethods
=
"[
\"
GET
\"
,
\"
POST
\"
]"
set
+e
if
[
-n
"
$8
"
]
;
then
defMethods
=
$8
fi
if
[
-z
"
$svcId
"
]
;
then
echo
"Warnning, failed to get the service[
$5
] identifier, route cannot be created."
;
else
# idempotent
declare
routesAdded
=
$(
curl
-X
GET
${
kongServiceBaseUrl
}
/
$5
/routes
)
declare
routeid
=
$(
echo
$routesAdded
|
${
JQ_EXEC
}
.data[0].id | sed
's/\"//g'
)
if
[
"
$routeid
"
==
"null"
]
;
then
curl
-X
POST
$1
\
--connect-timeout
$2
\
--max-time
$3
\
--retry
$4
\
-H
"accept: application/json"
\
-H
"Content-Type: application/json"
\
-d
"{
\"
service
\"
: "
{
\"
id
\"
:
\"
$svcId
\"
}
",
\"
paths
\"
: "
[
\"
$6
\"
]
",
\"
methods
\"
: "
$defMethods
",
\"
strip_path
\"
:
$7
,
\"
hosts
\"
: "
[
\"
$kongRouteDomain
\"
]
"}"
;
fi
fi
set
-e
}
declare
services
=
$(
ls
-l
src/services | awk
'NR>1'
)
declare
servicePrefix
=
""
declare
serviceName
=
""
declare
serviceNameWithVersion
=
""
declare
serviceFullName
=
""
declare
serviceUrl
=
""
declare
serviceRouteUrl
=
""
for
service
in
${
services
}
do
servicePrefix
=(
$(
echo
${
service
}
| awk
'{print $9}'
)
)
serviceName
=
"
${
servicePrefix
}
-api"
serviceNameWithVersion
=
"
${
serviceName
}
-
${
releaseVersion
}
"
serviceFullName
=
"
${
serviceName
}
.
${
fdnOfK8s
}
"
serviceUrl
=
"http://
${
serviceFullName
}
/api/
${
servicePrefix
}
"
echo
"Begin creating service[
${
serviceNameWithVersion
}
]"
createService
${
kongServiceUrl
}
${
maxConnectTime
}
${
maxTime
}
${
retryCount
}
${
serviceNameWithVersion
}
${
serviceUrl
}
echo
"Begin creating route of service[
${
serviceNameWithVersion
}
]"
serviceRouteUrl
=
"/api/
${
releaseVersion
}
/
${
servicePrefix
}
"
createRoute
${
kongServiceUrl
}
${
maxConnectTime
}
${
maxTime
}
${
retryCount
}
${
serviceNameWithVersion
}
${
serviceRouteUrl
}
true
done
echo
""
echo
"Dynamicly building gateway route successfully !!!"
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment