Skip to content

Commit

Permalink
Merge pull request #223 from ubiquity-os/development
Browse files Browse the repository at this point in the history
Merge development into main
  • Loading branch information
gentlementlegen authored Dec 10, 2024
2 parents b39be07 + bb72c0a commit 12669eb
Show file tree
Hide file tree
Showing 16 changed files with 238 additions and 63 deletions.
4 changes: 3 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"pavlovcik",
"ghijklmnopqrstuvwxyz",
"GHIJKLMNOPQRSTUVWXYZ",
"ubiquityos"
"ubiquityos",
"azurefunc",
"marplex"
],
"dictionaries": ["typescript", "node", "software-terms"],
"import": ["@cspell/dict-typescript/cspell-ext.json", "@cspell/dict-node/cspell-ext.json", "@cspell/dict-software-terms"],
Expand Down
10 changes: 10 additions & 0 deletions .funcignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.js.map
*.ts
.git*
.vscode
__azurite_db*__.json
__blobstorage__
__queuestorage__
local.settings.json
test
tsconfig.json
4 changes: 2 additions & 2 deletions .github/knip.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { KnipConfig } from "knip";

const config: KnipConfig = {
entry: ["src/kernel.ts", "src/adapters/cloudflare-worker.ts", "deploy/setup-kv-namespace.ts"],
entry: ["src/kernel.ts", "src/adapters/cloudflare-worker.ts", "deploy/setup-kv-namespace.ts", "src/index.ts"],
project: ["src/**/*.ts"],
ignore: ["jest.config.ts"],
ignoreBinaries: ["i", "publish"],
ignoreBinaries: ["i"],
ignoreExportsUsedInFile: true,
ignoreDependencies: ["@mswjs/data", "esbuild", "eslint-config-prettier", "eslint-plugin-prettier", "msw", "ts-node"],
};
Expand Down
137 changes: 137 additions & 0 deletions .github/workflows/azure-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Docs for the Azure Web Apps Deploy action: https://github.com/azure/functions-action
# More GitHub Actions for Azure: https://github.com/Azure/actions

name: Build and deploy Node.js project to Azure Function App - ubiquity-os

on:
push:
branches:
- development
workflow_dispatch:

env:
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
NODE_VERSION: '20.10.0'

jobs:
build:
runs-on: windows-latest
steps:
- name: 'Checkout GitHub Action'
uses: actions/checkout@v4

- name: Setup Node ${{ env.NODE_VERSION }} Environment
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

- uses: oven-sh/setup-bun@v2

- name: 'Resolve Project Dependencies Using Bun'
shell: pwsh
run: |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
bun install --frozen-lockfile
bun run jest:test
bun run build
bun rimraf node_modules
bun install --frozen-lockfile --production
popd
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v4
with:
name: node-app
path: .

update-environment:
runs-on: ubuntu-latest
needs: build

permissions:
id-token: write

steps:
- name: Generate local.settings.json
env:
GITHUB_SECRETS: ${{ toJson(secrets) }}
shell: bash
run: |
# Parse the JSON secrets
secrets=$(echo "$GITHUB_SECRETS" | jq -c '.')
# Create the base settings object
settings=$(jq -n '{
"IsEncrypted": false,
"Values": {}
}')
# Define excluded prefixes
excluded_prefixes=("GITHUB_" "ACTIONS_" "AZUREAPPSERVICE_")
# Iterate through secrets and add non-excluded ones
for secret_name in $(echo "$secrets" | jq -r 'keys[]'); do
# Check if the secret should be included
include=true
for prefix in "${excluded_prefixes[@]}"; do
if [[ "$secret_name" == "$prefix"* ]]; then
include=false
break
fi
done
# Add the secret if it passes the filter
if [ "$include" = true ]; then
secret_value=$(echo "$secrets" | jq -r ".[\"$secret_name\"]")
settings=$(echo "$settings" | jq --arg name "$secret_name" --arg value "$secret_value" '.Values[$name] = $value')
fi
done
# Output the final settings to local.settings.json
echo "$settings" | jq '.' > local.settings.json
- uses: azure/login@v2
with:
client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID }}
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID }}
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID }}

- name: Azure CLI script to upload environment
uses: azure/cli@v2
with:
azcliversion: latest
inlineScript: |
az account show
az functionapp config appsettings set \
--name ubiquity-os \
--resource-group ubiquity-os_group \
--settings @local.settings.json
deploy:
runs-on: windows-latest
needs: build

permissions:
id-token: write #This is required for requesting the JWT

steps:
- name: Download artifact from build job
uses: actions/download-artifact@v4
with:
name: node-app

- name: Login to Azure
uses: azure/login@v2
with:
client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID }}
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID }}
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID }}

- name: 'Run Azure Functions Action'
uses: Azure/functions-action@v1
id: fa
with:
app-name: 'ubiquity-os'
slot-name: 'Production'
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}

