Skip to content

Commit 6410904

Browse files
authored
Merge pull request #27 from oracle-devrel/improve-environment-automation
Improve Environment Automation
2 parents 6537230 + 4091789 commit 6410904

16 files changed

+202
-139
lines changed

deploy/k8s/overlays/prod/kustomization.yaml.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ resources:
66
images:
77
- name: app
88
newName: {{region_key}}.ocir.io/{{{tenancy_namespace}}}/{{{project_name}}}/app
9-
newTag: {{{web_version}}}
9+
newTag: {{{app_version}}}
1010
- name: backend
1111
newName: {{region_key}}.ocir.io/{{{tenancy_namespace}}}/{{{project_name}}}/backend
1212
newTag: {{{backend_version}}}

deploy/terraform/.terraform.lock.hcl

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deploy/terraform/data.tf

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@ data "oci_identity_tenancy" "tenant_details" {
44
provider = oci
55
}
66

7-
data "oci_identity_regions" "home" {
8-
filter {
9-
name = "key"
10-
values = [data.oci_identity_tenancy.tenant_details.home_region_key]
11-
}
7+
data "oci_identity_region_subscriptions" "region_subscriptions" {
8+
tenancy_id = var.tenancy_ocid
129

1310
provider = oci
1411
}

deploy/terraform/genai.tf

Lines changed: 0 additions & 7 deletions
This file was deleted.

deploy/terraform/outputs.tf

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,8 @@
1-
locals {
2-
model_collection = data.oci_generative_ai_models.genai_models.model_collection[0]
3-
cohere_models = tolist([for each in local.model_collection.items : each
4-
if contains(each.capabilities, "TEXT_GENERATION")
5-
&& each.vendor == "cohere"])
6-
}
71

82
output "project" {
93
value = "${var.project_name}${random_string.deploy_id.result}"
104
}
115

12-
# output "load_balancer" {
13-
# value = oci_core_public_ip.reserved_ip.ip_address
14-
# }
15-
16-
# output "web_instances" {
17-
# value = oci_core_instance.web[*].private_ip
18-
# }
19-
20-
# output "backend_instances" {
21-
# value = oci_core_instance.backend[*].private_ip
22-
# }
23-
24-
output "cohere_model_id" {
25-
value = local.cohere_models[0].id
26-
}
27-
28-
# output "ssh_bastion_session_backend" {
29-
# value = oci_bastion_session.backend_session.ssh_metadata.command
30-
# }
31-
32-
# output "ssh_bastion_session_web" {
33-
# value = oci_bastion_session.web_session.ssh_metadata.command
34-
# }
35-
366
output "db_service" {
377
value = "${local.project_name}${local.deploy_id}"
388
}

deploy/terraform/provider.tf

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
locals {
2+
home_region_key = [for key, value in data.oci_identity_region_subscriptions.region_subscriptions.region_subscriptions: key if value.is_home_region == true][0]
3+
home_region = data.oci_identity_region_subscriptions.region_subscriptions.region_subscriptions[local.home_region_key]
4+
}
5+
16
provider "oci" {
2-
tenancy_ocid = var.tenancy_ocid
3-
region = var.region
7+
tenancy_ocid = var.tenancy_ocid
8+
region = var.region
9+
config_file_profile = var.config_file_profile
410
}
511

612
provider "oci" {
7-
alias = "home"
8-
tenancy_ocid = var.tenancy_ocid
9-
region = lookup(data.oci_identity_regions.home.regions[0], "name")
13+
alias = "home"
14+
tenancy_ocid = var.tenancy_ocid
15+
region = local.home_region.region_name
16+
config_file_profile = var.config_file_profile
1017
}
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
region = "{{ regionName }}"
22
tenancy_ocid = "{{ tenancyId }}"
3+
config_file_profile = "{{ profile }}"
34
compartment_ocid = "{{ compartmentId }}"
45
ssh_public_key = "{{{ ssh_public_key }}}"
56
ssh_private_key_path = "{{{ ssh_private_key_path }}}"
67
cert_fullchain = "{{{ cert_fullchain }}}"
7-
cert_private_key = "{{{ cert_private_key }}}"
8-
genai_endpoint = "{{{ genai_endpoint }}}"
9-
10-
# web_artifact_url = ""
11-
# backend_artifact_url = ""
12-
# ansible_web_artifact_url = ""
13-
# ansible_backend_artifact_url = ""
8+
cert_private_key = "{{{ cert_private_key }}}"

deploy/terraform/variables.tf

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ variable "region" {
77
default = "us-chicago-1"
88
}
99

10+
variable "config_file_profile" {
11+
type = string
12+
}
13+
1014
variable "compartment_ocid" {
1115
type = string
1216
}
@@ -32,39 +36,7 @@ variable "project_name" {
3236
default = "genai"
3337
}
3438

35-
# variable "web_artifact_url" {
36-
# type = string
37-
# }
38-
39-
# variable "backend_artifact_url" {
40-
# type = string
41-
# }
42-
43-
# variable "ansible_web_artifact_url" {
44-
# type = string
45-
# }
46-
47-
# variable "ansible_backend_artifact_url" {
48-
# type = string
49-
# }
50-
51-
# variable "instance_shape" {
52-
# default = "VM.Standard.E4.Flex"
53-
# }
54-
55-
# variable "web_node_count" {
56-
# default = "1"
57-
# }
58-
59-
# variable "backend_node_count" {
60-
# default = "1"
61-
# }
62-
6339
variable "artifacts_par_expiration_in_days" {
6440
type = number
6541
default = 7
66-
}
67-
68-
variable "genai_endpoint" {
69-
type = string
7042
}

scripts/clean.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ console.log(`Files in ${chalk.green(walletK8sPath)} deleted`);
3636
// ${regionKey}.ocir.io/${namespace}/${projectName}/backend:${backendBersion}
3737

3838
await $`rm -rf ./.artifacts`;
39+
await $`rm -rf ./.certs`;
3940
await $`rm -rf ./deploy/terraform/generated/wallet`;
4041

4142
config.clear();

scripts/kustom.mjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import Configstore from "configstore";
33
import clear from "clear";
44
import Mustache from "mustache";
5+
import { parse, stringify } from "yaml";
6+
import { readFile, writeFile } from "node:fs/promises";
57
import { getOutputValues } from "./lib/terraform.mjs";
68
import { exitWithError } from "./lib/utils.mjs";
79

@@ -16,6 +18,7 @@ const config = new Configstore(projectName, { projectName });
1618

1719
const compartmentId = config.get("compartmentId");
1820
const namespace = config.get("namespace");
21+
const profile = config.get("profile");
1922
const regionName = config.get("regionName");
2023
const regionKey = config.get("regionKey");
2124
const webVersion = config.get("webVersion");
@@ -28,6 +31,7 @@ const genAiModelSummarization = config.get("genAiModelSummarization");
2831

2932
const { db_service, db_password } = await getOutputValues("./deploy/terraform");
3033

34+
await addProfileToKubeconfig(profile);
3135
await createBackendProperties();
3236
await createProdKustomization();
3337
await copyCerts();
@@ -150,3 +154,25 @@ async function createRegistrySecret() {
150154
exitWithError(error.stderr);
151155
}
152156
}
157+
158+
async function addProfileToKubeconfig(profile = "DEFAULT") {
159+
if (profile === "DEFAULT") return;
160+
161+
const kubeconfigPath = "./deploy/terraform/generated/kubeconfig";
162+
163+
let yamlContent = await readFile(kubeconfigPath, {
164+
encoding: "utf-8",
165+
});
166+
167+
const profileFlag = "--profile";
168+
const profileValue = profile;
169+
170+
const kubeconfig = parse(yamlContent);
171+
const execArgs = kubeconfig.users[0].user.exec.args;
172+
kubeconfig.users[0].user.exec.args = [...execArgs, profileFlag, profileValue];
173+
const newKubeconfigContent = stringify(kubeconfig);
174+
175+
await writeFile(kubeconfigPath, newKubeconfigContent, {
176+
encoding: "utf-8",
177+
});
178+
}

