Skip to content

Commit 8359d23

Browse files
Merge branch 'main' into lio-config
2 parents 8bb149a + d237cb0 commit 8359d23

File tree

952 files changed

+80629
-2551
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

952 files changed

+80629
-2551
lines changed
Lines changed: 91 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,100 @@
11
name: Trigger Docs Samples Rebuild
2+
permissions:
3+
contents: read
4+
pull-requests: read
25

36
on:
4-
push:
5-
branches: main
7+
pull_request:
8+
types: [opened, synchronize, reopened]
9+
branches:
10+
- "**"
611
paths:
7-
- 'samples/**'
12+
- "samples/**"
813

914
jobs:
15+
# python-lint:
16+
# runs-on: ubuntu-latest
17+
# steps:
18+
# - name: Checkout code
19+
# uses: actions/checkout@v4
20+
21+
# - name: Get list of changed files
22+
# id: changed
23+
# run: |
24+
# files=$(git diff --name-only origin/${{ github.base_ref }}...${{ github.head_ref }} | grep '\.py$' || true)
25+
# echo "files=$files" >> "$GITHUB_OUTPUT"
26+
27+
# - name: Run Ruff linter
28+
# uses: astral-sh/ruff-action@v1
29+
# with:
30+
# args: check
31+
# src: ${{ steps.changed.outputs.files }}
32+
33+
# - name: Run Ruff formatter check
34+
# uses: astral-sh/ruff-action@v1
35+
# with:
36+
# args: "format --check"
37+
# src: ${{ steps.changed.outputs.files }}
38+
39+
js-ts-lint:
40+
runs-on: ubuntu-latest
41+
steps:
42+
- name: Checkout code
43+
uses: actions/checkout@v4
44+
45+
- name: Set up Node.js
46+
uses: actions/setup-node@v4
47+
with:
48+
node-version: "20"
49+
50+
- name: Get list of changed JS/TS files
51+
id: changed_js
52+
run: |
53+
files=$(git diff --name-only origin/${{ github.base_ref }}...${{ github.head_ref }} | grep -E '\.(js|ts|jsx|tsx)$' || true)
54+
echo "files=$files" >> "$GITHUB_OUTPUT"
55+
56+
- name: Run ESLint (JS/TS only)
57+
run: |
58+
if [ -n "${{ steps.changed_js.outputs.files }}" ]; then
59+
npx eslint ${{ steps.changed_js.outputs.files }}
60+
else
61+
echo "No JS/TS files to lint."
62+
fi
63+
64+
- name: Run Prettier check (JS/TS only)
65+
run: |
66+
if [ -n "${{ steps.changed_js.outputs.files }}" ]; then
67+
npx prettier --check ${{ steps.changed_js.outputs.files }}
68+
else
69+
echo "No JS/TS files to format check."
70+
fi
71+
72+
# go-lint:
73+
# runs-on: ubuntu-latest
74+
# steps:
75+
# - name: Checkout code
76+
# uses: actions/checkout@v4
77+
78+
# - name: Set up Golang
79+
# uses: actions/setup-go@v5
80+
# with:
81+
# go-version: stable
82+
83+
# - name: Run golangci-lint
84+
# uses: golangci/golangci-lint-action@v8
85+
# with:
86+
# args: --enable gofmt --enable goimports
87+
# only-new-issues: true
88+
# version: latest
89+
1090
build-json:
1191
runs-on: ubuntu-latest
92+
# needs: [python-lint, js-ts-lint, go-lint]
93+
needs: [js-ts-lint]
1294
steps:
13-
- name: Trigger CLI Autodoc
14-
uses: peter-evans/repository-dispatch@v1
15-
with:
16-
token: ${{ secrets.DOCS_ACTION_TRIGGER_TOKEN }}
17-
repository: DefangLabs/defang-docs
18-
event-type: sample-update
95+
- name: Trigger CLI Autodoc
96+
uses: peter-evans/repository-dispatch@v1
97+
with:
98+
token: ${{ secrets.DOCS_ACTION_TRIGGER_TOKEN }}
99+
repository: DefangLabs/defang-docs
100+
event-type: sample-update