49 changes: 0 additions & 49 deletions .github/workflows/sync-template.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,4 @@ junit.xml

*.pem
test-dashboard.md
local.settings.json
Binary file modified bun.lockb
Binary file not shown.
20 changes: 20 additions & 0 deletions host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
},
"extensions": {
"http": {
"routePrefix": ""
}
}
}
12 changes: 12 additions & 0 deletions local.settings.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "node",
"APP_WEBHOOK_SECRET": "xxxxxx",
"APP_ID": "123456",
"APP_PRIVATE_KEY": "-----BEGIN PRIVATE KEY-----",
"ENVIRONMENT": "development | production",
"OPENAI_API_KEY": "123456"
}
}
19 changes: 15 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"version": "2.5.3",
"private": false,
"description": "The kernel for UbiquityOS.",
"module": "dist/index.mjs",
"main": "dist/index.js",
"main": "dist/*.js",
"typings": "dist/index.d.ts",
"files": [
"dist"
Expand All @@ -14,6 +13,7 @@
"engines": {
"node": ">=20.10.0"
},
"type": "module",
"scripts": {
"dev": "run-p worker proxy",
"predev": "tsx predev.ts",
Expand All @@ -32,7 +32,13 @@
"jest:test": "jest --coverage",
"plugin:hello-world": "tsx tests/__mocks__/hello-world-plugin.ts",
"setup-kv": "bun --env-file=.dev.vars scripts/setup-kv-namespace.ts",
"setup": "tsx ./scripts/setup.ts"
"setup": "tsx ./scripts/setup.ts",
"start:azure": "run-p proxy build:watch start",
"start": "func start --port 8787",
"prestart": "bun run build",
"build": "tsup",
"build:watch": "tsup --watch",
"prebuild": "rimraf dist"
},
"keywords": [
"typescript",
Expand All @@ -42,7 +48,9 @@
"open-source"
],
"dependencies": {
"@azure/functions": "^4.6.0",
"@cfworker/json-schema": "2.0.1",
"@marplex/hono-azurefunc-adapter": "^1.0.1",
"@octokit/auth-app": "7.1.0",
"@octokit/core": "6.1.2",
"@octokit/plugin-paginate-rest": "11.3.3",
Expand All @@ -54,7 +62,7 @@
"@octokit/webhooks": "13.3.0",
"@octokit/webhooks-types": "7.5.1",
"@sinclair/typebox": "0.34.3",
"@ubiquity-os/plugin-sdk": "^1.1.0",
"@ubiquity-os/plugin-sdk": "^1.1.1",
"dotenv": "16.4.5",
"hono": "^4.6.12",
"openai": "^4.70.2",
Expand All @@ -78,6 +86,7 @@
"@types/jest": "29.5.12",
"@types/node": "20.14.10",
"@types/node-rsa": "^1.1.4",
"azure-functions-core-tools": "^4.0.6610",
"cspell": "8.9.0",
"esbuild": "0.23.0",
"eslint": "9.7.0",
Expand All @@ -95,10 +104,12 @@
"open": "^10.1.0",
"ora": "^8.1.1",
"prettier": "3.3.3",
"rimraf": "^6.0.1",
"smee-client": "^2.0.4",
"toml": "3.0.0",
"tomlify-j0.4": "3.0.0",
"ts-node": "^10.9.2",
"tsup": "^8.3.5",
"tsx": "4.16.2",
"typescript": "5.6.3",
"typescript-eslint": "7.16.0",
Expand Down
10 changes: 10 additions & 0 deletions src/functions/http-trigger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { app } from "@azure/functions";
import { azureHonoHandler } from "@marplex/hono-azurefunc-adapter";
import { app as honoApp } from "../kernel";

app.http("http-trigger", {
methods: ["GET", "POST"],
authLevel: "anonymous",
route: "{*proxy}",
handler: azureHonoHandler(honoApp.fetch),
});
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { app } from "@azure/functions";

app.setup({
enableHttpStream: true,
});
5 changes: 5 additions & 0 deletions src/kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ import OpenAI from "openai";
import { Context, Hono, HonoRequest } from "hono";
import { env as honoEnv, getRuntimeKey } from "hono/adapter";
import { StatusCode } from "hono/utils/http-status";
import packageJson from "../package.json";

export const app = new Hono();

app.get("/", (c) => {
return c.text(`Welcome to UbiquityOS kernel version ${packageJson.version}`);
});

app.post("/", async (ctx: Context) => {
try {
const env = honoEnv(ctx);
Expand Down
2 changes: 1 addition & 1 deletion src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dotenv.config({ path: ".dev.vars" });

const smee = new SmeeClient({
source: process.env.WEBHOOK_PROXY_URL || "https://smee.io/new",
target: "http://localhost:8787/events",
target: "http://localhost:8787",
logger: console,
});

Expand Down
Loading

0 comments on commit 12669eb

Please sign in to comment.