Skip to content

Commit

Permalink
Refactored to use Testcontainers in dev only
Browse files Browse the repository at this point in the history
  • Loading branch information
samie committed Jul 9, 2024
1 parent 02c0c50 commit 74d75f1
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 64 deletions.
5 changes: 4 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,18 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>ollama</artifactId>
<scope>test</scope>
</dependency>
<dependency> <!-- upgrade to avoid CVE -->
<dependency> <!-- upgrade to avoid CVE in Testcontainers -->
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.26.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
50 changes: 0 additions & 50 deletions src/main/java/com/example/demo/OllamaService.java

This file was deleted.

13 changes: 0 additions & 13 deletions src/test/java/com/example/demo/DemoApplicationTests.java

This file was deleted.

41 changes: 41 additions & 0 deletions src/test/java/com/example/demo/DevDemoApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.example.demo;

import com.github.dockerjava.api.model.Bind;
import com.github.dockerjava.api.model.ExposedPort;
import com.github.dockerjava.api.model.PortBinding;
import com.github.dockerjava.api.model.Ports;
import jakarta.annotation.PostConstruct;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.testcontainers.context.ImportTestcontainers;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.testcontainers.ollama.OllamaContainer;

import java.io.IOException;
import java.util.logging.Logger;


public class DevDemoApplication extends DemoApplication {

public static void main(String[] args) {

SpringApplication.run(DevDemoApplication.class, args);
}

@ServiceConnection
OllamaContainer ollama = new OllamaContainer("ollama/ollama:0.1.48")
.withReuse(true)
.withCreateContainerCmdModifier(cmd ->
{
cmd.withBinds(Bind.parse("ollama:/root/.ollama"));
cmd.withPortBindings(new PortBinding(Ports.Binding.bindPort(11434), new ExposedPort(11434)));
});


@PostConstruct
public void start() throws IOException, InterruptedException {
Logger.getGlobal().info("Starting Ollama container and loading model.");
ollama.start();
ollama.execInContainer("ollama", "pull", "mistral");
}

}

0 comments on commit 74d75f1

Please sign in to comment.