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
431a0d1e
Commit
431a0d1e
authored
Jan 10, 2019
by
据说甜蜜呢
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化脚本
parent
64fb4b91
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
69 deletions
+27
-69
devops/PipeLines/Creation/002_CreateConfig.sh
+3
-4
devops/PipeLines/Functions.config.sh
+4
-3
devops/PipeLines/Updating/002_SyncConfig.sh
+20
-62
No files found.
devops/PipeLines/Creation/002_CreateConfig.sh
View file @
431a0d1e
...
@@ -13,15 +13,14 @@ echo "Begin creating ${appName}'s settings to the configmap of k8s..."
...
@@ -13,15 +13,14 @@ echo "Begin creating ${appName}'s settings to the configmap of k8s..."
GetNameSpace namespace
GetNameSpace namespace
kubectl create namespace
${
namespace
}
kubectl create namespace
${
namespace
}
# global variable
GetAccessToken accessToken
GetAccessToken AccessToken
GetK8sApiServer k8sApiServer
GetK8sApiServer K8sApiServer
for
servicePrefix
in
`
ls
./src/Services|xargs
-d
'/'
`
for
servicePrefix
in
`
ls
./src/Services|xargs
-d
'/'
`
do
do
GetServiceName
${
servicePrefix
}
serviceName
GetServiceName
${
servicePrefix
}
serviceName
GetServiceDir
${
servicePrefix
}
${
serviceName
}
serviceDir
GetServiceDir
${
servicePrefix
}
${
serviceName
}
serviceDir
CreateConfig
${
Environment
}
${
namespace
}
${
K8sApiServer
}
${
serviceDir
}
${
servicePrefix
}
CreateConfig
${
Environment
}
${
namespace
}
${
k8sApiServer
}
${
serviceDir
}
${
servicePrefix
}
${
accessToken
}
done
done
echo
""
echo
""
...
...
devops/PipeLines/Functions.config.sh
View file @
431a0d1e
...
@@ -10,6 +10,7 @@ function CreateConfig()
...
@@ -10,6 +10,7 @@ function CreateConfig()
{
{
declare
ns
=
$2
declare
ns
=
$2
declare
apiServer
=
$3
declare
apiServer
=
$3
declare
token
=
$6
declare
createUrl
=
"
${
apiServer
}
/api/v1/namespaces/
$2
/configmaps?pretty=true"
declare
createUrl
=
"
${
apiServer
}
/api/v1/namespaces/
$2
/configmaps?pretty=true"
echo
""
echo
""
echo
"[environment:
$1
, namespace:
$2
]"
echo
"[environment:
$1
, namespace:
$2
]"
...
@@ -22,7 +23,7 @@ function CreateConfig()
...
@@ -22,7 +23,7 @@ function CreateConfig()
curl
-X
DELETE
$deleteUrl
-k
\
curl
-X
DELETE
$deleteUrl
-k
\
--connect-timeout
$2
--max-time
$3
--retry
$4
\
--connect-timeout
$2
--max-time
$3
--retry
$4
\
-H
'Authorization: Bearer '
${
AccessT
oken
}
''
-H
'Authorization: Bearer '
${
t
oken
}
''
set
-e
set
-e
...
@@ -32,13 +33,13 @@ function CreateConfig()
...
@@ -32,13 +33,13 @@ function CreateConfig()
--connect-timeout
$2
--max-time
$3
--retry
$4
\
--connect-timeout
$2
--max-time
$3
--retry
$4
\
-H
'Content-Type: application/json'
\
-H
'Content-Type: application/json'
\
-H
'cache-control: no-cache'
\
-H
'cache-control: no-cache'
\
-H
'Authorization: Bearer '
${
AccessT
oken
}
''
\
-H
'Authorization: Bearer '
${
t
oken
}
''
\
-d
'{
-d
'{
"kind": "ConfigMap",
"kind": "ConfigMap",
"apiVersion": "v1",
"apiVersion": "v1",
"metadata": {
"metadata": {
"name": "'
$5
'",
"name": "'
$5
'",
"namespace": "'
${
n
amespace
}
'"
"namespace": "'
${
n
s
}
'"
},
},
"data": {
"data": {
"'
$6
'":'
"
${
configInfo
}
"
'
"'
$6
'":'
"
${
configInfo
}
"
'
...
...
devops/PipeLines/Updating/002_SyncConfig.sh
View file @
431a0d1e
...
@@ -2,81 +2,39 @@
...
@@ -2,81 +2,39 @@
set
-e
set
-e
IFS
=
$'
\n\n
'
IFS
=
$'
\n\n
'
declare
appName
=(
$(
grep
-oP
'(?<=AppName>)[^<]+'
"devops/app.props"
)
)
# Import external functions
chmod +x ./devops/PipeLines/Functions.config.sh
source
./devops/PipeLines/Functions.config.sh
echo
"Begin creating
${
appName
}
's settings to the configmap of k8s..."
GetAppName appName
echo
""
echo
"Begin synchronizing
${
appName
}
's settings to the configmap of k8s..."
declare
noPublishable
=(
$(
grep
-oP
'(?<=NoPublishable>)[^<]+'
"/tmp/cicd.props"
)
)
GetCiCdSettings allPublishable noPublishable
if
[
"
${
noPublishable
}
"
==
"1"
]
;
if
[
"
${
noPublishable
}
"
==
"1"
]
;
then
then
echo
""
echo
""
echo
"Tips: No services need to be synced config."
echo
"Tips: No services need to be synced config."
else
else
function
create
()
GetNameSpace namespace
{
GetAccessToken accessToken
if
[
"
$6
"
==
"1"
]
;
GetK8sApiServer k8sApiServer
then
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
)
for
ServicePrefix
in
`
ls
./src/Services|xargs
-d
'/'
`
do
curl
-X
POST
$createUrl
-k
\
IsPublishableOf ServicePrefix isPublishable
--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
if
[
"
${
isPublishable
}
"
==
"1"
]
;
declare
maxConnectTime
=
20
then
declare
retryCount
=
5
GetServiceName
${
ServicePrefix
}
serviceName
GetServiceDir
${
ServicePrefix
}
${
serviceName
}
serviceDir
send
"
$4
/appsettings.json"
$maxConnectTime
$maxTime
$retryCount
"
$5
.appsettings.json"
"appsettings.json"
CreateConfig
${
Environment
}
${
namespace
}
${
k8sApiServer
}
${
serviceDir
}
${
servicePrefix
}
${
accessToken
}
send
"
$4
/appsettings.
$1
.json"
$maxConnectTime
$maxTime
$retryCount
"
$(
echo
$5
.appsettings.
$1
.json | tr
'A-Z'
'a-z'
)
"
"appsettings.
$1
.json"
else
else
echo
""
echo
""
echo
"Tips:
$5
will not be synced config!!!"
echo
"Tips:
$5
will not be synced config!!!"
fi
fi
}
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"
)
)
declare
services
=
$(
ls
-l
src/services | awk
'NR>1'
)
declare
servicePrefix
=
""
for
service
in
${
services
}
do
servicePrefix
=(
$(
echo
${
service
}
| awk
'{print $9}'
)
)
declare
isPublishable
=(
$(
grep
-oP
"(?<=
${
servicePrefix
}
Publishable>)[^<]+"
"/tmp/cicd.props"
)
)
Create
${
Environment
}
${
namespaceOfK8s
}
${
k8sApiServer
}
"./src/
${
servicePrefix
}
.API"
"
${
servicePrefix
}
"
${
isPublishable
}
done
done
fi
fi
echo
""
echo
""
echo
"End creating app settings to the configmap of k8s..."
echo
"End synchronizing app settings to the configmap of k8s..."
\ No newline at end of file
\ 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