From 9e8a381de04f95cb7d82b0bcd5fffacf87f739d5 Mon Sep 17 00:00:00 2001 From: Mikhail Klementev Date: Sat, 13 May 2023 19:51:57 +0000 Subject: [PATCH] feat: implement basic debian container image --- distro/debian/debian.go | 52 +++++++++++++++++++++++++++++++++++++++++ kernel/kernel.go | 7 ++++++ 2 files changed, 59 insertions(+) diff --git a/distro/debian/debian.go b/distro/debian/debian.go index 138fee1..ae07f12 100644 --- a/distro/debian/debian.go +++ b/distro/debian/debian.go @@ -2,6 +2,7 @@ package debian import ( "errors" + "fmt" "regexp" "strconv" "strings" @@ -202,3 +203,54 @@ func MatchImagePkg(km config.KernelMask) (pkgs []string, err error) { return } + +func DockerEnvs(km config.KernelMask) (envs []string) { + envs = append(envs, "DEBIAN_FRONTEND=noninteractive") + return +} + +func DockerCommands(km config.KernelMask) (commands []string) { + release := releaseFromString(km.DistroRelease) + + var snapshot string + + switch release { + case Wheezy: + snapshot = "20160605T173546Z" + case Jessie: + snapshot = "20190212T020859Z" + case Stretch: + snapshot = "20200719T110630Z" + case Buster: + snapshot = "20220911T180237Z" + case Bullseye: + snapshot = "20221218T103830Z" + default: + log.Fatal().Msgf("%s not supported", release) + return + } + + params := "[check-valid-until=no trusted=yes]" + mirror := "http://snapshot.debian.org" + repourl := fmt.Sprintf("%s/archive/debian/%s/", mirror, snapshot) + + cmdf := func(f string, s ...interface{}) { + commands = append(commands, fmt.Sprintf(f, s...)) + } + + repo := fmt.Sprintf("deb %s %s %s main contrib", + params, repourl, release) + + cmdf("echo '%s' > /etc/apt/sources.list", repo) + + repo = fmt.Sprintf("deb %s %s %s-updates main contrib", + params, repourl, release) + + cmdf("echo '%s' >> /etc/apt/sources.list", repo) + + cmdf("apt-get update") + cmdf("apt-get install -y wget") + cmdf("mkdir -p /lib/modules") + + return +} diff --git a/kernel/kernel.go b/kernel/kernel.go index b8d023a..94679f7 100644 --- a/kernel/kernel.go +++ b/kernel/kernel.go @@ -288,6 +288,13 @@ func GenerateBaseDockerImage(registry string, commands []config.DockerCommand, packages += " libdtrace-ctf" } d += fmt.Sprintf("RUN yum -y install %s\n", packages) + case config.Debian: + for _, e := range debian.DockerEnvs(sk) { + d += "ENV " + e + "\n" + } + for _, c := range debian.DockerCommands(sk) { + d += "RUN " + c + "\n" + } default: err = fmt.Errorf("%s not yet supported", sk.DistroType.String()) return