Skip to content

Commit 27f7f1c

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/linda-golang' into linda-golang
2 parents be123e4 + 2cc9c46 commit 27f7f1c

File tree

20 files changed

+353
-132
lines changed

20 files changed

+353
-132
lines changed

.github/workflows/deploy-changed-samples.yml

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,49 @@ jobs:
2020
- name: Checkout code
2121
uses: actions/checkout@v4
2222
with:
23-
fetch-depth: 1
24-
25-
- name: Fetch main branch
26-
run: git fetch origin main:main # Fetch the main branch reference for comparison
23+
fetch-depth: 0
2724

2825
- name: Identify changed samples
2926
run: |
30-
git diff --name-only HEAD main | grep '^samples/' | awk -F'/' '{print $1"/"$2}' | sort | uniq > changed_samples.txt
31-
if [ ! -s changed_samples.txt ]; then
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
3240
echo "No samples have changed. Exiting..."
33-
exit 0
3441
fi
35-
3642
- name: Install Golang
3743
uses: actions/setup-go@v5
3844
with:
3945
go-version-file: tools/testing/go.mod
4046
cache-dependency-path: |
4147
tools/testing/go.sum
48+
if: env.should_continue == 'true'
4249

4350
- name: Build the test tool using Go
4451
run: |
4552
go mod tidy
4653
go build ./cmd/loadtest
4754
working-directory: tools/testing/
55+
if: env.should_continue == 'true'
4856

4957
- name: Install Defang
5058
run: |
5159
eval "$(curl -fsSL s.defang.io/install)"
60+
if: env.should_continue == 'true'
5261

