Create rolling releases using the Gitlab API. (#171)
* Create rolling releases using the Gitlab API. This commit builds rolling releases of Container images using the latest commit on master branch if the pipeline passed for it. The script which gets the references is still un-tested and should be tested. The latest commit hashes are passed as arguments to the Dockerfile, which is then used by PIP to install the specific version of the dependency.
This commit is contained in:
38
get_latest_ref.py
Executable file
38
get_latest_ref.py
Executable file
@@ -0,0 +1,38 @@
|
||||
#! /usr/bin/env python
|
||||
import os
|
||||
import sys
|
||||
import gitlab
|
||||
|
||||
|
||||
def usage():
|
||||
print("{} <project_name> <project_branch>")
|
||||
|
||||
|
||||
def main():
|
||||
if 2 > len(sys.argv) > 3:
|
||||
usage()
|
||||
|
||||
project_name = sys.argv[1]
|
||||
if len(sys.argv) > 2:
|
||||
branch_name = sys.argv[2]
|
||||
else:
|
||||
branch_name = 'master'
|
||||
|
||||
gl_token = os.getenv('GITLAB_TOKEN')
|
||||
if gl_token is None:
|
||||
print('GITLAB_TOKEN not set!')
|
||||
exit(1)
|
||||
gl = gitlab.Gitlab('https://gitlab.com/', gl_token)
|
||||
|
||||
project = gl.projects.get(project_name)
|
||||
branch = project.branches.get(branch_name)
|
||||
top_commit = project.commits.get(branch.commit['short_id'])
|
||||
|
||||
if top_commit.last_pipeline['status'] == 'success':
|
||||
print(top_commit.short_id)
|
||||
else:
|
||||
exit(1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user