Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
Helm-Automation-Script
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
harshavardhan.c
Helm-Automation-Script
Commits
23d70cd4
Commit
23d70cd4
authored
Oct 11, 2022
by
harshavardhan.c
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
enh: updated code for prepartion of helm-chart preparation.
parent
2c37df7c
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
220 additions
and
143 deletions
+220
-143
.env
.env
+3
-3
helm_automate_script.py
helm_automate_script.py
+130
-140
scripts/core/git_handler.py
scripts/core/git_handler.py
+87
-0
No files found.
.env
View file @
23d70cd4
DB_URI=sqlite:///./ilens_versions.db
DB_URI=sqlite:///./ilens_versions.db
CONFIG_MAP_VARIABLES=MONGO_URI
CONFIG_MAP_VARIABLES=MONGO_URI
HELM_REPO = https://gitlab-pm.knowledgelens.com/
faizan.azim/utest
HELM_REPO = https://gitlab-pm.knowledgelens.com/
KnowledgeLens/Products/iLens-2.0/core/devops/helm-charts
GIT_USERNAME =
faizan.azim
GIT_USERNAME =
harshavardhan.c
GIT_TOKEN =
MFz2FuGSasbQtBkpdfr6
GIT_TOKEN =
FEMA6PnP63fJCs6DrtZJ
GLOBAL_VARIABLES_FILE=ilens-global-configmap.yml
GLOBAL_VARIABLES_FILE=ilens-global-configmap.yml
helm_automate_script.py
View file @
23d70cd4
This diff is collapsed.
Click to expand it.
scripts/core/git_handler.py
0 → 100644
View file @
23d70cd4
import
os
import
git
import
gitlab
from
scripts.logging
import
logging
default_link
=
"https://gitlab-pm.knowledgelens.com/"
HELM_PATH
=
"/ilens-core/ilens-modules"
HELM_STORE_PATH
=
"./helm-charts"
class
GitHandler
:
def
__init__
(
self
,
access_token
,
user_name
):
self
.
access_token
=
access_token
self
.
user_name
=
user_name
def
clone_repository
(
self
,
repo_link
,
module_output_path
,
clone_branch
):
try
:
if
repo_link
.
split
(
"https://"
)[
-
1
]
.
startswith
(
"gitlab-pm"
):
repo_link
=
repo_link
.
replace
(
"https://"
,
f
"https://{self.user_name}:{self.access_token}@"
)
repo
=
git
.
Repo
.
clone_from
(
repo_link
,
module_output_path
,
branch
=
clone_branch
)
return
True
except
Exception
as
e
:
logging
.
exception
(
f
"Exception occurred while cloning the git repo - {repo_link} - {e.args}"
)
return
False
def
clone_repository_with_defined_file
(
self
,
repo_link
:
str
,
file_output_path
,
clone_branch
,
clone_file_path
):
try
:
base_url
=
os
.
environ
.
get
(
"GIT_BASE_URL"
,
default
=
default_link
)
repo_link_split
=
repo_link
.
split
(
base_url
)
if
not
repo_link_split
:
return
False
gl
=
gitlab
.
Gitlab
(
url
=
base_url
,
private_token
=
self
.
access_token
)
search_str
=
repo_link_split
[
-
1
]
.
replace
(
".git"
,
""
)
pl
=
gl
.
projects
.
list
(
search
=
search_str
)
if
not
pl
:
return
False
pl
=
pl
[
0
]
with
open
(
file_output_path
,
'wb'
)
as
f
:
pl
.
files
.
raw
(
file_path
=
clone_file_path
,
ref
=
clone_branch
,
streamed
=
True
,
action
=
f
.
write
)
return
True
except
Exception
as
e
:
logging
.
exception
(
f
"Exception occurred while cloning the git repo - {repo_link} - {e.args}"
)
return
False
def
get_git_url_by_module_name
(
self
,
module_name
):
try
:
base_url
=
os
.
environ
.
get
(
"GIT_BASE_URL"
,
default
=
default_link
)
gl
=
gitlab
.
Gitlab
(
url
=
base_url
,
private_token
=
self
.
access_token
)
pl
=
gl
.
projects
.
list
(
search
=
module_name
,
group
=
"/KnowledgeLens/Products/iLens-2.0"
)
return
pl
[
0
]
.
web_url
if
pl
else
''
except
Exception
as
e
:
logging
.
exception
(
f
"Exception occurred while fetching repo details - {e.args}"
)
return
False
def
pull_global_config
(
self
,
repo_link
:
str
,
branch
:
str
,
file_name
:
str
):
base_url
=
os
.
environ
.
get
(
"GIT_BASE_URL"
,
default
=
default_link
)
repo_link_split
=
repo_link
.
split
(
base_url
)
if
not
repo_link_split
:
return
False
gl
=
gitlab
.
Gitlab
(
url
=
base_url
,
private_token
=
self
.
access_token
)
search_str
=
repo_link_split
[
-
1
]
.
replace
(
".git"
,
""
)
if
pl
:
=
gl
.
projects
.
list
(
search
=
search_str
):
pl
=
pl
[
0
]
else
:
return
False
with
open
(
file_name
,
'wb'
)
as
f
:
pl
.
files
.
raw
(
file_path
=
f
'{HELM_PATH[1:]}/{file_name}'
,
ref
=
branch
,
streamed
=
True
,
action
=
f
.
write
)
return
True
def
remove_all_files_from_repo
(
self
,
repo_link
:
str
,
branch
:
str
,
exclude_file
:
list
):
base_url
=
os
.
environ
.
get
(
"GIT_BASE_URL"
,
default
=
default_link
)
repo_link_split
=
repo_link
.
split
(
base_url
)
if
not
repo_link_split
:
return
False
gl
=
gitlab
.
Gitlab
(
url
=
base_url
,
private_token
=
self
.
access_token
)
search_str
=
repo_link_split
[
-
1
]
.
replace
(
".git"
,
""
)
if
pl
:
=
gl
.
projects
.
list
(
search
=
search_str
):
pl
=
pl
[
0
]
else
:
return
False
items
=
pl
.
repository_tree
(
path
=
HELM_PATH
,
ref
=
branch
)
print
(
items
)
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