Skip to content

Commit 8332042

Browse files
edwardrfedw-defang
andauthored
Add configs needed by each sample to samples-v2.json (#60)
* Add configs needed by each sample to samples-v2.json * Checkout samples before run prep samples * 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 --------- Co-authored-by: Edward J <[email protected]>
1 parent 1e92d4c commit 8332042

File tree

5 files changed

+80
-9
lines changed

5 files changed

+80
-9
lines changed

.github/workflows/test-deploy.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ jobs:
2828
path: defang
2929
ref: main
3030

31+
- name: Checkout DefangLabs/samples
32+
uses: actions/checkout@v3
33+
with:
34+
repository: DefangLabs/samples
35+
path: samples
36+
ref: main
37+
3138
- name: Set up Go
3239
uses: actions/setup-go@v2
3340
with:

docs/tutorials/generate-new-code-using-ai.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Defang supports generating new project outlines using integration with an AI mod
1111

1212
In this tutorial we'll use the following prompt:
1313

14-
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.
14+
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.
1515

1616
## Step 1 - Use the CLI generate command
1717
```text

package-lock.json

Lines changed: 33 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"prism-react-renderer": "^2.1.0",
3232
"react": "^18.2.0",
3333
"react-dom": "^18.2.0",
34-
"react-markdown": "^9.0.1"
34+
"react-markdown": "^9.0.1",
35+
"yaml": "^2.4.5"
3536
},
3637
"devDependencies": {
3738
"@docusaurus/module-type-aliases": "3.0.0",

scripts/prep-samples.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const fs = require('fs');
22
const path = require('path');
3+
const YAML = require('yaml');
34

45
const samplesDir = path.join(__dirname, '..', 'samples', 'samples');
56

@@ -29,7 +30,36 @@ directories.forEach((sample) => {
2930
const tags = readme.match(/Tags: (.*)/)[1].split(',').map(tag => tag.trim());
3031
const languages = readme.match(/Languages: (.*)/)[1].split(',').map(language => language.trim());
3132

32-
jsonArray.push({
33+
let configs = [];
34+
try {
35+
composeFile = fs.readFileSync(path.join(samplesDir, sample, 'compose.yaml'), 'utf8');
36+
compose = YAML.parse(composeFile);
37+
38+
for (var name in compose.services) {
39+
service = compose.services[name]
40+
if (Array.isArray(service.environment)) {
41+
service.environment.forEach(env => {
42+
if (!env.includes("=")) {
43+
configs.push(env);
44+
}
45+
});
46+
} else {
47+
for (var name in service.environment) {
48+
value = service.environment[name];
49+
if (value === null || value === undefined || value === "") {
50+
configs.push(name);
51+
}
52+
}
53+
}
54+
}
55+
} catch (error) {
56+
// Ignore if the sample doesn't have a compose file
57+
if (error.code != 'ENOENT') {
58+
console.log(`failed to parese compose for configs for sample`, sample, error);
59+
}
60+
}
61+
62+
const sampleSummary = {
3363
name: directoryName,
3464
category: languages?.[0],
3565
readme,
@@ -38,7 +68,12 @@ directories.forEach((sample) => {
3868
shortDescription,
3969
tags,
4070
languages,
41-
});
71+
};
72+
if (configs.length > 0) {
73+
sampleSummary.configs = configs;
74+
}
75+
jsonArray.push(sampleSummary);
76+
4277
console.log(`@@ Added ${sample}`);
4378
});
4479

0 commit comments

Comments
 (0)