mirror of
https://github.com/morten-olsen/mini-loader.git
synced 2026-02-08 01:36:26 +01:00
docs: completed v1 docs (#36)
This commit is contained in:
@@ -15,20 +15,18 @@ Before diving into mini loader, ensure you have the following:
|
||||
|
||||
## Contents
|
||||
|
||||
- [Creating you first workload](./installation.md): Learn how to write workloads and execute them locally with the mini loader CLI
|
||||
- [Running the server](./pushing-managing-loads.md): Instructions on how to run the server locally using docker.
|
||||
- [Interacting with the server](./interacting-with-server.md): Learn the basic commands used to manage workloads.
|
||||
- [Managing secrets](./managing-secrets.md): Upload secrets to the server that can be used inside your scripts.
|
||||
- [Authorization](./setting-up-oidc.md): Extend the authorization using OIDC
|
||||
- [Create an API](./creating-an-api.md): Create a workload which exposes a HTTP api
|
||||
- [Creating you first workload](./03-tutorial/01-first-workload.md): Learn how to write workloads and execute them locally with the mini loader CLI
|
||||
- [Running the server](./03-tutorial/02-setup-server.md): Instructions on how to run the server locally using docker.
|
||||
- [Interacting with the server](./03-tutorial/03-interacting-with-server.md): Learn the basic commands used to manage workloads.
|
||||
- [Managing secrets](./03-tutorial/04-managing-secrets.md): Upload secrets to the server that can be used inside your scripts.
|
||||
- [Create an API](./03-tutorial/05-creating-an-api.md): Create a workload which exposes a HTTP api
|
||||
|
||||
## Getting Help
|
||||
|
||||
If you encounter any issues or have questions, please refer to the [FAQs](./faqs.md)
|
||||
If you encounter any issues or have questions, please refer to the [FAQs](./04-faqs.md)
|
||||
|
||||
## Let's Get Started!
|
||||
|
||||
Ready to streamline your workload management? Let's jump right into [creating your first workload](./first-workload.md) and set up the mini loader CLI!
|
||||
Ready to streamline your workload management? Let's jump right into [creating your first workload](./03-tutorial/01-first-workload.md) and set up the mini loader CLI!
|
||||
|
||||
|
||||
[Next: create a workload](./first-workload.md)
|
||||
[Next: create a workload](./03-tutorial/01-first-workload.md)
|
||||
@@ -46,4 +46,4 @@ After running the command, you should see an output confirming that a new artifa
|
||||
|
||||
Congratulations on setting up and running your first script with mini loader! You're now ready to take the next step.
|
||||
|
||||
[Next: Setting Up the Server](./setup-server.md)
|
||||
[Next: Setting Up the Server](./02-setup-server.md)
|
||||
@@ -1,7 +1,8 @@
|
||||
Certainly! Here's a revised version of your documentation page to make it
|
||||
Certainly! Here's a revised version of your documentation page to make it
|
||||
|
||||
## Quick Start with mini loader using Docker
|
||||
|
||||
This guide will help you quickly set up and run a mini loader server using Docker. Follow these simple steps to deploy your server and start interacting with it using the [mini-loader CLI](./first-workload.md).
|
||||
This guide will help you quickly set up and run a mini loader server using Docker. Follow these simple steps to deploy your server and start interacting with it using the [mini-loader CLI](./01-first-workload.md).
|
||||
|
||||
### Step 1: Deploy the mini loader Container
|
||||
|
||||
@@ -57,4 +58,4 @@ This command lists all the loads currently on your server, confirming that the C
|
||||
|
||||
You've successfully deployed and configured your mini loader server using Docker! You're now ready to start interacting with the server.
|
||||
|
||||
[Next: Interacting with the Server](./interacting-with-server.md)
|
||||
[Next: Interacting with the Server](./03-interacting-with-server.md)
|
||||
@@ -67,4 +67,4 @@ Replace `<id>` with the identifier of the artifact you wish to download.
|
||||
|
||||
You're now equipped to manage loads, runs, logs, and artifacts using the mini loader CLI. For advanced usage, such as managing secrets, proceed to the next section.
|
||||
|
||||
[Next: Managing Secrets](./managing-secrets.md)
|
||||
[Next: Managing Secrets](./04-managing-secrets.md)
|
||||
81
docs/03-tutorial/04-managing-secrets.md
Normal file
81
docs/03-tutorial/04-managing-secrets.md
Normal file
@@ -0,0 +1,81 @@
|
||||
## Managing Secrets
|
||||
|
||||
### Introduction
|
||||
|
||||
In many workflows, accessing sensitive data such as API tokens or credentials is essential. To handle this securely, you can use secrets management. This tutorial demonstrates how to manage secrets using the CLI and implement them in a simple Node.js workload.
|
||||
|
||||
### Creating Secrets with the CLI
|
||||
|
||||
To create a new secret, use the `mini-loader` CLI as follows:
|
||||
|
||||
```bash
|
||||
mini-loader secrets set <id>
|
||||
```
|
||||
|
||||
For example, to store a GitHub personal access token, you would use:
|
||||
|
||||
```bash
|
||||
mini-loader secrets set githubtoken
|
||||
```
|
||||
|
||||
Upon execution, you'll be prompted to enter your access token.
|
||||
|
||||
### Implementing Secrets in Your Workload
|
||||
|
||||
Next, let's create a Node.js script (`github.js`) that uses this token to fetch your GitHub username and saves it as an artifact.
|
||||
|
||||
1. **Create `github.js` File:**
|
||||
|
||||
```javascript
|
||||
import { secrets, artifacts } from '@morten-olsen/mini-loader';
|
||||
import { Octokit } from '@octokit/rest';
|
||||
|
||||
// Retrieve the secret
|
||||
const accessToken = secrets.get('githubtoken');
|
||||
|
||||
// Main async function to fetch and save GitHub username
|
||||
async function run() {
|
||||
const octokit = new Octokit({ auth: accessToken });
|
||||
const user = await octokit.users.getAuthenticated();
|
||||
await artifacts.create('user', JSON.stringify(user.data.login));
|
||||
}
|
||||
|
||||
// Execute the function
|
||||
run().catch(console.error);
|
||||
```
|
||||
|
||||
This script initializes the Octokit client with the access token, fetches the authenticated user's data, and then saves the username as an artifact.
|
||||
|
||||
2. **Run the Script:**
|
||||
|
||||
Execute your script with `mini-loader`:
|
||||
|
||||
```bash
|
||||
mini-loader loads push github.js -r -ai
|
||||
```
|
||||
|
||||
### Managing Local Secrets
|
||||
|
||||
If you're running the script locally, you can manage secrets either by using a `.secrets` file or setting an environment variable.
|
||||
|
||||
1. **Using a `.secrets` File:**
|
||||
|
||||
Create a file named `.secrets` and add your token:
|
||||
|
||||
```
|
||||
githubtoken=<your-token>
|
||||
```
|
||||
|
||||
2. **Using Environment Variables:**
|
||||
|
||||
Prefix your environment variable with `ML_S_` and run the script:
|
||||
|
||||
```bash
|
||||
ML_S_githubtoken=<your-token> mini-loader local run github.js -ai
|
||||
```
|
||||
|
||||
### Conclusion
|
||||
|
||||
By following these steps, you can securely manage and use secrets within your workloads, enhancing the security and integrity of your applications.
|
||||
|
||||
[Next: Creating an API](./05-creating-an-api.md)
|
||||
52
docs/03-tutorial/05-creating-an-api.md
Normal file
52
docs/03-tutorial/05-creating-an-api.md
Normal file
@@ -0,0 +1,52 @@
|
||||
## Creating an API Inside Your Workload
|
||||
|
||||
Workloads in mini loader can set up simple HTTP servers by connecting to a socket file, a feature supported by many JavaScript server libraries.
|
||||
|
||||
### Binding Your Workload to an HTTP Endpoint
|
||||
|
||||
To expose your workload as an HTTP server, specify the path parameter using the `getPath()` method provided by the `@morten-olsen/mini-loader` package. This method dynamically assigns a path for your API.
|
||||
|
||||
### Important Note
|
||||
|
||||
Please be aware that the gateway provided by mini loader isn't fully featured. As such, certain functionalities like streaming and WebSockets may not be supported.
|
||||
|
||||
### Example: Setting Up a Server with Fastify
|
||||
|
||||
Here's how you can create a simple API server using Fastify in TypeScript:
|
||||
|
||||
```typescript
|
||||
import { http } from '@morten-olsen/mini-loader';
|
||||
import fastify from 'fastify';
|
||||
|
||||
const server = fastify();
|
||||
|
||||
// Handling all requests and returning the requested URL
|
||||
server.all('*', async (req) => {
|
||||
return req.url;
|
||||
});
|
||||
|
||||
// Listening on the path provided by mini loader
|
||||
server.listen({
|
||||
path: http.getPath(),
|
||||
});
|
||||
```
|
||||
|
||||
With this setup, your server will respond to all incoming requests by returning the requested URL.
|
||||
|
||||
### Deploying Your Workload
|
||||
|
||||
Now, you can push and run your workload just like any other script:
|
||||
|
||||
```bash
|
||||
mini-loader loads push -r my-script.ts
|
||||
```
|
||||
|
||||
### Accessing Your Server
|
||||
|
||||
After pushing your workload, mini loader will display the run ID. You can use this ID to access your server. For example, to make a request to your server, you can use `curl`:
|
||||
|
||||
```bash
|
||||
curl http://localhost:4500/gateway/{your-run-id}
|
||||
```
|
||||
|
||||
Replace `{your-run-id}` with the actual run ID provided by mini loader.
|
||||
Reference in New Issue
Block a user