-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored to use Testcontainers in dev only
- Loading branch information
Showing
4 changed files
with
45 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
|
||
} |