Skip to content

Commit

Permalink
chore: remove gocritic (#13)
Browse files Browse the repository at this point in the history
Signed-off-by: Sertac Ozercan <[email protected]>
  • Loading branch information
sozercan authored Dec 3, 2023
1 parent 175d8a5 commit 65979e8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
4 changes: 0 additions & 4 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ run:
timeout: 5m

linters-settings:
gocritic:
enabled-tags:
- performance
lll:
line-length: 200

misspell:
locale: US
staticcheck:
Expand Down
50 changes: 25 additions & 25 deletions pkg/aikit2llb/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ const (
func Aikit2LLB(c *config.Config) (llb.State, *specs.Image) {
var merge llb.State
s := llb.Image(debianSlim)
s, merge = copyModels(c, &s)
s, merge = addLocalAI(c, &s, &merge)
s, merge = copyModels(c, s)
s, merge = addLocalAI(c, s, merge)
if c.Runtime == utils.RuntimeNVIDIA {
s = installCuda(&s, &merge)
s = installCuda(s, merge)
}
imageCfg := NewImageConfig(c)
return s, imageCfg
}

func copyModels(c *config.Config, s *llb.State) (llb.State, llb.State) {
func copyModels(c *config.Config, s llb.State) (llb.State, llb.State) {
db := llb.Image(distrolessBase)
initState := s
savedState := s

// create config file if defined
if c.Config != "" {
*s = s.Run(shf("echo \"%s\" >> /config.yaml", c.Config)).Root()
s = s.Run(shf("echo \"%s\" >> /config.yaml", c.Config)).Root()
}

for _, model := range c.Models {
Expand All @@ -54,21 +54,21 @@ func copyModels(c *config.Config, s *llb.State) (llb.State, llb.State) {
copyOpts = append(copyOpts, &llb.CopyInfo{
CreateDestPath: true,
})
*s = s.File(
s = s.File(
llb.Copy(m, fileNameFromURL(model.Source), "/models/"+fileNameFromURL(model.Source), copyOpts...),
llb.WithCustomName("Copying "+fileNameFromURL(model.Source)+" to /models"), //nolint: goconst
)

// create prompt templates if defined
for _, pt := range model.PromptTemplates {
if pt.Name != "" && pt.Template != "" {
*s = s.Run(shf("echo \"%s\" >> /models/%s.tmpl", pt.Template, pt.Name)).Root()
s = s.Run(shf("echo \"%s\" >> /models/%s.tmpl", pt.Template, pt.Name)).Root()
}
}
}
diff := llb.Diff(*initState, *s)
diff := llb.Diff(savedState, s)
merge := llb.Merge([]llb.State{db, diff})
return *s, merge
return s, merge
}

func fileNameFromURL(urlString string) string {
Expand All @@ -79,25 +79,24 @@ func fileNameFromURL(urlString string) string {
return path.Base(parsedURL.Path)
}

func installCuda(s *llb.State, merge *llb.State) llb.State {
initState := s

func installCuda(s llb.State, merge llb.State) llb.State {
cudaKeyringURL := "https://developer.download.nvidia.com/compute/cuda/repos/debian12/x86_64/cuda-keyring_1.1-1_all.deb"
cudaKeyring := llb.HTTP(cudaKeyringURL)
*s = s.File(
s = s.File(
llb.Copy(cudaKeyring, fileNameFromURL(cudaKeyringURL), "/"),
llb.WithCustomName("Copying "+fileNameFromURL(cudaKeyringURL)), //nolint: goconst
)
*s = s.Run(shf("dpkg -i cuda-keyring_1.1-1_all.deb && rm cuda-keyring_1.1-1_all.deb")).Root()
*s = s.Run(shf("apt-get update && apt-get install -y ca-certificates && apt-get update && apt-get install -y libcublas-%[1]s cuda-cudart-%[1]s && apt-get clean", cudaVersion), llb.IgnoreCache).Root()
s = s.Run(shf("dpkg -i cuda-keyring_1.1-1_all.deb && rm cuda-keyring_1.1-1_all.deb")).Root()
savedState := s
s = s.Run(shf("apt-get update && apt-get install -y ca-certificates && apt-get update && apt-get install -y libcublas-%[1]s cuda-cudart-%[1]s && apt-get clean", cudaVersion), llb.IgnoreCache).Root()

diff := llb.Diff(*initState, *s)
*merge = llb.Merge([]llb.State{*merge, diff})
return *merge
diff := llb.Diff(savedState, s)
merge = llb.Merge([]llb.State{merge, diff})
return merge
}

func addLocalAI(c *config.Config, s *llb.State, merge *llb.State) (llb.State, llb.State) {
initState := s
func addLocalAI(c *config.Config, s llb.State, merge llb.State) (llb.State, llb.State) {
savedState := s
var localAIURL string
switch c.Runtime {
case utils.RuntimeNVIDIA:
Expand All @@ -111,15 +110,16 @@ func addLocalAI(c *config.Config, s *llb.State, merge *llb.State) (llb.State, ll
}

var opts []llb.HTTPOption
opts = append(opts, llb.Filename("local-ai"), llb.Chmod(0o755))
opts = append(opts, llb.Filename("local-ai"))
opts = append(opts, llb.Chmod(0o755))
localAI := llb.HTTP(localAIURL, opts...)
*s = s.File(
s = s.File(
llb.Copy(localAI, "local-ai", "/usr/bin"),
llb.WithCustomName("Copying "+fileNameFromURL(localAIURL)+" to /usr/bin"), //nolint: goconst
)

diff := llb.Diff(*initState, *s)
return *s, llb.Merge([]llb.State{*merge, diff})
diff := llb.Diff(savedState, s)
return s, llb.Merge([]llb.State{merge, diff})
}

func shf(cmd string, v ...interface{}) llb.RunOption {
Expand Down

0 comments on commit 65979e8

Please sign in to comment.