expose package metadata to mutate scripts

未关闭
#337 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
18/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
go
领域
tooling

调研方向

This is a design proposal, not a ready change. Read the description of the mutate script environment, where content is the only predeclared input, and the proposed PackageInfo fields (name, version, arch, control). Done means the maintainers settle whether a load()-based module is acceptable, given the closed #40 precedent for re.star. Do not start an implementation until that decision is made.

由索引模型根据 Issue 内容生成。

描述

low priority enhancement idea

context

a mutate script sometimes needs facts about the package it is slicing that are not in the rootfs as a file: its version or its architecture. today the only input a script has is content, so it has to recover those facts from file names.

concrete case, rabbitmq-server 4.3.2 on 26.10 (canonical/chisel-releases#1428). the debian wrapper at /usr/lib/rabbitmq/bin/rabbitmq-script-wrapper finds the plugins directory at run time with

RB_VERSION=$(dpkg-query -W rabbitmq-server | awk '{print $2}' | cut -d- -f1)
export RABBITMQ_PLUGINS_DIR=/usr/lib/rabbitmq/lib/rabbitmq_server-${RB_VERSION}/plugins

a chiselled rootfs has no dpkg database, so the slice patches the version in at cut time. to get the version the mutate lists /usr/lib/rabbitmq/lib/, strips the rabbitmq_server- prefix and the trailing slash and fails if there is not exactly one match:

prefix = "rabbitmq_server-"
dirs = content.list("/usr/lib/rabbitmq/lib/")
versions = [d[len(prefix):-1] for d in dirs if d.startswith(prefix)]
if len(versions) != 1:
  fail("expected one rabbitmq_server directory, found %s" % versions)

proposal

let a mutate script ask for the package's metadata explicitly.

concrete proposal

use starlark's own module mechanism rather than more predeclared names:

load("deb.star", "deb")

content.write(wrapper, script.replace(dpkg_line, deb.version))

with deb a starlarkstruct.Module built from the slice's PackageInfo, e.g.

  • deb.name, deb.version, deb.arch: the strings chisel selected the package by
  • deb.control: the parsed control stanza as a dict, so deb.control["Depends"] and friends come for free without picking fields one by one

load() keeps the default namespace at content only, so existing scripts see no change, and a script that uses the module says so on its first line. the module is read-only data; nothing about what a script may read or write in the rootfs changes.

prior art

  • #40 proposed a re.star module through load() in 2023 and was closed
主要语言
Go
星标
434
派生
74
平均合并
1 天 30 分钟
30 天内合并 PR
1

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

canonical/chisel 的其他 Issue

查看 canonical/chisel 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。