Skip to content

Commit

Permalink
feat(images): Add gptscript image (#2319)
Browse files Browse the repository at this point in the history
* feat(images): Add gptscript image

Signed-off-by: RJ Sampson <[email protected]>

* feat(gptscript): Add apk-tools and busybox

Signed-off-by: RJ Sampson <[email protected]>

* fix(gptscript): Run as root

Needed for apk tools

Signed-off-by: RJ Sampson <[email protected]>

---------

Signed-off-by: RJ Sampson <[email protected]>
  • Loading branch information
EyeCantCU authored Mar 7, 2024
1 parent b6e48a5 commit ea35992
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 0 deletions.
57 changes: 57 additions & 0 deletions images/gptscript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!--monopod:start-->
# gptscript
| | |
| - | - |
| **OCI Reference** | `cgr.dev/chainguard/gptscript` |


* [View Image in Chainguard Academy](https://edu.chainguard.dev/chainguard/chainguard-images/reference/gptscript/overview/)
* [View Image Catalog](https://console.enforce.dev/images/catalog) for a full list of available tags.
* [Contact Chainguard](https://www.chainguard.dev/chainguard-images) for enterprise support, SLAs, and access to older tags.*

---
<!--monopod:end-->

<!--overview:start-->
Minimal [gptscript](https://github.com/gptscript-ai/gptscript) container image.
<!--overview:end-->

<!--getting:start-->
## Download this Image
The image is available on `cgr.dev`:

```
docker pull cgr.dev/chainguard/gptscript:latest
```
<!--getting:end-->

<!--body:start-->

## Usage

Before using our gptscript image, you'll need an [OpenAI API key](https://platform.openai.com/api-keys).

After retrieving your key, run the container with the following command:

```bash
docker run -e "OPENAI_API_KEY=<YOUR OPENAI API KEY>" cgr.dev/chainguard/gptscript:latest
```

Azure OpenAI may also be used:

```bash
docker run \
-e "OPENAI_API_KEY=<YOUR API KEY>" \
-e "OPENAI_BASE_URL=<YOUR ENDPOINT>" \
-e "OPENAI_API_TYPE=AZURE" \
-e "OPENAI_AZURE_DEPLOYMENT=<YOUR DEPLOYMENT NAME>" \
cgr.dev/chainguard/gptscript:latest
```

To run a basic hello world test, run the following:

```bash
docker run -e "OPENAI_API_KEY=<YOUR OPENAI API KEY>" cgr.dev/chainguard/gptscript:latest https://get.gptscript.ai/echo.gpt --input 'Hello, World!'
```

<!--body:end-->
35 changes: 35 additions & 0 deletions images/gptscript/config/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
terraform {
required_providers {
apko = { source = "chainguard-dev/apko" }
}
}

variable "extra_packages" {
description = "The additional packages to install (e.g. gptscript)."
default = ["gptscript"]
}

variable "environment" {
default = {}
}

module "accts" {
source = "../../../tflib/accts"
run-as = 0
uid = 65532
gid = 65532
name = "nonroot"
}

output "config" {
value = jsonencode({
contents = {
packages = var.extra_packages
}
accounts = module.accts.block
environment = var.environment
entrypoint = {
command = "gptscript"
}
})
}
40 changes: 40 additions & 0 deletions images/gptscript/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
terraform {
required_providers {
oci = { source = "chainguard-dev/oci" }
}
}

variable "target_repository" {
description = "The docker repo into which the image and attestations should be published."
}

module "config" {
source = "./config"
extra_packages = ["apk-tools", "busybox", "gptscript"]
}

module "latest" {
source = "../../tflib/publisher"
name = basename(path.module)
target_repository = var.target_repository
config = module.config.config
build-dev = true
}

module "test" {
source = "./tests"

digest = module.latest.image_ref
}

resource "oci_tag" "latest" {
depends_on = [module.test]
digest_ref = module.latest.image_ref
tag = "latest"
}

resource "oci_tag" "latest-dev" {
depends_on = [module.test]
digest_ref = module.latest.dev_ref
tag = "latest-dev"
}
12 changes: 12 additions & 0 deletions images/gptscript/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: gptscript
image: cgr.dev/chainguard/gptscript
logo: https://storage.googleapis.com/chainguard-academy/logos/gptscript.svg
endoflife: ""
console_summary: ""
short_description: Minimal [gptscript](https://github.com/gptscript-ai/gptscript) container image.
compatibility_notes: ""
readme_file: README.md
upstream_url: https://github.com/gptscript-ai/gptscript
keywords:
- ai
- languages
16 changes: 16 additions & 0 deletions images/gptscript/tests/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
terraform {
required_providers {
oci = { source = "chainguard-dev/oci" }
}
}

variable "digest" {
description = "The image digest to run tests over."
}

data "oci_string" "ref" { input = var.digest }

data "oci_exec_test" "smoke" {
digest = var.digest
script = "${path.module}/smoke.sh"
}
14 changes: 14 additions & 0 deletions images/gptscript/tests/smoke.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

set -o errexit -o nounset -o errtrace -o pipefail -x

CONTAINER_NAME="gptscript-$(uuidgen)"

# Start container
docker run \
-d --rm \
--name "${CONTAINER_NAME}" \
"${IMAGE_NAME}"

# Stop container when script exits
trap "docker stop ${CONTAINER_NAME}" EXIT
5 changes: 5 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,11 @@ module "google-cloud-sdk" {
target_repository = "${var.target_repository}/google-cloud-sdk"
}

module "gptscript" {
source = "./images/gptscript"
target_repository = "${var.target_repository}/gptscript"
}

module "graalvm-native" {
source = "./images/graalvm-native"
target_repository = "${var.target_repository}/graalvm-native"
Expand Down

0 comments on commit ea35992

Please sign in to comment.