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

refactor merge diff ops #10

Merged
merged 1 commit into from
May 13, 2022
Merged
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
41 changes: 24 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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").
Expand Down Expand Up @@ -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 {
Expand All @@ -243,6 +250,6 @@ func main() {
log.Fatal(err)
}

buildDeps(opt.languages, opt.version)
buildImg(opt.languages, opt.version)

}