Skip to content

Commit 06329f3

Browse files
authored
Merge pull request #307 from junior/tf_scripts_update
Terraform Scripts update for Oracle Digital Assistant
2 parents a8c1860 + 97f8117 commit 06329f3

33 files changed

+504
-200
lines changed

deploy/basic/Dockerfile

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ARG oracleClientVersion=19.10
1010
# ----- STOREFRONT ----- #
1111
# Build stage (node/npm) #
1212
###############################
13-
FROM --platform=${BUILDPLATFORM:-linux/amd64} node:14-alpine as storefront-builder
13+
FROM --platform=${BUILDPLATFORM:-linux/amd64} node:16-alpine as storefront-builder
1414

1515
RUN apk update && apk add --no-cache \
1616
autoconf \
@@ -51,7 +51,7 @@ RUN npm run build
5151
# ----- API Gateway ----- #
5252
# Build stage (node/npm) #
5353
###############################
54-
FROM --platform=${TARGETPLATFORM:-linux/amd64} node:14-alpine as api-builder
54+
FROM --platform=${TARGETPLATFORM:-linux/amd64} node:16-alpine as api-builder
5555

5656
WORKDIR /app/api
5757
COPY src/api/. .
@@ -68,7 +68,7 @@ RUN rm -rf test scripts && \
6868
###############################
6969
# ----- Image Assets ----- #
7070
###############################
71-
FROM --platform=${BUILDPLATFORM:-linux/amd64} node:14-alpine as assets-builder
71+
FROM --platform=${BUILDPLATFORM:-linux/amd64} node:16-alpine as assets-builder
7272

7373
RUN apk update && apk add --no-cache \
7474
autoconf \
@@ -103,7 +103,7 @@ RUN rm -rf node_modules products hero *.md
103103
###############################
104104

105105
# ##### Go Builder image
106-
FROM --platform=linux/amd64 golang:1.16 AS catalogue-builder-amd64
106+
FROM --platform=linux/amd64 golang:1.17 AS catalogue-builder-amd64
107107

108108
WORKDIR /go/src/mushop/catalogue
109109

@@ -133,7 +133,7 @@ RUN GO111MODULE=on GOARCH=amd64 GOOS=linux \
133133
###############################
134134

135135
# ##### Go Builder image
136-
FROM --platform=linux/arm64 golang:1.16 AS catalogue-builder-arm64
136+
FROM --platform=linux/arm64 golang:1.17 AS catalogue-builder-arm64
137137

138138
WORKDIR /go/src/mushop/catalogue
139139

deploy/basic/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ After complete the Build steps 1 and 2, generate the binaries:
124124
125125
```shell
126126
docker run -v $PWD:/transfer --rm --entrypoint cp mushop-basic:latest /package/mushop-basic.tar.xz /transfer/deploy/basic/terraform/scripts/mushop-basic.tar.xz
127-
```
127+
```
128128
129129
1. Copy mushop media images to populate the object storage:
130130

deploy/basic/terraform/.terraform.lock.hcl

+16-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deploy/basic/terraform/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# CHANGELOG
22

3+
2022-02-08 (v2.1.0)
4+
5+
- Terraform OCI Provider Updated to the latest
6+
- Oracle Digital Assistant support on the storefront
7+
- Schema update
8+
39
2021-07-28 (v2.0.1)
410

511
- Terraform OCI Provider Updated to the latest

deploy/basic/terraform/VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.1
1+
2.1.0

deploy/basic/terraform/datasources.tf

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019-2021 Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2019-2022 Oracle and/or its affiliates. All rights reserved.
22
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
33
#
44

@@ -149,6 +149,11 @@ locals {
149149
mushop_media_visibility = var.object_storage_mushop_media_visibility
150150
mushop_app_par = "https://objectstorage.${var.region}.oraclecloud.com${oci_objectstorage_preauthrequest.mushop_lite_preauth.access_uri}"
151151
wallet_par = "https://objectstorage.${var.region}.oraclecloud.com${oci_objectstorage_preauthrequest.mushop_wallet_preauth.access_uri}"
152+
oda_enabled = var.oda_enabled
153+
oda_uri = var.oda_uri
154+
oda_channel_id = var.oda_channel_id
155+
oda_secret = var.oda_secret
156+
oda_user_init_message = var.oda_user_init_message
152157
})
153158
catalogue_sql_template = templatefile("${path.module}/scripts/catalogue.template.sql",
154159
{

deploy/basic/terraform/outputs.tf

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
# Copyright (c) 2019-2021 Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2019-2022 Oracle and/or its affiliates. All rights reserved.
22
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
33
#
44

5+
output "lb_public_url_button" {
6+
value = format("http://%s", lookup(oci_load_balancer_load_balancer.mushop_lb.ip_address_details[0], "ip_address"))
7+
}
58
output "lb_public_url" {
69
value = format("http://%s", lookup(oci_load_balancer_load_balancer.mushop_lb.ip_address_details[0], "ip_address"))
710
}
11+
output "lb_nip_host_url" {
12+
value = format("http://mushop-%s.nip.io", join("", formatlist("%02x", split(".", lookup(oci_load_balancer_load_balancer.mushop_lb.ip_address_details[0], "ip_address")))))
13+
}
814
output "autonomous_database_password" {
915
value = random_string.autonomous_database_admin_password.result
1016
sensitive = true
@@ -31,6 +37,10 @@ output "platform" {
3137
output "mushop_basic_source_code" {
3238
value = "https://github.com/oracle-quickstart/oci-cloudnative/tree/master/deploy/basic"
3339
}
40+
output "mushop_basic_version" {
41+
value = file("${path.module}/VERSION")
42+
}
43+
3444
### Important Security Notice ###
3545
# The private key generated by this resource will be stored unencrypted in your Terraform state file.
3646
# Use of this resource for production deployments is not recommended.

deploy/basic/terraform/providers.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019-2021 Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2019-2022 Oracle and/or its affiliates. All rights reserved.
22
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
33
#
44

@@ -7,8 +7,8 @@ terraform {
77
required_providers {
88
oci = {
99
source = "hashicorp/oci"
10-
version = ">= 4.42.0"
11-
# https://registry.terraform.io/providers/hashicorp/oci/4.42.0
10+
version = ">= 4.62.0"
11+
# https://registry.terraform.io/providers/hashicorp/oci/4.62.0
1212
}
1313
local = {
1414
source = "hashicorp/local"

deploy/basic/terraform/schema.yaml

+83-3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ groupings:
7070
- object_storage_mushop_media_compartment_ocid
7171
- object_storage_mushop_media_visibility
7272

73+
- title: "Advanced Resource Options - Oracle Digital Assistant"
74+
variables:
75+
- oda_enabled
76+
- oda_uri
77+
- oda_channel_id
78+
- oda_secret
79+
- oda_user_init_message
80+
7381
- title: "Extras Hidden"
7482
variables:
7583
- user_ocid
@@ -464,23 +472,90 @@ variables:
464472
- not:
465473
- use_only_always_free_eligible_resources
466474

475+
oda_enabled:
476+
type: boolean
477+
title: "Enable Oracle Digital Assistant?"
478+
description: "Enables the Oracle Digital Assistant as widget on the storefront. (chatbot balloon will appear on the MuShop UI) \nNOTE: This stack currently does not provision ODA, you need to bring your ODA instance and bot details."
479+
visible:
480+
and:
481+
- show_advanced
482+
483+
oda_uri:
484+
type: string
485+
title: "Oracle Digital Assistant URI"
486+
description: "The ODA URI. Do not include https: and slashes. e.g.: oda-xxxxxxx-x.data..digitalassistant.oci.oraclecloud.com"
487+
visible:
488+
and:
489+
- show_advanced
490+
- oda_enabled
491+
492+
oda_channel_id:
493+
type: string
494+
title: "Oracle Digital Assistant Channel ID"
495+
description: "Oracle Digital Assistant Channel Id to be used with MuShop."
496+
visible:
497+
and:
498+
- show_advanced
499+
- oda_enabled
500+
501+
oda_secret:
502+
type: string
503+
title: "Oracle Digital Assistant Channel Secret"
504+
description: "Oracle Digital Assistant Channel Secret. Only used if client auth is enabled."
505+
visible:
506+
and:
507+
- show_advanced
508+
- oda_enabled
509+
510+
oda_user_init_message:
511+
type: string
512+
title: "Oracle Digital Assistant user hidden init message"
513+
description: "Hidden Init Message if any. Makes the Digital Assistant proactive. e.g.: Trending Today"
514+
visible:
515+
and:
516+
- show_advanced
517+
- oda_enabled
518+
467519
outputGroups:
468-
- title: "MuShop App details"
520+
- title: MuShop App details
469521
outputs:
470522
- lb_public_url
523+
- lb_nip_host_url
524+
525+
- title: Passwords and Keys
526+
outputs:
471527
- autonomous_database_password
472528
- generated_private_key_pem
529+
530+
- title: Deployment Info
531+
outputs:
473532
- deploy_id
474533
- deployed_to_region
475-
- mushop_basic_source_code
476534
- platform
535+
536+
- title: Dev Notes
537+
outputs:
477538
- dev
478539
- comments
540+
- mushop_source_code
541+
- mushop_version
479542

480543
outputs:
544+
lb_public_url_button:
545+
type: link
546+
title: MuShop URL Button
547+
displayText: Open MuShop
548+
visible: true
549+
481550
lb_public_url:
482551
type: link
483-
title: Open
552+
title: MuShop
553+
displayText: Storefront
554+
visible: true
555+
556+
lb_nip_host_url:
557+
type: link
558+
title: "Alternative Hostname"
484559
visible: true
485560

486561
autonomous_database_password:
@@ -515,6 +590,11 @@ outputs:
515590
title: "MuShop Basic source code"
516591
visible: true
517592

593+
mushop_basic_version:
594+
type: string
595+
title: "MuShop Basic Stack Version used"
596+
visible: true
597+
518598
comments:
519599
type: string
520600
title: "Comments"

deploy/basic/terraform/scripts/deploy.template.sh

+28
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
99
#
1010

11+
ME=$(basename $0)
12+
1113
get_object() {
1214
out_file=$1
1315
os_uri=$2
@@ -66,3 +68,29 @@ if [[ "$MUSHOP_MEDIA_VISIBILITY" == Private ]]; then
6668
get_media_pars /root/mushop_media_pars_list.txt
6769
echo "Images loaded"
6870
fi
71+
72+
# If enabled, configure storefront to load ODA's web-sdk
73+
ODA_ENABLED=${oda_enabled}
74+
if [[ "$ODA_ENABLED" = true ]]; then
75+
76+
WWW_DIR=/app/storefront
77+
ODA_SCRIPTS_DIR=$WWW_DIR/scripts/oda
78+
79+
export ODA_URI=${oda_uri}
80+
export ODA_CHANNEL_ID=${oda_channel_id}
81+
export ODA_SECRET=${oda_secret}
82+
export ODA_USER_INIT_MESSAGE=${oda_user_init_message}
83+
84+
echo "$ME: Preparing index.html to enable Oracle Digital Assistant"
85+
storefrontindex="$WWW_DIR/index.html"
86+
[ -w $WWW_DIR ] && echo "$ME: Enabling ODA SDK..." || (echo "$ME: File System Not Writable. Exiting..." && exit 0)
87+
sed -i -e 's|<!-- head placeholder 1 -->|<script src="scripts/oda/settings.js"></script>|g' "$storefrontindex" || (echo "$ME: *** Failed to enable ODA SDK. Exiting..." && exit 0)
88+
sed -i -e 's|<!-- head placeholder 2 -->|<script src="scripts/oda/web-sdk.js" onload="initSdk('$(echo -e "\x27")'Bots'$(echo -e "\x27")')"></script>|g' "$storefrontindex" || (echo "$ME: *** Failed to enable ODA SDK. Exiting..." && exit 0)
89+
90+
echo "$ME: Setting ODA variables"
91+
odasettingsfile="$ODA_SCRIPTS_DIR/settings.js"
92+
[ -w $odasettingsfile ] && echo "$ME: Running envsubst to update ODA settings.js" || (echo "$ME: settings.js Not Writable. Exiting..." && exit 0)
93+
(tmpfile=$(mktemp) && \
94+
(cp -a $odasettingsfile $tmpfile) && \
95+
(cat $odasettingsfile | envsubst > $tmpfile && mv $tmpfile $odasettingsfile)) || (echo "$ME: *** Failed to update settings.js. Exiting..." && exit 0)
96+
fi

deploy/basic/terraform/terraform.tfvars.example

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2020-2022 Oracle and/or its affiliates. All rights reserved.
22
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
33
#
44

@@ -59,3 +59,10 @@ use_only_always_free_eligible_resources = true
5959
# Object Storage
6060
object_storage_mushop_media_compartment_ocid = "" # e.g.: "ocid1.compartment..."
6161
object_storage_mushop_media_visibility = "Public"
62+
63+
# Oracle Digital Assistant
64+
oda_enabled = false
65+
oda_uri = ""
66+
oda_channel_id = ""
67+
oda_secret = ""
68+
oda_user_init_message = ""

deploy/basic/terraform/tf_msz.tfvars.example

+7
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,10 @@ use_only_always_free_eligible_resources = false
5959
# Object Storage
6060
object_storage_mushop_media_compartment_ocid = "" # e.g.: "ocid1.compartment..."
6161
object_storage_mushop_media_visibility = "Private"
62+
63+
# Oracle Digital Assistant
64+
oda_enabled = false
65+
oda_uri = ""
66+
oda_channel_id = ""
67+
oda_secret = ""
68+
oda_user_init_message = ""

deploy/basic/terraform/variables.tf

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019-2021 Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2019-2022 Oracle and/or its affiliates. All rights reserved.
22
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
33
#
44

@@ -159,6 +159,23 @@ variable "object_storage_mushop_media_visibility" {
159159
default = "Public"
160160
}
161161

162+
# Oracle Digital Assistant
163+
variable "oda_enabled" {
164+
default = false
165+
}
166+
variable "oda_uri" {
167+
default = ""
168+
}
169+
variable "oda_channel_id" {
170+
default = ""
171+
}
172+
variable "oda_secret" {
173+
default = ""
174+
}
175+
variable "oda_user_init_message" {
176+
default = ""
177+
}
178+
162179
# MuShop Services
163180
variable "services_in_mock_mode" {
164181
default = "carts,orders,users"

0 commit comments

Comments
 (0)