Skip to content

Commit

Permalink
now building
Browse files Browse the repository at this point in the history
  • Loading branch information
mike dupont committed Oct 11, 2023
1 parent 739ccf6 commit 815bb5c
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 189 deletions.
29 changes: 11 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
# Dockerfile: https://github.com/max-pfeiffer/python-poetry/blob/main/build/Dockerfile
ARG BASE_IMAGE
FROM ${BASE_IMAGE}
ARG APPLICATION_SERVER_PORT
RUN apt update
RUN apt install -y git

LABEL maintainer="Mike DuPont <[email protected]>"

Expand All @@ -16,36 +17,28 @@ ENV PYTHONUNBUFFERED=1 \
POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_CACHE_DIR="/application_root/.cache" \
VIRTUAL_ENVIRONMENT_PATH="/application_root/.venv" \
APPLICATION_SERVER_PORT=$APPLICATION_SERVER_PORT
POETRY_HOME="/opt/poetry"
# https://python-poetry.org/docs/#installing-manually
RUN python -m venv ${VIRTUAL_ENVIRONMENT_PATH}

# Adding the virtual environment to PATH in order to "activate" it.
# https://docs.python.org/3/library/venv.html#how-venvs-work
ENV PATH="$VIRTUAL_ENVIRONMENT_PATH/bin:$PATH"

# Principle of least privilege: create a new user for running the application
RUN groupadd -g 1001 python_application && \
useradd -r -u 1001 -g python_application python_application

# Set the WORKDIR to the application root.
# https://www.uvicorn.org/settings/#development
# https://docs.docker.com/engine/reference/builder/#workdir
WORKDIR ${PYTHONPATH}
RUN chown python_application:python_application ${PYTHONPATH}

# Create cache directory and set permissions because user 1001 has no home
# and poetry cache directory.
# https://python-poetry.org/docs/configuration/#cache-directory
RUN mkdir ${POETRY_CACHE_DIR} && chown python_application:python_application ${POETRY_CACHE_DIR}

# Use the unpriveledged user to run the application
USER 1001
RUN mkdir ${POETRY_CACHE_DIR}

WORKDIR /opt/ai-ticket
COPY pyproject.toml /opt/ai-ticket/
COPY setup.cfg /opt/ai-ticket/
COPY README.md /opt/ai-ticket/
COPY requirements.txt /opt/ai-ticket/
COPY ./src/ /opt/ai-ticket/src/
RUN pip install /opt/ai-ticket/

RUN apt update
RUN apt install -y git
RUN pip install --trusted-host pypi.python.org -r requirements.txt

RUN ls ${VIRTUAL_ENVIRONMENT_PATH}/bin/activate
RUN pip install /opt/ai-ticket/ && pip install --trusted-host pypi.python.org -r requirements.txt
69 changes: 46 additions & 23 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,49 @@
version: '3'
services:
ai_ticket:
build: .
act_base:
# the base image of github action

act_base: #root base of action
build: vendor/act_base

poetry_base: # use poetry
build:
context: vendor/python-poetry/build
args:
OFFICIAL_PYTHON_IMAGE: act_base
POETRY_VERSION: 1.6.1
depends_on:
- act_base

ai_ticket: # the ticket to unite
build:
context: .
args:
BASE_IMAGE: act_base
depends_on:
- poetry_base

basic_agent: #basic agnet
build:
context: vendor/basic_agent/
args:
OFFICIAL_PYTHON_IMAGE: act_base
depends_on:
- ai_ticket

autogpt:

#entrypoint: bash -c "poetry run pip install /opt/ai-ticket && poetry run autogpt --install-plugin-deps --skip-news -y"
entrypoint: bash -c "poetry run pip install /opt/ai-ticket && poetry run autogpt --install-plugin-deps --skip-news -y --ai-name 'meta-autogpt' --ai-role 'you will introspect autogpt and reveal its internals via reflection and comprehension' --ai-goal 'Observe your behaviour' --ai-goal 'Reflect over your outcomes' --ai-goal 'Orient yourself to your knowledge' --ai-goal 'Decide on your next step' --ai-goal 'Act on your chosen next experiment' "
mockopenai: # interface
depends_on:
- ai_ticket
environment:
- GITHUB_PAT=${GITHUB_PAT}
- GITHUB_REPO=${GITHUB_REPO}
build:
context: vendor/lollms/
args:
OFFICIAL_PYTHON_IMAGE: localhost/ai-ticket_ai_ticket:latest
ports:
- "5000:8080"

autogpt: #the beast
entrypoint: bash -c "poetry run pip install /opt/ai-ticket && poetry run autogpt --install-plugin-deps --skip-news -y --ai-name 'meta-autogpt' --ai-role 'you will introspect autogpt and reveal its internals via reflection and comprehension' --ai-goal 'Observe your behaviour' --ai-goal 'Reflect over your outcomes' --ai-goal 'Orient yourself to your knowledge' --ai-goal 'Decide on your next step' --ai-goal 'Act on your chosen next experiment' "


# uncomment thse next 3 lines for debugging
Expand All @@ -24,20 +57,10 @@ services:
- OPENAI_API_BASE=http://mockopenai:8080/v1
build:
context: vendor/Auto-GPT/
depends_on:
- ai_ticket
- mockopenai
dockerfile: slim/Dockerfile
args:
OFFICIAL_PYTHON_IMAGE: localhost/ai-ticket_ai_ticket:latest

mockopenai:
depends_on:
- ai_ticket

environment:
- GITHUB_PAT=${GITHUB_PAT}
- GITHUB_REPO=${GITHUB_REPO}

build:
context: vendor/lollms/
ports:
- "5000:8080"

- basic_agent
- mockopenai
49 changes: 0 additions & 49 deletions dockerbuild/Dockerfile

This file was deleted.

96 changes: 27 additions & 69 deletions dockerbuild/images.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,10 @@
from pathlib import Path
from typing import Optional
from dockerbuild.baseimage import ExampleApplicationImage

import docker
from pathlib import Path
from docker.models.images import Image

from dockerbuild.constants import (
BASE_IMAGES,
APPLICATION_SERVER_PORT,
)


class DockerImage:
def __init__(
self,
docker_client: docker.client,
target_architecture: str,
version: str,
):
self.docker_client: docker.client = docker_client
self.dockerfile_name: str = "Dockerfile"
self.dockerfile_directory: Optional[Path] = None
self.image_name: Optional[str] = None
self.image_tag: Optional[str] = None
self.version: Optional[str] = version
self.target_architecture: str = target_architecture


class AITicketPoetryImage(DockerImage):
class AITicketPoetryImage(ExampleApplicationImage):
def __init__(
self,
docker_client: docker.client,
Expand All @@ -37,63 +15,43 @@ def __init__(
# An image name is made up of slash-separated name components,
# optionally prefixed by a registry hostname.
# see: https://docs.docker.com/engine/reference/commandline/tag/
self.image_name: str = "h4ckermike/ai-ticket:test_ai_ticket"
self.dockerfile_directory: Path = Path(__file__).parent.resolve()

def build(self) -> Image:
self.image_tag: str = f"{self.version}-{self.target_architecture}"

buildargs: dict[str, str] = {
"BASE_IMAGE": BASE_IMAGES[self.target_architecture],
"APPLICATION_SERVER_PORT": APPLICATION_SERVER_PORT,
}

image: Image = self.docker_client.images.build(
path=str(self.dockerfile_directory),
dockerfile=self.dockerfile_name,
tag=f"{self.image_name}:{self.image_tag}",
buildargs=buildargs,
)[0]
return image


class ExampleApplicationImage(DockerImage):
def build(
self,
target: str,
base_image_tag: str,
) -> Image:
self.image_tag = f"{self.version}-{self.target_architecture}"
self.image_name: str = "h4ckermike/ai-ticket"
self.dockerfile_directory: Path = Path(__file__).parent.parent.resolve()

buildargs: dict[str, str] = {
"BASE_IMAGE": base_image_tag,
}
image: Image = self.docker_client.images.build(
path=str(self.dockerfile_directory),
dockerfile=self.dockerfile_name,
tag=f"{self.image_name}:{self.image_tag}",
target=target,
buildargs=buildargs,
)[0]
return image


class ActBaseImage(ExampleApplicationImage):
class AutoGptImage(ExampleApplicationImage):
def __init__(
self,
docker_client: docker.client,
target_architecture: str,
version: str,
):
super().__init__(docker_client, target_architecture, version)
# An image name is made up of slash-separated name components,
# optionally prefixed by a registry hostname.
# see: https://docs.docker.com/engine/reference/commandline/tag/
self.image_name: str = "act_base"
self.image_name: str = "h4ckermike/act_base"
self.dockerfile_directory: Path = (
Path(__file__).parent.parent.resolve()
/ "vendor"
/ "act_base"
)
class ActBaseImage(ExampleApplicationImage):
def __init__( self, docker_client: docker.client, target_architecture: str, version: str,
):
super().__init__(docker_client, target_architecture, version)
self.image_name: str = "h4ckermike/autogpt"
self.dockerfile_directory: Path = (
Path(__file__).parent.parent.resolve()
/ "vendor"
/ "Auto-GPT/"
)

class OpenAIImage(ExampleApplicationImage):
def __init__( self, docker_client: docker.client,target_architecture: str,version: str ):
super().__init__(docker_client, target_architecture, version)
self.image_name: str = "h4ckermike/mockopenai"
self.dockerfile_directory: Path = (
Path(__file__).parent.parent.resolve()
/ "vendor"
/ "lollms/"
)


Loading

0 comments on commit 815bb5c

Please sign in to comment.