fix: Add org.opencontainers.image.source LABEL for CI images (#113)

This commit is contained in:
Gerald Pinder 2024-03-03 06:01:24 -05:00 committed by GitHub
parent 2c8776d2f2
commit e6f97d4258
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 37 additions and 0 deletions

View file

@ -131,6 +131,38 @@ fn get_gitlab_registry_path() -> Option<String> {
)
}
fn get_repo_url() -> Option<String> {
Some(
match (
// GitHub vars
env::var(GITHUB_SERVER_URL),
env::var(GITHUB_RESPOSITORY),
// GitLab vars
env::var(CI_SERVER_PROTOCOL),
env::var(CI_SERVER_HOST),
env::var(CI_PROJECT_NAMESPACE),
env::var(CI_PROJECT_NAME),
) {
(Ok(github_server), Ok(github_repo), _, _, _, _) => {
format!("{github_server}/{github_repo}")
}
(
_,
_,
Ok(ci_server_protocol),
Ok(ci_server_host),
Ok(ci_project_namespace),
Ok(ci_project_name),
) => {
format!(
"{ci_server_protocol}://{ci_server_host}/{ci_project_namespace}/{ci_project_name}"
)
}
_ => return None,
},
)
}
fn modules_exists() -> bool {
let mod_path = Path::new("modules");
mod_path.exists() && mod_path.is_dir()

View file

@ -26,6 +26,9 @@ FROM {{ recipe.base_image }}:{{ recipe.image_version }}
LABEL {{ blue_build_utils::constants::BUILD_ID_LABEL }}="{{ build_id }}"
LABEL org.opencontainers.image.title="{{ recipe.name }}"
LABEL org.opencontainers.image.description="{{ recipe.description }}"
{%- if let Some(repo) = self::get_repo_url() %}
LABEL org.opencontainers.image.source="{{ repo }}"
{%- endif %}
LABEL io.artifacthub.package.readme-url=https://raw.githubusercontent.com/blue-build/cli/main/README.md
ARG RECIPE={{ recipe_path.display() }}

View file

@ -26,7 +26,9 @@ pub const GITHUB_ACTIONS: &str = "GITHUB_ACTIONS";
pub const GITHUB_ACTOR: &str = "GITHUB_ACTOR";
pub const GITHUB_EVENT_NAME: &str = "GITHUB_EVENT_NAME";
pub const GITHUB_REF_NAME: &str = "GITHUB_REF_NAME";
pub const GITHUB_RESPOSITORY: &str = "GITHUB_REPOSITORY";
pub const GITHUB_REPOSITORY_OWNER: &str = "GITHUB_REPOSITORY_OWNER";
pub const GITHUB_SERVER_URL: &str = "GITHUB_SERVER_URL";
pub const GITHUB_SHA: &str = "GITHUB_SHA";
pub const GITHUB_TOKEN: &str = "GH_TOKEN";
pub const GITHUB_WORKFLOW_REF: &str = "GITHUB_WORKFLOW_REF";