Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Livelabs reservation #63

Merged
merged 32 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion basis/bin/auto_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ if [ -f $STATE_FILE ]; then
get_output_from_tfstate "COMPUTE_IP" "compute_ip"

# Bastion
get_attribute_from_tfstate "BASTION_IP" "starter_bastion" "public_ip"
get_output_from_tfstate "BASTION_IP" "bastion_public_ip"

# JDBC_URL
get_output_from_tfstate "JDBC_URL" "jdbc_url"
Expand Down
6 changes: 3 additions & 3 deletions basis/src/terraform/datasource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ output "oracle-dev-linux-latest-name" {
*/

locals {
oracle-linux-latest-name = coalesce( data.oci_core_images.oraclelinux.images.0.display_name, "Oracle-Linux-8.8-2023.10.24-0")
oracle_linux_latest_name = coalesce( data.oci_core_images.oraclelinux.images.0.display_name, "Oracle-Linux-8.8-2023.10.24-0")
}

output "oracle-linux-latest-name" {
value = local.oracle-linux-latest-name
output "oracle_linux_latest_name" {
value = local.oracle_linux_latest_name
}

## Object Storage
Expand Down
22 changes: 12 additions & 10 deletions option/src/db/db_free/db_node_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,26 @@ dnf -y localinstall oracle-database-free-23c-1.0-1.el8.x86_64.rpm
# echo DB_PASSWORD=$DB_PASSWORD
(echo "${DB_PASSWORD}"; echo "${DB_PASSWORD}";) | /etc/init.d/oracle-free-23c configure

# Install ORDS in silent mode
dnf install -y graalvm22-ee-17-jdk
dnf install -y ords
cat >> $HOME/password.txt << EOF
ls -al /usr/local/bin
if [ "$TF_VAR_language" = "apex" ]; then
# Install ORDS in silent mode
dnf install -y graalvm22-ee-17-jdk
dnf install -y ords
cat >> $HOME/password.txt << EOF
${DB_PASSWORD}
${DB_PASSWORD}
EOF

ls -al /usr/local/bin
/usr/local/bin/ords --config /etc/ords/config install --admin-user SYS --proxy-user --db-hostname localhost --db-port 1521 --db-servicename FREE --log-folder /etc/ords/logs --feature-sdw true --feature-db-api true --feature-rest-enabled-sql true --password-stdin < password.txt
/etc/init.d/ords start
/usr/local/bin/ords --config /etc/ords/config install --admin-user SYS --proxy-user --db-hostname localhost --db-port 1521 --db-servicename FREE --log-folder /etc/ords/logs --feature-sdw true --feature-db-api true --feature-rest-enabled-sql true --password-stdin < password.txt
/etc/init.d/ords start
firewall-cmd --zone=public --add-port=8080/tcp --permanent
else
echo "TF_VAR_language=$TF_VAR_language. APEX not installed."
fi

# Open the Firewall
firewall-cmd --zone=public --add-port=1521/tcp --permanent
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload


cat >> /home/opc/.bash_profile << EOF

# Setup Oracle Free environment
Expand Down
2 changes: 1 addition & 1 deletion option/src/db/db_free/deploy_db_node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ get_output_from_tfstate "DB_FREE_IP" "db_free_ip"
# done

scp -o StrictHostKeyChecking=no -oProxyCommand="ssh -o StrictHostKeyChecking=no -W %h:%p opc@$BASTION_IP" src/db/db_node_init.sh opc@$DB_FREE_IP:/tmp/.
ssh -o StrictHostKeyChecking=no -J opc@$BASTION_IP opc@$DB_FREE_IP "chmod +x /tmp/db_node_init.sh; sudo -i -u root DB_PASSWORD=$TF_VAR_db_password /tmp/db_node_init.sh 2>&1 | tee -a /tmp/db_node_init.log"
ssh -o StrictHostKeyChecking=no -J opc@$BASTION_IP opc@$DB_FREE_IP "chmod +x /tmp/db_node_init.sh; sudo -i -u root DB_PASSWORD=$TF_VAR_db_password TF_VAR_language=$TF_VAR_language /tmp/db_node_init.sh 2>&1 | tee -a /tmp/db_node_init.log"

22 changes: 22 additions & 0 deletions option/src/db/mysql_shared_compute/db_node_init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Run as root
#
# Install MySQL on OL8
# Doc: https://docs.oracle.com/cd/E17952_01/mysql-8.0-en/linux-installation-yum-repo.html
wget https://repo.mysql.com//mysql80-community-release-el8-5.noarch.rpm
yum -y install mysql80-community-release-el8-5.noarch.rpm
yum repolist enabled | grep "mysql.*-community.*"
yum -y module disable mysql
dnf -y install mysql-community-server
systemctl start mysqld

dnf -y install mysql-shell
export TMP_PASSWORD=`grep 'temporary password' /var/log/mysqld.log | sed 's/.*: //g'`
mysqlsh root@localhost --password=$TMP_PASSWORD --sql << EOF
ALTER USER 'root'@'localhost' IDENTIFIED BY '$DB_PASSWORD';
EOF

# Open the Firewall
# firewall-cmd --zone=public --add-port=3306/tcp --permanent
# firewall-cmd --reload


23 changes: 23 additions & 0 deletions option/src/db/mysql_shared_compute/deploy_db_node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd $SCRIPT_DIR/..
#!/bin/bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd $SCRIPT_DIR/..
. env.sh -silent

# Start ssh-agent to do a Jump from the BASTION to the DB_NODE
eval "$(ssh-agent -s)"
ssh-add $TF_VAR_ssh_private_path
# Do not rely on DB_NODE_IP in case of group with DATABASE and DB_FREE like the testsuite
get_output_from_tfstate "MYSQL_COMPUTE_IP" "mysql_compute_ip"

# Wait that the host is up
# until ssh -o StrictHostKeyChecking=no -J opc@$BASTION_IP opc@$DB_FREE_IP echo test; do
# sleep 5
# echo "SSH - Waiting for $DB_FREE_IP"
# done

scp -o StrictHostKeyChecking=no -oProxyCommand="ssh -o StrictHostKeyChecking=no -W %h:%p opc@$BASTION_IP" src/db/db_node_init.sh opc@$MYSQL_COMPUTE_IP:/tmp/.
ssh -o StrictHostKeyChecking=no -J opc@$BASTION_IP opc@$MYSQL_COMPUTE_IP "chmod +x /tmp/db_node_init.sh; sudo -i -u root DB_PASSWORD=$TF_VAR_db_password TF_VAR_language=$TF_VAR_language /tmp/db_node_init.sh 2>&1 | tee -a /tmp/db_node_init.log"

10 changes: 3 additions & 7 deletions option/terraform/bastion.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ resource "oci_core_instance" "starter_bastion" {
freeform_tags = local.freeform_tags
}

# Output the private and public IPs of the instance
output "bastion_private_ips" {
value = [oci_core_instance.starter_bastion.*.private_ip]
}

output "bastion_public_ips" {
value = [oci_core_instance.starter_bastion.*.public_ip]
# Output the public IPs
output "bastion_public_ip" {
value = oci_core_instance.starter_bastion.public_ip
}
9 changes: 2 additions & 7 deletions option/terraform/bastion_existing.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ data "oci_core_instance" "starter_bastion" {
instance_id = var.bastion_ocid
}

# Output the private and public IPs of the instance
output "bastion_private_ips" {
value = [data.oci_core_instance.starter_bastion.*.private_ip]
}

output "bastion_public_ips" {
value = [data.oci_core_instance.starter_bastion.*.public_ip]
output "bastion_public_ip" {
value = data.oci_core_instance.starter_bastion.public_ip
}
3 changes: 3 additions & 0 deletions option/terraform/bastion_shared_compute.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "bastion_public_ip" {
value = oci_core_instance.starter_instance.public_ip
}
File renamed without changes.
12 changes: 12 additions & 0 deletions option/terraform/db_free_shared_compute.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# DB23c Free in OCI Compute
locals {
db_free_ip = oci_core_instance.starter_instance.private_ip
# TNS Connect String (Description....)
db_url = format("%s:1521/FREEPDB1", local.db_free_ip)
db_host = oci_core_instance.starter_instance.private_ip
jdbc_url = format("jdbc:oracle:thin:@%s", local.db_url)
}

output "db_free_ip" {
value = local.db_free_ip
}
10 changes: 10 additions & 0 deletions option/terraform/mysql_shared_compute.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
locals {
db_host = oci_core_instance.starter_instance.private_ip
db_port = "3306"
db_url = format("localhost:%s", local.db_port)
jdbc_url = "jdbc:mysql://localhost/db1"
}

output "mysql_compute_ip" {
value = local.db_host
}
17 changes: 17 additions & 0 deletions option/test_suite_group_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ loop_shape() {
}

loop_db() {
OPTION_DB_INSTALL=default
# OPTION_DB=database
# loop_ui
OPTION_DB=atp
Expand Down Expand Up @@ -110,8 +111,24 @@ loop_lang () {
loop_ui
}

loop_shared_compute() {
# Shared compute / LiveLabs Green Button
OPTION_SHAPE=amd
OPTION_LANG=java
OPTION_JAVA_VM=jdk
OPTION_JAVA_FRAMEWORK=springboot
OPTION_DB_INSTALL=shared_compute
OPTION_UI=html
OPTION_DB=db_free
mkdir_deploy
build_option
OPTION_DB=mysql
build_option
}

loop_deploy() {
OPTION_DEPLOY=compute
loop_shared_compute
loop_lang
OPTION_DEPLOY=container_instance
loop_lang
Expand Down
13 changes: 8 additions & 5 deletions option/test_suite_shared.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,19 @@ build_test_destroy () {
cat ${TEST_DIR}_time.txt

if [ "$OPTION_LANG" == "java" ]; then
echo "$CSV_DATE,$OPTION_DEPLOY,$OPTION_LANG,$OPTION_JAVA_FRAMEWORK,$OPTION_JAVA_VM,$OPTION_DB,$OPTION_UI,$OPTION_SHAPE,$CSV_NAME,$CSV_HTML_OK,$CSV_JSON_OK,$CSV_BUILD_SECOND,$CSV_DESTROY_SECOND,$CSV_RUN100_OK,$CSV_RUN100_SECOND" >> $TEST_HOME/result.csv
echo "$CSV_DATE,$OPTION_DEPLOY,$OPTION_LANG,$OPTION_JAVA_FRAMEWORK,$OPTION_JAVA_VM,$OPTION_DB,$OPTION_DB_INSTALL,$OPTION_UI,$OPTION_SHAPE,$CSV_NAME,$CSV_HTML_OK,$CSV_JSON_OK,$CSV_BUILD_SECOND,$CSV_DESTROY_SECOND,$CSV_RUN100_OK,$CSV_RUN100_SECOND" >> $TEST_HOME/result.csv
else
echo "$CSV_DATE,$OPTION_DEPLOY,$OPTION_LANG,-,-,$OPTION_DB,$OPTION_UI,$OPTION_SHAPE,$CSV_NAME,$CSV_HTML_OK,$CSV_JSON_OK,$CSV_BUILD_SECOND,$CSV_DESTROY_SECOND,$CSV_RUN100_OK,$CSV_RUN100_SECOND" >> $TEST_HOME/result.csv
echo "$CSV_DATE,$OPTION_DEPLOY,$OPTION_LANG,-,-,$OPTION_DB,$OPTION_DB_INSTALL,$OPTION_UI,$OPTION_SHAPE,$CSV_NAME,$CSV_HTML_OK,$CSV_JSON_OK,$CSV_BUILD_SECOND,$CSV_DESTROY_SECOND,$CSV_RUN100_OK,$CSV_RUN100_SECOND" >> $TEST_HOME/result.csv
fi
if [ "$CSV_JSON_OK" != "1" ] || [ "$CSV_HTML_OK" != "1" ]; then
echo "$CSV_DATE,$OPTION_DEPLOY,$OPTION_LANG,$OPTION_JAVA_FRAMEWORK,$OPTION_JAVA_VM,$OPTION_DB,$OPTION_UI,$OPTION_SHAPE,$CSV_NAME,$CSV_HTML_OK,$CSV_JSON_OK,$CSV_BUILD_SECOND,$CSV_DESTROY_SECOND,$CSV_RUN100_OK,$CSV_RUN100_SECOND" >> $TEST_HOME/errors.csv
echo "$CSV_DATE,$OPTION_DEPLOY,$OPTION_LANG,$OPTION_JAVA_FRAMEWORK,$OPTION_JAVA_VM,$OPTION_DB,$OPTION_DB_INSTALL,$OPTION_UI,$OPTION_SHAPE,$CSV_NAME,$CSV_HTML_OK,$CSV_JSON_OK,$CSV_BUILD_SECOND,$CSV_DESTROY_SECOND,$CSV_RUN100_OK,$CSV_RUN100_SECOND" >> $TEST_HOME/errors.csv
fi
}

build_option() {
if [ "$OPTION_LANG" == "java" ] && [ "$OPTION_DEPLOY" != "function" ]; then
if [ "$OPTION_DB_INSTALL" == "shared_compute" ]; then
NAME=shared-compute-${OPTION_DB}
elif [ "$OPTION_LANG" == "java" ] && [ "$OPTION_DEPLOY" != "function" ]; then
NAME=${OPTION_LANG}-${OPTION_JAVA_FRAMEWORK}-${OPTION_JAVA_VM}-${OPTION_DB}-${OPTION_UI}
else
NAME=${OPTION_LANG}-${OPTION_DB}-${OPTION_UI}
Expand All @@ -132,6 +134,7 @@ build_option() {
-java_vm $OPTION_JAVA_VM \
-database $OPTION_DB \
-db_password $TEST_DB_PASSWORD \
-db_install $OPTION_DB_INSTALL \
-group_common dummy \
-shape $OPTION_SHAPE \
-compartment_ocid $EX_COMPARTMENT_OCID \
Expand Down Expand Up @@ -187,7 +190,7 @@ pre_test_suite() {
cd $TEST_HOME/group_common
./build.sh
date
echo "CSV_DATE,OPTION_DEPLOY,OPTION_LANG,OPTION_JAVA_FRAMEWORK,OPTION_JAVA_VM,OPTION_DB,OPTION_UI,OPTION_SHAPE,CSV_NAME,CSV_HTML_OK,CSV_JSON_OK,CSV_BUILD_SECOND,CSV_DESTROY_SECOND,CSV_RUN100_OK,CSV_RUN100_SECOND" > $TEST_HOME/result.csv
echo "CSV_DATE,OPTION_DEPLOY,OPTION_LANG,OPTION_JAVA_FRAMEWORK,OPTION_JAVA_VM,OPTION_DB,OPTION_DB_INSTALL,OPTION_UI,OPTION_SHAPE,CSV_NAME,CSV_HTML_OK,CSV_JSON_OK,CSV_BUILD_SECOND,CSV_DESTROY_SECOND,CSV_RUN100_OK,CSV_RUN100_SECOND" > $TEST_HOME/result.csv
}

pre_git_refresh() {
Expand Down
28 changes: 21 additions & 7 deletions py_oci_starter.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def mandatory_options(mode):
no_default_options = ['-compartment_ocid', '-oke_ocid', '-vcn_ocid',
'-atp_ocid', '-db_ocid', '-db_compartment_ocid', '-pdb_ocid', '-mysql_ocid',
'-db_user', '-fnapp_ocid', '-apigw_ocid', '-bastion_ocid', '-auth_token',
'-subnet_ocid','-public_subnet_ocid','-private_subnet_ocid','-shape']
'-subnet_ocid','-public_subnet_ocid','-private_subnet_ocid','-shape','-db_install']

# hidden_options - allowed but not advertised
hidden_options = ['-zip', '-group_common','-group_name']
Expand All @@ -103,7 +103,8 @@ def allowed_options():
'-license': {'included', 'LICENSE_INCLUDED', 'byol', 'BRING_YOUR_OWN_LICENSE'},
'-infra_as_code': {'terraform_local', 'terraform_object_storage', 'resource_manager'},
'-mode': {CLI, GIT, ZIP},
'-shape': {'amd','freetier_amd','ampere'}
'-shape': {'amd','freetier_amd','ampere'},
'-db_install': {'default', 'shared_compute', 'kubernetes'}
}

def check_values():
Expand Down Expand Up @@ -157,7 +158,11 @@ def db_rules():
'pluggable': 'system', 'mysql': 'root', 'none': ''}
params['db_user'] = default_users[params['database']]
if params.get('database')=='none':
params.pop('db_password')
params.pop('db_password')
# shared_compute is valid only in compute deployment
if params.get('db_install') == "shared_compute":
if params.get('deploy')!='compute':
params.pop('db_install')


def language_rules():
Expand Down Expand Up @@ -680,7 +685,9 @@ def create_dir_shared():
# -- Bastion ------------------------------------------------------------
# Currently limited to provision the database ?
# XXXX In the future maybe as build machine ?
if 'bastion_ocid' in params:
if params.get('db_install') == "shared_compute":
cp_terraform("bastion_shared_compute.tf")
elif 'bastion_ocid' in params:
cp_terraform("bastion_existing.tf")
elif params.get('database')!='none':
cp_terraform("bastion.tf")
Expand Down Expand Up @@ -849,13 +856,20 @@ def create_output_dir():

if params.get('database') == "db_free":
cp_dir_src_db("oracle")
cp_terraform("db_free_compute.tf")
if params.get('db_install') == "shared_compute":
cp_terraform("db_free_shared_compute.tf")
else:
cp_terraform("db_free.tf")
output_copy_tree("option/src/db/db_free", "src/db")
output_move("src/db/deploy_db_node.sh", "bin/deploy_db_node.sh")

if params.get('database') == "mysql":
cp_dir_src_db("mysql")
if 'mysql_ocid' in params:
if params.get('db_install') == "shared_compute":
cp_terraform("mysql_shared_compute.tf")
output_copy_tree("option/src/db/mysql_shared_compute", "src/db")
output_move("src/db/deploy_db_node.sh", "bin/deploy_db_node.sh")
elif 'mysql_ocid' in params:
cp_terraform("mysql_existing.tf", "mysql_append.tf")
else:
cp_terraform("mysql.tf", "mysql_append.tf")
Expand Down Expand Up @@ -896,7 +910,7 @@ def create_group_common_dir():
output_replace_db_node_count()

if "db_free" in a_group_common:
cp_terraform("db_free_compute.tf")
cp_terraform("db_free.tf")
output_copy_tree("option/src/db/db_free", "src/db")
output_move("src/db/deploy_db_node.sh", "bin/deploy_db_node.sh")

Expand Down