scripts/lib/oci.mjs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
import { exitWithError } from "./utils.mjs";
33
import { where, max } from "underscore";
44

5-
export async function getRegions() {
5+
export async function getRegions(profile = "DEFAULT", tenancyId) {
66
try {
7-
const tenancyId = await getTenancyId();
87
const output = (
9-
await $`oci iam region-subscription list --tenancy-id ${tenancyId}`
8+
await $`oci iam region-subscription list \
9+
--tenancy-id ${tenancyId} \
10+
--profile ${profile}`
1011
).stdout.trim();
1112
const { data } = JSON.parse(output);
1213
return data
@@ -21,8 +22,8 @@ export async function getRegions() {
2122
}
2223
}
2324

24-
export async function getNamespace() {
25-
const output = (await $`oci os ns get`).stdout.trim();
25+
export async function getNamespace(profile) {
26+
const output = (await $`oci os ns get --profile ${profile}`).stdout.trim();
2627
const { data } = JSON.parse(output);
2728
return data;
2829
}
@@ -96,16 +97,22 @@ export async function getTenancyId() {
9697
return tenancyId;
9798
}
9899

99-
export async function searchCompartmentIdByName(compartmentName) {
100+
export async function searchCompartmentIdByName(
101+
profile = "DEFAULT",
102+
compartmentName
103+
) {
100104
if (!compartmentName) {
101105
exitWithError("Compartment name required");
102106
}
103107
if (compartmentName === "root") {
104108
return getTenancyId();
105109
}
106110
try {
107-
const { stdout, exitCode, stderr } =
108-
await $`oci iam compartment list --compartment-id-in-subtree true --name ${compartmentName} --query "data[].id"`;
111+
const { stdout, exitCode, stderr } = await $`oci iam compartment list \
112+
--compartment-id-in-subtree true \
113+
--name ${compartmentName} \
114+
--profile=${profile} \
115+
--query "data[].id"`;
109116
if (exitCode !== 0) {
110117
exitWithError(stderr);
111118
}
@@ -339,6 +346,7 @@ export async function getBucket(compartmentId, name) {
339346
}
340347

341348
export async function getLatestGenAIModels(
349+
profile,
342350
compartmentId,
343351
regionName,
344352
vendor = "cohere",
@@ -354,6 +362,7 @@ export async function getLatestGenAIModels(
354362
try {
355363
const { stdout, stderr, exitCode } =
356364
await $`oci generative-ai model-collection list-models \
365+
--profile ${profile} \
357366
--compartment-id ${compartmentId} \
358367
--region ${regionName}`;
359368

0 commit comments

Comments
 (0)