add HAKO-VERSION checking

This commit is contained in:
Luna 2025-06-10 21:39:03 -03:00
parent 33f45eae02
commit 30a510cb17
6 changed files with 68 additions and 33 deletions

View file

@ -28,8 +28,8 @@ func ensureConfigDir() error {
}
func getBaseDockerfile() string {
return fmt.Sprintf(`# HAKO-VERSION=%s
FROM debian:trixie-20250610
return fmt.Sprintf(`FROM debian:trixie-20250610
LABEL HAKO-VERSION=%s
RUN apt-get update && apt-get install -y \
curl \
@ -57,17 +57,17 @@ CMD ["/usr/bin/fish"]`, hakoVersion)
func getLanguageDockerfile(lang string) string {
switch lang {
case "go":
return fmt.Sprintf(`# HAKO-VERSION=%s
FROM hako-userland
return fmt.Sprintf(`FROM hako-userland
LABEL HAKO-VERSION=%s
RUN curl -fsSL https://go.dev/dl/go1.21.5.linux-amd64.tar.gz | tar -C /usr/local -xzf -
ENV PATH="/usr/local/go/bin:${PATH}"
WORKDIR /workspace
CMD ["/bin/bash"]`, hakoVersion)
CMD ["/usr/bin/fish"]`, hakoVersion)
case "py", "python":
return fmt.Sprintf(`# HAKO-VERSION=%s
FROM hako-userland
return fmt.Sprintf(`FROM hako-userland
LABEL HAKO-VERSION=%s
RUN apt-get update && apt-get install -y \
python3 \
@ -78,7 +78,7 @@ RUN apt-get update && apt-get install -y \
RUN ln -s /usr/bin/python3 /usr/bin/python
WORKDIR /workspace
CMD ["/bin/bash"]`, hakoVersion)
CMD ["/usr/bin/fish"]`, hakoVersion)
default:
return ""
}
@ -148,7 +148,6 @@ func createContainer(containerName, imageName, workspaceDir string) error {
// Mount workspace
args = append(args, "-v", workspaceDir+":/workspace")
args = append(args, "-it", imageName)
if err := runCommand("docker", args...); err != nil {
@ -206,3 +205,24 @@ func copyFromContainer(containerName, srcPath, destPath string) error {
func listHakoContainers() error {
return runCommand("docker", "ps", "-a", "--filter", "name=hako-", "--format", "table {{.Names}}\\t{{.Status}}\\t{{.Image}}")
}
func getImageVersion(imageName string) (string, error) {
output, err := runCommandOutput("docker", "image", "inspect", "-f", "{{index .Config.Labels \"HAKO-VERSION\"}}", imageName)
if err != nil {
return "", err
}
return strings.TrimSpace(output), nil
}
func checkVersionMismatch(imageName string) {
imageVersion, err := getImageVersion(imageName)
if err != nil {
// If we can't get the version, don't warn (might be old image without version)
return
}
if imageVersion != "" && imageVersion != hakoVersion {
fmt.Printf("\033[33mWarning: Image %s has version %s but hako executable is version %s\033[0m\n", imageName, imageVersion, hakoVersion)
fmt.Printf("\033[33mConsider running 'hako init' to rebuild with the current version\033[0m\n")
}
}