Skip to content
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

feat: Use Multi-stage builds to prevent COPY for modules and config #54

Merged
merged 5 commits into from
Feb 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions templates/Containerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# This stage is responsible for holding onto
# your config without copying it directly into
# the final image
FROM scratch as stage-config
COPY ./config /config

# Copy modules
# The default modules are inside ublue-os/bling
# Custom modules overwrite defaults
FROM scratch as stage-modules
COPY --from=ghcr.io/ublue-os/bling:latest /modules /modules
COPY ./modules /modules

# This stage is responsible for holding onto
# exports like the exports.sh
FROM docker.io/alpine as stage-exports
RUN printf {{ self::print_script(export_script) }} >> /exports.sh && chmod +x /exports.sh

FROM {{ recipe.base_image }}:{{ recipe.image_version }}

LABEL org.opencontainers.image.title="{{ recipe.name }}"
Expand Down Expand Up @@ -29,16 +47,6 @@ COPY --from=ghcr.io/blue-build/cli:
latest-installer
{%- endif %} /out/bluebuild /usr/bin/bluebuild

COPY config /tmp/config/

# Copy modules
# The default modules are inside ublue-os/bling
COPY --from=ghcr.io/ublue-os/bling:latest /modules /tmp/modules/
# Custom modules overwrite defaults
COPY modules /tmp/modules/

RUN printf {{ self::print_script(export_script) }} >> /tmp/exports.sh && chmod +x /tmp/exports.sh

ARG CONFIG_DIRECTORY="/tmp/config"
ARG IMAGE_NAME="{{ recipe.name }}"
ARG BASE_IMAGE="{{ recipe.base_image }}"
Expand All @@ -63,7 +71,12 @@ COPY {{ src }} {{ dest }}
{%- endfor %}
{%- endif %}
{%- else %}
RUN chmod +x /tmp/modules/{{ type }}/{{ type }}.sh && source /tmp/exports.sh && /tmp/modules/{{ type }}/{{ type }}.sh '{{ self::print_module_context(module) }}'
RUN \
--mount=type=bind,from=stage-config,src=/config,dst=/tmp/config,rw \
--mount=type=bind,from=stage-modules,src=/modules,dst=/tmp/modules,rw \
--mount=type=bind,from=stage-exports,src=/exports.sh,dst=/tmp/exports.sh \
chmod +x /tmp/modules/{{ type }}/{{ type }}.sh \
&& source /tmp/exports.sh && /tmp/modules/{{ type }}/{{ type }}.sh '{{ self::print_module_context(module) }}'
{%- endif %}
{%- endif %}
{%- endfor %}
Expand Down