Skip to content

Commit

Permalink
fix: Lowecase registry and update IMAGE_REGISTRY arg (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmpinder authored Feb 5, 2024
1 parent 8f44bf4 commit aab4c00
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
22 changes: 13 additions & 9 deletions src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,20 +376,24 @@ impl BuildCommand {
)
} else {
match (
env::var("CI_REGISTRY").ok(),
env::var("CI_PROJECT_NAMESPACE").ok(),
env::var("CI_PROJECT_NAME").ok(),
env::var("GITHUB_REPOSITORY_OWNER").ok(),
self.registry.as_ref(),
self.registry_path.as_ref(),
env::var("CI_REGISTRY").ok().map(|s| s.to_lowercase()),
env::var("CI_PROJECT_NAMESPACE")
.ok()
.map(|s| s.to_lowercase()),
env::var("CI_PROJECT_NAME").ok().map(|s| s.to_lowercase()),
env::var("GITHUB_REPOSITORY_OWNER")
.ok()
.map(|s| s.to_lowercase()),
self.registry.as_ref().map(|s| s.to_lowercase()),
self.registry_path.as_ref().map(|s| s.to_lowercase()),
) {
(_, _, _, _, Some(registry), Some(registry_path)) => {
trace!("registry={registry}, registry_path={registry_path}");
format!(
"{}/{}/{}",
registry.trim().trim_matches('/').to_lowercase(),
registry_path.trim().trim_matches('/').to_lowercase(),
recipe.name.trim().to_lowercase()
registry.trim().trim_matches('/'),
registry_path.trim().trim_matches('/'),
recipe.name.trim(),
)
}
(
Expand Down
18 changes: 17 additions & 1 deletion src/commands/template.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
fs,
env, fs,
path::{Path, PathBuf},
process,
};
Expand Down Expand Up @@ -234,3 +234,19 @@ fn get_files_list(module: &Module) -> Option<Vec<(String, String)>> {
.collect(),
)
}

fn get_github_repo_owner() -> Option<String> {
Some(env::var("GITHUB_REPOSITORY_OWNER").ok()?.to_lowercase())
}

fn get_gitlab_registry_path() -> Option<String> {
Some(
format!(
"{}/{}/{}",
env::var("CI_REGISTRY").ok()?,
env::var("CI_PROJECT_NAMESPACE").ok()?,
env::var("CI_PROJECT_NAME").ok()?,
)
.to_lowercase(),
)
}
10 changes: 9 additions & 1 deletion templates/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ LABEL io.artifacthub.package.readme-url=https://raw.githubusercontent.com/ublue-
LABEL io.artifacthub.package.logo-url=https://avatars.githubusercontent.com/u/120078124?s=200&v=4

ARG RECIPE={{ recipe_path.display() }}

{%- if let Some(repo_owner) = self::get_github_repo_owner() %}
ARG IMAGE_REGISTRY=ghcr.io/{{ repo_owner }}
{%- else if let Some(registry) = self::get_gitlab_registry_path() %}
ARG IMAGE_REGISTRY={{ registry }}
{%- else %}
ARG IMAGE_REGISTRY=localhost
{%- endif %}

{%- if self::has_cosign_file() %}
ARG IMAGE_REGISTRY=ghcr.io/ublue-os
COPY cosign.pub /usr/share/ublue-os/cosign.pub
{%- endif %}

Expand Down

0 comments on commit aab4c00

Please sign in to comment.