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: add data uri scheme encoding as valid source #313

Closed

Conversation

MatthewDolan
Copy link

Proposed Solution (2.b.) from #310.

Example Usage

Without additional sources:

example_config=$(cat <<EOF
description = "Description for example"
binaries = ["example"]
channel "unstable" {
 update = "5m"
 source = "git@github.com:cashapp/example.git#$EXAMPLE_VERSION"
}
EOF
)

override_sources=$(cat <<EOF
{"example": $(echo "$example_config" | jq -R -s '.')}
EOF
)

override_uri="data:application/json;base64,$(echo "$override_sources" | base64)"

HERMIT_ADDITIONAL_SOURCES="$override_uri" hermit ...

Example URI

> echo "$override_uri"
data:application/json;base64,eyJleGFtcGxlIjogImRlc2NyaXB0aW9uID0gXCJEZXNjcmlwdGlvbiBmb3IgZXhhbXBsZVwiCmJpbmFyaWVzID0gW1wiZXhhbXBsZVwiXQpjaGFubmVsIFwidW5zdGFibGVcIiB7CiB1cGRhdGUgPSBcIjVtXCIKIHNvdXJjZSA9IFwiZ2l0QGdpdGh1Yi5jb206Y2FzaGFwcC9leGFtcGxlLmdpdCNtYWluXCIKfQoifQo

@MatthewDolan MatthewDolan changed the title feat: 🖥 add data uri scheme encoding as valid source feat: add data uri scheme encoding as valid source Sep 7, 2022
@alecthomas
Copy link
Collaborator

alecthomas commented Sep 13, 2022

Hi sorry I took so long to respond!

I don't like the ergonomics of this 😢 - it is objectively not an improvement over creating a temporary directory, which is a similar amount of shell, more straightforward, and already works:

tmpsource="$(mktemp -d)"
trap 'rm -rf "${tmpsource}"' EXIT INT ERR
cat  > "$tmpsource/example.hcl" <<EOF
description = "Description for example"
binaries = ["example"]
channel "unstable" {
 update = "5m"
 source = "git@github.com:cashapp/example.git#$EXAMPLE_VERSION"
}
EOF
export HERMIT_ADDITIONAL_SOURCES="file://${tmpsource}"

I wonder though, if the most common case isn't overriding a single package? If that is true, we could have a dedicated envar for a single package. Something like:

export HERMIT_PACKAGE_OVERRIDE='
name = "example"
description = "Description for example"
binaries = ["example"]
channel "unstable" {
 update = "5m"
 source = "git@github.com:cashapp/example.git#$EXAMPLE_VERSION"
}
'

We could add an extra, optional, name attribute to a package to simplify how this is represented.

@alecthomas
Copy link
Collaborator

Another idea; introduce an additional higher-level HCL block specifically for this mechanism eg.

export HERMIT_PACKAGE_OVERRIDES='
package example {
  description = "Description for example"
  binaries = ["example"]
  channel "unstable" {
    update = "5m"
    source = "git@github.com:cashapp/example.git#$EXAMPLE_VERSION"
  }
}
'

@MatthewDolan
Copy link
Author

Another idea; introduce an additional higher-level HCL block specifically for this mechanism eg.

I like this idea the best! It's concise, readable, and doesn't require editing disk.

If I find a free moment, I will prototype something up. It's a little more than trivial because some of the code separation expects map[string]string so either I need to parse and then un-parse the hcl or I need to move some interfaces around.

@MatthewDolan
Copy link
Author

After further thought, I agree that this is the right path forward.

#313 (comment)

Closing the PR for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants