-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🦜 Support for binary builds 🦜 #381
Changes from all commits
6aabde5
fcd2483
dbb53de
7f59e4c
951f204
b0aefd8
a6dfc64
a1278db
e946a35
9b65051
2e8f476
cb9e4ba
6233948
92b0fd2
34f0f00
46e75f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
name: exporters | ||
version: v1.3.0 | ||
version: v1.3.1 | ||
apiVersion: v2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,24 @@ Then we get commit data from the following systems through their respective APIs | |
* GitHub Enterprise (including private endpoints) | ||
* Bitbucket _(coming soon)_ | ||
* Gitlab _(coming soon)_ | ||
|
||
## Binary Build Support | ||
|
||
OpenShift binary builds are a popular mechanism for building container images on OenShift but do not contain source code information. | ||
|
||
To support these types of build, you may annotate the build phase with the following annotations for pelorus to use: | ||
|
||
| Annotation | Example | Description | | ||
|---------------------------------|:----------------------------------|------------------------------:| | ||
| buildSpecRevisionGitCommit | cae392a | Short or Long Git Commit Hash | | ||
| buildSpecSourceGitUri | https://github.com/org/myapp.git | URL of the Source Repository | | ||
| buildSpecRevisionGitAuthorName | joe.bloggs | Name of the committer | | ||
|
||
Example command to put in your build pipeline each time you start an OpenShift `Build`: | ||
|
||
```bash | ||
oc annotate bc/${BUILD_CONFIG_NAME} --overwrite \ | ||
buildSpecSourceGitUri=${GIT_URL} \ | ||
buildSpecRevisionGitCommit=${GIT_COMMIT} \ | ||
buildSpecRevisionGitAuthorName="${GIT_AUTHOR}" | ||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also note that we also missing branch / ref in your PR. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,7 +182,11 @@ def get_metric_from_build(self, build, app, namespace, repo_url): | |
repo_url = self._get_repo_from_build_config(build) | ||
|
||
metric.repo_url = repo_url | ||
commit_sha = build.spec.revision.git.commit | ||
|
||
if build.spec.revision is None: | ||
commit_sha = self._get_revision_from_build(build) | ||
else: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add logic to get commit_sha if one was not resolved from the self._get_revision_from_build() func and not always when the build.spec.revision is not None? |
||
commit_sha = build.spec.revision.git.commit | ||
metric.build_name = build.metadata.name | ||
metric.build_config_name = build.metadata.labels.buildconfig | ||
metric.namespace = build.metadata.namespace | ||
|
@@ -191,7 +195,12 @@ def get_metric_from_build(self, build, app, namespace, repo_url): | |
|
||
metric.commit_hash = commit_sha | ||
metric.name = app | ||
metric.committer = build.spec.revision.git.author.name | ||
|
||
if build.spec.revision is None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, get it when metric.committer is not valid from the: I don't know if such use case is valid when information is missing from build.spec.revision and have generic option to fill that data in the build? |
||
metric.committer = self._get_author_from_build(build) | ||
else: | ||
metric.committer = build.spec.revision.git.author.name | ||
|
||
metric.image_location = build.status.outputDockerImageReference | ||
metric.image_hash = build.status.output.to.imageDigest | ||
# Check the cache for the commit_time, if not call the API | ||
|
@@ -264,6 +273,9 @@ def _get_repo_from_build_config(self, build): | |
build_config = v1_build_configs.get( | ||
namespace=build.status.config.namespace, name=build.status.config.name | ||
) | ||
if build.metadata.annotations.buildSpecSourceGitUri: | ||
return build.metadata.annotations.buildSpecSourceGitUri | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there needed validation of URI at some point? e.g. valid git URI regex? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is handled in the |
||
|
||
if build_config: | ||
if build_config.spec.source.git: | ||
git_uri = str(build_config.spec.source.git.uri) | ||
|
@@ -273,3 +285,25 @@ def _get_repo_from_build_config(self, build): | |
return git_uri + ".git" | ||
|
||
return None | ||
|
||
def _get_revision_from_build(self, build): | ||
""" | ||
Determines the git revision from the parent BuildConfig | ||
:param build: the Build resource | ||
:return: revisions as a str or None if not found | ||
""" | ||
if build.metadata.annotations.buildSpecSourceGitUri: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this mistake? Should it be:
I also don't understand the logic:
This is equivalent to just: Because:
Unless you wanted to return None if string is empty, then check the len(something) as well. But as on lines 276-277, I would add some validaitons if the revision is valid regex. |
||
return build.metadata.annotations.buildSpecRevisionGitCommit | ||
|
||
return None | ||
|
||
def _get_author_from_build(self, build): | ||
""" | ||
Determines the git author from the parent BuildConfig | ||
:param build: the Build resource | ||
:return: author as a str or None if not found | ||
""" | ||
if build.metadata.annotations.buildSpecRevisionGitAuthorName: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very similar comment as above with the unnecessary checking if value exists. |
||
return build.metadata.annotations.buildSpecRevisionGitAuthorName | ||
|
||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eformat do you think it's worth matching the annotations with similar labels that are result of build process?
Those labels are described here
Here is example: