Skip to content

Commit

Permalink
Merge pull request #8 from elwood-software/main
Browse files Browse the repository at this point in the history
Version 0.0.3
  • Loading branch information
traviskuhl authored Oct 24, 2024
2 parents 1490176 + 3d1bf39 commit 0a5bcdd
Show file tree
Hide file tree
Showing 185 changed files with 14,126 additions and 376 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,22 @@ jobs:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true

cli:
runs-on: ubuntu-latest
steps:
- uses: denoland/setup-deno@v2
with:
deno-version: v2.x

- run: deno check src/**/*.ts actions/**/*.ts
- name: build
run: deno task build-cli >> $GITHUB_OUTPUT

- name: Release
uses: softprops/action-gh-release@v2
with:
prerelease: false
make_latest: true
files: ./dist/*
tag_name: v${{ steps.build.outputs.new_version }}
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- uses: denoland/setup-deno@v1
- uses: denoland/setup-deno@v2
with:
deno-version: v1.x
deno-version: v2.x

- run: deno check src/**/*.ts actions/**/*.ts
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"deno.enable": true,
"deno.enablePaths": ["./"],
"deno.enablePaths": ["./src", "./actions", "./tests", "./schema", "./cli.ts","./mod.ts", "./bin", "./deno.json", "./build"],
"deno.lint": true,
"eslint.workingDirectories": [
{
Expand All @@ -17,9 +17,15 @@
"editor.formatOnSave": true,
"editor.formatOnPaste": true
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnPaste": true,
"editor.formatOnSave": true
},
"editor.tabSize": 2,
"cSpell.words": [
"deno",
"ffremote",
"supabase"
]
}
8 changes: 4 additions & 4 deletions actions/_deps.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// ASSERT
export { assert } from "jsr:@std/assert/assert";
export { assertEquals } from "jsr:@std/assert/assert-equals";
export { assertRejects } from "jsr:@std/assert/assert-rejects";
export { assertThrows } from "jsr:@std/assert/assert-throws";
export { assert } from "jsr:@std/assert@1.0.0";
export { assertEquals } from "jsr:@std/assert@1.0.0/equals";
export { assertRejects } from "jsr:@std/assert@1.0.0/rejects";
export { assertThrows } from "jsr:@std/assert@1.0.0/throws";

// PATH
export { basename } from "jsr:@std/path/basename";
Expand Down
34 changes: 34 additions & 0 deletions bin/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { parseArgs } from "jsr:@std/cli/parse-args";

import { main } from "../src/cli/main.ts";

const {
_,
cwd,
["workspace-dir"]: workspaceDir,
["remote-url"]: remoteUrl,
verbose,
report,
} = parseArgs(
Deno.args,
{
string: ["workspace-dir", "cwd", "report", "remote-url"],
alias: {
d: "workspace-dir",
r: "report",
c: "cwd",
},
boolean: ["verbose"],
},
);

await main({
_,
raw: Deno.args,
workflowFile: String(_[0]),
cwd,
workspaceDir,
verbose,
reportFile: report,
remoteUrl,
});
28 changes: 28 additions & 0 deletions bin/ffr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { parseArgs } from "jsr:@std/cli/parse-args";

import { main } from "../src/cli/ffr/main.ts";

const {
_,
cwd,
["remote-url"]: remoteUrl,
verbose,
} = parseArgs(
Deno.args,
{
string: ["cwd", "remote-url"],
alias: {
r: "report",
c: "cwd",
},
boolean: ["verbose"],
},
);

await main({
_,
raw: Deno.args,
cwd,
verbose,
remoteUrl,
});
71 changes: 71 additions & 0 deletions build/bin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { basename, join } from "node:path";
import * as zip from "jsr:@zip-js/zip-js";
import { increment, parse } from "jsr:@std/semver";

const __dirname = new URL(".", import.meta.url).pathname;

async function compile(src: string, dest: string) {
console.log(`Compiling ${src} to ${dest}`);

const cmd = new Deno.Command(Deno.execPath(), {
args: [
"compile",
"-A",
"--unstable-worker-options",
"--include",
join(__dirname, "../src/libs/expression/worker.ts"),
"--output",
dest,
src,
],
stderr: "inherit",
stdout: "inherit",
});

const result = await cmd.output();

console.log(` > Exit Code: ${result.code}`);

if (result.code !== 0) {
return;
}

// output
const output = await Deno.open(`${dest}.zip`, {
create: true,
write: true,
read: true,
});

const source = await Deno.open(dest, { read: true });

const zipWriter = new zip.ZipWriter(output.writable);
await zipWriter.add(basename(dest), source.readable);
await zipWriter.close();

await Deno.remove(dest);
}

const dest = join(__dirname, "../dist");

await Deno.mkdir(
dest,
{ recursive: true },
);

await Promise.all([
compile(
join(__dirname, "../bin/cli.ts"),
join(dest, "elwood-run"),
),
compile(
join(__dirname, "../bin/ffr.ts"),
join(dest, "ffr"),
),
]);

const currentVersion =
await (await fetch("https://elwood.run/ffremote/release/latest.txt")).text();
const nextVersion = increment(parse(currentVersion), "patch");

console.log(`new_version=${nextVersion}`);
8 changes: 8 additions & 0 deletions build/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ rm -rf /var/cache/yum
ln -sf /usr/bin/pip3 /usr/bin/pip
ln -sf /usr/bin/python3 /usr/bin/python

mkdir ./ffmpeg
cd ../ffmpeg
wget https://www.johnvansickle.com/ffmpeg/old-releases/ffmpeg-4.2.1-amd64-static.tar.xz
tar xvf ffmpeg-4.2.1-amd64-static.tar.xz
mv ffmpeg-4.2.1-amd64-static/ffmpeg /usr/local/bin
ln -s /usr/local/bin/ffmpeg/ffmpeg /usr/bin/ffmpeg
cd ..

# add our runner user
groupadd -g 3982 -o elwood_runner
useradd -m -u 3982 -g 3982 -o -s /bin/bash elwood_runner
Expand Down
9 changes: 7 additions & 2 deletions build/run.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ variable "skip_ami" {

variable "profile" {
type = string
default = null
default = "elwood"
}

variable "access_key" {
Expand Down Expand Up @@ -92,7 +92,12 @@ build {
"sudo mkdir -p /elwood/run/bin/",
"sudo mv /elwood/run-compiler/runtime /elwood/run/bin/runtime",
"sudo /elwood/run-compiler/build/bootstrap.sh",
"sudo rm -r /elwood/run-compiler"
"sudo rm -r /elwood/run-compiler",
"echo \"export ELWOOD_RUNNER_ROOT=/elwood/run\" >> /home/ec2-user/.bashrc",
"echo \"export ELWOOD_RUNNER_WORKSPACE_DIR=/elwood/run/runner/workspace\" >> /home/ec2-user/.bashrc",
"echo \"export ELWOOD_RUNNER_EXECUTION_UID=3982\" >> /home/ec2-user/.bashrc",
"echo \"export ELWOOD_RUNNER_EXECUTION_GID=3982\" >> /home/ec2-user/.bashrc",
"echo \"export ELWOOD_RUNNER_DENO_BIN=/elwood/run/runner/bin/deno\" >> /home/ec2-user/.bashrc",
]
}

Expand Down
80 changes: 80 additions & 0 deletions db/elwood-run-0.1.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@



CREATE TABLE @[email protected]_workflow (
instance_id UUID NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000'::UUID,
id UUID NOT NULL DEFAULT extensions.uuid_generate_v4(),
name TEXT NULL,
configuration JSONB NULL,
metadata JSONB NULL,
version SMALLINT NULL DEFAULT 0,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
CONSTRAINT run_workflow_pkey PRIMARY KEY (id),
CONSTRAINT idx_elwood_run_workflow_name UNIQUE (instance_id, name, version)
);

CREATE TABLE @[email protected] (
instance_id UUID NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000'::UUID,
id SERIAL NOT NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
summary TEXT NULL,
short_summary CHARACTER VARYING (255) NULL,
workflow_id UUID NOT NULL,
status TEXT NOT NULL DEFAULT 'queued'::TEXT,
result CHARACTER VARYING NULL DEFAULT 'none'::CHARACTER VARYING,
tracking_id UUID NOT NULL DEFAULT extensions.uuid_generate_v4(),
report JSONB NOT NULL DEFAULT '{}'::JSONB,
num INTEGER NULL DEFAULT 0,
metadata JSONB NULL DEFAULT '{}'::JSONB,
variables JSONB NULL DEFAULT '{}'::JSONB,
started_at TIMESTAMP WITH TIME ZONE NULL,
ended_at TIMESTAMP WITH TIME ZONE NULL,
CONSTRAINT run_pkey PRIMARY KEY (id),
CONSTRAINT idx_elwood_run_tracking_id UNIQUE (tracking_id),
CONSTRAINT elwood_run_workflow_id
FOREIGN KEY (workflow_id) REFERENCES apollo.run_workflow (id)
);

CREATE TABLE @[email protected]_event (
instance_id UUID NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000'::UUID,
id SERIAL NOT NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
type TEXT NULL,
tracking_id UUID NOT NULL DEFAULT extensions.uuid_generate_v4(),
data JSONB NOT NULL DEFAULT '{}'::JSONB,
CONSTRAINT run_event_pkey PRIMARY KEY (id)
);

CREATE VIEW public.elwood_run AS
SELECT
run.instance_id,
run.id,
run.created_at,
run.summary,
run.short_summary,
run.workflow_id,
run.status,
run.result,
run.tracking_id,
run.report,
run.num,
run.metadata,
run.variables,
run.started_at,
run.ended_at,
(
SELECT
run_workflow.configuration
FROM @[email protected]_workflow
WHERE run_workflow.id = run.workflow_id
) AS configuration
FROM @[email protected];

CREATE VIEW public.elwood_run_event AS
SELECT
run_event.id,
run_event.created_at,
run_event.type,
run_event.tracking_id,
run_event.data
FROM @[email protected]_event;
6 changes: 6 additions & 0 deletions db/elwood-run.control
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# elwood_run_db extension
comment = 'Elwood Run for your Supabase project'
default_version = '0.1.0'
requires = moddatetime
superuser = true
relocatable = false
42 changes: 42 additions & 0 deletions db/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Elwood Run Database Control

Get more information at [elwood.run/docs/db](https://elwood.run/docs/db).

This is a [PostgreSQL TLE](https://github.com/aws/pg_tle) (extension) which attempts to provide supabase projects.

Docs available at [elwood.run/docs/db](https://elwood.run/docs/db).

## Install or Update
```sql
/*
Requires:
- pg_tle: https://github.com/aws/pg_tle
- pgsql-http: https://github.com/pramsey/pgsql-http
*/
create extension if not exists http with schema extensions;
create extension if not exists pg_tle;
drop extension if exists "elwood-run-supabase";
select pgtle.uninstall_extension_if_exists('elwood-run-supabase');
select
pgtle.install_extension(
'elwood-run-supabase',
resp.contents ->> 'version',
'Elwood Run Database',
resp.contents ->> 'sql'
)
from http(
(
'GET',
'https://elwood.run/db/latest.json',
array[]::http_header[],
null,
null
)
) x,
lateral (
select
((row_to_json(x) -> 'content') #>> '{}')::json
) resp(contents);

create extension "elwood-run-supabase";
```
Loading

0 comments on commit 0a5bcdd

Please sign in to comment.