diff --git a/deploy/basic/Dockerfile b/deploy/basic/Dockerfile index 6f796529d..0fd6bfc53 100644 --- a/deploy/basic/Dockerfile +++ b/deploy/basic/Dockerfile @@ -99,7 +99,7 @@ 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 @@ -107,6 +107,10 @@ 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 \ diff --git a/deploy/basic/README.md b/deploy/basic/README.md index 50c2f40b6..6cbce87e5 100644 --- a/deploy/basic/README.md +++ b/deploy/basic/README.md @@ -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 diff --git a/deploy/basic/VERSION b/deploy/basic/VERSION index cb174d58a..d2d61a7e8 100644 --- a/deploy/basic/VERSION +++ b/deploy/basic/VERSION @@ -1 +1 @@ -1.2.1 \ No newline at end of file +1.2.2 \ No newline at end of file diff --git a/deploy/basic/terraform/atp.tf b/deploy/basic/terraform/atp.tf index 5ecad2e8f..049481517 100644 --- a/deploy/basic/terraform/atp.tf +++ b/deploy/basic/terraform/atp.tf @@ -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 : "" diff --git a/deploy/basic/terraform/compute.tf b/deploy/basic/terraform/compute.tf index 39c04a8a5..a04249ab7 100755 --- a/deploy/basic/terraform/compute.tf +++ b/deploy/basic/terraform/compute.tf @@ -1,4 +1,4 @@ -# 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. # @@ -6,15 +6,16 @@ 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 { @@ -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 @@ -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 } \ No newline at end of file diff --git a/deploy/basic/terraform/datasources.tf b/deploy/basic/terraform/datasources.tf index ef8a1df5c..8aa43b088 100755 --- a/deploy/basic/terraform/datasources.tf +++ b/deploy/basic/terraform/datasources.tf @@ -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" { @@ -81,9 +92,10 @@ 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 @@ -91,7 +103,7 @@ 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" } diff --git a/deploy/basic/terraform/loadbalancer.tf b/deploy/basic/terraform/loadbalancer.tf index 8495993be..e2be209c4 100644 --- a/deploy/basic/terraform/loadbalancer.tf +++ b/deploy/basic/terraform/loadbalancer.tf @@ -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 } } } diff --git a/deploy/basic/terraform/providers.tf b/deploy/basic/terraform/providers.tf index dd9e7babe..09f74db59 100755 --- a/deploy/basic/terraform/providers.tf +++ b/deploy/basic/terraform/providers.tf @@ -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" { diff --git a/deploy/basic/terraform/schema.yaml b/deploy/basic/terraform/schema.yaml index 84127e150..023276600 100644 --- a/deploy/basic/terraform/schema.yaml +++ b/deploy/basic/terraform/schema.yaml @@ -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 @@ -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: @@ -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 @@ -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 @@ -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?" diff --git a/deploy/basic/terraform/terraform.tfvars.example b/deploy/basic/terraform/terraform.tfvars.example index 1f17719e1..671192b1b 100644 --- a/deploy/basic/terraform/terraform.tfvars.example +++ b/deploy/basic/terraform/terraform.tfvars.example @@ -23,16 +23,20 @@ region = "us-phoenix-1" # Compute num_nodes = 2 -instance_shape = "VM.Standard.E2.1.Micro" +instance_shape = "VM.Standard.E2.1.Micro" # Micro shape for Always-free shape. If want to use flexible, change to "VM.Standard.E3.Flex" +instance_ocpus = 1 # instance_ocpus only used when instance_shape is a flex compute shape +instance_shape_config_memory_in_gbs = 16 # instance_shape_config_memory_in_gbs only used when instance_shape is a flex compute shape instance_visibility = "Public" generate_public_ssh_key = true public_ssh_key = "" is_pv_encryption_in_transit_enabled = false # Network Details -lb_shape = "10Mbps-Micro" -lb_compartment_ocid = "" # e.g.: "ocid1.compartment..." -create_secondary_vcn = false +lb_shape = "flexible" +lb_shape_details_minimum_bandwidth_in_mbps = 10 +lb_shape_details_maximum_bandwidth_in_mbps = 10 +lb_compartment_ocid = "" # e.g.: "ocid1.compartment..." +create_secondary_vcn = false # Autonomous Database autonomous_database_license_model = "LICENSE_INCLUDED" # LICENSE_INCLUDED or BRING_YOUR_OWN_LICENSE diff --git a/deploy/basic/terraform/tf_msz.tfvars.example b/deploy/basic/terraform/tf_msz.tfvars.example index 65b7723f8..c3cd0dafe 100644 --- a/deploy/basic/terraform/tf_msz.tfvars.example +++ b/deploy/basic/terraform/tf_msz.tfvars.example @@ -23,16 +23,20 @@ region = "us-phoenix-1" # Compute num_nodes = 2 -instance_shape = "VM.Standard2.1" +instance_shape = "VM.Standard.E3.Flex" +instance_ocpus = 1 # instance_ocpus only used when instance_shape is a flex compute shape +instance_shape_config_memory_in_gbs = 16 # instance_shape_config_memory_in_gbs only used when instance_shape is a flex compute shape instance_visibility = "Private" generate_public_ssh_key = true public_ssh_key = "" is_pv_encryption_in_transit_enabled = true # Network Details -lb_shape = "100Mbps" -lb_compartment_ocid = "" # e.g.: "ocid1.compartment..." The lb_compartment_ocid need to point to a non-MSZ compartment that allow IG -create_secondary_vcn = true +lb_shape = "flexible" +lb_shape_details_minimum_bandwidth_in_mbps = 100 +lb_shape_details_maximum_bandwidth_in_mbps = 100 +lb_compartment_ocid = "" # e.g.: "ocid1.compartment..." The lb_compartment_ocid need to point to a non-MSZ compartment that allow IG +create_secondary_vcn = true # Autonomous Database autonomous_database_license_model = "LICENSE_INCLUDED" # LICENSE_INCLUDED or BRING_YOUR_OWN_LICENSE diff --git a/deploy/basic/terraform/variables.tf b/deploy/basic/terraform/variables.tf index 2d12f661b..d7c239cca 100755 --- a/deploy/basic/terraform/variables.tf +++ b/deploy/basic/terraform/variables.tf @@ -28,7 +28,13 @@ variable "generate_public_ssh_key" { default = true } variable "instance_shape" { - default = "VM.Standard.E2.1.Micro" + default = "VM.Standard.E3.Flex" +} +variable "instance_ocpus" { + default = 1 +} +variable "instance_shape_config_memory_in_gbs" { + default = 16 } variable "image_operating_system" { default = "Oracle Linux" @@ -51,7 +57,7 @@ variable "lb_shape_details_minimum_bandwidth_in_mbps" { default = 10 } variable "lb_shape_details_maximum_bandwidth_in_mbps" { - default = 10 + default = 100 } variable "lb_compartment_ocid" { default = "" @@ -89,7 +95,7 @@ variable "autonomous_database_license_model" { default = "LICENSE_INCLUDED" } variable "autonomous_database_is_free_tier" { - default = true + default = false } variable "autonomous_database_cpu_core_count" { default = 1 @@ -140,11 +146,6 @@ variable "vault_key_key_shape_length" { default = 32 } -# Always Free only or support other shapes -variable "use_only_always_free_elegible_resources" { - default = true -} - # ORM Schema visual control variables variable "show_advanced" { default = false @@ -161,4 +162,25 @@ variable "object_storage_mushop_media_visibility" { # MuShop Services variable "services_in_mock_mode" { default = "carts,orders,users" -} \ No newline at end of file +} + +# Always Free only or support other shapes +variable "use_only_always_free_elegible_resources" { + default = true +} +## Always Free Locals +locals { + instance_shape = var.use_only_always_free_elegible_resources ? local.compute_shape_micro : var.instance_shape + lb_shape = var.use_only_always_free_elegible_resources ? local.lb_shape_flexible : var.lb_shape + lb_shape_details_minimum_bandwidth_in_mbps = var.use_only_always_free_elegible_resources ? 10 : var.lb_shape_details_minimum_bandwidth_in_mbps + lb_shape_details_maximum_bandwidth_in_mbps = var.use_only_always_free_elegible_resources ? 10 : var.lb_shape_details_maximum_bandwidth_in_mbps + autonomous_database_is_free_tier = var.use_only_always_free_elegible_resources ? true : var.autonomous_database_is_free_tier +} + +# Shapes +locals { + compute_shape_micro = "VM.Standard.E2.1.Micro" + compute_shape_flexible = "VM.Standard.E3.Flex" + compute_shape_flexible_description = "Cores for Standard.E3.Flex and BM.Standard.E3.128 Instances" + lb_shape_flexible = "flexible" +}