Skip to content

Commit

Permalink
Merge pull request #239 from junior/schema_updates
Browse files Browse the repository at this point in the history
Schema updates - MuShop Basic
  • Loading branch information
junior authored Mar 5, 2021
2 parents ce062c6 + 0bfdb27 commit f8a71a7
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 107 deletions.
6 changes: 5 additions & 1 deletion deploy/basic/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,18 @@ RUN rm -rf node_modules products hero *.md
###############################

# ##### Go Builder image
FROM golang:1.14 AS catalogue-builder
FROM golang:1.16 AS catalogue-builder
WORKDIR /go/src/mushop/catalogue

# # Catalogue Go Source
COPY src/catalogue/cmd/cataloguesvc/*.go cmd/cataloguesvc/
COPY src/catalogue/*.go ./
COPY src/catalogue/go.mod ./

# # Get Go Modules
RUN go get .
RUN go get mushop/catalogue/cmd/cataloguesvc

# # Build Catalogue service
RUN GO111MODULE=on GOARCH=amd64 GOOS=linux \
go build -a \
Expand Down
2 changes: 1 addition & 1 deletion deploy/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ After complete the Build steps 1 and 2, generate the binaries:

- Copy mushop media images to populate the object storage:

`docker run -v $PWD:/transfer --rm --entrypoint cp mushop-basic:latest /basic/image/*.png /transfer/deploy/basic/terraform/images/`
`docker run -v $PWD:/transfer --rm --entrypoint cp mushop-basic:latest -vr /basic/images/ /transfer/deploy/basic/terraform/`

- Rename the file `terraform.tfvars.example` to `terraform.tfvars`
- Change the credentials variables to your user and any other desirable variables
Expand Down
2 changes: 1 addition & 1 deletion deploy/basic/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.1
1.2.2
2 changes: 1 addition & 1 deletion deploy/basic/terraform/atp.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ resource "oci_database_autonomous_database" "mushop_autonomous_database" {
db_version = var.autonomous_database_db_version
display_name = "${var.autonomous_database_name}-${random_string.deploy_id.result}"
freeform_tags = local.common_tags
is_free_tier = var.autonomous_database_is_free_tier
is_free_tier = local.autonomous_database_is_free_tier
license_model = var.autonomous_database_license_model
nsg_ids = (var.autonomous_database_visibility == "Private") ? [oci_core_network_security_group.atp_nsg[0].id] : []
subnet_id = (var.autonomous_database_visibility == "Private") ? oci_core_subnet.mushop_main_subnet.id : ""
Expand Down
26 changes: 19 additions & 7 deletions deploy/basic/terraform/compute.tf
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
# Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2019-2021 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.
#

resource "oci_core_instance" "app_instance" {
availability_domain = random_shuffle.compute_ad.result[count.index % length(random_shuffle.compute_ad.result)]
compartment_id = var.compartment_ocid
display_name = "mushop-${random_string.deploy_id.result}-${count.index}"
shape = var.instance_shape
shape = local.instance_shape
is_pv_encryption_in_transit_enabled = var.is_pv_encryption_in_transit_enabled
freeform_tags = local.common_tags

create_vnic_details {
subnet_id = oci_core_subnet.mushop_main_subnet.id
display_name = "primaryvnic"
assign_public_ip = (var.instance_visibility == "Private") ? false : true
hostname_label = "mushop-${random_string.deploy_id.result}-${count.index}"
dynamic "shape_config" {
for_each = local.is_flexible_instance_shape ? [1] : []
content {
ocpus = var.instance_ocpus
memory_in_gbs = var.instance_shape_config_memory_in_gbs
}
}

source_details {
Expand All @@ -23,6 +24,13 @@ resource "oci_core_instance" "app_instance" {
kms_key_id = var.use_encryption_from_oci_vault ? (var.create_new_encryption_key ? oci_kms_key.mushop_key[0].id : var.encryption_key_id) : null
}

create_vnic_details {
subnet_id = oci_core_subnet.mushop_main_subnet.id
display_name = "primaryvnic"
assign_public_ip = (var.instance_visibility == "Private") ? false : true
hostname_label = "mushop-${random_string.deploy_id.result}-${count.index}"
}

metadata = {
ssh_authorized_keys = var.generate_public_ssh_key ? tls_private_key.compute_ssh_key.public_key_openssh : var.public_ssh_key
user_data = data.template_cloudinit_config.nodes.rendered
Expand All @@ -40,4 +48,8 @@ resource "oci_core_instance" "app_instance" {
resource "tls_private_key" "compute_ssh_key" {
algorithm = "RSA"
rsa_bits = 2048
}

locals {
is_flexible_instance_shape = (local.instance_shape == local.compute_shape_flexible) ? true : false
}
26 changes: 19 additions & 7 deletions deploy/basic/terraform/datasources.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,20 @@ data "oci_limits_limit_definitions" "compute_limit_definitions" {
compartment_id = var.tenancy_ocid
service_name = data.oci_limits_services.compute_services.services.0.name

filter {
name = "description"
values = [var.instance_shape]
dynamic "filter" {
for_each = local.is_flexible_instance_shape ? [1] : []
content {
name = "description"
values = [local.compute_shape_flexible_description]
}
}

dynamic "filter" {
for_each = local.is_flexible_instance_shape ? [] : [1]
content {
name = "description"
values = [local.instance_shape]
}
}
}
data "oci_limits_resource_availability" "compute_resource_availability" {
Expand All @@ -81,17 +92,18 @@ resource "random_shuffle" "compute_ad" {
result_count = length(local.compute_available_limit_ad_list)
}
locals {
compute_available_limit_ad_list = [for limit in data.oci_limits_resource_availability.compute_resource_availability : limit.availability_domain if(limit.available - var.num_nodes) >= 0]
compute_available_limit_error = length(local.compute_available_limit_ad_list) == 0 ? (
file("ERROR: No limits available for the chosen compute shape and number of nodes")) : 0
compute_multiplier_nodes_ocpus = (local.instance_shape == local.compute_shape_flexible) ? (var.num_nodes * var.instance_ocpus) : var.num_nodes
compute_available_limit_ad_list = [for limit in data.oci_limits_resource_availability.compute_resource_availability : limit.availability_domain if(limit.available - local.compute_multiplier_nodes_ocpus) >= 0]
compute_available_limit_check = length(local.compute_available_limit_ad_list) == 0 ? (
file("ERROR: No limits available for the chosen compute shape and number of nodes or OCPUs")) : 0
}

# Gets a list of supported images based on the shape, operating_system and operating_system_version provided
data "oci_core_images" "compute_images" {
compartment_id = var.compartment_ocid
operating_system = var.image_operating_system
operating_system_version = var.image_operating_system_version
shape = var.instance_shape
shape = local.instance_shape
sort_by = "TIMECREATED"
sort_order = "DESC"
}
Expand Down
8 changes: 4 additions & 4 deletions deploy/basic/terraform/loadbalancer.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
resource "oci_load_balancer_load_balancer" "mushop_lb" {
compartment_id = (var.lb_compartment_ocid != "") ? var.lb_compartment_ocid : var.compartment_ocid
display_name = "mushop-${random_string.deploy_id.result}"
shape = var.lb_shape
shape = local.lb_shape
subnet_ids = [oci_core_subnet.mushop_lb_subnet.id]
is_private = "false"
freeform_tags = local.common_tags

dynamic "shape_details" {
for_each = var.lb_shape == "flexible" ? [1] : []
for_each = local.lb_shape == "flexible" ? [1] : []
content {
minimum_bandwidth_in_mbps = var.lb_shape_details_minimum_bandwidth_in_mbps
maximum_bandwidth_in_mbps = var.lb_shape_details_maximum_bandwidth_in_mbps
minimum_bandwidth_in_mbps = local.lb_shape_details_minimum_bandwidth_in_mbps
maximum_bandwidth_in_mbps = local.lb_shape_details_maximum_bandwidth_in_mbps
}
}
}
Expand Down
24 changes: 18 additions & 6 deletions deploy/basic/terraform/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,24 @@
#

terraform {
required_version = ">= 0.12.29"
# required_providers {
# oci = ">= 3.90"
# tls = ">= 2.0"
# random = ">= 2.1"
# }
required_providers {
local = {
source = "hashicorp/local"
}
oci = {
source = "hashicorp/oci"
}
random = {
source = "hashicorp/random"
}
template = {
source = "hashicorp/template"
}
tls = {
source = "hashicorp/tls"
}
}
required_version = ">= 0.14"
}

provider "oci" {
Expand Down
146 changes: 84 additions & 62 deletions deploy/basic/terraform/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ groupings:
- title: "Optional Configuration"
variables:
- autonomous_database_name
- use_only_always_free_elegible_resources
- show_advanced
- generate_public_ssh_key
- public_ssh_key
Expand All @@ -40,9 +41,14 @@ groupings:
- create_vault_policies_for_group
- user_admin_group_for_vault_policy

- title: "Advanced Resource Options"
- title: "Advanced Resource Options - Compute"
variables:
- use_only_always_free_elegible_resources
- instance_shape
- instance_ocpus
- instance_shape_config_memory_in_gbs
- image_operating_system
- image_operating_system_version
- instance_visibility

- title: "Advanced Resource Options - Load Balancer"
variables:
Expand All @@ -54,13 +60,6 @@ groupings:
- create_lpg_policies_for_group
- user_admin_group_for_lpg_policy

- title: "Advanced Resource Options - Compute"
variables:
- instance_shape
- image_operating_system
- image_operating_system_version
- instance_visibility

- title: "Advanced Resource Options - ATP"
variables:
- autonomous_database_is_free_tier
Expand Down Expand Up @@ -208,9 +207,84 @@ variables:
type: boolean
title: "Use only always free eligible resources?"
description: "*** Unchecking this may use options that are not included or supported by Always Free eligible resources."
visible: true

instance_shape:
type: oci:core:instanceshape:name
title: "Select a shape for the compute instances"
description: "A shape is a template that determines the number of CPUs, amount of memory, and other resources allocated to a newly created instance."
dependsOn:
compartmentId: compartment_ocid
required: true
visible:
not:
- use_only_always_free_elegible_resources

instance_ocpus:
type: integer
minimum: 1
maximum: 64
title: "Number of OCPUs"
description: "You can customize the number of OCPUs to a flexible shape."
visible:
and:
- show_advanced
- not:
- use_only_always_free_elegible_resources
- eq:
- instance_shape
- "VM.Standard.E3.Flex"

instance_shape_config_memory_in_gbs:
type: integer
minimum: 1
maximum: 1024
title: "Amount of memory (GB)"
description: "You can customize the amount of memory allocated to a flexible shape."
visible:
and:
- not:
- use_only_always_free_elegible_resources
- eq:
- instance_shape
- "VM.Standard.E3.Flex"

image_operating_system:
type: string
title: "Compute Image OS"
description: "The OS/image installed on all compute instances."
required: true
visible:
and:
- and:
- show_advanced
- not:
- use_only_always_free_elegible_resources

image_operating_system_version:
type: string
title: "Compute Image OS Version"
description: "The OS/image version installed on all compute instances."
required: true
visible:
and:
- and:
- show_advanced
- not:
- use_only_always_free_elegible_resources

instance_visibility:
type: enum
enum:
- "Public"
- "Private"
title: "Choose instance visibility type"
description: "The instance visibility will define if assign a public ip address to the compute instance and if the subnet is public or private."
visible:
and:
- and:
- show_advanced
- not:
- use_only_always_free_elegible_resources

lb_shape:
type: enum
Expand Down Expand Up @@ -310,58 +384,6 @@ variables:
- not:
- use_only_always_free_elegible_resources

instance_shape:
type: oci:core:instanceshape:name
title: "Select a shape for the compute instances"
description: "A shape is a template that determines the number of CPUs, amount of memory, and other resources allocated to a newly created instance."
dependsOn:
compartmentId: compartment_ocid
required: true
visible:
and:
- and:
- show_advanced
- not:
- use_only_always_free_elegible_resources

image_operating_system:
type: string
title: "Compute Image OS"
description: "The OS/image installed on all compute instances."
required: true
visible:
and:
- and:
- show_advanced
- not:
- use_only_always_free_elegible_resources

image_operating_system_version:
type: string
title: "Compute Image OS Version"
description: "The OS/image version installed on all compute instances."
required: true
visible:
and:
- and:
- show_advanced
- not:
- use_only_always_free_elegible_resources

instance_visibility:
type: enum
enum:
- "Public"
- "Private"
title: "Choose instance visibility type"
description: "The instance visibility will define if assign a public ip address to the compute instance and if the subnet is public or private."
visible:
and:
- and:
- show_advanced
- not:
- use_only_always_free_elegible_resources

autonomous_database_is_free_tier:
type: boolean
title: "Use always free Autonomous Database?"
Expand Down
Loading

0 comments on commit f8a71a7

Please sign in to comment.