Skip to content

Commit

Permalink
Merge branch 'staging' into jm/ext-ts-guest-new
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Phillips <[email protected]>
  • Loading branch information
dphilla committed Mar 8, 2024
2 parents 97a64e8 + 64dbccf commit 0c8b048
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 81 deletions.
7 changes: 2 additions & 5 deletions docs/cli/reference/flags.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ The following global flags are available throughout the Scale CLI:
| `--debug` | Enable debug logging | `false` |
| `--no-color` | Disable color output | `false` |
| `--version` | Show the version of the Scale CLI | `false` |
| `--api-endpoint` | The URL of the Scale API endpoint | `api.scale.sh` |
| `--auth-endpoint` | The URL of the Scale Authentication API endpoint | `auth.scale.sh` |
| `--cache-directory` | The path to the Scale CLI cache directory (will be created if it does not exist) | `~/.config/scale/functions` |

## Environment Variables

The CLI will look for environment variables prefixed with `SCALE_` and convert them to the corresponding flag. For example, the environment variable `SCALE_API_ENDPOINT` will be converted to the `--api-endpoint` flag.
The CLI will look for environment variables prefixed with `SCALE_` and convert them to the corresponding flag. For example, the environment variable `SCALE_CACHE_DIRECTORY` will be converted to the `--cache-directory` flag.

## Configuration File

Expand All @@ -39,8 +37,7 @@ The configuration file itself can also be specified using the `--config` flag or
### Example Configuration File

```yaml ~/.config/scale/config.yml
api_endpoint: api.scale.sh
auth_endpoint: auth.scale.sh
cache_directory: /tmp/scale/functions
log: ~/scale.log
debug: true
```
4 changes: 2 additions & 2 deletions docs/cli/reference/function.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The `function` command is used to interact with Scale Functions locally. `fn` is
To create a new Scale Function, run the following command:

```bash
scale function new <name>
scale function new <name>:<tag>
```

