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
2 changes: 1 addition & 1 deletion .github/workflows/check-sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
}

- name: Install script dependencies
run: npm install
run: npm ci
working-directory: scripts

- name: Create / Update Template Repo
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/deploy-changed-samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ jobs:
eval "$(curl -fsSL s.defang.io/install)"
if: env.should_continue == 'true'

- name: Run tests
id: run-tests
- name: Deploy changed samples to staging
id: deploy-samples
shell: bash # implies set -o pipefail, so pipe below will keep the exit code from loadtest
if: env.should_continue == 'true'
env:
Expand Down Expand Up @@ -125,7 +125,7 @@ jobs:
./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
- name: Upload Output as Artifact
uses: actions/upload-artifact@v4
if: env.should_continue == 'true' && (success() || steps.run-tests.outcome == 'failure') # Always upload result unless cancelled
if: env.should_continue == 'true' && (success() || steps.deploy-samples.outcome == 'failure') # Always upload result unless cancelled
with:
name: program-output
path: output/**
2 changes: 1 addition & 1 deletion .github/workflows/publish-sample-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
cat modified.txt

- name: Install script dependencies
run: npm install
run: npm ci
working-directory: scripts

- name: Create / Update Template Repo Main
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-scripts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
node-version: "20"

- name: Install dependencies
run: npm install
run: npm ci
working-directory: scripts

- name: Run tests
Expand All @@ -52,7 +52,7 @@ jobs:
node-version: "20"

- name: Install dependencies
run: npm install
run: npm ci
working-directory: scripts

- name: Get changed samples
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-template-workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
node-version: "20"

- name: Install dependencies
run: npm install
run: npm ci
working-directory: scripts

- name: Update Template Workflows
Expand Down
14 changes: 14 additions & 0 deletions samples/defang-provider-handoff/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Defang Provider Handoff Sample

If you are using Defang to deploy your application into your customer's cloud accounts, you may want to provide a white-labeled static site that your customers can use to configure their cloud account for your deployment. This sample demonstrates how to do that.

The `compose.yaml` file in this directory defines a single service, `app`, which serves a static site on port 80. The static site is built from the `./app` directory, which contains an `index.html` file that provides instructions for the customer on how to configure their cloud account for your deployment.

---

Title: Defang Provider Handoff Sample

Short Description: A sample application that demonstrates how to provide a white-labeled static site for customers to configure their cloud accounts for your deployment.

Tags: Defang, Cloud, Deployment, Static Site
Languages: HTML, CSS, JavaScript
1 change: 1 addition & 0 deletions samples/defang-provider-handoff/compose.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
name: defang-provider-handoff
services:
app:
restart: unless-stopped
Expand Down
27 changes: 27 additions & 0 deletions samples/html-css-js/app/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Default .dockerignore file for Defang
**/__pycache__
**/.direnv
**/.DS_Store
**/.envrc
**/.git
**/.github
**/.idea
**/.next
**/.vscode
**/compose.*.yaml
**/compose.*.yml
**/compose.yaml
**/compose.yml
**/docker-compose.*.yaml
**/docker-compose.*.yml
**/docker-compose.yaml
**/docker-compose.yml
**/node_modules
**/Thumbs.db
Dockerfile
*.Dockerfile
# Ignore our own binary, but only in the root to avoid ignoring subfolders
defang
defang.exe
# Ignore our project-level state
.defang*
42 changes: 37 additions & 5 deletions tools/testing/deployer/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"regexp"
"strings"
"time"
"encoding/json"

"defang.io/tools/testing/detector"
"defang.io/tools/testing/logger"
Expand Down Expand Up @@ -207,15 +208,27 @@ func (d *CliDeployer) RunDeployTest(ctx context.Context, t test.TestInfo) (*test
result.DeploySucceeded = cmd.ProcessState.Success()
}

urls := findUrlsInOutput(d.Stdout.String())
if len(urls) == 0 {
result.Message = "No service URLs found in deployment output"
// run `defang ps --json` to get the service URLs instead of parsing the output of compose up, as the output may not be stable and may change in the future
cmd, err = d.RunCommand(ctx, nil, "defang", "ps", "--json")
if err != nil {
result.Message = fmt.Sprintf("Failed to run `defang ps --json` to get service URLs: %v", err)
log.Printf(result.Message)
return result, fmt.Errorf(result.Message)
}

services, err := parseTrailingServicesJSON(d.Stdout.Bytes(), log)
if err != nil {
result.Message = fmt.Sprintf("Failed to parse service URLs: %v", err)
log.Printf(result.Message)
return result, fmt.Errorf(result.Message)
}

result.TotalServices = len(urls)
for _, url := range urls {
result.TotalServices = len(services)
for _, svc := range services {
if svc.Endpoint == "" {
continue
}
url := svc.Endpoint
log.Printf(" * Testing service URL %v", url)
code, err := testURL(context.Background(), log, url) // Still do a URL test if the test context is cancelledt
if err == nil {
Expand All @@ -241,6 +254,25 @@ func (d *CliDeployer) RunDeployTest(ctx context.Context, t test.TestInfo) (*test
return result, nil
}

type ServiceEndpoint struct {
Service string `json:"service"`
Endpoint string `json:"endpoint"`
}

func parseTrailingServicesJSON(data []byte, log logger.Logger) ([]ServiceEndpoint, error) {
idx := bytes.LastIndex(data, []byte("["))
if idx == -1 {
return nil, fmt.Errorf("no JSON array found in output")
}

var services []ServiceEndpoint
if err := json.NewDecoder(bytes.NewReader(data[idx:])).Decode(&services); err != nil {
return nil, fmt.Errorf("Failed to decode `defang ps --json` output: %v", err)
}

return services, nil
}

func testURL(ctx context.Context, logger logger.Logger, url string) (int, error) {
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
if err != nil {
Expand Down
Loading