mirror of
https://github.com/morten-olsen/mini-loader.git
synced 2026-02-08 01:36:26 +01:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eeaad68f6e | ||
|
|
c7ca97f041 | ||
|
|
c8e02d8da4 | ||
|
|
9a5b27f1be |
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@@ -82,6 +82,8 @@ jobs:
|
|||||||
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
|
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
|
||||||
with:
|
with:
|
||||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
|
tags: |
|
||||||
|
latest
|
||||||
- name: Build and push Docker image
|
- name: Build and push Docker image
|
||||||
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
|
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -22,9 +22,11 @@ Also see [anti-features and limitations](./docs/anti-features.md)
|
|||||||
Get up and running with mini loader in just a few steps:
|
Get up and running with mini loader in just a few steps:
|
||||||
|
|
||||||
1. **Install the CLI**: `npm install -g @morten-olsen/mini-loader-cli`
|
1. **Install the CLI**: `npm install -g @morten-olsen/mini-loader-cli`
|
||||||
2. **Deploy the Server**: `docker run -p 4500:4500 -n mini-loader ghcr.io/morten-olsen/mini-loader:main`.
|
2. **Deploy the Server**: `docker run -p 4500:4500 —-name mini-loader ghcr.io/morten-olsen/mini-loader`.
|
||||||
3. **Push Your First Load**: `mini-loader loads push script.mjs -r -i first`
|
3. **Get your access token**: `docker exec mini-loader mini-loader-server create-token`
|
||||||
3. **See the logs**: `mini-loader logs ls -l first`
|
4. **Login**: `mini-loader auth login http://localhost:4500`
|
||||||
|
5. **Push Your First Load**: `mini-loader loads push script.mjs -r -i first`
|
||||||
|
6. **See the logs**: `mini-loader logs ls -l first`
|
||||||
|
|
||||||
For a detailed guide on getting started, please refer to the [Getting Started Tutorial](./docs/getting-started.md).
|
For a detailed guide on getting started, please refer to the [Getting Started Tutorial](./docs/getting-started.md).
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ This guide will help you quickly set up and run a mini loader server using Docke
|
|||||||
To begin, let's deploy the mini loader container. Run the following command in your terminal:
|
To begin, let's deploy the mini loader container. Run the following command in your terminal:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run -p 4500:4500 -n mini-loader ghcr.io/morten-olsen/mini-loader:main
|
docker run -p 4500:4500 -n mini-loader ghcr.io/morten-olsen/mini-loader:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
This command downloads the latest mini loader image and runs it, exposing port 4500.
|
This command downloads the latest mini loader image and runs it, exposing port 4500.
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
"@rollup/plugin-sucrase": "^5.0.2",
|
"@rollup/plugin-sucrase": "^5.0.2",
|
||||||
"@trpc/client": "^10.45.0",
|
"@trpc/client": "^10.45.0",
|
||||||
"commander": "^11.1.0",
|
"commander": "^11.1.0",
|
||||||
|
"dotenv": "^16.3.1",
|
||||||
"env-paths": "^3.0.0",
|
"env-paths": "^3.0.0",
|
||||||
"inquirer": "^9.2.12",
|
"inquirer": "^9.2.12",
|
||||||
"ora": "^8.0.1",
|
"ora": "^8.0.1",
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { createTRPCProxyClient, httpBatchLink } from '@trpc/client';
|
|||||||
import superjson from 'superjson';
|
import superjson from 'superjson';
|
||||||
import type { Runtime } from '@morten-olsen/mini-loader-server';
|
import type { Runtime } from '@morten-olsen/mini-loader-server';
|
||||||
import type { RootRouter } from '@morten-olsen/mini-loader-server';
|
import type { RootRouter } from '@morten-olsen/mini-loader-server';
|
||||||
|
import pkg from '../../package.json';
|
||||||
import { Context } from '../context/context.js';
|
import { Context } from '../context/context.js';
|
||||||
|
|
||||||
const createClient = (context: Context) => {
|
const createClient = (context: Context) => {
|
||||||
@@ -14,6 +15,7 @@ const createClient = (context: Context) => {
|
|||||||
httpBatchLink({
|
httpBatchLink({
|
||||||
url: `${context.host}/trpc`,
|
url: `${context.host}/trpc`,
|
||||||
headers: {
|
headers: {
|
||||||
|
'x-version': pkg.version,
|
||||||
authorization: `Bearer ${context.token}`,
|
authorization: `Bearer ${context.token}`,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { resolve } from 'path';
|
|||||||
import { run as runLoad } from '@morten-olsen/mini-loader-runner';
|
import { run as runLoad } from '@morten-olsen/mini-loader-runner';
|
||||||
import { bundle } from '../../bundler/bundler.js';
|
import { bundle } from '../../bundler/bundler.js';
|
||||||
import { step } from '../../utils/step.js';
|
import { step } from '../../utils/step.js';
|
||||||
|
import { readSecrets } from './local.utils.js';
|
||||||
|
|
||||||
const run = new Command('run');
|
const run = new Command('run');
|
||||||
|
|
||||||
@@ -12,12 +13,14 @@ run
|
|||||||
.action(async (script) => {
|
.action(async (script) => {
|
||||||
const location = resolve(script);
|
const location = resolve(script);
|
||||||
const { autoInstall } = run.opts();
|
const { autoInstall } = run.opts();
|
||||||
|
const secrets = await readSecrets();
|
||||||
|
|
||||||
const code = await step('Bundling', async () => {
|
const code = await step('Bundling', async () => {
|
||||||
return await bundle({ entry: location, autoInstall });
|
return await bundle({ entry: location, autoInstall });
|
||||||
});
|
});
|
||||||
const { promise, emitter } = await runLoad({
|
const { promise, emitter } = await runLoad({
|
||||||
script: code,
|
script: code,
|
||||||
|
secrets,
|
||||||
});
|
});
|
||||||
emitter.addListener('message', (message) => {
|
emitter.addListener('message', (message) => {
|
||||||
switch (message.type) {
|
switch (message.type) {
|
||||||
|
|||||||
25
packages/cli/src/commands/local/local.utils.ts
Normal file
25
packages/cli/src/commands/local/local.utils.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import dotenv from 'dotenv';
|
||||||
|
import { existsSync } from 'fs';
|
||||||
|
import { readFile } from 'fs/promises';
|
||||||
|
import { join } from 'path';
|
||||||
|
|
||||||
|
const ENV_PREFIX = 'ML_S_';
|
||||||
|
|
||||||
|
const readSecrets = async () => {
|
||||||
|
let secretLocation = join(process.cwd(), '.secret');
|
||||||
|
|
||||||
|
let secrets: Record<string, string> = {};
|
||||||
|
|
||||||
|
if (existsSync(secretLocation)) {
|
||||||
|
const content = await readFile(secretLocation, 'utf-8');
|
||||||
|
secrets = dotenv.parse(content);
|
||||||
|
}
|
||||||
|
for (const key in process.env) {
|
||||||
|
if (key.startsWith(ENV_PREFIX)) {
|
||||||
|
secrets[key.replace(ENV_PREFIX, '')] = process.env[key]!;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return secrets;
|
||||||
|
};
|
||||||
|
|
||||||
|
export { readSecrets };
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import { program } from 'commander';
|
import { Command, program } from 'commander';
|
||||||
|
import pkg from '../package.json';
|
||||||
import { loads } from './commands/loads/loads.js';
|
import { loads } from './commands/loads/loads.js';
|
||||||
import { runs } from './commands/runs/runs.js';
|
import { runs } from './commands/runs/runs.js';
|
||||||
import { logs } from './commands/logs/logs.js';
|
import { logs } from './commands/logs/logs.js';
|
||||||
@@ -17,4 +18,12 @@ program.addCommand(local);
|
|||||||
program.addCommand(auth);
|
program.addCommand(auth);
|
||||||
program.addCommand(contexts);
|
program.addCommand(contexts);
|
||||||
|
|
||||||
|
program.version(pkg.version);
|
||||||
|
|
||||||
|
const version = new Command('version');
|
||||||
|
version.action(() => {
|
||||||
|
console.log(pkg.version);
|
||||||
|
});
|
||||||
|
program.addCommand(version);
|
||||||
|
|
||||||
await program.parseAsync();
|
await program.parseAsync();
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"strict": true,
|
"strict": true,
|
||||||
|
"resolveJsonModule": true,
|
||||||
"allowSyntheticDefaultImports": true,
|
"allowSyntheticDefaultImports": true,
|
||||||
"jsx": "react"
|
"jsx": "react"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -18,7 +18,11 @@ start.action(async () => {
|
|||||||
const createToken = new Command('create-token');
|
const createToken = new Command('create-token');
|
||||||
createToken.action(async () => {
|
createToken.action(async () => {
|
||||||
const runtime = await Runtime.create();
|
const runtime = await Runtime.create();
|
||||||
const token = await runtime.auth.createToken({});
|
const token = await runtime.auth.createToken({
|
||||||
|
policy: {
|
||||||
|
'*:*': ['*'],
|
||||||
|
},
|
||||||
|
});
|
||||||
console.log(token);
|
console.log(token);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
8
pnpm-lock.yaml
generated
8
pnpm-lock.yaml
generated
@@ -63,6 +63,9 @@ importers:
|
|||||||
commander:
|
commander:
|
||||||
specifier: ^11.1.0
|
specifier: ^11.1.0
|
||||||
version: 11.1.0
|
version: 11.1.0
|
||||||
|
dotenv:
|
||||||
|
specifier: ^16.3.1
|
||||||
|
version: 16.3.1
|
||||||
env-paths:
|
env-paths:
|
||||||
specifier: ^3.0.0
|
specifier: ^3.0.0
|
||||||
version: 3.0.0
|
version: 3.0.0
|
||||||
@@ -2189,6 +2192,11 @@ packages:
|
|||||||
esutils: 2.0.3
|
esutils: 2.0.3
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/dotenv@16.3.1:
|
||||||
|
resolution: {integrity: sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==}
|
||||||
|
engines: {node: '>=12'}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/eastasianwidth@0.2.0:
|
/eastasianwidth@0.2.0:
|
||||||
resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==}
|
resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==}
|
||||||
dev: false
|
dev: false
|
||||||
|
|||||||
Reference in New Issue
Block a user