From e37f4c4f42f1fb2fee7798393343604337e259c3 Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Mon, 7 Aug 2023 13:45:22 -0700 Subject: [PATCH] DockerIt example Signed-off-by: Matt Williams --- examples/dockerit/Modelfile | 20 ++++++++++++++++++++ examples/dockerit/README.md | 15 +++++++++++++++ examples/dockerit/dockerit.py | 17 +++++++++++++++++ examples/dockerit/requirements.txt | 1 + 4 files changed, 53 insertions(+) create mode 100644 examples/dockerit/Modelfile create mode 100644 examples/dockerit/README.md create mode 100644 examples/dockerit/dockerit.py create mode 100644 examples/dockerit/requirements.txt diff --git a/examples/dockerit/Modelfile b/examples/dockerit/Modelfile new file mode 100644 index 00000000..3ba42e11 --- /dev/null +++ b/examples/dockerit/Modelfile @@ -0,0 +1,20 @@ +FROM llama2 +SYSTEM """ +You are an experience Devops engineer focused on docker. When given specifications for a particular need or application you know the best way to host that within a docker container. For instance if someone tells you they want an nginx server to host files located at /web you will answer as follows + +---start +FROM nginx:alpine +COPY /myweb /usr/share/nginx/html +EXPOSE 80 +---end + +Notice that the answer you should give is just the contents of the dockerfile with no explanation and there are three dashes and the word start at the beginning and 3 dashes and the word end. The full output can be piped into a file and run as is. Here is another example. The user will ask to launch a Postgres server with a password of abc123. And the response should be + +---start +FROM postgres:latest +ENV POSTGRES_PASSWORD=abc123 +EXPOSE 5432 +---end + +Again it's just the contents of the dockerfile an nothing else. +""" \ No newline at end of file diff --git a/examples/dockerit/README.md b/examples/dockerit/README.md new file mode 100644 index 00000000..4c200b5e --- /dev/null +++ b/examples/dockerit/README.md @@ -0,0 +1,15 @@ +# DockerIt + +DockerIt is a tool to help you build and run your application in a Docker container. It consists of a model that defines the system prompt and model weights to use, along with a python script to then build the container and run the image automatically. + +## Caveats + +This is an simple example. It's assuming the Dockerfile content generated is going to work. In many cases, even with simple web servers, it fails when trying to copy files that don't exist. It's simply an example of what you could possibly do. + +## Example Usage + +```bash +> python3 ./dockerit.py "simple postgres server with admin password set to 123" +Enter the name of the image: matttest +Container named happy_keller started with id: 7c201bb6c30f02b356ddbc8e2a5af9d7d7d7b8c228519c9a501d15c0bd9d6b3e +``` diff --git a/examples/dockerit/dockerit.py b/examples/dockerit/dockerit.py new file mode 100644 index 00000000..b013102f --- /dev/null +++ b/examples/dockerit/dockerit.py @@ -0,0 +1,17 @@ +import requests, json, docker, io, sys +inputDescription = " ".join(sys.argv[1:]) +imageName = input("Enter the name of the image: ") +client = docker.from_env() +s = requests.Session() +output="" +with s.post('http://localhost:11434/api/generate', json={'model': 'dockerit', 'prompt': inputDescription}, stream=True) as r: + for line in r.iter_lines(): + if line: + j = json.loads(line) + if "response" in j: + output = output +j["response"] +output = output[output.find("---start")+9:output.find("---end")-1] +f = io.BytesIO(bytes(output, 'utf-8')) +client.images.build(fileobj=f, tag=imageName) +container = client.containers.run(imageName, detach=True) +print("Container named", container.name, " started with id: ",container.id) diff --git a/examples/dockerit/requirements.txt b/examples/dockerit/requirements.txt new file mode 100644 index 00000000..6d0eac4b --- /dev/null +++ b/examples/dockerit/requirements.txt @@ -0,0 +1 @@ +docker \ No newline at end of file