Replies: 42 comments 1 reply
-
/cc @jeremyeder |
Beta Was this translation helpful? Give feedback.
-
This is an awesome suggestion! I wrote a tool which utilizes buildah for building images (and ansible as a frontend) and I had to solve the same issue: caching layers. It would be awesome if buildah had an API for caching. On the other hand, it will be really tricky because you would need to tell buildah up front what the script is and how are you changing the filesystem and then buildah would need to figure out if there is a matching entry in the cache. |
Beta Was this translation helpful? Give feedback.
-
@umohnani8 What do you think? Would this even be possible. We might be able to figure out that buildah from fedora Also how would we know that two buildah from fedora calls were related? |
Beta Was this translation helpful? Give feedback.
-
I guess that any of those
|
Beta Was this translation helpful? Give feedback.
-
@umohnani8 Any update on this issue? |
Beta Was this translation helpful? Give feedback.
-
@QiWang19 Can you look into this? |
Beta Was this translation helpful? Give feedback.
-
I'm very interested in this concept, great idea |
Beta Was this translation helpful? Give feedback.
-
@zvonkok and @gcs278 PRs would make this move along faster... |
Beta Was this translation helpful? Give feedback.
-
unbaked thought: could a design like redo be a good fit? A core idea of There are multiple implementations of redo, recording dependencies in different ways; each puts its own
But maybe a contract like "I'm doing whatever I want with So if we want a flat script, how would a script with arbitrary bash steps skip those steps? Maybe a 2-directional contract, with a buildah command reporting info on cache hit/miss? BTW, is it technically possible for buildah to "fast forward" the same container from current state to a an image found in cache? Or would we need |
Beta Was this translation helpful? Give feedback.
-
@cben interested in opening a PR for this? |
Beta Was this translation helpful? Give feedback.
-
I was also looking into this cache idea and actually spent some time playing about with That said, I think for
Using RedoThe short time I used
With this information, you can split a NAME=stage-name # could be random but keep in mind the lingering images
OUTPUT=$3
CONTAINER=$(buildah from fedora)
# do buildah steps
buildah commit $CONTAINER $NAME
echo $NAME > $OUTPUT This, in itself, is a do file, though it could also be written generically:
and the accompanying build instructions:
A stage leaves behind a file containing the output it made, in Built in supportInstead of relying on an external tool (although a tool that has many implementations and is not difficult to obtain),
The process of how it works:
So as an example: export CACHEFILE=.mybuild
buildah from fedora # saves its details (or hash of these details) and fedora. Also creates .mybuild.fedora-working-container
buildah run $CONTAINER -- yum install nginx # saves its details and advances the pointer
buildah copy $CONTAINER www /var/www # saves its details (including hash of the content it copied) and advances pointer
buildah commit end-image # saves its details and also end-image Now the same thing is executed again: export CACHEFILE=.mybuild
buildah from fedora # recognizes the start of .mybuild
buildah run $CONTAINER -- yum install nginx # recognizes the command hasn't changed and moves pointer
buildah copy $CONTAINER www/ /var/www # if www hasn't changed, recognizes and moves pointer
buildah commit second-image # recognizes end-image and recommits it as second-image It must be noted, if export CACHEFILE=.mybuild
buildah from fedora
buildah run --add-history $CONTAINER -- yum install nginx # now becomes a saved point
buildah copy $CONTAINER www/ /var/www # now if this changes, it can continue from after yum install nginx
buildah commit third-image With this system, even if instructions diverge, this creates multiple alternative paths that can still resolve to a saved image. |
Beta Was this translation helpful? Give feedback.
-
Note that the |
Beta Was this translation helpful? Give feedback.
-
It might also be noted that for the If the user wants to speed up its rebuild, they should also apply strategic uses of |
Beta Was this translation helpful? Give feedback.
-
Lastly, if this addition to |
Beta Was this translation helpful? Give feedback.
-
Sounds good, I don't know when we can get someone else to look at it. |
Beta Was this translation helpful? Give feedback.
-
A friendly reminder that this issue had no activity for 30 days. |
Beta Was this translation helpful? Give feedback.
-
A friendly reminder that this issue had no activity for 30 days. |
Beta Was this translation helpful? Give feedback.
-
A friendly reminder that this issue had no activity for 30 days. |
Beta Was this translation helpful? Give feedback.
-
A friendly reminder that this issue had no activity for 30 days. |
Beta Was this translation helpful? Give feedback.
-
@flouthoc PTAL |
Beta Was this translation helpful? Give feedback.
-
A friendly reminder that this issue had no activity for 30 days. |
Beta Was this translation helpful? Give feedback.
-
@kwshi @dsonck92 I have a different perspective to solution for this issue. So i am just posting it here. Could you guys please go through it and give your thoughts
Working of Build-from-bash
So
TLDR: CONS: |
Beta Was this translation helpful? Give feedback.
-
If buildah currently caches At least, that's what I'm getting from your For me, the original feature is not that important anymore, since I'm generating all my files inside a container inside CI, and only require a single copy into the final container, the CI has some caching capabilities. But I do think an intermediate containerfile generator could help. |
Beta Was this translation helpful? Give feedback.
-
Translating a bash script directly to Containerfile syntax is not feasible because of the complexity available with a full scripting language (if statements, for loops, external commands, etc...). If your bash script is simplistic enough that it can be translated to a Containerfile then you might as well write it in Containerfile syntax to start. The benefit to bash scripts is the additional flexibility not expressible using Containerfile syntax. A Containerfile generator is a great in between idea. Not as flexible as using a full bash script, but a lot more flexible than a static Containerfile. Something like that would be useful in a lot of cases. That said, it seems to me that a generator like that should probably be a separate project instead of part of buildah. |
Beta Was this translation helpful? Give feedback.
-
The original comment mentioned this:
How would this look like in practice? |
Beta Was this translation helpful? Give feedback.
-
@rhatdan I'm guessing you were the "Dan" mentioned in the original issue. Could you provide some more information on how to achieve this with
|
Beta Was this translation helpful? Give feedback.
-
I was guessing something like:
|
Beta Was this translation helpful? Give feedback.
-
The problem with this seems to me that it does not use the cache at all if this is used in a sequential manner such as a bash script. It will always create a container from What I would be looking for is a mechanism to skip the run steps if |
Beta Was this translation helpful? Give feedback.
-
You are correct this has never been implemented. Only the Caching for Containerfile exists. This discussion has always been about a mechanism to build a generate bash version of caching. |
Beta Was this translation helpful? Give feedback.
-
Just for some additional information, I'm currently using an approach pretty much exactly like @rhatdan outlined above. Each layer of my container is built in a separate bash function. The beginning of the function checks if the previous layer exists, and if not, builds it. The end of the function commits the current layer. #!/bin/sh
build_base() {
local dev=$(buildah from fedora)
# ... do stuff with $dev here
buildah commit $dev "base_image"
buildah rm $dev
}
build_next() {
buildah images "base_image" >/dev/null 2>&1 || build_base
local dev=$(buildah from "base_image")
# ... build the next layer
buildah commit $dev "next_image"
buildah rm $dev
}
# Control which layer to build based on the argument passed
[ "$1" = "base" ] && { build_base; exit; }
[ "$1" = "next" ] && { build_next; exit; }
# By default build the final layer
build_next This approach gives you caching, but it is a bit cumbersome. Maybe if buildah supported a |
Beta Was this translation helpful? Give feedback.
-
Description
Buildah can use cache/layers for building with
buildah bud
(#767). It would be beneficial if buildah could use a cache/layers for bash builds as well. I am using bash builds extensively as there are more convenient/useful for all of my use-cases.Dan mentioned that I could use commits in-between and base off the next step of them.
Nice idea but I think this will clutter up the script and the signal-to-noise ratio would be rather high.
BTW using bash scripts to build the images is/was a great idea, this way I can use everything, really everything as a tool that I can install on my Linux and I am not tied to a DSL that I cannot extend or is limited.
Describe the results you received:
Executing the buildah script a second time, buildah executes each step again.
Describe the results you expected:
Skip steps that did not change compared to the last invocation of the script.
Output of
rpm -q buildah
orapt list buildah
:Output of
buildah version
:Beta Was this translation helpful? Give feedback.
All reactions