Skip to content

Commit

Permalink
Merge pull request #307 from junior/tf_scripts_update
Browse files Browse the repository at this point in the history
Terraform Scripts update for Oracle Digital Assistant
  • Loading branch information
junior authored Feb 9, 2022
2 parents a8c1860 + 97f8117 commit 06329f3
Show file tree
Hide file tree
Showing 33 changed files with 504 additions and 200 deletions.
10 changes: 5 additions & 5 deletions deploy/basic/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ARG oracleClientVersion=19.10
# ----- STOREFRONT ----- #
# Build stage (node/npm) #
###############################
FROM --platform=${BUILDPLATFORM:-linux/amd64} node:14-alpine as storefront-builder
FROM --platform=${BUILDPLATFORM:-linux/amd64} node:16-alpine as storefront-builder

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

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

RUN apk update && apk add --no-cache \
autoconf \
Expand Down Expand Up @@ -103,7 +103,7 @@ RUN rm -rf node_modules products hero *.md
###############################

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

WORKDIR /go/src/mushop/catalogue

Expand Down Expand Up @@ -133,7 +133,7 @@ RUN GO111MODULE=on GOARCH=amd64 GOOS=linux \
###############################

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

WORKDIR /go/src/mushop/catalogue

Expand Down
2 changes: 1 addition & 1 deletion deploy/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ After complete the Build steps 1 and 2, generate the binaries:
```shell
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
```
```
1. Copy mushop media images to populate the object storage:
Expand Down
32 changes: 16 additions & 16 deletions deploy/basic/terraform/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions deploy/basic/terraform/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

2022-02-08 (v2.1.0)

- Terraform OCI Provider Updated to the latest
- Oracle Digital Assistant support on the storefront
- Schema update

2021-07-28 (v2.0.1)

- Terraform OCI Provider Updated to the latest
Expand Down
2 changes: 1 addition & 1 deletion deploy/basic/terraform/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.1
2.1.0
7 changes: 6 additions & 1 deletion deploy/basic/terraform/datasources.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019-2021 Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2019-2022 Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
#

Expand Down Expand Up @@ -149,6 +149,11 @@ locals {
mushop_media_visibility = var.object_storage_mushop_media_visibility
mushop_app_par = "https://objectstorage.${var.region}.oraclecloud.com${oci_objectstorage_preauthrequest.mushop_lite_preauth.access_uri}"
wallet_par = "https://objectstorage.${var.region}.oraclecloud.com${oci_objectstorage_preauthrequest.mushop_wallet_preauth.access_uri}"
oda_enabled = var.oda_enabled
oda_uri = var.oda_uri
oda_channel_id = var.oda_channel_id
oda_secret = var.oda_secret
oda_user_init_message = var.oda_user_init_message
})
catalogue_sql_template = templatefile("${path.module}/scripts/catalogue.template.sql",
{
Expand Down
12 changes: 11 additions & 1 deletion deploy/basic/terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# Copyright (c) 2019-2021 Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2019-2022 Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
#

output "lb_public_url_button" {
value = format("http://%s", lookup(oci_load_balancer_load_balancer.mushop_lb.ip_address_details[0], "ip_address"))
}
output "lb_public_url" {
value = format("http://%s", lookup(oci_load_balancer_load_balancer.mushop_lb.ip_address_details[0], "ip_address"))
}
output "lb_nip_host_url" {
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")))))
}
output "autonomous_database_password" {
value = random_string.autonomous_database_admin_password.result
sensitive = true
Expand All @@ -31,6 +37,10 @@ output "platform" {
output "mushop_basic_source_code" {
value = "https://github.com/oracle-quickstart/oci-cloudnative/tree/master/deploy/basic"
}
output "mushop_basic_version" {
value = file("${path.module}/VERSION")
}

### Important Security Notice ###
# The private key generated by this resource will be stored unencrypted in your Terraform state file.
# Use of this resource for production deployments is not recommended.
Expand Down
6 changes: 3 additions & 3 deletions deploy/basic/terraform/providers.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019-2021 Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2019-2022 Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
#

Expand All @@ -7,8 +7,8 @@ terraform {
required_providers {
oci = {
source = "hashicorp/oci"
version = ">= 4.42.0"
# https://registry.terraform.io/providers/hashicorp/oci/4.42.0
version = ">= 4.62.0"
# https://registry.terraform.io/providers/hashicorp/oci/4.62.0
}
local = {
source = "hashicorp/local"
Expand Down
86 changes: 83 additions & 3 deletions deploy/basic/terraform/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ groupings:
- object_storage_mushop_media_compartment_ocid
- object_storage_mushop_media_visibility

- title: "Advanced Resource Options - Oracle Digital Assistant"
variables:
- oda_enabled
- oda_uri
- oda_channel_id
- oda_secret
- oda_user_init_message

- title: "Extras Hidden"
variables:
- user_ocid
Expand Down Expand Up @@ -464,23 +472,90 @@ variables:
- not:
- use_only_always_free_eligible_resources

oda_enabled:
type: boolean
title: "Enable Oracle Digital Assistant?"
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."
visible:
and:
- show_advanced

oda_uri:
type: string
title: "Oracle Digital Assistant URI"
description: "The ODA URI. Do not include https: and slashes. e.g.: oda-xxxxxxx-x.data..digitalassistant.oci.oraclecloud.com"
visible:
and:
- show_advanced
- oda_enabled

oda_channel_id:
type: string
title: "Oracle Digital Assistant Channel ID"
description: "Oracle Digital Assistant Channel Id to be used with MuShop."
visible:
and:
- show_advanced
- oda_enabled

oda_secret:
type: string
title: "Oracle Digital Assistant Channel Secret"
description: "Oracle Digital Assistant Channel Secret. Only used if client auth is enabled."
visible:
and:
- show_advanced
- oda_enabled

oda_user_init_message:
type: string
title: "Oracle Digital Assistant user hidden init message"
description: "Hidden Init Message if any. Makes the Digital Assistant proactive. e.g.: Trending Today"
visible:
and:
- show_advanced
- oda_enabled

outputGroups:
- title: "MuShop App details"
- title: MuShop App details
outputs:
- lb_public_url
- lb_nip_host_url

- title: Passwords and Keys
outputs:
- autonomous_database_password
- generated_private_key_pem

- title: Deployment Info
outputs:
- deploy_id
- deployed_to_region
- mushop_basic_source_code
- platform

- title: Dev Notes
outputs:
- dev
- comments
- mushop_source_code
- mushop_version

outputs:
lb_public_url_button:
type: link
title: MuShop URL Button
displayText: Open MuShop
visible: true

lb_public_url:
type: link
title: Open
title: MuShop
displayText: Storefront
visible: true

lb_nip_host_url:
type: link
title: "Alternative Hostname"
visible: true

autonomous_database_password:
Expand Down Expand Up @@ -515,6 +590,11 @@ outputs:
title: "MuShop Basic source code"
visible: true

mushop_basic_version:
type: string
title: "MuShop Basic Stack Version used"
visible: true

comments:
type: string
title: "Comments"
Expand Down
28 changes: 28 additions & 0 deletions deploy/basic/terraform/scripts/deploy.template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#

ME=$(basename $0)

get_object() {
out_file=$1
os_uri=$2
Expand Down Expand Up @@ -66,3 +68,29 @@ if [[ "$MUSHOP_MEDIA_VISIBILITY" == Private ]]; then
get_media_pars /root/mushop_media_pars_list.txt
echo "Images loaded"
fi

# If enabled, configure storefront to load ODA's web-sdk
ODA_ENABLED=${oda_enabled}
if [[ "$ODA_ENABLED" = true ]]; then

WWW_DIR=/app/storefront
ODA_SCRIPTS_DIR=$WWW_DIR/scripts/oda

export ODA_URI=${oda_uri}
export ODA_CHANNEL_ID=${oda_channel_id}
export ODA_SECRET=${oda_secret}
export ODA_USER_INIT_MESSAGE=${oda_user_init_message}

echo "$ME: Preparing index.html to enable Oracle Digital Assistant"
storefrontindex="$WWW_DIR/index.html"
[ -w $WWW_DIR ] && echo "$ME: Enabling ODA SDK..." || (echo "$ME: File System Not Writable. Exiting..." && exit 0)
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)
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)

echo "$ME: Setting ODA variables"
odasettingsfile="$ODA_SCRIPTS_DIR/settings.js"
[ -w $odasettingsfile ] && echo "$ME: Running envsubst to update ODA settings.js" || (echo "$ME: settings.js Not Writable. Exiting..." && exit 0)
(tmpfile=$(mktemp) && \
(cp -a $odasettingsfile $tmpfile) && \
(cat $odasettingsfile | envsubst > $tmpfile && mv $tmpfile $odasettingsfile)) || (echo "$ME: *** Failed to update settings.js. Exiting..." && exit 0)
fi
9 changes: 8 additions & 1 deletion deploy/basic/terraform/terraform.tfvars.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2020-2022 Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
#

Expand Down Expand Up @@ -59,3 +59,10 @@ use_only_always_free_eligible_resources = true
# Object Storage
object_storage_mushop_media_compartment_ocid = "" # e.g.: "ocid1.compartment..."
object_storage_mushop_media_visibility = "Public"

# Oracle Digital Assistant
oda_enabled = false
oda_uri = ""
oda_channel_id = ""
oda_secret = ""
oda_user_init_message = ""
7 changes: 7 additions & 0 deletions deploy/basic/terraform/tf_msz.tfvars.example
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,10 @@ use_only_always_free_eligible_resources = false
# Object Storage
object_storage_mushop_media_compartment_ocid = "" # e.g.: "ocid1.compartment..."
object_storage_mushop_media_visibility = "Private"

# Oracle Digital Assistant
oda_enabled = false
oda_uri = ""
oda_channel_id = ""
oda_secret = ""
oda_user_init_message = ""
19 changes: 18 additions & 1 deletion deploy/basic/terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019-2021 Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2019-2022 Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
#

Expand Down Expand Up @@ -159,6 +159,23 @@ variable "object_storage_mushop_media_visibility" {
default = "Public"
}

# Oracle Digital Assistant
variable "oda_enabled" {
default = false
}
variable "oda_uri" {
default = ""
}
variable "oda_channel_id" {
default = ""
}
variable "oda_secret" {
default = ""
}
variable "oda_user_init_message" {
default = ""
}

# MuShop Services
variable "services_in_mock_mode" {
default = "carts,orders,users"
Expand Down
Loading

0 comments on commit 06329f3

Please sign in to comment.