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

remove mise binary from final image #7

Merged
merged 4 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions core/generate/__snapshots__/context_test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,13 @@
"name": "MISE_CACHE_DIR",
"value": "/mise/cache"
},
{
"path": "/mise/shims"
},
{
"caches": [
"apt",
"apt-lists"
],
"cmd": "sh -c 'apt-get update \u0026\u0026 apt-get install -y ca-certificates curl'",
"customName": "install apt packages: ca-certificates curl"
"cmd": "sh -c 'apt-get update \u0026\u0026 apt-get install -y ca-certificates curl git'",
"customName": "install apt packages: ca-certificates curl git"
},
{
"caches": [
Expand All @@ -77,6 +74,15 @@
],
"cmd": "sh -c 'mise trust -a \u0026\u0026 mise install'",
"customName": "install mise packages: go, node, python"
},
{
"path": "/mise/installs/go/1.23.5/bin"
},
{
"path": "/mise/installs/node/20.18.2/bin"
},
{
"path": "/mise/installs/python/3.13.1/bin"
}
],
"dependsOn": [
Expand All @@ -85,10 +91,7 @@
"name": "packages:mise",
"outputs": [
"/mise/shims",
"/mise/installs",
"/usr/local/bin/mise",
"/etc/mise/config.toml",
"/root/.local/state/mise"
"/mise/installs"
],
"useSecrets": false
},
Expand Down
29 changes: 26 additions & 3 deletions core/generate/mise_step_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (c *GenerateContext) newMiseStepBuilder() *MiseStepBuilder {
SupportingAptPackages: []string{},
Assets: map[string]string{},
DependsOn: []string{},
Outputs: &[]string{"/mise/shims", "/mise/installs", "/usr/local/bin/mise", "/etc/mise/config.toml", "/root/.local/state/mise"},
Outputs: &[]string{"/mise/shims", "/mise/installs"},
app: c.App,
env: c.Env,
}
Expand Down Expand Up @@ -88,8 +88,7 @@ func (b *MiseStepBuilder) Build(options *BuildStepOptions) (*plan.Step, error) {
plan.NewVariableCommand("MISE_CONFIG_DIR", "/mise"),
plan.NewVariableCommand("MISE_INSTALL_PATH", "/usr/local/bin/mise"),
plan.NewVariableCommand("MISE_CACHE_DIR", "/mise/cache"),
plan.NewPathCommand("/mise/shims"),
options.NewAptInstallCommand([]string{"curl", "ca-certificates"}),
options.NewAptInstallCommand([]string{"curl", "ca-certificates", "git"}),
plan.NewExecCommand("sh -c 'curl -fsSL https://mise.run | sh'",
plan.ExecOptions{
CustomName: "install mise",
Expand Down Expand Up @@ -146,6 +145,21 @@ func (b *MiseStepBuilder) Build(options *BuildStepOptions) (*plan.Step, error) {
})
}

// Packages installed have binaries available at /mise/installs/{package}/{version}/bin
// We need to add these to the PATH
for _, pkg := range b.sortedPackageNames() {
resolved, ok := options.ResolvedPackages[pkg]
if !ok || resolved.ResolvedVersion == nil {
continue
}

version := *resolved.ResolvedVersion

step.AddCommands([]plan.Command{
plan.NewPathCommand("/mise/installs/" + pkg + "/" + version + "/bin"),
})
}

step.Assets = b.Assets
step.Outputs = b.Outputs
step.UseSecrets = &[]bool{false}[0]
Expand All @@ -170,3 +184,12 @@ func (b *MiseStepBuilder) GetSupportingMiseConfigFiles(path string) []string {

return files
}

func (b *MiseStepBuilder) sortedPackageNames() []string {
packages := make([]string, 0, len(b.MisePackages))
for _, pkg := range b.MisePackages {
packages = append(packages, pkg.Name)
}
sort.Strings(packages)
return packages
}