.github/workflows/check-sample.yml

Lines changed: 21 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
jobs:
99
check_samples:
1010
runs-on: ubuntu-latest
11-
permissions:
11+
permissions:
1212
contents: write
1313
pull-requests: write
1414
steps:
@@ -18,62 +18,38 @@ jobs:
1818
# Fetch two to see changes in current commit
1919
fetch-depth: 2
2020

21+
- name: Install Defang
22+
run: |
23+
eval "$(curl -fsSL s.defang.io/install)"
24+
2125
- name: Run Checks
2226
id: checks
2327
run: |
28+
eval "$(curl -fsSL s.defang.io/install)"
2429
./scripts/check-sample-files.sh > checklist.txt
2530
./scripts/check-modified-samples.sh > modified.txt
2631
echo "@@ MODIFIED @@"
2732
cat modified.txt
33+
echo "@@ CHECKLIST @@"
34+
cat checklist.txt
35+
36+
# TODO: Uncomment the following lines to validate the Compose files
37+
# once we figure out how to prevent it from erroring on warnings.
38+
# - name: Validate Compose Files with Defang CLI
39+
# run: |
40+
# eval "$(curl -fsSL s.defang.io/install)"
41+
# cat modified.txt | xargs -n1 defang compose config -C > /dev/null
2842

2943
- name: Add checklist to PR description
3044
uses: actions/github-script@v5
3145
with:
3246
script: |
33-
const fs = require('fs');
34-
const pr_number = context.issue.number;
35-
const marker = '## Samples Checklist';
36-
37-
// Read the checklist from the file
38-
let checklist = fs.readFileSync('checklist.txt', 'utf8').trim();
39-
let error = false;
40-
41-
if(!checklist) {
42-
checklist = "✅"
43-
}
44-
else {
45-
error = true;
46-
}
47-
48-
// Get the current PR
49-
const { data: pullRequest } = await github.rest.pulls.get({
50-
owner: context.repo.owner,
51-
repo: context.repo.repo,
52-
pull_number: pr_number
53-
});
54-
55-
let newBody;
56-
const body = pullRequest.body || "";
57-
const markerIndex = body.indexOf(marker);
58-
59-
if (markerIndex !== -1) {
60-
// Replace the content below the marker
61-
newBody = body.substring(0, markerIndex + marker.length) + "\n" + checklist;
62-
} else {
63-
// Append the checklist if the marker doesn't exist
64-
newBody = body + "\n" + marker + "\n" + checklist;
65-
}
66-
67-
// Update the PR description
68-
await github.rest.pulls.update({
69-
owner: context.repo.owner,
70-
repo: context.repo.repo,
71-
pull_number: pr_number,
72-
body: newBody
73-
});
74-
75-
if(error) {
76-
throw new Error("Incomplete samples checklist. Please fix the issues and try again.");
47+
const script = require('./scripts/add-checklist-to-pr.js');
48+
try {
49+
await script({github, context});
50+
core.info(`Checklist successfully added to PR description`);
51+
} catch (error) {
52+
core.setFailed(`Script execution failed: ${error.message}`);
7753
}
7854
7955
- name: Create / Update Template Repo
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: Deploy Changed Samples
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "samples/**"
7+
8+
permissions:
9+
contents: read
10+
id-token: write
11+
12+
jobs:
13+
deploy_changed_samples:
14+
runs-on: ubuntu-latest
15+
concurrency:
16+
group: deploy_samples-group
17+
environment: deploy-changed-samples
18+
timeout-minutes: 90
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Identify changed samples
26+
run: |
27+
git fetch origin main
28+
LAST_ANCESTOR=$(git merge-base HEAD origin/main)
29+
git diff --name-only HEAD $LAST_ANCESTOR \
30+
| grep '^samples/' \
31+
| awk -F'/' '{print $1"/"$2}' \
32+
| sort \
33+
| uniq > changed_samples.txt
34+
if [ -s changed_samples.txt ]; then
35+
echo "should_continue=true" >> $GITHUB_ENV
36+
echo "The following samples have changed:"
37+
cat changed_samples.txt
38+
else
39+
echo "should_continue=false" >> $GITHUB_ENV
40+
echo "No samples have changed. Exiting..."
41+
fi
42+
- name: Install Golang
43+
uses: actions/setup-go@v5
44+
with:
45+
go-version-file: tools/testing/go.mod
46+
cache-dependency-path: |
47+
tools/testing/go.sum
48+
if: env.should_continue == 'true'
49+
50+
- name: Build the test tool using Go
51+
run: |
52+
go mod tidy
53+
go build ./cmd/loadtest
54+
working-directory: tools/testing/
55+
if: env.should_continue == 'true'
56+
57+
- name: Install Defang
58+
run: |
59+
eval "$(curl -fsSL s.defang.io/install)"
60+
if: env.should_continue == 'true'
61+
62+
- name: Run tests
63+
id: run-tests
64+
shell: bash # implies set -o pipefail, so pipe below will keep the exit code from loadtest
65+
if: env.should_continue == 'true'
66+
env:
67+
FIXED_VERIFIER_PK: ${{ secrets.FIXED_VERIFIER_PK }}
68+
TEST_ANTHROPIC_API_KEY: ${{ secrets.TEST_ANTHROPIC_API_KEY }}
69+
TEST_AWS_ACCESS_KEY: ${{ secrets.TEST_AWS_ACCESS_KEY }}
70+
TEST_AWS_SECRET_KEY: ${{ secrets.TEST_AWS_SECRET_KEY }}
71+
TEST_BOARD_PASSWORD: ${{ secrets.TEST_BOARD_PASSWORD }}
72+
TEST_DATABASE_HOST: ${{ secrets.TEST_DATABASE_HOST }}
73+
TEST_DATABASE_NAME: ${{ secrets.TEST_DATABASE_NAME }}
74+
TEST_DATABASE_PASSWORD: ${{ secrets.TEST_DATABASE_PASSWORD }}
75+
TEST_DATABASE_URL: ${{ secrets.TEST_DATABASE_URL }}
76+
TEST_DATABASE_USERNAME: ${{ secrets.TEST_DATABASE_USERNAME }}
77+
TEST_HASURA_GRAPHQL_ADMIN_SECRET: ${{ secrets.TEST_HASURA_GRAPHQL_ADMIN_SECRET }}
78+
TEST_HASURA_GRAPHQL_DATABASE_URL: ${{ secrets.TEST_HASURA_GRAPHQL_DATABASE_URL }}
79+
TEST_HF_TOKEN: ${{ secrets.TEST_HF_TOKEN }}
80+
TEST_MB_DB_DBNAME: ${{ secrets.TEST_MB_DB_DBNAME }}
81+
TEST_MB_DB_HOST: ${{ secrets.TEST_MB_DB_HOST }}
82+
TEST_MB_DB_PASS: ${{ secrets.TEST_MB_DB_PASS }}
83+
TEST_MB_DB_PORT: ${{ secrets.TEST_MB_DB_PORT }}
84+
TEST_MB_DB_USER: ${{ secrets.TEST_MB_DB_USER }}
85+
TEST_MISTRAL_API_KEY: ${{ secrets.TEST_MISTRAL_API_KEY }}
86+
TEST_MODEL: ${{ secrets.TEST_MODEL }}
87+
TEST_MONGO_INITDB_ROOT_USERNAME: ${{ secrets.TEST_MONGO_INITDB_ROOT_USERNAME }}
88+
TEST_MONGO_INITDB_ROOT_PASSWORD: ${{ secrets.TEST_MONGO_INITDB_ROOT_PASSWORD }}
89+
TEST_NC_DB: ${{ secrets.TEST_NC_DB }}
90+
TEST_NC_S3_ENDPOINT: ${{ secrets.TEST_NC_S3_ENDPOINT }}
91+
TEST_NC_S3_BUCKET_NAME: ${{ secrets.TEST_NC_S3_BUCKET_NAME }}
92+
TEST_NC_S3_REGION: ${{ secrets.TEST_NC_S3_REGION }}
93+
TEST_NC_S3_ACCESS_KEY: ${{ secrets.TEST_NC_S3_ACCESS_KEY }}
94+
TEST_NC_S3_ACCESS_SECRET: ${{ secrets.TEST_NC_S3_ACCESS_SECRET }}
95+
TEST_OPENAI_KEY: ${{ secrets.TEST_OPENAI_KEY }}
96+
TEST_POSTGRES_PASSWORD: ${{ secrets.TEST_POSTGRES_PASSWORD }}
97+
TEST_PROJECT_HONEYPOT_KEY: ${{ secrets.TEST_PROJECT_HONEYPOT_KEY}}
98+
TEST_QUEUE: ${{ secrets.TEST_QUEUE }}
99+
TEST_SECRET_KEY: ${{ secrets.TEST_SECRET_KEY }}
100+
TEST_SECRET_KEY_BASE: ${{ secrets.TEST_SECRET_KEY_BASE }}
101+
TEST_SESSION_SECRET: ${{ secrets.TEST_SESSION_SECRET }}
102+
TEST_SLACK_CHANNEL_ID: ${{ secrets.TEST_SLACK_CHANNEL_ID }}
103+
TEST_SLACK_TOKEN: ${{ secrets.TEST_SLACK_TOKEN }}
104+
TEST_SHARED_SECRETS: ${{ secrets.TEST_SHARED_SECRETS}}
105+
TEST_TAVILY_API_KEY: ${{ secrets.TEST_TAVILY_API_KEY }}
106+
TEST_ALLOWED_HOSTS: ${{ secrets.TEST_ALLOWED_HOSTS }}
107+
run: |
108+
SAMPLES=$(sed 's|^samples/||' changed_samples.txt | paste -s -d ',' -)
109+
echo "Running tests for samples: $SAMPLES"
110+
mkdir output
111+
# concurrency is set to 10 to avoid exhausting our fargate vCPU limits when running
112+
# kaniko builds, which consume 4 vCPUs each. the limit is currently set to 60--6.5 of
113+
# which are used to run the staging stack. So floor((60-6.5)/4) = 13 is our upper limit
114+
./tools/testing/loadtest -c fabric-staging.defang.dev:443 --timeout=15m --concurrency=10 -s $SAMPLES -o output --markdown=true | tee output/summary.log | grep -v '^\s*[-*]' # removes load sample log lines
115+
- name: Upload Output as Artifact
116+
uses: actions/upload-artifact@v4
117+
if: env.should_continue == 'true' && (success() || steps.run-tests.outcome == 'failure') # Always upload result unless cancelled
118+
with:
119+
name: program-output
120+
path: output/**

.github/workflows/publish-sample-template.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- main
77

88
jobs:
9-
check_samples:
9+
publish_samples:
1010
runs-on: ubuntu-latest
1111
permissions:
1212
contents: write

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Defang Software Labs
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Defang Samples
22

3-
Samples to show you how to create and deploy apps with Defang.
3+
Samples to show you how to develop, deploy, and debug cloud applications with Defang.
44

55
Browse through the [./samples](./samples) directory, or search and browse in the [docs](https://docs.defang.io/docs/samples).
6+
7+
## Adding Samples
8+
9+
To start working on a new sample, run `. ./scripts/new-sample` from the root of the repository. This will create a new sample directory, with some basic scaffolding to get you started. Look for `#REMOVE_ME_AFTER_EDITING` in your new project to look for things that you should probably be changing/checking per sample. Feel free to remove files, like `compose.dev.yaml` if they aren't necessary for your sample.
10+
11+
### Testing Samples
12+
13+
When you add a new sample, make sure to add any config vals to the `deploy-changed-samples.yml` workflow. They need to be prefixed with `TEST_` and those values need to be set in the repo secrets.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
FROM mcr.microsoft.com/devcontainers/python:3.13-bookworm
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"build": {
3+
"dockerfile": "Dockerfile",
4+
"context": ".."
5+
},
6+
"features": {
7+
"ghcr.io/defanglabs/devcontainer-feature/defang-cli:1.0.4": {},
8+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
9+
"ghcr.io/devcontainers/features/aws-cli:1": {}
10+
}
11+
}

0 commit comments

Comments
 (0)