particle-os-cli/template/templates/Containerfile.j2
Gerald Pinder a7d862abf0
feat: Embed build scripts and extract into temp dir for build (#516)
This decouples the need for a published image for the bulid scripts and
will now embed them into the binary instead. This will make it so that
anyone that forks the CLI is able to make adjustments to the build
scripts and use them immediately.

This will be needed for testing #515
2025-08-10 16:09:42 -04:00

59 lines
2.1 KiB
Django/Jinja

{%- import "modules/modules.j2" as modules -%}
{%- include "stages.j2" %}
{%- set main_stage = recipe.name|replace('/', "-") %}
# Main image
FROM {{ recipe.base_image }}@{{ base_digest }} AS {{ main_stage }}
ARG RECIPE={{ recipe_path.display() }}
ARG IMAGE_REGISTRY={{ registry }}
ARG BB_BUILD_FEATURES="{{ get_features() }}"
{%- if self::config_dir_exists() && !self::files_dir_exists() %}
ARG CONFIG_DIRECTORY="/tmp/config"
{%- else %}
ARG CONFIG_DIRECTORY="/tmp/files"
{%- endif %}
ARG MODULE_DIRECTORY="/tmp/modules"
ARG IMAGE_NAME="{{ recipe.name }}"
ARG BASE_IMAGE="{{ recipe.base_image }}"
{%- if self::should_color() %}
ARG FORCE_COLOR=1
ARG CLICOLOR_FORCE=1
ARG RUST_LOG_STYLE=always
{%- endif %}
# Key RUN
RUN --mount=type=bind,from=stage-keys,src=/keys,dst=/tmp/keys \
mkdir -p /etc/pki/containers/ \
&& cp /tmp/keys/* /etc/pki/containers/
# Bin RUN
RUN --mount=type=bind,from=stage-bins,src=/bins,dst=/tmp/bins \
mkdir -p /usr/bin/ \
&& cp /tmp/bins/* /usr/bin/
{%- if should_install_nu() %}
RUN --mount=type=bind,from={{ blue_build_utils::constants::NUSHELL_IMAGE }}:{{ get_nu_version() }},src=/nu,dst=/tmp/nu \
mkdir -p /usr/libexec/bluebuild/nu \
&& cp -r /tmp/nu/* /usr/libexec/bluebuild/nu/
{%- endif %}
RUN --mount=type=bind,src={{ build_scripts_dir.display() }},dst=/scripts/ \
/scripts/pre_build.sh
{% call modules::main_modules_run(recipe.modules_ext, os_version) %}
RUN --mount=type=bind,src={{ build_scripts_dir.display() }},dst=/scripts/ \
/scripts/post_build.sh
# Labels are added last since they cause cache misses with buildah
LABEL {{ blue_build_utils::constants::BUILD_ID_LABEL }}="{{ build_id }}"
LABEL org.opencontainers.image.title="{{ recipe.name }}"
LABEL org.opencontainers.image.description="{{ recipe.description }}"
LABEL org.opencontainers.image.source="{{ repo }}"
LABEL org.opencontainers.image.base.digest="{{ base_digest }}"
LABEL org.opencontainers.image.base.name="{{ recipe.base_image }}:{{ recipe.image_version }}"
LABEL org.opencontainers.image.created="{{ self::current_timestamp() }}"
LABEL io.artifacthub.package.readme-url=https://raw.githubusercontent.com/blue-build/cli/main/README.md