Skip to content

Commit 0243cb3

Browse files
committed
fix: Refactored the terraform scripts and fixing the deployment button.
1 parent 7b767c7 commit 0243cb3

24 files changed

Lines changed: 103 additions & 12 deletions

ai/use-cases/sentiment-intelligence/README.md

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ Sentiment Intelligence is a React and FastAPI demonstration application for
44
brand monitoring, customer-feedback analysis, and natural-language data access
55
with Oracle Autonomous AI Database, Select AI, and OCI Generative AI.
66

7-
[![Deploy to Oracle Cloud](https://oci-resourcemanager-plugin.plugins.oci.oraclecloud.com/latest/deploy-to-oracle-cloud.svg)](https://cloud.oracle.com/resourcemanager/stacks/create?zipUrl=https://github.com/oracle-devrel/ai-quick-deploys/releases/latest/download/sentiment-intel-stack.zip)
7+
8+
[![Deploy to Oracle Cloud](https://oci-resourcemanager-plugin.plugins.oci.oraclecloud.com/latest/deploy-to-oracle-cloud.svg)](https://cloud.oracle.com/resourcemanager/stacks/create?zipUrl=https://github.com/oracle-devrel/technology-engineering/raw/refs/heads/aicoe-sentiment-intelligence/ai/use-cases/sentiment-intelligence/sentiment-intelligence.zip)
9+
810

911
> Click the button above to deploy this application directly to your OCI tenancy
1012
> using **OCI Resource Manager**. It provisions a VCN, an OKE Kubernetes cluster,
@@ -35,7 +37,8 @@ sentiment-intelligence/
3537
|-- backend/ FastAPI, python-oracledb, Select AI and OCI SDK (+ Dockerfile)
3638
|-- rag-documents/ Optional sample documents for a separately configured RAG index
3739
|-- scripts/ Developer helper scripts (run.sh starts both services locally)
38-
|-- terraform/ OCI infrastructure as code (OKE, Autonomous DB, OCIR) + Resource Manager schema
40+
|-- deployment/ OCI infrastructure as code (OKE, Autonomous DB, OCIR) + Resource Manager schema
41+
|-- sentiment-intelligence.zip OCI Resource Manager stack package (auto-built from deployment/)
3942
|-- README.md
4043
`-- .gitignore
4144
```
@@ -172,7 +175,7 @@ npm run build
172175

173176
## Deploy to Oracle Cloud Infrastructure
174177

175-
The `terraform/` directory contains infrastructure as code that provisions a
178+
The `deployment/` directory contains infrastructure as code that provisions a
176179
complete runtime on Oracle Cloud Infrastructure:
177180

178181
- A VCN with public, private, and database subnets, gateways, and security lists.
@@ -215,11 +218,14 @@ Resource Manager creates the VCN, OKE cluster, Autonomous Database, OCIR
215218
repositories, and Kubernetes deployments. After apply, push the application
216219
images and complete the post-deploy steps below.
217220

218-
> The button's `zipUrl` must point to a publicly reachable archive of the
219-
> `terraform/` directory. Generate one with
220-
> `cd terraform && zip -r ../sentiment-intel-stack.zip . -x '*.terraform*' 'terraform.tfvars'`
221-
> and host it (for example, as a GitHub release asset), then update the `zipUrl`
222-
> in the button link to match.
221+
> The button's `zipUrl` points at the committed `sentiment-intelligence.zip`
222+
> served raw from this repo on `main`:
223+
> `https://raw.githubusercontent.com/oracle-devrel/technology-engineering/main/ai/use-cases/sentiment-intelligence/sentiment-intelligence.zip`.
224+
> That archive is the `deployment/` directory, rebuilt automatically by the
225+
> pre-commit hook (or manually with `./deployment/build-stack-zip.sh`). It
226+
> resolves once this change is merged to `main` and pushed; until then, upload
227+
> the zip directly via **Resource Manager → Stacks → Create Stack → My
228+
> Configuration**.
223229
224230
### Option 2: Deploy with the Terraform CLI
225231

@@ -233,7 +239,7 @@ images and complete the post-deploy steps below.
233239

234240
1. **Configure variables**:
235241
```bash
236-
cd terraform
242+
cd deployment
237243
cp terraform.tfvars.example terraform.tfvars
238244
# Edit terraform.tfvars with your OCI configuration and DB password
239245
```
@@ -279,10 +285,10 @@ images and complete the post-deploy steps below.
279285

280286
### Option 3: Automated helper script
281287

282-
`terraform/build_and_deploy.sh` wraps the full flow:
288+
`deployment/build_and_deploy.sh` wraps the full flow:
283289

284290
```bash
285-
cd terraform
291+
cd deployment
286292
cp terraform.tfvars.example terraform.tfvars # then edit it
287293
./build_and_deploy.sh deploy # build + push images, apply infra, wire up kubectl
288294

@@ -294,6 +300,26 @@ cp terraform.tfvars.example terraform.tfvars # then edit it
294300
./build_and_deploy.sh destroy # Tear down everything
295301
```
296302

303+
### Resource Manager stack package
304+
305+
`sentiment-intelligence.zip` at the project root is the Resource Manager stack
306+
package — every `deployment/` artifact (Terraform root, modules, and
307+
`schema.yaml`) archived with the configuration at the zip root, which is what
308+
Resource Manager requires. It is regenerated by `deployment/build-stack-zip.sh`.
309+
310+
A git pre-commit hook keeps the package in sync: whenever files under
311+
`deployment/` are staged, it rebuilds the zip and stages it in the same commit.
312+
Because git hooks are not cloned, install it once after cloning:
313+
314+
```bash
315+
cp ai/use-cases/sentiment-intelligence/deployment/hooks/pre-commit \
316+
"$(git rev-parse --git-dir)/hooks/pre-commit"
317+
chmod +x "$(git rev-parse --git-dir)/hooks/pre-commit"
318+
```
319+
320+
The hook is scoped to this project and is a no-op for any other commit in the
321+
monorepo.
322+
297323
### Post-deploy application setup
298324

299325
The Terraform provisions infrastructure only; it does not seed the application
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
# =============================================================================
3+
# Build the OCI Resource Manager stack package.
4+
#
5+
# Produces ../sentiment-intelligence.zip containing every artifact Resource
6+
# Manager needs to create the stack: the Terraform root (*.tf), the child
7+
# modules, and schema.yaml — all at the ROOT of the zip (RMS requires the
8+
# configuration at the archive root, not nested in a folder).
9+
#
10+
# Deployment-time and local-only files are excluded (state, plans, the
11+
# provider cache, tfvars with secrets, editor/OS cruft).
12+
#
13+
# Run manually or via the git pre-commit hook, which regenerates the zip
14+
# whenever files under deployment/ are staged.
15+
# =============================================================================
16+
set -euo pipefail
17+
18+
DEPLOY_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
19+
PROJECT_ROOT="$(dirname "$DEPLOY_DIR")"
20+
ZIP_PATH="$PROJECT_ROOT/sentiment-intelligence.zip"
21+
22+
# Delete the previous package so the zip is a fresh, exact snapshot.
23+
rm -f "$ZIP_PATH"
24+
25+
# Package the deployment sources with the config at the archive root.
26+
( cd "$DEPLOY_DIR" && zip -r -q "$ZIP_PATH" . \
27+
-x '*.terraform*' \
28+
'*.tfstate*' \
29+
'tfplan' '*.tfplan' \
30+
'terraform.tfvars' \
31+
'build-stack-zip.sh' \
32+
'*.DS_Store' \
33+
'*/.DS_Store' )
34+
35+
echo "Built $ZIP_PATH"

ai/use-cases/sentiment-intelligence/terraform/build_and_deploy.sh renamed to ai/use-cases/sentiment-intelligence/deployment/build_and_deploy.sh

File renamed without changes.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
# =============================================================================
3+
# Monorepo pre-commit hook.
4+
#
5+
# Scoped: only acts when files under the sentiment-intelligence deployment
6+
# sources are staged. For any other commit in the monorepo it does nothing.
7+
#
8+
# When deployment/ files are staged it rebuilds sentiment-intelligence.zip
9+
# (the OCI Resource Manager stack package) and stages it, so the committed
10+
# package always matches the committed Terraform sources.
11+
# =============================================================================
12+
set -euo pipefail
13+
14+
PROJECT="ai/use-cases/sentiment-intelligence"
15+
DEPLOY_SRC="$PROJECT/deployment/"
16+
BUILD_SCRIPT="$PROJECT/deployment/build-stack-zip.sh"
17+
ZIP="$PROJECT/sentiment-intelligence.zip"
18+
19+
# Any staged (added/copied/modified/renamed) files under deployment/?
20+
if git diff --cached --name-only --diff-filter=ACMR -z \
21+
| grep -zq "^$DEPLOY_SRC"; then
22+
23+
if [ ! -x "$BUILD_SCRIPT" ]; then
24+
echo "pre-commit: $BUILD_SCRIPT not found or not executable; skipping stack package build." >&2
25+
else
26+
echo "pre-commit: rebuilding $ZIP from staged deployment sources..."
27+
"./$BUILD_SCRIPT"
28+
git add "$ZIP"
29+
fi
30+
fi

ai/use-cases/sentiment-intelligence/terraform/locals.tf renamed to ai/use-cases/sentiment-intelligence/deployment/locals.tf

File renamed without changes.

ai/use-cases/sentiment-intelligence/terraform/main.tf renamed to ai/use-cases/sentiment-intelligence/deployment/main.tf

File renamed without changes.

ai/use-cases/sentiment-intelligence/terraform/modules/adb/main.tf renamed to ai/use-cases/sentiment-intelligence/deployment/modules/adb/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ resource "oci_database_autonomous_database" "adb" {
88
db_name = var.db_name
99
admin_password = var.admin_password
1010
cpu_core_count = var.cpu_core_count
11-
data_storage_size_in_gbs = var.data_storage_size_in_gb
11+
data_storage_size_in_gb = var.data_storage_size_in_gb
1212
db_workload = var.db_workload
1313
is_free_tier = var.is_free_tier
1414
license_model = var.license_model

ai/use-cases/sentiment-intelligence/terraform/modules/adb/outputs.tf renamed to ai/use-cases/sentiment-intelligence/deployment/modules/adb/outputs.tf

File renamed without changes.

ai/use-cases/sentiment-intelligence/terraform/modules/adb/variables.tf renamed to ai/use-cases/sentiment-intelligence/deployment/modules/adb/variables.tf

File renamed without changes.

ai/use-cases/sentiment-intelligence/terraform/modules/network/main.tf renamed to ai/use-cases/sentiment-intelligence/deployment/modules/network/main.tf

File renamed without changes.

0 commit comments

Comments
 (0)