Skip to content

Commit

Permalink
Merge pull request #9 from pinecone-io/address-awesome-azd-issues
Browse files Browse the repository at this point in the history
Address awesome azd issues
  • Loading branch information
cwaddingham authored Aug 22, 2024
2 parents c247653 + f7e0414 commit 8bcc8d8
Show file tree
Hide file tree
Showing 17 changed files with 371 additions and 292 deletions.
Empty file modified .azd/hooks/postdeploy.sh
100644 → 100755
Empty file.
11 changes: 11 additions & 0 deletions .azd/hooks/postprovision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ merge_env_files() {
script_dir="$(dirname "$(readlink -f "$0")")"

env_local="$script_dir/../../.env.local"

# If AZURE_ENV_NAME isn't set get it from azd. Failing that, prompt for it.
if [ -z $AZURE_ENV_NAME ];then
AZURE_ENV_NAME=$(azd env get-values | grep AZURE_ENV_NAME | awk -F= '{print $NF}' | sed -e 's/"//g')
if [ -z $AZURE_ENV_NAME ]; then
echo -n "AZURE_ENV_NAME not set, please provide: "
read value
AZURE_ENV_NAME=$value
fi
fi

env_azd="$script_dir/../../.azure/${AZURE_ENV_NAME}/.env"

env_azure="$script_dir/../../.env.azure"
Expand Down
Empty file modified .azd/hooks/predeploy.sh
100644 → 100755
Empty file.
12 changes: 12 additions & 0 deletions .azd/hooks/preprovision.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,15 @@ $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path

# Run script to generate an `env-vars.json` file used by the infra scripts
& $(Join-Path $scriptDir "../scripts/create-infra-env-vars.ps1")

if [ -z $AZURE_ENV_NAME ]; then
# The Azure environment hasn't been set yet. Check if there's a directory under .azure and use that. Otherwise, prompt for one.
num_envs=$(ls .azure/ | grep -v -e .gitignore -e config.json | wc -l)
if [ $num_envs = 1 ];then
export AZURE_ENV_NAME=`ls .azure/ | grep -v -e .gitignore -e config.json | sed -e 's/\///'`
else
echo -n "Unable to determine AZURE_ENV_NAME, please provide it: "
read value
export AZURE_ENV_NAME=$value
fi
fi
4 changes: 2 additions & 2 deletions .azd/hooks/preprovision.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/bash


script_dir="$(dirname "$(readlink -f "$0")")"

# Run script to generate the environment variables in .env
"$script_dir/../scripts/create-env.sh"

# Run script to generate an `env-vars.json` file used by the infra scripts
"$script_dir/../scripts/create-infra-env-vars.sh"

"$script_dir/../scripts/create-infra-env-vars.sh"
8 changes: 4 additions & 4 deletions .azd/scripts/create-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ update_env_var() {
local var_value=$2
for i in "${!env_vars[@]}"; do
if [[ "${env_vars[$i]}" == "$var_name="* ]]; then
env_vars[$i]="$var_name=\"$var_value\""
env_vars[$i]="$var_name=$var_value"
return
fi
done
env_vars+=("$var_name=\"$var_value\"")
env_vars+=("$var_name=$var_value")
}

# Initialize the env_vars array
Expand Down Expand Up @@ -99,8 +99,8 @@ read_env_vars "$template_path"
for entry in "${required_vars[@]}"; do
if [[ -z ${!entry} ]]; then
echo -n "$entry is not set in the current environment, please supply it: "
read -r line
update_env_var "$entry" "$line"
read -r value
update_env_var "$entry" "$value"
fi
done

Expand Down
12 changes: 7 additions & 5 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
"image": "mcr.microsoft.com/devcontainers/python:3.10-bullseye",
"features": {
// See https://containers.dev/features for list of features
"ghcr.io/devcontainers/features/docker-in-docker:2": {
},
"ghcr.io/azure/azure-dev/azd:latest": {}
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/azure/azure-dev/azd:latest": {},
"ghcr.io/devcontainers/features/node:1": {
"version": "lts"
}
},
"customizations": {
"vscode": {
Expand All @@ -23,9 +25,9 @@
"forwardPorts": [
// Forward ports if needed for local development
],
"postCreateCommand": "",
"postCreateCommand": "npm install",
"remoteUser": "vscode",
"hostRequirements": {
"memory": "8gb"
}
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ TODO.md

tmp/*
src/**/__pycache__/

assets/processed_files
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The quickest way to try this `azd` template out is using [GitHub Codespaces](htt
[![Open in GitHub Codespaces](https://img.shields.io/static/v1?style=for-the-badge&label=GitHub+Codespaces&message=Open&color=brightgreen&logo=github)](https://github.com/codespaces/new/pinecone-io/pinecone-assistant-azd)
[![Open in Dev Container](https://img.shields.io/static/v1?style=for-the-badge&label=Dev+Containers&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/pinecone-io/pinecone-assistant-azd)

You can also get started quickly using a terminal. Simply run `azd init -t pinecone-assistant-azd` to clone the project.
You can also get started quickly using a terminal. Simply run `azd init -t pinecone-io/pinecone-assistant-azd` to clone the project.

### Create a Pinecone API key

Expand Down Expand Up @@ -83,6 +83,13 @@ azd provision
azd deploy
```

**Note:**
> If deployment fails initially, try running
```bash
sh ./.azd/hooks/postprovision
```
> to make sure your environment is setup properly.
This will provision the necessary Azure resources, run the Python import script to seed your new assistant with the sample PDFs in /assets, and deploy the application to Azure.

### Adding new files to the Assistant
Expand Down
2 changes: 0 additions & 2 deletions assets/processed_files

This file was deleted.

4 changes: 3 additions & 1 deletion infra/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ targetScope = 'subscription'
@minLength(1)
@maxLength(6)
@description('Name of the the environment e.g. `dev`, `uat`, `prod`')
param environmentName string
param environmentName string

@minLength(1)
@description('Primary location for all resources')
Expand Down Expand Up @@ -34,6 +34,8 @@ var abbrs = loadJsonContent('./abbreviations.json')
// This file is created by a `preprovision` hook - if you're seeing an error here and elsewhere because this file doesn't exist, run `.azd/scripts/create-infra-env-vars.ps1` directly or via `azd provision` to create the file
var envVars = loadJsonContent('./env-vars.json')

// Conditionally set environmentName if it is empty

var projectName = envVars.PROJECT_NAME
var webAppServiceName = envVars.SERVICE_WEB_SERVICE_NAME

Expand Down
3 changes: 0 additions & 3 deletions infra/main.parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"environmentName": {
"value": "dev"
},
"location": {
"value": "eastus"
},
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "pinecone-assistant-sample-app",
"version": "0.1.0",
"private": true,
"packageManager": "pnpm@9.7.1",
"packageManager": "pnpm@9.8.0",
"scripts": {
"dev": "next dev",
"build": "next build",
Expand All @@ -14,27 +14,27 @@
},
"dependencies": {
"@types/uuid": "^10.0.0",
"ai": "^3.3.12",
"ai": "^3.3.15",
"extended-eventsource": "^1.4.9",
"next": "14.2.5",
"next": "14.2.6",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-markdown": "^9.0.1",
"uuid": "^10.0.0",
"dotenv": "16.4.5"
},
"devDependencies": {
"@pinecone-database/pinecone": "3.0.0",
"@types/node": "^22.4.1",
"@types/react": "^18.3.3",
"@pinecone-database/pinecone": "3.0.1",
"@types/node": "^22.5.0",
"@types/react": "^18.3.4",
"@types/react-dom": "^18.3.0",
"autoprefixer": "^10.4.20",
"eslint": "^9.9.0",
"eslint-config-next": "14.2.5",
"eslint": "^8.56.0",
"eslint-config-next": "14.2.6",
"postcss": "^8.4.41",
"tailwind": "^4.0.0",
"tailwindcss": "^3.4.10",
"typescript": "^5.5.4",
"dotenv": "16.4.5"
}
}
}
Loading

0 comments on commit 8bcc8d8

Please sign in to comment.