From 24e96b8de0016e81982c5f391b9258b569b0c1fd Mon Sep 17 00:00:00 2001 From: Surya Kant Date: Sun, 1 May 2022 11:56:50 +0530 Subject: [PATCH] refactor merge diff ops --- main.go | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/main.go b/main.go index 1c3af16..b8e0656 100644 --- a/main.go +++ b/main.go @@ -166,10 +166,10 @@ func buildCEnv(baseImg llb.State) llb.State { Run(llb.Shlex("apt-get -y --no-install-recommends install cmake build-essential")).Root() } -func buildMetacallBase(baseImg llb.State, version string) llb.State { +func buildDevDepsBase(baseImg llb.State, version string) llb.State { return baseImg. Run(llb.Shlex("apt-get update")). - Run(llb.Shlex("apt-get -y --no-install-recommends install git ca-certificates cmake build-essential")). + Run(llb.Shlex("apt-get -y --no-install-recommends install git wget gpg apt-transport-https ca-certificates cmake build-essential")). Run(llb.Shlexf("git clone --depth 1 --single-branch --branch=%v https://github.com/metacall/core.git", version)). Run(llb.Shlex("mkdir core/build")). Dir("core/build"). @@ -197,32 +197,39 @@ func buildRubyRuntime(baseImg llb.State) llb.State { func buildRpcRuntime(baseImg llb.State) llb.State { return baseImg. - Run(llb.Shlex("apt-get -y --no-install-recommends install libcurl4")). - Run(llb.Shlex("apt-mark hold libcurl4")).Root() + Run(llb.Shlex("apt-get -y --no-install-recommends install libcurl4")).Root() } -func buildDeps(langs []LanguageType, version string) { +func buildlangdevimage(devDepsLang llb.State, devDepsBase llb.State) llb.State { + merged := llb.Merge([]llb.State{devDepsLang, devDepsBase}) + finalImg := merged.Dir("core/build").Run(llb.Shlex("cmake -DOPTION_BUILD_LOADERS_PY=On -DOPTION_BUILD_LOADERS_NODE=On ..")). + Run(llb.Shlexf("make -j%v", runtime.NumCPU())).Root() + return finalImg - // Pulls Debian BaseImage from registry - baseImg := llb.Image("docker.io/library/debian:bullseye-slim") +} + +func buildImg(langs []LanguageType, version string) { + + base := llb.Image("docker.io/library/debian:bullseye-slim") + + devDepsBase := buildDevDepsBase(base, version) + + devDepsLang := base - metacallBase := buildMetacallBase(baseImg, version) for _, v := range langs { - baseImg = envDepsFuncMap[v](baseImg) + devDepsLang = envDepsFuncMap[v](devDepsLang) } - baseImg = baseImg.Run(llb.Shlex("apt-get update")). - Run(llb.Shlex("apt-get -y install --no-install-recommends wget gpg apt-transport-https cmake build-essential")).Root() + devLang := buildlangdevimage(devDepsLang, devDepsBase) + devLangBuild := llb.Diff(devDepsBase, devLang) + runtimeDeps := base.Run(llb.Shlex("apt-get update")).Root() for _, v := range langs { - baseImg = runtimeDepsFuncMap[v](baseImg) + runtimeDeps = runtimeDepsFuncMap[v](runtimeDeps) } - diffed := llb.Diff(baseImg, metacallBase) - - merged := llb.Merge([]llb.State{diffed, baseImg}) + finalImg := llb.Merge([]llb.State{devLangBuild, devDepsBase, runtimeDeps}) - finalImg := merged.Dir("core/build").Run(llb.Shlex("cmake -DOPTION_BUILD_LOADERS_PY=On -DOPTION_BUILD_LOADERS_NODE=On ..")).Root() langdepsllb, err := finalImg.Marshal(context.TODO(), llb.LinuxAmd64) if err != nil { @@ -243,6 +250,6 @@ func main() { log.Fatal(err) } - buildDeps(opt.languages, opt.version) + buildImg(opt.languages, opt.version) }