mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-20 02:24:59 +00:00
fix: use rice when embedding large binaries (#5309)
* fix(embed): use go-rice for large backend assets Golang embed FS has a hard limit that we might exceed when providing many binary alternatives. Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * simplify golang deps Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * chore(tests): switch to testcontainers and print logs Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(tests): do not build a test binary Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * small fixup Signed-off-by: Ettore Di Giacinto <mudler@localai.io> --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
parent
7ebd7b2454
commit
21bdfe5fa4
14 changed files with 180 additions and 122 deletions
|
@ -7,24 +7,27 @@ import (
|
|||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/go-connections/nat"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/ory/dockertest/v3"
|
||||
"github.com/ory/dockertest/v3/docker"
|
||||
"github.com/sashabaranov/go-openai"
|
||||
"github.com/testcontainers/testcontainers-go"
|
||||
"github.com/testcontainers/testcontainers-go/wait"
|
||||
)
|
||||
|
||||
var pool *dockertest.Pool
|
||||
var resource *dockertest.Resource
|
||||
var container testcontainers.Container
|
||||
var client *openai.Client
|
||||
|
||||
var containerImage = os.Getenv("LOCALAI_IMAGE")
|
||||
var containerImageTag = os.Getenv("LOCALAI_IMAGE_TAG")
|
||||
var modelsDir = os.Getenv("LOCALAI_MODELS_DIR")
|
||||
var apiPort = os.Getenv("LOCALAI_API_PORT")
|
||||
var apiEndpoint = os.Getenv("LOCALAI_API_ENDPOINT")
|
||||
var apiKey = os.Getenv("LOCALAI_API_KEY")
|
||||
|
||||
const (
|
||||
defaultApiPort = "8080"
|
||||
)
|
||||
|
||||
func TestLocalAI(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "LocalAI E2E test suite")
|
||||
|
@ -32,15 +35,14 @@ func TestLocalAI(t *testing.T) {
|
|||
|
||||
var _ = BeforeSuite(func() {
|
||||
|
||||
if apiPort == "" {
|
||||
apiPort = "8080"
|
||||
}
|
||||
|
||||
var defaultConfig openai.ClientConfig
|
||||
if apiEndpoint == "" {
|
||||
startDockerImage()
|
||||
apiPort, err := container.MappedPort(context.Background(), nat.Port(defaultApiPort))
|
||||
Expect(err).To(Not(HaveOccurred()))
|
||||
|
||||
defaultConfig = openai.DefaultConfig(apiKey)
|
||||
apiEndpoint = "http://localhost:" + apiPort + "/v1" // So that other tests can reference this value safely.
|
||||
apiEndpoint = "http://localhost:" + apiPort.Port() + "/v1" // So that other tests can reference this value safely.
|
||||
defaultConfig.BaseURL = apiEndpoint
|
||||
} else {
|
||||
GinkgoWriter.Printf("docker apiEndpoint set from env: %q\n", apiEndpoint)
|
||||
|
@ -58,26 +60,23 @@ var _ = BeforeSuite(func() {
|
|||
})
|
||||
|
||||
var _ = AfterSuite(func() {
|
||||
if resource != nil {
|
||||
Expect(pool.Purge(resource)).To(Succeed())
|
||||
if container != nil {
|
||||
Expect(container.Terminate(context.Background())).To(Succeed())
|
||||
}
|
||||
//dat, err := os.ReadFile(resource.Container.LogPath)
|
||||
//Expect(err).To(Not(HaveOccurred()))
|
||||
//Expect(string(dat)).To(ContainSubstring("GRPC Service Ready"))
|
||||
//fmt.Println(string(dat))
|
||||
})
|
||||
|
||||
var _ = AfterEach(func() {
|
||||
//Expect(dbClient.Clear()).To(Succeed())
|
||||
// Add any cleanup needed after each test
|
||||
})
|
||||
|
||||
type logConsumer struct {
|
||||
}
|
||||
|
||||
func (l *logConsumer) Accept(log testcontainers.Log) {
|
||||
GinkgoWriter.Write([]byte(log.Content))
|
||||
}
|
||||
|
||||
func startDockerImage() {
|
||||
p, err := dockertest.NewPool("")
|
||||
Expect(err).To(Not(HaveOccurred()))
|
||||
Expect(p.Client.Ping()).To(Succeed())
|
||||
|
||||
pool = p
|
||||
|
||||
// get cwd
|
||||
cwd, err := os.Getwd()
|
||||
Expect(err).To(Not(HaveOccurred()))
|
||||
|
@ -88,20 +87,43 @@ func startDockerImage() {
|
|||
}
|
||||
|
||||
proc := runtime.NumCPU()
|
||||
options := &dockertest.RunOptions{
|
||||
Repository: containerImage,
|
||||
Tag: containerImageTag,
|
||||
// Cmd: []string{"server", "/data"},
|
||||
PortBindings: map[docker.Port][]docker.PortBinding{
|
||||
"8080/tcp": []docker.PortBinding{{HostPort: apiPort}},
|
||||
|
||||
req := testcontainers.ContainerRequest{
|
||||
|
||||
Image: fmt.Sprintf("%s:%s", containerImage, containerImageTag),
|
||||
ExposedPorts: []string{defaultApiPort},
|
||||
LogConsumerCfg: &testcontainers.LogConsumerConfig{
|
||||
Consumers: []testcontainers.LogConsumer{
|
||||
&logConsumer{},
|
||||
},
|
||||
},
|
||||
Env: []string{"MODELS_PATH=/models", "DEBUG=true", "THREADS=" + fmt.Sprint(proc), "LOCALAI_SINGLE_ACTIVE_BACKEND=true"},
|
||||
Mounts: []string{md + ":/models"},
|
||||
Env: map[string]string{
|
||||
"MODELS_PATH": "/models",
|
||||
"DEBUG": "true",
|
||||
"THREADS": fmt.Sprint(proc),
|
||||
"LOCALAI_SINGLE_ACTIVE_BACKEND": "true",
|
||||
},
|
||||
Files: []testcontainers.ContainerFile{
|
||||
{
|
||||
HostFilePath: md,
|
||||
ContainerFilePath: "/models",
|
||||
FileMode: 0o755,
|
||||
},
|
||||
},
|
||||
WaitingFor: wait.ForAll(
|
||||
wait.ForListeningPort(nat.Port(defaultApiPort)),
|
||||
// wait.ForHTTP("/v1/models").WithPort(nat.Port(apiPort)).WithStartupTimeout(50*time.Minute),
|
||||
),
|
||||
}
|
||||
|
||||
GinkgoWriter.Printf("Launching Docker Container %q\n%+v\n", containerImageTag, options)
|
||||
r, err := pool.RunWithOptions(options)
|
||||
GinkgoWriter.Printf("Launching Docker Container %s:%s\n", containerImage, containerImageTag)
|
||||
|
||||
ctx := context.Background()
|
||||
c, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
|
||||
ContainerRequest: req,
|
||||
Started: true,
|
||||
})
|
||||
Expect(err).To(Not(HaveOccurred()))
|
||||
|
||||
resource = r
|
||||
container = c
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue