Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/generate-new-code-using-ai.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 33 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
39 changes: 37 additions & 2 deletions scripts/prep-samples.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require('fs');
const path = require('path');
const YAML = require('yaml');

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

Expand Down Expand Up @@ -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,
Expand All @@ -38,7 +68,12 @@ directories.forEach((sample) => {
shortDescription,
tags,
languages,
});
};
if (configs.length > 0) {
sampleSummary.configs = configs;
}
jsonArray.push(sampleSummary);

console.log(`@@ Added ${sample}`);
});

Expand Down