Skip to content

Commit

Permalink
chore: package datasets and aws encryption provider
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Nov 5, 2024
1 parent a4cff0f commit fe14e6a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 43 deletions.
23 changes: 8 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
# First Stage: Builder
FROM cgr.dev/chainguard/wolfi-base AS builder

# Install build dependencies
RUN apk add --no-cache go npm make git pnpm curl

# Set the working directory
WORKDIR /app

# Copy the source code
COPY . .

RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/go/pkg/mod \
make in-docker-build

# Second Stage: Final
FROM cgr.dev/chainguard/wolfi-base AS final

# Install build dependencies
RUN apk add --no-cache git python-3.13 py3.13-pip openssh-server npm bash tini
COPY --chmod=0755 /tools/package-chrome.sh /
RUN /package-chrome.sh && rm /package-chrome.sh
RUN sed -E 's/^#(PermitRootLogin)no/\1yes/' /etc/ssh/sshd_config -i
RUN ssh-keygen -A
RUN mkdir /run/sshd && /usr/sbin/sshd


# Copy the compiled application from the builder stage
COPY --from=builder /app/bin/otto8 /bin/
COPY --link --from=builder /app/otto8-tools /otto8-tools
RUN <<EOF
Expand All @@ -41,9 +28,14 @@ set -e
mkdir -p /run/sshd
/usr/sbin/sshd -D &
mkdir -p /data/cache
# This is YAML
export OTTO_SERVER_VERSIONS="$(cat <<VERSIONS
Tools: $(cd /otto8-tools && git rev-parse HEAD)
WorkspaceProvider: $(cd /otto8-tools/workspace-provider && git rev-parse HEAD)
"github.com/otto8-ai/tools": "$(cd /otto8-tools && git rev-parse HEAD)"
"github.com/gptscript-ai/workspace-provider": "$(cd /otto8-tools/workspace-provider && git rev-parse HEAD)"
"github.com/gptscript-ai/datasets": "$(cd /otto8-tools/datasets && git rev-parse HEAD)"
"github.com/kubernetes-sigs/aws-encryption-provider": "$(cd /otto8-tools/aws-encryption-provider && git rev-parse HEAD)"
# double echo to remove trailing whitespace
"chrome": "$(echo $(/opt/google/chrome/chrome --version))"
VERSIONS
)"
exec tini -- otto8 server
Expand All @@ -54,6 +46,7 @@ ENV HOME=/data
ENV XDG_CACHE_HOME=/data/cache
ENV GPTSCRIPT_SYSTEM_TOOLS_DIR=/otto8-tools/
ENV OTTO_SERVER_WORKSPACE_TOOL=/otto8-tools/workspace-provider
ENV OTTO_SERVER_DATASETS_TOOL=/otto8-tools/datasets
ENV OTTO_SERVER_TOOL_REGISTRY=/otto8-tools
WORKDIR /data
VOLUME /data
Expand Down
31 changes: 8 additions & 23 deletions pkg/api/handlers/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,24 @@ package handlers

import (
"os"
"strings"

"github.com/otto8-ai/otto8/pkg/api"
"github.com/otto8-ai/otto8/pkg/version"
"sigs.k8s.io/yaml"
)

type versionResponse struct {
Otto string `json:"otto,omitempty"`
Tools string `json:"tools,omitempty"`
WorkspaceProvider string `json:"workspaceProvider,omitempty"`
}

func GetVersion(req api.Context) error {
return req.Write(getVersionResponse())
}

func getVersionResponse() *versionResponse {
// Retrieve the multi-line environment variable
envVar := os.Getenv("OTTO_SERVER_VERSIONS")
// Initialize a map to store the parsed key-value pairs
func getVersionResponse() map[string]string {
values := make(map[string]string)

// Parse the environment variable into the map
for _, line := range strings.Split(envVar, "\n") {
if parts := strings.SplitN(line, ":", 2); len(parts) == 2 {
values[parts[0]] = parts[1]
versions := os.Getenv("OTTO_SERVER_VERSIONS")
if versions != "" {
if err := yaml.Unmarshal([]byte(versions), &values); err != nil {
values["error"] = err.Error()
}
}

// Populate the versionResponse struct using the map
return &versionResponse{
Otto: version.Get().String(),
Tools: strings.TrimSpace(values["Tools"]),
WorkspaceProvider: strings.TrimSpace(values["WorkspaceProvider"]),
}
values["otto"] = version.Get().String()
return values
}
10 changes: 6 additions & 4 deletions pkg/services/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Config struct {
ToolRegistry string `usage:"The tool reference for the tool registry" default:"github.com/otto8-ai/tools"`
WorkspaceProviderType string `usage:"The type of workspace provider to use for non-knowledge workspaces" default:"directory" env:"OTTO_WORKSPACE_PROVIDER_TYPE"`
WorkspaceTool string `usage:"The tool reference for the workspace provider" default:"github.com/gptscript-ai/workspace-provider"`
DatasetTool string `usage:"The tool reference for the dataset provider" default:"github.com/gptscript-ai/datasets"`
HelperModel string `usage:"The model used to generate names and descriptions" default:"gpt-4o-mini"`

AuthConfig
Expand All @@ -78,11 +79,12 @@ type Services struct {
GatewayServer *gserver.Server
}

func newGPTScript(ctx context.Context, workspaceTool string) (*gptscript.GPTScript, error) {
func newGPTScript(ctx context.Context, workspaceTool, datasetsTool string) (*gptscript.GPTScript, error) {
if os.Getenv("GPTSCRIPT_URL") != "" {
return gptscript.NewGPTScript(gptscript.GlobalOptions{
URL: os.Getenv("GPTSCRIPT_URL"),
WorkspaceTool: workspaceTool,
URL: os.Getenv("GPTSCRIPT_URL"),
WorkspaceTool: workspaceTool,
DatasetToolRepo: datasetsTool,
})
}

Expand Down Expand Up @@ -155,7 +157,7 @@ func New(ctx context.Context, config Config) (*Services, error) {
config.UIHostname = "https://" + config.UIHostname
}

c, err := newGPTScript(ctx, config.WorkspaceTool)
c, err := newGPTScript(ctx, config.WorkspaceTool, config.DatasetTool)
if err != nil {
return nil, err
}
Expand Down
20 changes: 19 additions & 1 deletion tools/package-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,22 @@ if [ ! -e workspace-provider ]; then
fi

cd workspace-provider
CGO_ENABLED=0 go build -ldflags="-s -w" -o bin/gptscript-go-tool .
go build -ldflags="-s -w" -o bin/gptscript-go-tool .

cd ..

if [ ! -e datasets ]; then
git clone --depth=1 https://github.com/gptscript-ai/datasets
fi

cd datasets
go build -ldflags="-s -w" -o bin/gptscript-go-tool .

cd ../..

if [ ! -e aws-encryption-provider ]; then
git clone --depth=1 https://github.com/kubernetes-sigs/aws-encryption-provider
fi

cd aws-encryption-provider
go build -o ../otto8-tools/aws-encryption-provider/bin/aws-encryption-provider cmd/server/main.go

0 comments on commit fe14e6a

Please sign in to comment.