@@ -74,41 +74,40 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize
7474
7575// Run creates an instance of the Ollama container type
7676func Run (ctx context.Context , img string , opts ... testcontainers.ContainerCustomizer ) (* OllamaContainer , error ) {
77- req := testcontainers.GenericContainerRequest {
78- ContainerRequest : testcontainers.ContainerRequest {
79- Image : img ,
80- ExposedPorts : []string {"11434/tcp" },
81- WaitingFor : wait .ForListeningPort ("11434/tcp" ).WithStartupTimeout (60 * time .Second ),
82- },
83- Started : true ,
77+ moduleOpts := []testcontainers.ContainerCustomizer {
78+ testcontainers .WithExposedPorts ("11434/tcp" ),
79+ testcontainers .WithWaitStrategy (wait .ForListeningPort ("11434/tcp" ).WithStartupTimeout (60 * time .Second )),
8480 }
8581
86- // Always request a GPU if the host supports it.
87- opts = append (opts , withGpu ())
88-
82+ // Check if we need to use the local process
8983 var local * localProcess
9084 for _ , opt := range opts {
91- if err := opt .Customize (& req ); err != nil {
92- return nil , fmt .Errorf ("customize: %w" , err )
93- }
9485 if l , ok := opt .(* localProcess ); ok {
9586 local = l
87+ break
9688 }
9789 }
9890
91+ // Only request a GPU if NOT using local process and the host supports it.
92+ if local == nil {
93+ opts = append (opts , withGpu ())
94+ }
95+
96+ moduleOpts = append (moduleOpts , opts ... )
97+
9998 // Now we have processed all the options, we can check if we need to use the local process.
10099 if local != nil {
101- return local .run (ctx , req )
100+ return local .run (ctx , img , moduleOpts )
102101 }
103102
104- container , err := testcontainers .GenericContainer (ctx , req )
103+ ctr , err := testcontainers .Run (ctx , img , moduleOpts ... )
105104 var c * OllamaContainer
106- if container != nil {
107- c = & OllamaContainer {Container : container }
105+ if ctr != nil {
106+ c = & OllamaContainer {Container : ctr }
108107 }
109108
110109 if err != nil {
111- return c , fmt .Errorf ("generic container : %w" , err )
110+ return c , fmt .Errorf ("run ollama : %w" , err )
112111 }
113112
114113 return c , nil
0 commit comments