-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2119fc5
commit 17729e3
Showing
1 changed file
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { init, Wasmer } from "@wasmer/sdk/node"; | ||
|
||
const WASMER_TOKEN = process.env.WASMER_TOKEN; | ||
const APP_OWNER = process.env.APP_OWNER; | ||
const APP_NAME = process.env.APP_NAME || "my-echo-env-app"; | ||
if (!WASMER_TOKEN) { | ||
throw new Error( | ||
"Please set the `WASMER_TOKEN` environment variable.\nYou can create a token in https://wasmer.io/settings/access-tokens", | ||
); | ||
} | ||
if (!APP_OWNER) { | ||
throw new Error( | ||
"Please set the `APP_OWNER` to your username in Wasmer (or a namespace you own).", | ||
); | ||
} | ||
|
||
await init({ | ||
// registryUrl: process.env.WASMER_REGISTRY, | ||
token: WASMER_TOKEN, | ||
}); | ||
|
||
// initializeLogger("trace"); | ||
|
||
const php_file = `<?php | ||
echo "PHP app created from @wasmer/sdk!<br />"; | ||
var_dump($_ENV);`; | ||
|
||
const manifest = { | ||
command: [ | ||
{ | ||
module: "php/php:php", | ||
name: "run", | ||
runner: "https://webc.org/runner/wasi", | ||
annotations: { | ||
wasi: { | ||
// env: ["JS_PATH=/src/index.js"], | ||
"main-args": ["-t", "/app", "-S", "localhost:8080"], | ||
}, | ||
}, | ||
}, | ||
], | ||
dependencies: { | ||
"php/php": "=8.3.401", | ||
}, | ||
fs: { | ||
"/app": { | ||
"index.php": php_file, | ||
}, | ||
}, | ||
}; | ||
|
||
console.log("Creating Package..."); | ||
let wasmerPackage = await Wasmer.createPackage(manifest); | ||
// console.log("NISE"); | ||
|
||
let appConfig = { | ||
name: APP_NAME, | ||
owner: APP_OWNER, | ||
package: wasmerPackage, | ||
domains: ["syrusakbary-my-echo-env-app.wasmer.app"], | ||
default: true, | ||
}; | ||
|
||
console.log("Deploying app..."); | ||
let res = await Wasmer.deployApp(appConfig); | ||
console.log(`Deployed successfully: ${res.url}`); | ||
|
||
// console.log("------"); | ||
// console.log("Deploying a new version of the app"); | ||
|
||
// const newEchoServer = ` | ||
// async function handler(request) { | ||
// const out = JSON.stringify({ | ||
// "second":"version!", | ||
// }); | ||
// return new Response(out, { | ||
// headers: { "content-type": "application/json" }, | ||
// }); | ||
// } | ||
|
||
// addEventListener("fetch", (fetchEvent) => { | ||
// fetchEvent.respondWith(handler(fetchEvent.request)); | ||
// }); | ||
// `; | ||
|
||
// let newManifest = { | ||
// command: [ | ||
// { | ||
// module: "wasmer/winterjs:winterjs", | ||
// name: "script", | ||
// runner: "https://webc.org/runner/wasi", | ||
// annotations: { | ||
// wasi: { | ||
// env: ["JS_PATH=/src/index.js"], | ||
// "main-args": ["/src/index.js"], | ||
// }, | ||
// }, | ||
// }, | ||
// ], | ||
// dependencies: { | ||
// "wasmer/winterjs": "1.2.0", | ||
// }, | ||
// fs: { | ||
// "/src": { | ||
// "index.js": newEchoServer, | ||
// }, | ||
// }, | ||
// }; | ||
|
||
// console.log("Creating Package..."); | ||
// let wasmerNewPackage = await Wasmer.createPackage(newManifest); | ||
// console.log("Deploying app..."); | ||
// let appNewConfig = { | ||
// name: APP_NAME, | ||
// owner: APP_OWNER, | ||
// package: wasmerNewPackage, | ||
// default: true, | ||
// }; | ||
|
||
// let newVersion = await Wasmer.deployApp(appNewConfig); | ||
// console.log(`Deployed successfully: ${newVersion.url}`); |