5362
- name: Run tests
5463
id: run-tests
5564
shell: bash # implies set -o pipefail, so pipe below will keep the exit code from loadtest
65+
if: env.should_continue == 'true'
5666
env:
5767
FIXED_VERIFIER_PK: ${{ secrets.FIXED_VERIFIER_PK }}
5868
TEST_AWS_ACCESS_KEY: ${{ secrets.TEST_AWS_ACCESS_KEY }}
@@ -71,6 +81,8 @@ jobs:
7181
TEST_MB_DB_PASS: ${{ secrets.TEST_MB_DB_PASS }}
7282
TEST_MB_DB_PORT: ${{ secrets.TEST_MB_DB_PORT }}
7383
TEST_MB_DB_USER: ${{ secrets.TEST_MB_DB_USER }}
84+
TEST_MONGO_INITDB_ROOT_USER: ${{ secrets.TEST_MONGO_INITDB_ROOT_USER }}
85+
TEST_MONGO_INITDB_ROOT_PASSWORD: ${{ secrets.TEST_MONGO_INITDB_ROOT_PASSWORD }}
7486
TEST_NC_DB: ${{ secrets.TEST_NC_DB }}
7587
TEST_NC_S3_ENDPOINT: ${{ secrets.TEST_NC_S3_ENDPOINT }}
7688
TEST_NC_S3_BUCKET_NAME: ${{ secrets.TEST_NC_S3_BUCKET_NAME }}
@@ -87,16 +99,14 @@ jobs:
8799
run: |
88100
SAMPLES=$(sed 's|^samples/||' changed_samples.txt | paste -s -d ',' -)
89101
echo "Running tests for samples: $SAMPLES"
90-
91102
mkdir output
92103
# concurrency is set to 10 to avoid exhausting our fargate vCPU limits when running
93104
# kaniko builds, which consume 4 vCPUs each. the limit is currently set to 60--6.5 of
94105
# which are used to run the staging stack. So floor((60-6.5)/4) = 13 is our upper limit
95106
./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
96-
97107
- name: Upload Output as Artifact
98108
uses: actions/upload-artifact@v4
99-
if: success() || steps.run-tests.outcome == 'failure' # Always upload result unless cancelled
109+
if: env.should_continue == 'true' && (success() || steps.run-tests.outcome == 'failure') # Always upload result unless cancelled
100110
with:
101111
name: program-output
102112
path: output/**

samples/angular-express/README.md

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,56 @@
22

33
[![1-click-deploy](https://defang.io/deploy-with-defang.png)](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-angular-express-template%26template_owner%3DDefangSamples)
44

5-
This project demonstrates both client-side component rendering and hydration with Angular, as well as server-side rendering with Node.js and Socket.IO for real-time communication. It also includes Docker configurations for easy deployment.
5+
This sample demonstrates how to deploy a full-stack Angular and Node.js application with Defang. It uses Socket.IO for real-time communication. The Docker setup ensures the app can be easily built and deployed.
66

7-
## NOTE
7+
## Prerequisites
88

9-
This sample showcases how you could deploy a full-stack application with Angular and Node.js using Defang. The Docker setup ensures the app can be easily built and deployed.
9+
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
10+
2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account
11+
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)
12+
4. Install [Node.js](https://nodejs.org/en/download/package-manager/)
13+
5. Install [Angular CLI](https://angular.io/cli)
1014

11-
## Essential Setup Files
15+
## Development
16+
For development, we use two local containers, one for the frontend Angular service and one for the backend service in Express. It also uses Caddy as a web server for serving static files.
1217

13-
1. Download [Defang CLI](https://github.com/defang-io/defang)
14-
2. (Optional) If you are using [Defang BYOC](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) authenticated with your AWS account
15-
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)
18+
To run the application locally, you can use the following command:
1619

17-
## Prerequisites
20+
```bash
21+
docker compose -f compose.dev.yaml up --build
22+
```
1823

19-
1. Download [Defang CLI](https://github.com/defang-io/defang)
20-
2. (Optional) If you are using [Defang BYOC](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) make sure you have properly authenticated your AWS account
21-
3. [Node.js](https://nodejs.org/en/download/package-manager/)
22-
4. [Angular CLI](https://angular.io/cli)
24+
## Configuration
2325

24-
## A Step-by-Step Guide for deployment
26+
For this sample, you will not need to provide [configuration](https://docs.defang.io/docs/concepts/configuration).
2527

26-
1. Open the terminal and type `defang login`
27-
2. Type `defang compose up` in the CLI
28-
3. Your app should be up and running with Defang in minutes!
28+
If you wish to provide configuration, see below for an example of setting a configuration for a value named `API_KEY`.
2929

30-
## Development
30+
```bash
31+
defang config set API_KEY
32+
```
33+
34+
## Deployment
35+
36+
> [!NOTE]
37+
> Download [Defang CLI](https://github.com/DefangLabs/defang)
38+
39+
### Defang Playground
40+
41+
Deploy your application to the Defang Playground by opening up your terminal and typing:
42+
```bash
43+
defang compose up
44+
```
45+
46+
### BYOC (AWS)
3147

32-
For development, we use two local containers, one for the frontend Angular service and one for the backend service in Express. It also uses Caddy as a web server for serving static files. To run the sample locally after cloning the repository, you can run on Docker by doing:
48+
If you want to deploy to your own cloud account, you can use Defang BYOC:
3349

34-
1. `docker compose -f compose.dev.yaml up --build`
50+
1. [Authenticate your AWS account](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html), and check that you have properly set your environment variables like `AWS_PROFILE`, `AWS_REGION`, `AWS_ACCESS_KEY_ID`, and `AWS_SECRET_ACCESS_KEY`.
51+
2. Run in a terminal that has access to your AWS environment variables:
52+
```bash
53+
defang --provider=aws compose up
54+
```
3555

3656
---
3757

@@ -41,4 +61,4 @@ Short Description: A full-stack application using Angular for the frontend and N
4161

4262
Tags: Angular, Node.js, Socket.IO, TypeScript, JavaScript
4363

44-
Languages: nodejs
64+
Languages: nodejs

samples/bullmq-bullboard-redis/README.md

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,66 @@
22

33
[![1-click-deploy](https://defang.io/deploy-with-defang.png)](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-bullmq-bullboard-redis-template%26template_owner%3DDefangSamples)
44

5-
This sample project demonstrates how to deploy a BullMQ message queue on top of managed Redis with a queue processor and a dashboard to monitor the queue.
5+
This sample demonstrates how to deploy a BullMQ message queue on top of managed Redis with a queue processor and a dashboard to monitor the queue.
66

7-
Once your app is up and running you can go to the `/board` route for the `board` service to see the Bull Board dashboard and use the username `admin` and the password you set to log in (see [Deploying](#deploying)).
7+
Once your app is up and running you can go to the `/board` route for the `board` service to see the Bull Board dashboard and use the username `admin` and the board password you set to log in (see [Configuration](#configuration)).
88

9-
To add a job to the queue, you can go to the `/add` route of the `api` service. This will use some default values so you can test things out. You can also see an example of a post request in the [sample http request](./api/add.test.http) file.
9+
To add a job to the queue, you can go to the `/add` route of the `api` service. This will use some default values so you can test things out. You can also see an example of a post request in the [sample HTTP request](./api/add.test.http) file.
1010

1111
The `worker` service is the queue processor that will process the jobs added to the queue. You can see in the `compose.yaml` file that the `worker` service is set to scale to 2 instances. This means that there will be 2 workers processing jobs from the queue. You can set this to your desired number of workers, but we wanted to show how you can increase the number of workers to handle more jobs.
1212

1313
## Prerequisites
1414

15-
1. Download <a href="https://github.com/defang-io/defang">Defang CLI</a>
16-
2. (optional) If you are using <a href="https://docs.defang.io/docs/concepts/defang-byoc">Defang BYOC</a>, make sure you have properly <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html">authenticated your AWS account</a>.
15+
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
16+
2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account
17+
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)
1718

18-
## Deploying
19+
## Development
1920

20-
1. Open the terminal and type `defang login`
21-
2. Run `defang config set BOARD_PASSWORD` to set the password for the BullBoard dashboard.
22-
3. Type `defang compose up` in the CLI.
23-
4. Your app will be running within a few minutes.
21+
To run the application locally, you can use the following command:
2422

25-
## Local Development
23+
```bash
24+
docker compose -f compose.dev.yaml up --build
25+
```
2626

27-
1. Run `docker compose -f compose.dev.yaml up --build`
27+
## Configuration
28+
29+
For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration):
30+
31+
> Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
32+
33+
### `BOARD_PASSWORD`
34+
Set a board password and use together with the board username `admin` when signing in.
35+
```bash
36+
defang config set BOARD_PASSWORD
37+
```
38+
39+
### `QUEUE`
40+
```bash
41+
defang config set QUEUE
42+
```
43+
44+
## Deployment
45+
46+
> [!NOTE]
47+
> Download [Defang CLI](https://github.com/DefangLabs/defang)
48+
49+
### Defang Playground
50+
51+
Deploy your application to the Defang Playground by opening up your terminal and typing:
52+
```bash
53+
defang compose up
54+
```
55+
56+
### BYOC (AWS)
57+
58+
If you want to deploy to your own cloud account, you can use Defang BYOC:
59+
60+
1. [Authenticate your AWS account](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html), and check that you have properly set your environment variables like `AWS_PROFILE`, `AWS_REGION`, `AWS_ACCESS_KEY_ID`, and `AWS_SECRET_ACCESS_KEY`.
61+
2. Run in a terminal that has access to your AWS environment variables:
62+
```bash
63+
defang --provider=aws compose up
64+
```
2865

2966
---
3067

samples/bullmq-bullboard-redis/api/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Use the slim version of Node.js v20 on Debian Bookworm as the base image
22
FROM node:20-bookworm-slim
33

4+
# Install tools for healthcheck
5+
RUN apt-get update && apt-get install -y \
6+
curl \
7+
&& rm -rf /var/lib/apt/lists/*
8+
49
# Set the working directory
510
WORKDIR /app
611

samples/bullmq-bullboard-redis/board/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Use the slim version of Node.js on Debian Bookworm as the base image
22
FROM node:20-bookworm-slim
33

4+
# Install tools for healthcheck
5+
RUN apt-get update && apt-get install -y \
6+
curl \
7+
&& rm -rf /var/lib/apt/lists/*
8+
49
# Set the working directory
510
WORKDIR /app
611

samples/bullmq-bullboard-redis/compose.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ services:
1212
- REDIS=redis://redisx:6379
1313
- BOARD_PASSWORD
1414
- QUEUE
15+
healthcheck:
16+
test: ["CMD", "curl", "-f", "127.0.0.1:3000"]
1517
depends_on:
1618
- redisx
1719
#deploy:
@@ -31,6 +33,8 @@ services:
3133
environment:
3234
- REDIS=redis://redisx:6379
3335
- QUEUE
36+
healthcheck:
37+
test: ["CMD", "curl", "-f", "127.0.0.1:3001"]
3438
depends_on:
3539
- redisx
3640
#deploy:
@@ -41,15 +45,13 @@ services:
4145
worker:
4246
restart: unless-stopped
4347
deploy:
44-
replicas: 2
48+
replicas: 1
4549
build:
4650
context: ./worker
4751
dockerfile: Dockerfile
4852
environment:
4953
- REDIS=redis://redisx:6379
5054
- QUEUE
51-
healthcheck:
52-
test: ["CMD", "wget", "-q", "--spider", "127.0.0.1:3000"]
5355
depends_on:
5456
- redisx
5557
#deploy:

samples/csharp-dotnet/README.md

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,64 @@
22

33
[![1-click-deploy](https://defang.io/deploy-with-defang.png)](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-csharp-dotnet-template%26template_owner%3DDefangSamples)
44

5-
This project is a simple task manager application using ASP.NET Core. We show case how to deploy it to both Defang and Docker for both prod and dev environments.
5+
This sample project is a simple task manager application using ASP.NET Core for the backend and JavaScript for client-side component rendering.
66

7-
## NOTE
7+
It showcases how you could deploy a full-stack application with ASP.NET Core and JavaScript using Defang. The Docker setup ensures the app can be easily built and tested during development.
88

9-
This sample showcases how you could deploy a full-stack application with ASP.NET Core and JavaScript using Defang. The Docker setup ensures the app can be easily built and tested during development.
10-
11-
## Essential Setup Files
9+
## Prerequisites
1210

13-
1. Download [Defang CLI](https://github.com/defang-io/defang)
14-
2. (Optional) If you are using [Defang BYOC](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) authenticated with your AWS account
11+
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
12+
2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account
1513
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)
14+
4. Install [ASP.NET Core](https://dotnet.microsoft.com/download/dotnet-core)
1615

17-
## Prerequisites
16+
## Development
1817

19-
1. Download [Defang CLI](https://github.com/defang-io/defang)
20-
2. (Optional) If you are using [Defang BYOC](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) make sure you have properly authenticated your AWS account
21-
3. [ASP.NET Core](https://dotnet.microsoft.com/download/dotnet-core)
18+
For development, we use two local containers, one for the frontend service and one for the backend service in ASP.NET Core. It also uses Caddy as a web server for serving static files.
2219

23-
## A Step-by-Step Guide for deployment
20+
To run the application locally, you can use the following command:
2421

25-
1. Open the terminal and type `defang login`
26-
2. Type `defang compose up` in the CLI
27-
3. Your app should be up and running with Defang in minutes!
22+
```bash
23+
docker compose -f compose.dev.yaml up --build
24+
```
25+
## Configuration
2826

29-
## Development
27+
For this sample, you will not need to provide [configuration](https://docs.defang.io/docs/concepts/configuration).
28+
29+
If you wish to provide configuration, see below for an example of setting a configuration for a value named `API_KEY`.
30+
31+
```bash
32+
defang config set API_KEY
33+
```
34+
35+
## Deployment
36+
37+
> [!NOTE]
38+
> Download [Defang CLI](https://github.com/DefangLabs/defang)
39+
40+
### Defang Playground
41+
42+
Deploy your application to the Defang Playground by opening up your terminal and typing:
43+
```bash
44+
defang compose up
45+
```
46+
47+
### BYOC (AWS)
3048

31-
For development, we use two local containers, one for the frontend service and one for the backend service in ASP.NET Core. It also uses Caddy as a web server for serving static files. To run the sample locally after cloning the repository, you can run on Docker by doing:
49+
If you want to deploy to your own cloud account, you can use Defang BYOC:
3250

33-
`docker compose -f compose.dev.yaml up --build`
51+
1. [Authenticate your AWS account](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html), and check that you have properly set your environment variables like `AWS_PROFILE`, `AWS_REGION`, `AWS_ACCESS_KEY_ID`, and `AWS_SECRET_ACCESS_KEY`.
52+
2. Run in a terminal that has access to your AWS environment variables:
53+
```bash
54+
defang --provider=aws compose up
55+
```
3456

3557
---
3658

3759
Title: C# & ASP.NET Core
3860

39-
Short Description: A task manager using ASP.NET Core containerized with Docker.
61+
Short Description: A simple task manager application using C# and ASP.NET Core.
4062

4163
Tags: ASP.NET Core, JavaScript, C#
4264

43-
Languages: C#
65+
Languages: C#

0 commit comments

Comments
 (0)