mirror of
https://github.com/morten-olsen/mini-loader.git
synced 2026-02-08 01:36:26 +01:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a08f9e1c91 | ||
|
|
e0c41d9220 | ||
|
|
028b65587e |
17
.github/workflows/release.yml
vendored
17
.github/workflows/release.yml
vendored
@@ -71,12 +71,24 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Log in to the Container registry
|
- name: Log in to the Container registry
|
||||||
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
|
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
|
||||||
with:
|
with:
|
||||||
registry: ${{ env.REGISTRY }}
|
registry: ${{ env.REGISTRY }}
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Retrieve version
|
||||||
|
run: |
|
||||||
|
echo "TAG_NAME=$(git describe --tag --abbrev=0) >> $GITHUB_OUTPUT
|
||||||
|
id: version
|
||||||
|
|
||||||
- name: Extract metadata (tags, labels) for Docker
|
- name: Extract metadata (tags, labels) for Docker
|
||||||
id: meta
|
id: meta
|
||||||
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
|
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
|
||||||
@@ -84,11 +96,16 @@ jobs:
|
|||||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
tags: |
|
tags: |
|
||||||
latest
|
latest
|
||||||
|
${{ steps.version.outputs.TAG_NAME }}
|
||||||
|
|
||||||
- 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:
|
||||||
context: .
|
context: .
|
||||||
file: ./docker/Dockerfile
|
file: ./docker/Dockerfile
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
push: true
|
push: true
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
"packageManager": "pnpm@8.10.4",
|
"packageManager": "pnpm@8.10.4",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepare": "pnpm run build",
|
|
||||||
"build": "turbo build",
|
"build": "turbo build",
|
||||||
"build:dev": "tsc --build --watch",
|
"build:dev": "tsc --build --watch",
|
||||||
"test:lint": "eslint ./packages/*/src",
|
"test:lint": "eslint ./packages/*/src",
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ 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';
|
import { readSecrets } from './local.utils.js';
|
||||||
|
import { Config } from '../../config/config.js';
|
||||||
|
|
||||||
const run = new Command('run');
|
const run = new Command('run');
|
||||||
|
|
||||||
@@ -12,6 +13,7 @@ run
|
|||||||
.argument('script')
|
.argument('script')
|
||||||
.action(async (script) => {
|
.action(async (script) => {
|
||||||
const location = resolve(script);
|
const location = resolve(script);
|
||||||
|
const config = new Config();
|
||||||
const { autoInstall } = run.opts();
|
const { autoInstall } = run.opts();
|
||||||
const secrets = await readSecrets();
|
const secrets = await readSecrets();
|
||||||
|
|
||||||
@@ -21,6 +23,7 @@ run
|
|||||||
const { promise, emitter } = await runLoad({
|
const { promise, emitter } = await runLoad({
|
||||||
script: code,
|
script: code,
|
||||||
secrets,
|
secrets,
|
||||||
|
cacheLocation: config.cacheLocation,
|
||||||
});
|
});
|
||||||
emitter.addListener('message', (message) => {
|
emitter.addListener('message', (message) => {
|
||||||
switch (message.type) {
|
switch (message.type) {
|
||||||
|
|||||||
@@ -7,12 +7,13 @@ type ConfigValues = {
|
|||||||
context?: string;
|
context?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const paths = envPaths('mini-loader');
|
||||||
|
|
||||||
class Config {
|
class Config {
|
||||||
#location: string;
|
#location: string;
|
||||||
#config?: ConfigValues;
|
#config?: ConfigValues;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
const paths = envPaths('mini-loader');
|
|
||||||
this.#location = join(paths.config, 'config.json');
|
this.#location = join(paths.config, 'config.json');
|
||||||
if (existsSync(this.#location)) {
|
if (existsSync(this.#location)) {
|
||||||
this.#config = JSON.parse(readFileSync(this.#location, 'utf-8'));
|
this.#config = JSON.parse(readFileSync(this.#location, 'utf-8'));
|
||||||
@@ -23,6 +24,10 @@ class Config {
|
|||||||
return this.#config?.context || 'default';
|
return this.#config?.context || 'default';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get cacheLocation() {
|
||||||
|
return join(paths.cache, this.context);
|
||||||
|
}
|
||||||
|
|
||||||
public setContext = (context: string) => {
|
public setContext = (context: string) => {
|
||||||
this.#config = {
|
this.#config = {
|
||||||
...(this.#config || {}),
|
...(this.#config || {}),
|
||||||
|
|||||||
@@ -5,10 +5,11 @@ type RunOptions = {
|
|||||||
script: string;
|
script: string;
|
||||||
input?: Buffer | string;
|
input?: Buffer | string;
|
||||||
secrets?: Record<string, string>;
|
secrets?: Record<string, string>;
|
||||||
|
cacheLocation: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const run = async ({ script, input, secrets }: RunOptions) => {
|
const run = async ({ script, input, secrets, cacheLocation }: RunOptions) => {
|
||||||
const info = await setup({ script, input, secrets });
|
const info = await setup({ script, input, secrets, cacheLocation });
|
||||||
|
|
||||||
const worker = new Worker(info.scriptLocation, {
|
const worker = new Worker(info.scriptLocation, {
|
||||||
stdin: false,
|
stdin: false,
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import os from 'os';
|
|
||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from 'nanoid';
|
||||||
import { chmod, mkdir, rm, writeFile } from 'fs/promises';
|
import { chmod, mkdir, rm, writeFile } from 'fs/promises';
|
||||||
import { createServer } from 'net';
|
import { createServer } from 'net';
|
||||||
@@ -9,6 +8,7 @@ type SetupOptions = {
|
|||||||
input?: Buffer | string;
|
input?: Buffer | string;
|
||||||
script: string;
|
script: string;
|
||||||
secrets?: Record<string, string>;
|
secrets?: Record<string, string>;
|
||||||
|
cacheLocation: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type RunEvents = {
|
type RunEvents = {
|
||||||
@@ -20,7 +20,7 @@ type RunEvents = {
|
|||||||
const setup = async (options: SetupOptions) => {
|
const setup = async (options: SetupOptions) => {
|
||||||
const { input, script, secrets } = options;
|
const { input, script, secrets } = options;
|
||||||
const emitter = new EventEmitter<RunEvents>();
|
const emitter = new EventEmitter<RunEvents>();
|
||||||
const dataDir = join(os.tmpdir(), 'mini-loader', nanoid());
|
const dataDir = join(options.cacheLocation, nanoid());
|
||||||
|
|
||||||
await mkdir(dataDir, { recursive: true });
|
await mkdir(dataDir, { recursive: true });
|
||||||
await chmod(dataDir, 0o700);
|
await chmod(dataDir, 0o700);
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ class RunnerInstance extends EventEmitter<RunnerInstanceEvents> {
|
|||||||
script,
|
script,
|
||||||
secrets: allSecrets,
|
secrets: allSecrets,
|
||||||
input,
|
input,
|
||||||
|
cacheLocation: config.files.cache,
|
||||||
});
|
});
|
||||||
this.#run = current;
|
this.#run = current;
|
||||||
const { promise, emitter } = current;
|
const { promise, emitter } = current;
|
||||||
|
|||||||
Reference in New Issue
Block a user