Skip to content
Open
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
16 changes: 11 additions & 5 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"features": {
"ghcr.io/devcontainers/features/node:1": {},
"ghcr.io/jlaundry/devcontainer-features/azure-functions-core-tools:1": {},
"ghcr.io/devcontainers/features/azure-cli:1": {}
"ghcr.io/devcontainers/features/azure-cli:1": {},
"ghcr.io/azure/azure-dev/azd:0": {},
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
},
"customizations": {
"vscode": {
Expand All @@ -16,10 +18,14 @@
"ms-dotnettools.csdevkit",
"ms-azuretools.vscode-azurefunctions",
"humao.rest-client",
"ms-azuretools.vscode-azurestaticwebapps"
"ms-azuretools.vscode-azurestaticwebapps",
"ms-azuretools.vscode-bicep",
"GitHub.copilot-chat",
"ms-azuretools.azure-dev",
"ms-azuretools.vscode-docker"
]
}
}
},

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
Expand All @@ -33,11 +39,11 @@
// }

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "dotnet restore",
"postCreateCommand": "curl -Lo bicep https://github.com/Azure/bicep/releases/latest/download/bicep-linux-x64 && chmod +x ./bicep && sudo mv ./bicep /usr/local/bin/bicep",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
"remoteUser": "root"
}
8 changes: 4 additions & 4 deletions api/Search.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Azure.Core.Serialization;
using Azure.Search.Documents;
using Azure.Search.Documents.Models;
using Azure.Identity;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
Expand All @@ -15,9 +16,8 @@ namespace WebSearch.Function
{
public class Search
{
private static string searchApiKey = Environment.GetEnvironmentVariable("SearchApiKey", EnvironmentVariableTarget.Process);
private static string searchServiceName = Environment.GetEnvironmentVariable("SearchServiceName", EnvironmentVariableTarget.Process);
private static string searchIndexName = Environment.GetEnvironmentVariable("SearchIndexName", EnvironmentVariableTarget.Process) ?? "good-books";
private static string searchServiceName = Environment.GetEnvironmentVariable("SEARCH_SERVICE_NAME", EnvironmentVariableTarget.Process);
private static string searchIndexName = Environment.GetEnvironmentVariable("SEARCH_INDEX_NAME", EnvironmentVariableTarget.Process) ?? "good-books";

private readonly ILogger<Lookup> _logger;

Expand All @@ -40,7 +40,7 @@ public async Task<HttpResponseData> RunAsync(
SearchClient searchClient = new(
serviceEndpoint,
searchIndexName,
new AzureKeyCredential(searchApiKey)
new DefaultAzureCredential() // Use DefaultAzureCredential for authentication
);

SearchOptions options = new()
Expand Down
19 changes: 19 additions & 0 deletions api/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Stage 1: Build the application
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build-env

WORKDIR /src
COPY . ./

# Restore and publish the project
RUN dotnet publish *.csproj -c Release -o /home/site/wwwroot

# Stage 2: Create the runtime image
FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated9.0

ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true

# Copy the published output from the build stage
COPY --from=build-env /home/site/wwwroot /home/site/wwwroot

EXPOSE 80
5 changes: 2 additions & 3 deletions api/sample.local.settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
"Values": {
"AzureWebJobsStorage": "",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
"SearchApiKey": "",
"SearchServiceName": "",
"SearchIndexName": "good-books"
"SEARCH_SERVICE_NAME": "",
"SEARCH_INDEX_NAME": "good-books"
},
"Host": {
"CORS": "*"
Expand Down
19 changes: 19 additions & 0 deletions azure.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: container-full-stack
infra:
provider: bicep
services:
server:
project: ./api
host: containerapp
language: docker
client:
project: ./client
host: containerapp
language: docker
hooks:
postprovision:
- name: Bulk Insert Data
command: |
cd ./bulk-insert
dotnet build
dotnet run
1 change: 1 addition & 0 deletions bulk-insert/BulkInsert.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<ItemGroup>
<PackageReference Include="Azure.Search.Documents" Version="11.4.0" />
<PackageReference Include="ServiceStack.Text" Version="6.4.0" />
<PackageReference Include="Azure.Identity" Version="1.9.0" />
</ItemGroup>

</Project>
16 changes: 9 additions & 7 deletions bulk-insert/Program.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@

using Azure;
using Azure;
using Azure.Identity;
using Azure.Search.Documents;
using Azure.Search.Documents.Indexes;
using Azure.Search.Documents.Indexes.Models;
using AzureSearch.BulkInsert;
using ServiceStack;

const string BOOKS_URL = "https://raw.githubusercontent.com/Azure-Samples/azure-search-sample-data/main/good-books/books.csv";
const string SEARCH_ENDPOINT = "https://YOUR-SEARCH-RESOURCE-NAME.search.windows.net";
const string SEARCH_KEY = "YOUR-SEARCH-ADMIN-KEY";
const string SEARCH_INDEX_NAME = "good-books";
const string SEARCH_SERVICE_NAME = Environment.GetEnvironmentVariable("SEARCH_SERVICE_NAME") ?? throw new InvalidOperationException("SEARCH_SERVICE_NAME environment variable is not set.");
const string SEARCH_INDEX_NAME = Environment.GetEnvironmentVariable("SEARCH_INDEX_NAME") ?? "good-books";
const string SEARCH_ENDPOINT = $"https://{SEARCH_SERVICE_NAME}.search.windows.net";


Uri searchEndpointUri = new(SEARCH_ENDPOINT);

// Use DefaultAzureCredential for authentication
SearchClient client = new(
searchEndpointUri,
SEARCH_INDEX_NAME,
new AzureKeyCredential(SEARCH_KEY));
new AzureDeveloperCliCredential());

SearchIndexClient clientIndex = new(
searchEndpointUri,
new AzureKeyCredential(SEARCH_KEY));
new AzureDeveloperCliCredential());

await CreateIndexAsync(clientIndex);
await BulkInsertAsync(client);
Expand Down
18 changes: 18 additions & 0 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Use an official Node.js runtime as a base image
FROM node:18-alpine

# Set the working directory
WORKDIR /usr/src/app

# Copy the static files to the container
COPY . .

# Expose the port the app runs on
ENV PORT=3000
EXPOSE 3000

# Use a simple HTTP server to serve the static files
RUN npm install -g http-server

# Start the HTTP server
CMD ["http-server", "-p", "3000"]
Loading