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
785b5345
Commit
785b5345
authored
Jan 10, 2019
by
据说甜蜜呢
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
删除文件
parent
e975d1aa
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
0 additions
and
374 deletions
+0
-374
devops/PipeLines/Updating/001 AnalysingGitChanges.sh
+0
-92
devops/PipeLines/Updating/002 SyncConfig.sh
+0
-83
devops/PipeLines/Updating/003 CI.sh
+0
-71
devops/PipeLines/Updating/004 CD.sh
+0
-60
devops/PipeLines/Updating/005 K8sIsReady.sh
+0
-40
devops/PipeLines/Updating/006 CleanK8s.sh
+0
-28
No files found.
devops/PipeLines/Updating/001 AnalysingGitChanges.sh
deleted
100644 → 0
View file @
e975d1aa
#!/bin/bash
set
-e
IFS
=
$'
\n\n
'
function
AddHeadConfig
()
{
# sync config for later retries, not affected by cross-job.
echo
"<Project>
<PropertyGroup>
<AllPublishable>
${
1
}
</AllPublishable>
<NoPublishable>
${
2
}
</NoPublishable>"
>
/tmp/cicd.props
}
function
AddConfig
()
{
# sync config for later retries, not affected by cross-job.
declare
name
=
${
1
}
declare
publishable
=
${
2
}
if
[
"
${
publishable
}
"
==
"1"
]
;
then
echo
"<
${
name
}
Publishable>
${
publishable
}
</
${
name
}
Publishable>"
>>
/tmp/cicd.props
fi
}
function
AddTailConfig
()
{
echo
"</PropertyGroup>
</Project>"
>>
/tmp/cicd.props
}
if
[
"
${
AllPublishable
}
"
==
"1"
]
;
then
AddHeadConfig
"1"
,
"0"
AddTailConfig
echo
"All micro-services will be released."
else
echo
"Start analyzing the git difference log..."
echo
""
echo
"the difference: "
git diff
--name-only
ORIG_HEAD
echo
""
declare
changes
=
$(
git diff
--name-only
ORIG_HEAD
)
# Publishable by prefix
function
IsPublishable
()
{
if
echo
$changes
|
grep
"
$1
"
>
/dev/null
then
eval
"
$2
='1'"
else
eval
"
$2
='0'"
let
count
=
$3
+1
eval
$3
=
"
${
count
}
"
fi
}
declare
isPublishable
declare
publishableCount
=
0
;
AddHeadConfig
"1"
,
"0"
for
servicePrefix
in
`
ls
./src/Services|xargs
-d
'/'
`
do
# Notes: manual control, mandatory release, will not analyzing changes
isPublishable
=
$(
eval echo
${
servicePrefix
}
Publishable
)
if
[
"
${
isPublishable
}
"
==
"1"
]
;
then
AddConfig
"
${
servicePrefix
}
"
"
${
isPublishable
}
"
echo
"Tips[Hard Release]:
${
servicePrefix
}
will be released."
else
# Analyzing git changes
IsPublishable
"src/
${
servicePrefix
}
"
isPublishable publishableCount
AddConfig
"
${
servicePrefix
}
"
"
${
isPublishable
}
"
echo
"Tips[Soft Release]:
${
servicePrefix
}
will be released."
fi
done
AddTailConfig
declare
serviceCount
=
$(
ls
-l
src/services |
grep
"^d"
| wc
-l
)
if
[
"
${
publishableCount
}
"
==
"
${
serviceCount
}
"
]
;
then
AddHeadConfig
"0"
,
"1"
AddTailConfig
echo
"Tips: No services need to be released."
fi
echo
""
echo
"End analyzing the difference log..."
fi
\ No newline at end of file
devops/PipeLines/Updating/002 SyncConfig.sh
deleted
100644 → 0
View file @
e975d1aa
#!/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..."
declare
noPublishable
=(
$(
grep
-oP
'(?<=NoPublishable>)[^<]+'
"/tmp/cicd.props"
)
)
if
[
"
${
noPublishable
}
"
==
"1"
]
;
then
echo
""
echo
"Tips: No services need to be synced config."
else
function
create
()
{
if
[
"
$6
"
==
"1"
]
;
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
)
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"
else
echo
""
echo
"Tips:
$5
will not be synced config!!!"
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
fi
echo
""
echo
"End creating app settings to the configmap of k8s..."
\ No newline at end of file
devops/PipeLines/Updating/003 CI.sh
deleted
100644 → 0
View file @
e975d1aa
#!/bin/bash
set
-e
# Import external functions
chmod +x ./devops/PipeLines/functions.sh
./devops/PipeLines/functions.sh
GetAppName appName
echo
"Continuous integration for
${
appName
}
starting..."
GetCiCdSettings allPublishable noPublishable
if
[
"
${
noPublishable
}
"
==
"1"
]
;
then
echo
""
echo
"Tips: No services need to be cied."
else
declare
solutionName
=(
$(
grep
-oP
'(?<=SolutionName>)[^<]+'
"devops/app.props"
)
)
dotnet build
${
solutionName
}
echo
"Please check the version of each microservice carefully !!!"
declare
major
=(
$(
grep
-oP
'(?<=VersionMajor>)[^<]+'
"build/version.props"
)
)
declare
minor
=(
$(
grep
-oP
'(?<=VersionMinor>)[^<]+'
"build/version.props"
)
)
declare
patch
=(
$(
grep
-oP
'(?<=VersionPatch>)[^<]+'
"build/version.props"
)
)
declare
version
=
${
major
}
.
${
minor
}
.
${
patch
}
declare
registryUserName
=(
$(
grep
-oP
'(?<=ImageUserName>)[^<]+'
"build/deploy.props"
)
)
declare
publishOutputDir
=
./publish
rm
-fr
${
publishOutputDir
}
mkdir
-p
${
publishOutputDir
}
function
CI
()
{
declare
publishable
=
$1
declare
imagename
=
$2
echo
""
if
[
"
${
publishable
}
"
==
"1"
]
;
then
declare
imagefullname
=
${
RegistryHost
}
/
${
registryUserName
}
/
${
imagename
}
:
${
version
}
declare
publishFile
=
$3
echo
"begin delivery of master branch for
${
imagename
}
..."
mkdir
-p
${
publishOutputDir
}
/
${
imagename
}
dotnet publish
${
publishFile
}
-o
../../publish/
${
imagename
}
-c
release
--no-restore
docker build
-t
${
imagefullname
}
${
publishOutputDir
}
/
${
imagename
}
docker push
${
imagefullname
}
echo
"delivery of master branch for
${
imagename
}
:
${
version
}
has been successful."
else
echo
"Tips: master branch for
${
imagename
}
:
${
version
}
will not be cied!!!"
fi
}
declare
services
=
$(
ls
-l
src/services | awk
'NR>1'
)
declare
servicePrefix
=
""
declare
serviceName
=
""
declare
isPublishable
=
"0"
for
service
in
${
services
}
do
servicePrefix
=(
$(
echo
${
service
}
| awk
'{print $9}'
)
)
isPublishable
=(
$(
grep
-oP
"(?<=
${
servicePrefix
}
Publishable>)[^<]+"
"/tmp/cicd.props"
)
)
GetServiceName
"
${
servicePrefix
}
"
serviceName
CI
${
isPublishable
}
"
${
servicePrefix
}
"
"./src/
${
servicePrefix
}
/
${
serviceName
}
.csproj"
done
fi
echo
""
echo
"Continuous integration for
${
appName
}
has been successful."
\ No newline at end of file
devops/PipeLines/Updating/004 CD.sh
deleted
100644 → 0
View file @
e975d1aa
#!/bin/bash
set
-e
# Import external functions
chmod +x ./devops/PipeLines/functions.sh
sh ./devops/PipeLines/functions.sh
GetAppName appName
echo
"Continuous deployment of
${
Environment
}
branch for
${
appName
}
starting..."
GetCiCdSettings allPublishable noPublishable
if
[
"
${
noPublishable
}
"
==
"1"
]
;
then
echo
""
echo
"Tips: No services need to be cded."
else
echo
"Please check the version of each microservice carefully !!!"
echo
""
GetVersion version
GetNameSpace namespace
GetImageRegistrySettings registryHost registryUserName
function
CD
()
{
declare
publishable
=
$1
declare
appName
=
$2
declare
imageName
=
$3
echo
""
if
[
"
${
publishable
}
"
==
"1"
]
;
then
kubectl
-n
${
namespace
}
set
image deployments/
${
appName
}
"
${
appName
}
=
${
registryHost
}
/
${
registryUserName
}
/
${
imageName
}
:
${
version
}
"
;
if
[
"
${
Environment
}
"
==
"Staging"
]
;
then
kubectl
-n
${
namespace
}
scale deploy
${
appName
}
--replicas
=
0
;
kubectl
-n
${
namespace
}
scale deploy
${
appName
}
--replicas
=
1
;
fi
echo
"deployment of
${
Environment
}
branch for
${
appName
}
:
${
version
}
has been successful."
else
echo
"Tips:
${
Environment
}
branch for
${
appName
}
:
${
version
}
will not be cded!!!"
fi
}
declare
services
=
$(
ls
-l
src/services | awk
'NR>1'
)
declare
servicePrefix
=
""
declare
serviceName
=
""
declare
isPublishable
=
"0"
for
service
in
${
services
}
do
servicePrefix
=(
$(
echo
${
service
}
| awk
'{print $9}'
)
)
isPublishable
=(
$(
grep
-oP
"(?<=
${
servicePrefix
}
Publishable>)[^<]+"
"/tmp/cicd.props"
)
)
GetServiceName
"
${
servicePrefix
}
"
serviceName
CD
${
apiPublishable
}
"
${
serviceName
}
"
"
${
serviceName
}
"
done
fi
echo
""
echo
"Continuous deployment of
${
Environment
}
branch for
${
appName
}
has been successful."
devops/PipeLines/Updating/005 K8sIsReady.sh
deleted
100644 → 0
View file @
e975d1aa
#!/bin/bash
IFS
=
$'
\n\n
'
# Import external functions
chmod +x ./devops/PipeLines/functions.sh
sh ./devops/PipeLines/functions.sh
#1: ready, 0: not ready.
declare
ready
=
0
GetNameSpace namespace
while
[
$((${
ready
}))
==
0
]
do
sleep 10s
echo
""
declare
allIsReady
=
1
for
row
in
$(
kubectl
-n
${
namespace
}
get deployment
)
do
echo
""
declare
name
=
$(
echo
"
${
row
}
"
|awk
'{print $1}'
)
declare
desired
=
$(
echo
"
${
row
}
"
|awk
'{print $2}'
)
declare
current
=
$(
echo
"
${
row
}
"
|awk
'{print $3}'
)
declare
uptodate
=
$(
echo
"
${
row
}
"
|awk
'{print $4}'
)
declare
available
=
$(
echo
"
${
row
}
"
|awk
'{print $5}'
)
echo
"deployment:
${
name
}
, desired:
${
desired
}
, current:
${
current
}
, uptodate:
${
uptodate
}
, available:
${
available
}
"
if
[
$((${
desired
}))
==
$((${
current
}))
-a
$((${
current
}))
==
$((${
uptodate
}))
-a
$((${
uptodate
}))
==
$((${
available
}))
]
;
then
echo
"
${
name
}
has been ready."
;
else
echo
"
${
name
}
has been not ready."
;
allIsReady
=
0
fi
done
if
[
$((${
allIsReady
}))
==
1
]
;
then
ready
=
1
fi
done
\ No newline at end of file
devops/PipeLines/Updating/006 CleanK8s.sh
deleted
100644 → 0
View file @
e975d1aa
#!/bin/bash
IFS
=
$'
\n\n
'
# Import external functions
chmod +x ./devops/PipeLines/functions.sh
sh ./devops/PipeLines/functions.sh
GetNameSpace namespace
declare
replicas
=
$(
kubectl
-n
${
namespace
}
get rs
)
for
row
in
$replicas
do
declare
name
=
$(
echo
"
${
row
}
"
|awk
'{print $1}'
)
declare
desired
=
$(
echo
"
${
row
}
"
|awk
'{print $2}'
)
declare
current
=
$(
echo
"
${
row
}
"
|awk
'{print $3}'
)
declare
ready
=
$(
echo
"
${
row
}
"
|awk
'{print $4}'
)
# echo "replica set: ${name}, desired: ${desired}"
if
[
$((${
desired
}))
==
0
-a
$((${
current
}))
==
0
-a
$((${
ready
}))
==
0
]
;
then
# echo ${name}
kubectl
-n
${
namespace
}
delete rs
${
name
}
--grace-period
=
0
--force
fi
done
echo
'clean successful...'
exit
0
\ 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