This will create a new scale function in the current directory in the [Go](https://golang.org/) programming language.
Expand All @@ -23,7 +23,7 @@ This will create a new scale function in the current directory in the [Go](https
You can also specify the language of the function you want to create by using the `--language` flag:

```bash
scale function new <name> --language <language>
scale function new <name>:<tag> --language <language>
```

The following languages are currently supported:
Expand Down
4 changes: 2 additions & 2 deletions docs/cli/reference/registry.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ and are [authenticated](/cli/auth) with your Scale account.
To push a function to the registry, use the `push` command:

```bash
scale registry function push [<name>:<tag> | [<org>/<name>:<tag>]
scale registry function push [<org>/<name>:<tag>]
```

The function must be built and available locally in the function cache to be pushed to the registry.
Expand Down Expand Up @@ -68,7 +68,7 @@ scale registry function delete [<org>/<name>:<tag>]
To push a signature to the registry, use the `push` command:

```bash
scale registry signature push [<name>:<tag> | [<org>/<name>:<tag>]
scale registry signature push [<org>/<name>:<tag>]
```

The signature must be built and available locally in the signature cache to be pushed to the registry.
Expand Down
9 changes: 6 additions & 3 deletions docs/cli/reference/signatures.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ The `signature` command is used to interact with Scale Signatures locally. `sig`
To create a new Scale Signature, run the following command:

```bash
scale signature new <name>
scale signature new
```

This will create a new scale signature in the current directory in the [Go](https://golang.org/) programming language.

You can also specify the language of the signature you want to create by using the `--language` flag:

```bash
scale signature new <name> --language <language>
scale signature new --language <language>
```

The following languages are currently supported:
Expand All @@ -41,6 +41,9 @@ Generate a scale signature from a signature file
scale signature generate <name:tag>
```

This will generate the signature defined in the local directory, in your `local/` organization.


<Note>
To learn about how to install the toolchain for a specific language, see the documentation for that language:

Expand All @@ -53,7 +56,7 @@ scale signature generate <name:tag>
Create a new scale signature with the given name and tag.

```bash
scale signature use <name:tag>
scale signature use <org>/<name:tag>
```

## List
Expand Down
34 changes: 17 additions & 17 deletions docs/getting-started/quick-start.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,25 @@ the guides for your Guest Language below to install the toolchain.
## Create a New Function

Once you have the Scale CLI and the toolchain for your Guest Language installed, you can create a new function by
running the following command:
running the following command, passing a `<name>:<tag>` pair to the `new` command:

```bash
scale new hello-world
scale new hello:1.0
```

This will create a new scale function in the current directory. You can also specify a different directory by passing the
`--directory` or `-d` flag:

```bash
scale new hello-world -d /path/to/directory
scale new hello:1.0 -d /path/to/directory
```

<Note>
By default, the CLI will create a new function using Golang as the Guest Language. If you want to use Rust instead,
you can pass the `--language` or `-l` flag:

```bash
scale new hello-world -l rust
scale new hello:1.0 -l rust
```
</Note>

Expand All @@ -60,8 +60,8 @@ The following files will be created in the directory depending on the language y
<CodeGroup>
```yaml scalefile
version: v1alpha
name: hello-world
tag: latest
name: hello
tag: 1.0
signature: [email protected]
language: go
dependencies:
Expand Down Expand Up @@ -104,8 +104,8 @@ The following files will be created in the directory depending on the language y
<CodeGroup>
```yaml scalefile
version: v1alpha
name: hello-world
tag: latest
name: hello
tag: 1.0
signature: [email protected]
language: rust
dependencies:
Expand Down Expand Up @@ -176,14 +176,14 @@ interfaces it provides, you can check out the [HTTP Signature Reference](/signat
Once you've created a new function, you can build it by running the following command:

```bash
scale build
scale function build
```

This will build the function and save it to the `Cache Directory` (which defaults to `~/.config/scale/functions` on Linux and macOS).
You can also specify a different directory by passing the `--cache-directory` flag:

```bash
scale build --cache-directory /path/to/directory
scale function build --cache-directory /path/to/directory
```

<Info>
Expand All @@ -200,22 +200,22 @@ scale function list
```
NAME (1) TAG ORG LANGUAGE SIGNATURE HASH VERSION
------------------- -------- ------------- ---------- ------------- ------------------------------------------------------------------ ---------
hello-world latest rust [email protected] 8dad03b701cd124b55ff5caf7a36a9af5d19759fc73a9e8299bea4816f929777 v1alpha
hello 1.0 local rust [email protected] 8dad03b701cd124b55ff5caf7a36a9af5d19759fc73a9e8299bea4816f929777 v1alpha
```

## Run the Function

Once you've built the function, you can run it by running the following command:

```bash
scale run hello-world:latest
scale run local/hello:1.0
```

This will start a local HTTP server on port `8080` and will run the function whenever you make a request to it. You can
also specify a different port by passing the `--listen` or `-l` flag:

```bash
scale run hello-world:latest -l :3000
scale run local/hello:1.0 -l :3000
```

<Note>
Expand Down Expand Up @@ -270,14 +270,14 @@ scale auth status
Once you've authenticated with the Scale API, you can push your function to the Scale Registry by running the following command:

```bash
scale push hello-world:latest
scale function push hello:1.0
```

This will push the function to the Scale Registry and make it available for use in your existing services. By default
the function will be private, but you can make it public by passing the `--public` flag:

```bash
scale push hello-world:latest --public
scale function push hello:1.0 --public
```

<Note>
Expand All @@ -292,7 +292,7 @@ Once you've pushed a function to the Scale Registry, you can pull it and use it
you can run the following command:

```bash
scale pull <your organization>/hello-world:latest
scale function pull <your organization>/hello:1.0
```

<Note>
Expand All @@ -306,7 +306,7 @@ This will pull the function from the Scale Registry and save it to the `Cache Di
You can also specify a different directory by passing the `--cache-directory` flag:

```bash
scale pull <your organization>/hello-world:latest --cache-directory /path/to/directory
scale function pull <your organization>/hello:1.0 --cache-directory /path/to/directory
```

<Note>
Expand Down
10 changes: 5 additions & 5 deletions docs/languages/golang/adapters/fasthttp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Now you're ready to start using Scale Functions in your Golang application!
To get started, let's create a Scale Function that returns a simple 'Hello World' message. This is as simple as
running the following command:
```bash
scale new hello-world
scale fn new hello
```

<Note>
Expand Down Expand Up @@ -74,10 +74,10 @@ you can learn how to import the Scale Function from the Scale Registry using our

Run the following command to export the Scale Function locally:
```bash
scale function export hello-world:latest .
scale function export hello:latest .
```

This will create a `hello-world-latest.scale` file in the current directory. Now we have everything we need to import
This will create a `hello-latest.scale` file in the current directory. Now we have everything we need to import
the Scale Function into our Golang application.

<Tip>
Expand All @@ -100,7 +100,7 @@ import (
"github.com/loopholelabs/scalefile/scalefunc"
)

//go:embed hello-world-latest.scale
//go:embed hello-latest.scale
var embeddedFunction []byte

func main() {
Expand All @@ -117,4 +117,4 @@ func main() {
Now we can run our Golang application and test out our Scale Function:
```bash
go run main.go
```
```
10 changes: 5 additions & 5 deletions docs/languages/golang/adapters/net-http.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Now you're ready to start using Scale Functions in your Golang application!
To get started, let's create a Scale Function that returns a simple 'Hello World' message. This is as simple as
running the following command:
```bash
scale new hello-world
scale fn new hello
```

<Note>
Expand Down Expand Up @@ -77,10 +77,10 @@ you can learn how to import the Scale Function from the Scale Registry using our

Run the following command to export the Scale Function locally:
```bash
scale function export hello-world:latest .
scale function export hello:latest .
```

This will create a `hello-world-latest.scale` file in the current directory. Now we have everything we need to import
This will create a `hello-latest.scale` file in the current directory. Now we have everything we need to import
the Scale Function into our Golang application.

<Tip>
Expand All @@ -103,7 +103,7 @@ import (
"github.com/loopholelabs/scalefile/scalefunc"
)

//go:embed hello-world-latest.scale
//go:embed hello-latest.scale
var embeddedFunction []byte

func main() {
Expand All @@ -121,4 +121,4 @@ func main() {
Now we can run our Golang application and test out our Scale Function:
```bash
go run main.go
```
```
4 changes: 2 additions & 2 deletions docs/languages/golang/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ it.
scale "github.com/loopholelabs/scale/go"
)

//go:embed hello-world-latest.scale
//go:embed hello-latest.scale
var embeddedFunction []byte

func main() {
Expand Down Expand Up @@ -209,7 +209,7 @@ it.
)

func main() {
sf, _ := registry.Download("hello-world", "latest")
sf, _ := registry.Download("hello", "latest")

ctx := context.Background()
r := scale.New(ctx, sf)
Expand Down
14 changes: 7 additions & 7 deletions docs/languages/javascript-typescript/adapters/nextjs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Now you're ready to start using Scale Functions in your Next.js App!
To get started, let's create a Scale Function that returns a simple 'Hello World' message. This is as simple as
running the following command:
```bash
scale new hello-world
scale fn new hello:1.0
```

<Note>
Expand All @@ -71,17 +71,17 @@ func Scale(ctx *signature.Context) (*signature.Context, error) {

Now lets build the Scale Function and export it locally:
```bash
scale build && scale function export hello-world:latest .
scale build && scale function export hello:1.0.
```

This will create a `hello-world-latest.scale` file in the current directory. Because of the way [Next.js](https://nextjs.org/)
This will create a `hello-latest.scale` file in the current directory. Because of the way [Next.js](https://nextjs.org/)
deploys Edge Functions, we also need to export a raw version of the Scale Function. To do this, we can use the
`--raw` flag with the previous export command:
```bash
scale function export hello-world:latest . --raw
scale function export hello:latest . --raw
```

This will create a `hello-world-latest.wasm` file in the current directory. Now we have everything we need to import
This will create a `hello-latest.wasm` file in the current directory. Now we have everything we need to import
the Scale Function into our Next.js App.

<Tip>
Expand All @@ -95,9 +95,9 @@ import { NextRequest } from 'next/server';
import { NextJS } from '@loopholelabs/scale-http-adapters';
import { New, Func } from "@loopholelabs/scale";
// @ts-ignore
import example from "./hello-world-latest.scale"
import example from "./hello-latest.scale"
// @ts-ignore
import exampleModule from "./hello-world-latest.wasm?module"
import exampleModule from "./hello-latest.wasm?module"

export const config = {
runtime: 'edge',
Expand Down
6 changes: 3 additions & 3 deletions docs/languages/javascript-typescript/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ it.
```javascript
import { New } from "@loopholelabs/scale";
// @ts-ignore
import sf from "./hello-world.scale";
import sf from "./hello.scale";

(async () => {
const r = await New([sf]);
Expand All @@ -195,7 +195,7 @@ it.
import { New } from "@loopholelabs/scale";
import { Read } from "@loopholelabs/scalefile/scalefunc/helpers";

const sf = Read("./hello-world.scale");
const sf = Read("./hello.scale");

(async () => {
const r = await New([sf]);
Expand All @@ -211,7 +211,7 @@ it.
import { Download } from '@loopholelabs/scale/registry'
import { New } from "@loopholelabs/scale";

const sf = Download("hello-world", "latest");
const sf = Download("hello", "latest");
(async () => {
const r = await New([sf]);
const i = await r.Instance(null);
Expand Down
Loading

0 comments on commit 0c8b048

Please sign in to comment.