Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SMART
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UNI-KLU
SMART
Commits
6f8b2f9c
Commit
6f8b2f9c
authored
Mar 31, 2020
by
Alexander Lercher
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/build-individual-images' into develop
parents
ee159e16
3b02443e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
21 deletions
+88
-21
build.py
bin/build.py
+8
-3
deploy.py
bin/deploy.py
+80
-18
No files found.
bin/build.py
View file @
6f8b2f9c
...
@@ -2,14 +2,16 @@ import os
...
@@ -2,14 +2,16 @@ import os
import
shutil
import
shutil
import
sys
import
sys
# if len(sys.argv) != 2:
# raise Exception("Push to Docker Hub will not work, please provide username as argument")
DOCKER_COMPOSE_NAME
=
"Dockerfile"
DOCKER_COMPOSE_NAME
=
"Dockerfile"
ROOT
=
'./'
ROOT
=
'./'
SOURCEPATH
=
f
'{ROOT}src/'
SOURCEPATH
=
f
'{ROOT}src/'
DOCKER_USERNAME
=
"alexx882"
DOCKER_USERNAME
=
"alexx882"
p_image_name
=
None
if
len
(
sys
.
argv
)
==
2
:
# parameter contains image to build
p_image_name
=
sys
.
argv
[
1
]
paths
=
[]
paths
=
[]
for
r
,
_
,
f
in
os
.
walk
(
SOURCEPATH
):
for
r
,
_
,
f
in
os
.
walk
(
SOURCEPATH
):
for
filename
in
f
:
for
filename
in
f
:
...
@@ -21,6 +23,9 @@ command_args = [{'path': path,
...
@@ -21,6 +23,9 @@ command_args = [{'path': path,
for
path
for
path
in
paths
]
in
paths
]
if
p_image_name
is
not
None
:
command_args
=
[
x
for
x
in
command_args
if
x
[
'name'
]
==
p_image_name
]
error
:
int
=
0
error
:
int
=
0
res_str
=
[]
res_str
=
[]
for
command_arg
in
command_args
:
for
command_arg
in
command_args
:
...
...
bin/deploy.py
View file @
6f8b2f9c
import
os
import
os
import
sys
import
sys
# apply or delete config
def
print_help
():
kube_command
=
'apply'
print
(
"""
if
len
(
sys
.
argv
)
==
2
:
Use this script to apply or delete Kubernetes deployments and services.
kube_command
=
sys
.
argv
[
1
]
Parameters: [deploy|delete|redeploy [microservice_name]]
paths
=
[]
for
p
,
_
,
f
in
os
.
walk
(
'./'
):
deploy ... applies all deployments and services from files
for
file
in
f
:
delete ... deletes all deployments and services from files
if
'deployment.yml'
==
file
:
redeploy ... deletes and applies all microservices without deleting the database deployments
paths
.
append
(
os
.
path
.
normpath
(
p
))
microservice_name ... only apply/delete for one microservice
"""
)
error
:
int
=
0
for
path
in
paths
:
exit_val
=
os
.
system
(
f
"kubectl {kube_command} -f {path}"
)
def
get_microservice_name_from_path
(
path
)
->
str
:
if
exit_val
!=
0
:
'''
error
=
exit_val
Extracts the microservice name from the path.
:param path: The path, eg. src
\
data-hub
\
stage-discovery-microservice
\
deployment
sys
.
exit
(
1
if
error
>
0
else
0
)
'''
\ No newline at end of file
name
=
path
.
split
(
os
.
path
.
normpath
(
'/'
))[
-
2
]
if
'microservice'
in
name
:
name
=
'-'
.
join
(
name
.
split
(
'-'
)[:
-
1
])
return
name
def
update_deployments_from_file
(
kube_command
,
paths
,
del_db
=
True
)
->
int
:
'''
Applies the kube_command to all paths.
Returns >0 if at least one error occured.
:param kube_command: The command to use for kubectl
:param paths: The list of paths to apply the kubectl command for
:param del_db: Also remove the corresponding db for the microservice
:returns: >0, if an error occured
'''
exit_val
=
0
for
path
in
paths
:
if
del_db
:
exit_val
+=
os
.
system
(
f
"kubectl {kube_command} -f {path}"
)
else
:
# use the single delete command to keep database (which is in same file)
exit_val
+=
delete_deployment
(
get_microservice_name_from_path
(
path
))
return
exit_val
def
delete_deployment
(
name
)
->
int
:
'''Delete a single deployment by name.'''
exit_val
=
os
.
system
(
f
"kubectl delete deployment {name}"
)
return
exit_val
if
__name__
==
'__main__'
:
deployment_file_paths
=
[]
for
p
,
_
,
f
in
os
.
walk
(
'./'
):
for
file
in
f
:
if
'deployment.yml'
==
file
:
deployment_file_paths
.
append
(
os
.
path
.
normpath
(
p
))
command
=
sys
.
argv
[
1
]
if
len
(
sys
.
argv
)
>
1
else
'deploy'
if
command
==
'help'
:
print_help
()
sys
.
exit
(
0
)
img_name
=
None
if
len
(
sys
.
argv
)
>
2
:
img_name
=
sys
.
argv
[
2
]
deployment_file_paths
=
[
p
for
p
in
deployment_file_paths
if
(
img_name
in
p
)]
error_val
=
0
if
command
==
'delete'
or
command
==
'redeploy'
:
error_val
+=
update_deployments_from_file
(
'delete'
,
deployment_file_paths
,
command
==
'delete'
)
if
command
==
'deploy'
or
command
==
'redeploy'
:
error_val
+=
update_deployments_from_file
(
'apply'
,
deployment_file_paths
)
sys
.
exit
(
1
if
error_val
>
0
else
0
)
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