fix: Use different mount options based on build engine
This commit is contained in:
parent
a7d862abf0
commit
2a1cab3598
7 changed files with 43 additions and 6 deletions
1
integration-tests/test-repo/.gitignore
vendored
1
integration-tests/test-repo/.gitignore
vendored
|
|
@ -2,3 +2,4 @@
|
||||||
/Containerfile.*
|
/Containerfile.*
|
||||||
/.bluebuild*
|
/.bluebuild*
|
||||||
/secrets
|
/secrets
|
||||||
|
/.bluebuild-scripts_*
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ use log::{debug, info, trace, warn};
|
||||||
use miette::{IntoDiagnostic, Result};
|
use miette::{IntoDiagnostic, Result};
|
||||||
use oci_distribution::Reference;
|
use oci_distribution::Reference;
|
||||||
|
|
||||||
use crate::commands::validate::ValidateCommand;
|
use crate::{DriverTemplate, commands::validate::ValidateCommand};
|
||||||
|
|
||||||
use super::BlueBuildCommand;
|
use super::BlueBuildCommand;
|
||||||
|
|
||||||
|
|
@ -175,6 +175,7 @@ impl GenerateCommand {
|
||||||
.base_digest(base_digest)
|
.base_digest(base_digest)
|
||||||
.maybe_nushell_version(recipe.nushell_version.as_ref())
|
.maybe_nushell_version(recipe.nushell_version.as_ref())
|
||||||
.build_features(build_features)
|
.build_features(build_features)
|
||||||
|
.build_engine(Driver::get_build_driver().build_engine())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let output_str = template.render().into_diagnostic()?;
|
let output_str = template.render().into_diagnostic()?;
|
||||||
|
|
|
||||||
15
src/lib.rs
15
src/lib.rs
|
|
@ -8,6 +8,8 @@ use std::{
|
||||||
os::unix::fs::PermissionsExt,
|
os::unix::fs::PermissionsExt,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use blue_build_process_management::drivers::types::BuildDriverType;
|
||||||
|
use blue_build_template::BuildEngine;
|
||||||
use blue_build_utils::constants::{BLUE_BUILD_SCRIPTS_DIR_IGNORE, GITIGNORE_PATH};
|
use blue_build_utils::constants::{BLUE_BUILD_SCRIPTS_DIR_IGNORE, GITIGNORE_PATH};
|
||||||
use miette::{Context, IntoDiagnostic, Result, miette};
|
use miette::{Context, IntoDiagnostic, Result, miette};
|
||||||
use rust_embed::Embed;
|
use rust_embed::Embed;
|
||||||
|
|
@ -17,6 +19,19 @@ pub mod commands;
|
||||||
|
|
||||||
shadow_rs::shadow!(shadow);
|
shadow_rs::shadow!(shadow);
|
||||||
|
|
||||||
|
pub(crate) trait DriverTemplate {
|
||||||
|
fn build_engine(&self) -> BuildEngine;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DriverTemplate for BuildDriverType {
|
||||||
|
fn build_engine(&self) -> BuildEngine {
|
||||||
|
match self {
|
||||||
|
Self::Buildah | Self::Podman => BuildEngine::Oci,
|
||||||
|
Self::Docker => BuildEngine::Docker,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Embed)]
|
#[derive(Embed)]
|
||||||
#[folder = "scripts/"]
|
#[folder = "scripts/"]
|
||||||
pub(crate) struct BuildScripts;
|
pub(crate) struct BuildScripts;
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,12 @@ use uuid::Uuid;
|
||||||
|
|
||||||
pub use askama::Template;
|
pub use askama::Template;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub enum BuildEngine {
|
||||||
|
Oci,
|
||||||
|
Docker,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Template, Builder)]
|
#[derive(Debug, Clone, Template, Builder)]
|
||||||
#[template(path = "Containerfile.j2", escape = "none", whitespace = "minimize")]
|
#[template(path = "Containerfile.j2", escape = "none", whitespace = "minimize")]
|
||||||
pub struct ContainerFileTemplate<'a> {
|
pub struct ContainerFileTemplate<'a> {
|
||||||
|
|
@ -31,6 +37,7 @@ pub struct ContainerFileTemplate<'a> {
|
||||||
|
|
||||||
#[builder(default)]
|
#[builder(default)]
|
||||||
build_features: &'a [String],
|
build_features: &'a [String],
|
||||||
|
build_engine: BuildEngine,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ContainerFileTemplate<'_> {
|
impl ContainerFileTemplate<'_> {
|
||||||
|
|
@ -56,6 +63,17 @@ impl ContainerFileTemplate<'_> {
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join(",")
|
.join(",")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn scripts_mount(&self, dest: &str) -> String {
|
||||||
|
format!(
|
||||||
|
"--mount=type=bind,src={},dst={dest},{}",
|
||||||
|
self.build_scripts_dir.display(),
|
||||||
|
match self.build_engine {
|
||||||
|
BuildEngine::Oci => "Z",
|
||||||
|
BuildEngine::Docker => "ro",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Template, Builder)]
|
#[derive(Debug, Clone, Template, Builder)]
|
||||||
|
|
|
||||||
|
|
@ -40,12 +40,14 @@ RUN --mount=type=bind,from={{ blue_build_utils::constants::NUSHELL_IMAGE }}:{{ g
|
||||||
&& cp -r /tmp/nu/* /usr/libexec/bluebuild/nu/
|
&& cp -r /tmp/nu/* /usr/libexec/bluebuild/nu/
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
RUN --mount=type=bind,src={{ build_scripts_dir.display() }},dst=/scripts/ \
|
RUN \
|
||||||
|
{{ scripts_mount("/scripts/") }} \
|
||||||
/scripts/pre_build.sh
|
/scripts/pre_build.sh
|
||||||
|
|
||||||
{% call modules::main_modules_run(recipe.modules_ext, os_version) %}
|
{% call modules::main_modules_run(recipe.modules_ext, os_version) %}
|
||||||
|
|
||||||
RUN --mount=type=bind,src={{ build_scripts_dir.display() }},dst=/scripts/ \
|
RUN \
|
||||||
|
{{ scripts_mount("/scripts/") }} \
|
||||||
/scripts/post_build.sh
|
/scripts/post_build.sh
|
||||||
|
|
||||||
# Labels are added last since they cause cache misses with buildah
|
# Labels are added last since they cause cache misses with buildah
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ RUN \
|
||||||
{%- if module.module_type.typ() == "akmods" %}
|
{%- if module.module_type.typ() == "akmods" %}
|
||||||
--mount=type=bind,from=stage-akmods-{{ module.generate_akmods_info(os_version).stage_name }},src=/rpms,dst=/tmp/rpms,rw \
|
--mount=type=bind,from=stage-akmods-{{ module.generate_akmods_info(os_version).stage_name }},src=/rpms,dst=/tmp/rpms,rw \
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
--mount=type=bind,src={{ build_scripts_dir.display() }},dst=/tmp/scripts/ \
|
{{ scripts_mount("/tmp/scripts/") }} \
|
||||||
--mount=type=cache,dst=/var/cache/rpm-ostree,id=rpm-ostree-cache-{{ recipe.name }}-{{ recipe.image_version }},sharing=locked \
|
--mount=type=cache,dst=/var/cache/rpm-ostree,id=rpm-ostree-cache-{{ recipe.name }}-{{ recipe.image_version }},sharing=locked \
|
||||||
--mount=type=cache,dst=/var/cache/libdnf5,id=dnf-cache-{{ recipe.name }}-{{ recipe.image_version }},sharing=locked \
|
--mount=type=cache,dst=/var/cache/libdnf5,id=dnf-cache-{{ recipe.name }}-{{ recipe.image_version }},sharing=locked \
|
||||||
{%- for secret_var in module.secrets.envs() %}
|
{%- for secret_var in module.secrets.envs() %}
|
||||||
|
|
@ -78,7 +78,7 @@ RUN \
|
||||||
{%- else %}
|
{%- else %}
|
||||||
--mount=type=bind,from={{ module.get_module_image() }},src=/modules,dst=/tmp/modules,rw \
|
--mount=type=bind,from={{ module.get_module_image() }},src=/modules,dst=/tmp/modules,rw \
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
--mount=type=bind,src={{ build_scripts_dir.display() }},dst=/tmp/scripts/ \
|
{{ scripts_mount("/tmp/scripts/") }} \
|
||||||
{%- for secret_var in module.secrets.envs() %}
|
{%- for secret_var in module.secrets.envs() %}
|
||||||
{{ secret_var }} \
|
{{ secret_var }} \
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ COPY --from={{ blue_build_utils::constants::NUSHELL_IMAGE }}:{{ get_nu_version()
|
||||||
|
|
||||||
# Add compatibility for modules
|
# Add compatibility for modules
|
||||||
RUN --mount=type=bind,from=stage-bins,src=/bins/,dst=/tmp/bins/ \
|
RUN --mount=type=bind,from=stage-bins,src=/bins/,dst=/tmp/bins/ \
|
||||||
--mount=type=bind,src={{ build_scripts_dir.display() }},dst=/tmp/scripts/ \
|
{{ scripts_mount("/tmp/scripts/") }} \
|
||||||
/tmp/scripts/setup.sh
|
/tmp/scripts/setup.sh
|
||||||
|
|
||||||
{%- if self::config_dir_exists() %}
|
{%- if self::config_dir_exists() %}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue