Skip to content

Commit

Permalink
fix: docker entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
wenfengwang committed Jun 16, 2024
1 parent bca0852 commit ec690ac
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 124 deletions.
44 changes: 0 additions & 44 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,47 +1,3 @@
NPI_CMD_ROOT = $(shell pwd)
GIT_COMMIT = $(shell git log -1 --format='%h' | awk '{print $0}')
DATE = $(shell date +%Y-%m-%d_%H:%M:%S%z)

VERSION ?= ${GIT_COMMIT}
IMAGE_TAG ?= ${VERSION}

#os linux or darwin
GOOS ?= darwin
#arch amd64 or arm64
GOARCH ?= amd64

CMD_OUTPUT_DIR ?= ${NPI_CMD_ROOT}/bin

LD_FLAGS = -X 'main.Version=${VERSION}'
LD_FLAGS += -X 'main.GitCommit=${GIT_COMMIT}'
LD_FLAGS += -X 'main.BuildDate=${DATE}'
LD_FLAGS += -X 'main.Platform=${GOOS}/${GOARCH}'

GO_BUILD = GOOS=$(GOOS) GOARCH=$(GOARCH) go build -C ${NPI_CMD_ROOT}/cli -trimpath
DOCKER_PLATFORM ?= linux/arm64,linux/amd64

build-npi:
$(GO_BUILD) -ldflags "${LD_FLAGS}" -o ${CMD_OUTPUT_DIR}/npi ${NPI_CMD_ROOT}/cli

release-npi-cli:
$(GO_BUILD) -ldflags "${LD_FLAGS}" -o ${CMD_OUTPUT_DIR}/cli/npi ${NPI_CMD_ROOT}/cli
zip -j ${CMD_OUTPUT_DIR}/npi-${VERSION}-${GOOS}-${GOARCH}.zip ${CMD_OUTPUT_DIR}/npi

docker-build:
docker buildx build --platform ${DOCKER_PLATFORM} -t npiai/npi:${IMAGE_TAG} . --push

docker-build-gateway:
docker buildx build --platform linux/amd64 -t npiai/gateway:latest -f build/gateway.Dockerfile proto/go --push

docker-build-base:
docker buildx build --platform ${DOCKER_PLATFORM} -t npiai/base:3.10 -f build/base.Dockerfile build --push

docker-build-local:
docker build -t npiai/npi:${IMAGE_TAG} .

clean:
rm -rf bin

release:
poetry publish --build -u __token__ -p ${PYPI_TOKEN}
rm -rf dist
47 changes: 47 additions & 0 deletions build/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
NPI_CMD_ROOT = $(shell pwd)
GIT_COMMIT = $(shell git log -1 --format='%h' | awk '{print $0}')
DATE = $(shell date +%Y-%m-%d_%H:%M:%S%z)

VERSION ?= ${GIT_COMMIT}
IMAGE_TAG ?= ${VERSION}

#os linux or darwin
GOOS ?= darwin
#arch amd64 or arm64
GOARCH ?= amd64

CMD_OUTPUT_DIR ?= ${NPI_CMD_ROOT}/bin

LD_FLAGS = -X 'main.Version=${VERSION}'
LD_FLAGS += -X 'main.GitCommit=${GIT_COMMIT}'
LD_FLAGS += -X 'main.BuildDate=${DATE}'
LD_FLAGS += -X 'main.Platform=${GOOS}/${GOARCH}'

GO_BUILD = GOOS=$(GOOS) GOARCH=$(GOARCH) go build -C ${NPI_CMD_ROOT}/cli -trimpath
DOCKER_PLATFORM ?= linux/arm64,linux/amd64

build-npi:
$(GO_BUILD) -ldflags "${LD_FLAGS}" -o ${CMD_OUTPUT_DIR}/npi ${NPI_CMD_ROOT}/cli

release-npi-cli:
$(GO_BUILD) -ldflags "${LD_FLAGS}" -o ${CMD_OUTPUT_DIR}/cli/npi ${NPI_CMD_ROOT}/cli
zip -j ${CMD_OUTPUT_DIR}/npi-${VERSION}-${GOOS}-${GOARCH}.zip ${CMD_OUTPUT_DIR}/npi

docker-build:
docker buildx build --platform ${DOCKER_PLATFORM} -t npiai/npi:${IMAGE_TAG} . --push

docker-build-gateway:
docker buildx build --platform linux/amd64 -t npiai/gateway:latest -f build/gateway.Dockerfile proto/go --push

docker-build-base:
docker buildx build --platform ${DOCKER_PLATFORM} -t npiai/base:3.10 -f build/base.Dockerfile build --push

docker-build-local:
docker build -t npiai/npi:${IMAGE_TAG} .

clean:
rm -rf bin

release:
poetry publish --build -u __token__ -p ${PYPI_TOKEN}
rm -rf dist
Binary file added dist/npiai-0.1.0-py3-none-any.whl
Binary file not shown.
Binary file added dist/npiai-0.1.0.tar.gz
Binary file not shown.
Binary file removed npiai/app/github/Archive.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion npiai/app/github/__test__/close_issue.spec.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio

from npiai import agent_wrapper
from npiai import GitHub
from npiai.app import GitHub


async def main():
Expand Down
2 changes: 1 addition & 1 deletion npiai/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import yaml
from litellm.types.completion import ChatCompletionToolMessageParam
from litellm.utils import ChatCompletionMessageToolCall
from litellm.types.utils import ChatCompletionMessageToolCall

from npiai.types import FunctionRegistration
from npiai.utils import logger
Expand Down
59 changes: 30 additions & 29 deletions npiai/poetry.lock → poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion npiai/pyproject.toml → pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ openai = "^1.30.3"
termcolor = "^2.4.0"
loguru = "^0.7.2"
twilio = "^9.1.0"
litellm = "^1.38.10"
litellm = "1.40.15"
pydantic = "^2.7.3"
simplegmail = "^4.1.1"
markdownify = "^0.12.1"
Expand Down
15 changes: 13 additions & 2 deletions server/reconcile/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/npi-ai/npi/server/service"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"time"
)

// state transition:
Expand Down Expand Up @@ -81,10 +82,20 @@ func (tc *toolReconciler) Start(ctx context.Context) error {
}

func (tc *toolReconciler) BuildingHandler(ctx context.Context, ws model.ToolInstance) error {
if err := tc.builderSvc.Build(ctx, ws.Metadata); err != nil {
imageURI, err := tc.builderSvc.Build(ctx, ws.Metadata)
if err != nil {
return err
}
return nil
// update tool instance
_, err = tc.coll.UpdateOne(ctx,
bson.M{"_id": ws.ID},
bson.M{
"$set": bson.M{
"image": imageURI,
"updated_at": time.Now(),
},
})
return db.ConvertError(err)
}

func (tc *toolReconciler) DeployingHandler(ctx context.Context, ws model.ToolInstance) error {
Expand Down
42 changes: 42 additions & 0 deletions server/scripts/entrypoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import os
import sys
import importlib
import time


def print_tool_spec():
# Add the directory containing the file to sys.path
module_dir, module_name = os.path.split('/npiai/tools/app.py')
module_name = os.path.splitext(module_name)[0] # Remove the .py extension

if module_dir not in sys.path:
sys.path.append(module_dir)

# Now you can import the module using its name
module = importlib.import_module(module_name)
# Create an instance of the class
tool_class = getattr(module, 'GitHub')
instance = tool_class()
print(instance.export())


async def main():
# Add the directory containing the file to sys.path
module_dir, module_name = os.path.split('app.py')
module_name = os.path.splitext(module_name)[0] # Remove the .py extension

if module_dir not in sys.path:
sys.path.append(module_dir)

# Now you can import the module using its name
module = importlib.import_module(module_name)
# Create an instance of the class
tool_class = getattr(module, 'GitHub')
instance = tool_class()

async with instance as i:
# await i.wait() TODO add this method to BaseApp class
time.sleep(1000)

if __name__ == '__main__':
print_tool_spec()
Loading

0 comments on commit ec690ac

Please sign in to comment.