From bb2f540eafec5684ca7fe8cac3429a18d2802a34 Mon Sep 17 00:00:00 2001 From: Edward J Date: Thu, 27 Jun 2024 14:56:27 -0700 Subject: [PATCH 1/3] Add configs needed by each sample to samples-v2.json --- package-lock.json | 38 +++++++++++++++++++++++++++++++++----- package.json | 3 ++- scripts/prep-samples.js | 39 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 72 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index ca0456ff0..032255b6b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,7 +22,8 @@ "prism-react-renderer": "^2.1.0", "react": "^18.2.0", "react-dom": "^18.2.0", - "react-markdown": "^9.0.1" + "react-markdown": "^9.0.1", + "yaml": "^2.4.5" }, "devDependencies": { "@docusaurus/module-type-aliases": "3.0.0", @@ -5615,6 +5616,14 @@ "node": ">=10" } }, + "node_modules/cosmiconfig/node_modules/yaml": { + "version": "1.10.2", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.2.tgz", + "integrity": "sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==", + "engines": { + "node": ">= 6" + } + }, "node_modules/cross-fetch": { "version": "3.1.8", "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.8.tgz", @@ -5911,6 +5920,14 @@ "postcss": "^8.2.15" } }, + "node_modules/cssnano/node_modules/yaml": { + "version": "1.10.2", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.2.tgz", + "integrity": "sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==", + "engines": { + "node": ">= 6" + } + }, "node_modules/csso": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/csso/-/csso-4.2.0.tgz", @@ -7278,6 +7295,14 @@ "node": ">=6" } }, + "node_modules/fork-ts-checker-webpack-plugin/node_modules/yaml": { + "version": "1.10.2", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.2.tgz", + "integrity": "sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==", + "engines": { + "node": ">= 6" + } + }, "node_modules/form-data": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", @@ -16395,11 +16420,14 @@ "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==" }, "node_modules/yaml": { - "version": "1.10.2", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.2.tgz", - "integrity": "sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==", + "version": "2.4.5", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.4.5.tgz", + "integrity": "sha512-aBx2bnqDzVOyNKfsysjA2ms5ZlnjSAW2eG3/L5G/CSujfjLJTJsEw1bGw8kCf04KodQWk1pxlGnZ56CRxiawmg==", + "bin": { + "yaml": "bin.mjs" + }, "engines": { - "node": ">= 6" + "node": ">= 14" } }, "node_modules/yocto-queue": { diff --git a/package.json b/package.json index 9244d8c4b..4541adeee 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,8 @@ "prism-react-renderer": "^2.1.0", "react": "^18.2.0", "react-dom": "^18.2.0", - "react-markdown": "^9.0.1" + "react-markdown": "^9.0.1", + "yaml": "^2.4.5" }, "devDependencies": { "@docusaurus/module-type-aliases": "3.0.0", diff --git a/scripts/prep-samples.js b/scripts/prep-samples.js index 025324460..291cac144 100644 --- a/scripts/prep-samples.js +++ b/scripts/prep-samples.js @@ -1,5 +1,6 @@ const fs = require('fs'); const path = require('path'); +const YAML = require('yaml'); const samplesDir = path.join(__dirname, '..', 'samples', 'samples'); @@ -29,7 +30,36 @@ directories.forEach((sample) => { const tags = readme.match(/Tags: (.*)/)[1].split(',').map(tag => tag.trim()); const languages = readme.match(/Languages: (.*)/)[1].split(',').map(language => language.trim()); - jsonArray.push({ + let configs = []; + try { + composeFile = fs.readFileSync(path.join(samplesDir, sample, 'compose.yaml'), 'utf8'); + compose = YAML.parse(composeFile); + + for (var name in compose.services) { + service = compose.services[name] + if (Array.isArray(service.environment)) { + service.environment.forEach(env => { + if (!env.includes("=")) { + configs.push(env); + } + }); + } else { + for (var name in service.environment) { + value = service.environment[name]; + if (value === null || value === undefined || value === "") { + configs.push(name); + } + } + } + } + } catch (error) { + // Ignore if the sample doesn't have a compose file + if (error.code != 'ENOENT') { + console.log(`failed to parese compose for configs for sample`, sample, error); + } + } + + const sampleSummary = { name: directoryName, category: languages?.[0], readme, @@ -38,7 +68,12 @@ directories.forEach((sample) => { shortDescription, tags, languages, - }); + }; + if (configs.length > 0) { + sampleSummary.configs = configs; + } + jsonArray.push(sampleSummary); + console.log(`@@ Added ${sample}`); }); From 4e177e6fc8a971db0b6b991e4e02c285a9d0437a Mon Sep 17 00:00:00 2001 From: Edward J Date: Tue, 2 Jul 2024 11:15:05 -0700 Subject: [PATCH 2/3] Checkout samples before run prep samples --- .github/workflows/test-deploy.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index 78ed25ddd..4ac10fe9d 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -28,6 +28,13 @@ jobs: path: defang ref: main + - name: Checkout DefangLabs/samples + uses: actions/checkout@v3 + with: + repository: DefangLabs/samples + path: samples + ref: main + - name: Set up Go uses: actions/setup-go@v2 with: From ff09ea3c909b67767b5aac5d8b915dbb82db7da0 Mon Sep 17 00:00:00 2001 From: Edward J Date: Tue, 2 Jul 2024 11:36:07 -0700 Subject: [PATCH 3/3] Fix `Could not parse expression with acorn` error '{}' is interpreted as javascript by mdx, so curly brackets needs escaping, either via '\{' '\}' or put it in code blocks. https://mdxjs.com/docs/troubleshooting-mdx/#could-not-parse-expression-with-acorn-error --- docs/tutorials/generate-new-code-using-ai.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/tutorials/generate-new-code-using-ai.mdx b/docs/tutorials/generate-new-code-using-ai.mdx index b840a9256..ecc9fddf6 100644 --- a/docs/tutorials/generate-new-code-using-ai.mdx +++ b/docs/tutorials/generate-new-code-using-ai.mdx @@ -11,7 +11,7 @@ Defang supports generating new project outlines using integration with an AI mod In this tutorial we'll use the following prompt: -A basic service with 2 REST endpoints. The default endpoint will be for health check and should return a JSON object like this: { "status": "OK" }. The /echo endpoint will echo back all request parameters in the response. +A basic service with 2 REST endpoints. The default endpoint will be for health check and should return a JSON object like this: `{ "status": "OK" }`. The /echo endpoint will echo back all request parameters in the response. ## Step 1 - Use the CLI generate command ```text