Skip to content

Commit 1665138

Browse files
committed
Add required AZD metadata
1 parent 26a2de7 commit 1665138

File tree

5 files changed

+109
-11
lines changed

5 files changed

+109
-11
lines changed

.github/workflows/azure-dev.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Deploy to Azure
2+
on:
3+
workflow_dispatch:
4+
permissions:
5+
id-token: write
6+
contents: read
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
env:
11+
AZURE_CLIENT_ID: ${{ vars.AZURE_CLIENT_ID }}
12+
AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }}
13+
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
14+
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
15+
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
- name: Install azd
20+
uses: Azure/setup-azd@v1.0.0
21+
- name: Log in with Azure (Federated Credentials)
22+
run: |
23+
azd auth login `
24+
--client-id "$Env:AZURE_CLIENT_ID" `
25+
--federated-credential-provider "github" `
26+
--tenant-id "$Env:AZURE_TENANT_ID"
27+
shell: pwsh
28+
- name: Provision Infrastructure
29+
run: azd provision --no-prompt
30+
env:
31+
AZD_INITIAL_ENVIRONMENT_CONFIG: ${{ secrets.AZD_INITIAL_ENVIRONMENT_CONFIG }}
32+
AZURE_RESOURCE_GROUP: ${{ vars.AZURE_RESOURCE_GROUP }}
33+
- name: Deploy Application
34+
run: azd deploy --no-prompt
35+
env:
36+
AZURE_RESOURCE_GROUP: ${{ vars.AZURE_RESOURCE_GROUP }}

azure.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
name: cosmos-db-nosql-rust-quickstart
44
metadata:
55
template: cosmos-db-nosql-rust-quickstart
6+
services:
7+
web:
8+
project: ./src
9+
language: js
10+
host: containerapp
11+
docker:
12+
path: ./Dockerfile
13+
context: ./
14+
pipeline:
15+
provider: github
616
hooks:
717
postprovision:
818
posix:

readme.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<!--
2+
---
3+
page_type: sample
4+
name: "Quickstart: Azure Cosmos DB for NoSQL and Azure SDK for Rust"
5+
description: This is a simple web application to illustrate common basic usage of Azure Cosmos DB for NoSQL and the Azure SDK for Rust.
6+
urlFragment: template
7+
languages:
8+
- rust
9+
- azdeveloper
10+
products:
11+
- azure-cosmos-db
12+
---
13+
-->
14+
15+
# Quickstart: Azure Cosmos DB for NoSQL client library for Go
16+
17+
This is a simple web application to illustrate common basic usage of Azure Cosmos DB for NoSQL's client library for Rust. This sample application accesses an existing account, database, and container using the [`azure_data_cosmos`](https://docs.rs/azure_data_cosmos) and [`azure_identity`](https://docs.rs/azure_identity) crates.
18+
19+
## Prerequisites
20+
21+
- [Docker](https://www.docker.com/)
22+
- [Azure Developer CLI](https://aka.ms/azd-install)
23+
- [Rust 1+](https://go.dev/dl/)
24+
25+
## Quickstart
26+
27+
1. Log in to Azure Developer CLI.
28+
29+
```bash
30+
azd auth login
31+
```
32+
33+
> [!TIP]
34+
> This is only required once per-install.
35+
36+
1. Initialize this template (`cosmos-db-nosql-rust-quickstart`) using `azd init`
37+
38+
```bash
39+
azd init --template cosmos-db-nosql-rust-quickstart
40+
```
41+
42+
1. Ensure that **Docker** is running in your environment.
43+
44+
1. Use `azd up` to provision your Azure infrastructure and deploy the web application to Azure.
45+
46+
```bash
47+
azd up
48+
```
49+
50+
1. Observed the deployed web application
51+
52+
![Screenshot of the deployed web application.](assets/web.png)

src/.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
debug/
2+
target/
3+
Cargo.lock

src/app/cosmos.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use futures::StreamExt;
22
use serde_json;
3-
use azure_data_cosmos::{CosmosClient, CosmosClientOptions, PartitionKey};
3+
use azure_data_cosmos::{CosmosClient, PartitionKey};
44
use azure_identity::DefaultAzureCredential;
55
use crate::item::Item;
66

@@ -17,10 +17,7 @@ where
1717

1818
let credential = DefaultAzureCredential::new().unwrap();
1919

20-
let client_options = CosmosClientOptions::default();
21-
let client_options = Some(client_options);
22-
23-
let service_client = match CosmosClient::new(&endpoint, credential, client_options) {
20+
let client = match CosmosClient::new(&endpoint, credential, None) {
2421
Ok(client) => client,
2522
Err(e) => {
2623
eprintln!("Error creating CosmosClient: {}", e);
@@ -29,10 +26,10 @@ where
2926
};
3027
callback("Client created".to_string());
3128

32-
let database_client = service_client.database_client(&database_name);
29+
let database = client.database(&database_name);
3330
callback(format!("Get database:\t {}", database_name));
3431

35-
let container_client = database_client.container_client(&container_name);
32+
let container = database.container(&container_name);
3633
callback(format!("Get container:\t {}", container_name));
3734

3835
{
@@ -47,7 +44,7 @@ where
4744

4845
let partition_key = PartitionKey::from(item.category.clone());
4946

50-
let upsert_response = container_client.upsert_item(partition_key, item, None).await;
47+
let upsert_response = container.upsert_item(partition_key, item, None).await;
5148

5249
match upsert_response {
5350
Ok(r) => {
@@ -80,7 +77,7 @@ where
8077

8178
let partition_key = PartitionKey::from(item.category.clone());
8279

83-
let upsert_response = container_client.upsert_item(partition_key, item, None).await;
80+
let upsert_response = container.upsert_item(partition_key, item, None).await;
8481

8582
match upsert_response {
8683
Ok(r) => {
@@ -105,7 +102,7 @@ where
105102
let item_id = "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb";
106103
let item_partition_key = "gear-surf-surfboards";
107104

108-
let read_response = container_client.read_item::<Item>(item_partition_key, item_id, None).await;
105+
let read_response = container.read_item::<Item>(item_partition_key, item_id, None).await;
109106

110107
match read_response {
111108
Ok(r) => {
@@ -133,7 +130,7 @@ where
133130

134131
let query = format!("SELECT * FROM c WHERE c.category = '{}'", item_partition_key);
135132

136-
let page_response = container_client.query_items::<Item>(&query, partition_key, None);
133+
let page_response = container.query_items::<Item>(&query, partition_key, None);
137134

138135
callback("Run query:".to_string());
139136
match page_response {

0 commit comments

Comments
 (0)