- macOS, Linux, or Windows 10/11 with the Windows Subsystem for Linux set up
- .NET 9.0 SDK
- Dapr
- Docker Desktop
These instructions allow you to run the Contoso Ads applications "natively" on your development machine including their Dapr sidecars. PostgreSQL and Azure Storage, emulated using Azurite, run in Docker Containers.
Run the following shell script in bash or zsh to create the required storage artifacts and a secrets file. You only need to execute this step once, as long as you don't delete the Docker volume that stores Azurite's workspace (see Stopping and cleaning up).
cd contosoads-containerapp
# Run Azurite
docker compose -f compose.deps.yaml up -d
# Create a secrets.json store for Dapr and Azurite
# This file is already included in .gitignore
cat << EOF > secrets.json
{
"storageAccount": "devstoreaccount1",
"storageAccountKey": "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="
}
EOF
# Copy secrets file to every project
cp secrets.json src/ContosoAds.Web/
mv secrets.json src/ContosoAds.ImageProcessor/
# Create blob container and queues
export AZURE_STORAGE_CONNECTION_STRING="DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;"
az storage container create -n images --public-access blob
az storage queue create -n thumbnail-request
az storage queue create -n thumbnail-result
docker compose -f compose.deps.yaml down
Next, make sure the endpoint settings for all Dapr components located in the
components
directory use 127.0.0.1
as endpoint (these are the default
settings).
# imageprocessor-storage.yaml and web-storage.yaml
- name: endpoint
value: "http://127.0.0.1:10000"
# thumbnail-request-receiver.yaml, thumbnail-request-sender.yaml,
# thumbnail-result-receiver.yaml and thumbnail-result-sender.yaml
- name: endpoint
value: "http://127.0.0.1:10001"
Run the following commands in a shell to compile the source code on the fly and start the application and its dependencies:
cd contosoads-containerapp
docker compose -f compose.deps.yaml --profile all up -d
dapr run -f .
Open https://localhost:7125 in your favorite browser to use the Contoso Ads web application.
To stop the application, enter CTRL-C
in the terminal window where you have run
dapr run -f .
.
To shut down the PostgreSQL and Azurite containers run
docker compose -f compose.deps.yaml --profile all down
If you want to remove all Docker volumes created for PostgreSQL and Azurite (e.g., to quickly start from scratch with an empty database and storage), run
docker compose -f compose.deps.yaml --profile all down -v
Open ContosoAds.sln in your favorite IDE or code editor to change the source code, build it, and runs tests.
To build the application and run in the included tests, execute the following commands.
cd contosoads-containerapp
dotnet build
dotnet test