Every individual RUN, COPY and ADD action creates an extra container layer, so there was plenty of room for improvement in our Containerfile. This optimization gets rid of 4 useless layers from our final container image, and shrinks the final OCI download size as follows: - Removing the "mkdir /tmp/scripts" layer. It's not necessary to manually create the target directory for the container copy action. - Removing the manual "chmod +x" for the scripts, and putting that step inside "build.sh" instead. - Removing the manual copying of "build.sh", by instead placing it at "scripts/build.sh" so that it's automatically copied together with all the other scripts in one layer instead. - Removing the separate "chmod +x build.sh && run build script" step by merging it with the "cleanup temp files and then finalize the container" step, so that we don't create a pointless extra filesystem layer just for the build.sh script execution. These changes also reduce the size of the final image, because we're cleaning up the image in the exact same step that we run the "build.sh". If we didn't combine these steps, we'd still be keeping a useless extra layer with all the /tmp/ and /var/ junk files that were left over after the build. Most seriously, the "/var/cache" folder contained copies of ALL RPM FILES that build.sh installed via "rpm-ostree install". This meant that we were generating a very big layer with a lot of junk data that shipped in the final image. Our build now only generates 7 layers (instead of 11), and users will have a much smaller OCI download since we aren't shipping the cached RPM "build leftovers" or temp files via useless extra layers anymore.
31 lines
1.2 KiB
Docker
31 lines
1.2 KiB
Docker
ARG FEDORA_MAJOR_VERSION=38
|
|
ARG BASE_IMAGE_URL=ghcr.io/ublue-os/silverblue-main
|
|
|
|
FROM ${BASE_IMAGE_URL}:${FEDORA_MAJOR_VERSION}
|
|
ARG RECIPE
|
|
|
|
# Copy static configurations and component files.
|
|
# Warning: If you want to place anything in "/etc" of the final image, you MUST
|
|
# place them in "./usr/etc" in your repo, so that they're written to "/usr/etc"
|
|
# on the final system. That is the proper directory for "system" configuration
|
|
# templates on immutable Fedora distros, whereas the normal "/etc" is ONLY meant
|
|
# for manual overrides and editing by the machine's admin AFTER installation!
|
|
# See issue #28 (https://github.com/ublue-os/startingpoint/issues/28).
|
|
COPY usr /usr
|
|
|
|
# Copy the recipe that we're building.
|
|
COPY ${RECIPE} /usr/share/ublue-os/recipe.yml
|
|
|
|
# "yq" used in build.sh and the "setup-flatpaks" just-action to read recipe.yml.
|
|
# Copied from the official container image since it's not available as an RPM.
|
|
COPY --from=docker.io/mikefarah/yq /usr/bin/yq /usr/bin/yq
|
|
|
|
# Copy the build script and all custom scripts.
|
|
COPY scripts /tmp/scripts
|
|
|
|
# Run the build script, then clean up temp files and finalize container build.
|
|
RUN chmod +x /tmp/scripts/build.sh && \
|
|
/tmp/scripts/build.sh && \
|
|
rm -rf /tmp/* /var/* && \
|
|
ostree container commit
|