Using dhall to modify container image definition #71
Replies: 4 comments 1 reply
-
To fix your immediate issue I suggest you use env PODENV="$(podenv --dhall-env)" dhall <<< '(env:PODENV).Hub.fedora.latest.use ["gnome-tweaks"]' ... which should display: < Container :
{ containerfile : Text
, image_home : Optional Text
, image_name : Optional Text
, image_update : Optional Text
, image_volumes : List Text
}
| Image : Text
| Nix : Text
>.Container
{ containerfile =
''
FROM registry.fedoraproject.org/fedora:latest
ARG USER_UID
RUN useradd -u ''${USER_UID} -d /home/fedora -m fedora && mkdir -p /home/fedora/.cache /home/fedora/.config /run/user/''${USER_UID} /run/user/0 && chown -R ''${USER_UID}:''${USER_UID} /home/fedora /run/user/
RUN dnf update -y
RUN dnf install -y gnome-tweaks
''
, image_home = Some "/home/fedora"
, image_name = None Text
, image_update = Some "dnf update -y"
, image_volumes = [ "cache-dnf-latest:/var/cache/dnf" ]
} Now to understand how to tweak the runtime, here are some notes about the dhall language: let bindingsThe error you get is because let greeting = "Hello"
let name = "alice"
in greeting ++ " " ++ name The whole let gretting =
let name = "alice"
in "Hello " ++ name
let mark = "!"
in greeting ++ mark ... which is equivalent to ImportsExpression can be imported using url, environment or files. When using podenv, the $ podenv --dhall-env
https://raw.githubusercontent.com/podenv/hub/41c0711660bb9baa169f761a48bc04d23a4f484b/package.dhall sha256:<semantic-hash> It is quite convenient to be able to follow how the imports are resolved, so let's track where So Functions
-- | add is a function that takes a natural `x` and returns a function that takes another natural `y`
-- that will return `x + y`
let add = \(x : Natural) -> \(y : Natural) -> x + y
-- | add2 provides the first argument of add, resulting in a function that expects a natural `y`, and
-- add2 will returns `2 + y`
let add2 = add 2
in add2 40 ... which is equivalent to So when you write And here is the actual definition of As you can see in that last link, the image definition is rather simple, it just let you run extra steps before doing the package install, which happens to be enough for the current hub usage. I am not sure what you mean by |
Beta Was this translation helpful? Give feedback.
-
Another solution for your example is to use the (env:PODENV).Hub.fedora.useSimple "gnome-tweaks" "Gnome tweaks"
with capabilities = {
, dbus = True
, dri = True
, pipewire = True
, wayland = True
} Here is a bit more information about dhall record: record with attribute = valueIt is often necessary to override an attribute of a record, for example to set the capabilities of an existing application. let person = { name = "alice", friend = "bob" }
in person with friend = "eve" ... is equivalent to record1
|
Beta Was this translation helpful? Give feedback.
-
You are welcome, I hope this is useful :-) Ok I understand what you want. So Thus we can define a function to modify that record. For example here is a function that takes an extra_after Text command, an image ContainerBuild record, and it returns a new ContainerBuild: \(extra_after : Text) ->
\(image : (env:Podenv).ContainerBuild.Type) ->
image with containerfile = image.containerfile ++ extra_after ++ "\n" Which you can use like this: let Podenv = env:PODENV
let add_final_task =
\(extra_after : Text) ->
\(image : Podenv.ContainerBuild.Type) ->
image with containerfile = image.containerfile ++ extra_after ++ "\n"
let container =
\(packages : List Text) ->
let extra_before =
''
RUN command 1
''
let extra_after =
''
RUN command 2
''
let image = Podenv.Hub.fedora.useImage "latest" extra_before packages
in Podenv.Container (add_final_task extra_after image)
in Podenv.Application::{
, description = Some "Gnome tweaks"
, runtime = container [ "gnome-tweaks" ]
, command = [ "gnome-tweaks" ]
, capabilities = Podenv.Capabilities::{
, dbus = True
, dri = True
, pipewire = True
, wayland = True
}
} And if you put that expression in a file named
|
Beta Was this translation helpful? Give feedback.
-
For completeness, note that you can also provide your own ContainerBuild record without using the one provided by the fedora let Podenv = env:PODENV
let Text/concatSep =
https://prelude.dhall-lang.org/v17.0.0/Text/concatSep sha256:e4401d69918c61b92a4c0288f7d60a6560ca99726138ed8ebc58dca2cd205e58
let container =
\(packages : List Text) ->
let extra_before =
''
RUN command 1
''
let extra_after =
''
RUN command 2
''
let image =
Podenv.ContainerBuild::{
, containerfile =
''
FROM registry.fedoraproject.org/fedora:latest
ARG USER_UID
RUN useradd -u ''${USER_UID} -d /home/fedora -m fedora && mkdir -p /home/fedora/.cache /home/fedora/.config /run/user/''${USER_UID} /run/user/0 && chown -R ''${USER_UID}:''${USER_UID} /home/fedora /run/user/
${extra_before}
RUN dnf update -y
RUN dnf install -y ${Text/concatSep " " packages}
${extra_after}
''
, image_home = Some "/home/fedora"
, image_update = Some "dnf update -y"
, image_volumes = [ "cache-dnf-latest:/var/cache/dnf" ]
}
in Podenv.Container image
in Podenv.Application::{
, description = Some "Gnome tweaks"
, runtime = container [ "gnome-tweaks" ]
, command = [ "gnome-tweaks" ]
, capabilities = Podenv.Capabilities::{
, dbus = True
, dri = True
, pipewire = True
, wayland = True
}
} As a matter of fact, you can use dhall semantic hash to verify the two versions are identicals, for example running: env PODENV="$(podenv --dhall-env)" dhall hash --file ./tweaks.dhall ... shall display |
Beta Was this translation helpful? Give feedback.
-
Hi, Thanks for your help in #64
I'm new to dhall so still trying to get my head around it.
Would you be able to advise on the recommended way of extending existing image without the need for extra argument ?
Currently I'm getting around it by specifying empty
RUN echo
as shown below:But when I remove the extra bit it throws:
Also it would be great to understand how to extend it multiple times AKA:
RUN command
RUN command
again.Beta Was this translation helpful? Give feedback.
All reactions