Skip to content

Commit

Permalink
Merge pull request #49 from mgueury/main
Browse files Browse the repository at this point in the history
APEX v1
  • Loading branch information
MarcGueury authored Jul 13, 2023
2 parents 2c80390 + d3dbcb2 commit 546e376
Show file tree
Hide file tree
Showing 54 changed files with 18,933 additions and 203 deletions.
6 changes: 5 additions & 1 deletion basis/bin/add_api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ if [ "$APIM_HOST" != "" ]; then
FIRST_LETTER_UPPERCASE=`echo $TF_VAR_prefix | sed -e "s/\b\(.\)/\u\1/g"`
if [ "$TF_VAR_ui_strategy" == "api" ]; then
APIGW_URL=https://${APIGW_HOSTNAME}/${TF_VAR_prefix}
curl -k "https://${APIM_HOST}/ords/apim/rest/add_api?git_repo_url=${TF_VAR_git_url}&impl_name=${FIRST_LETTER_UPPERCASE}&icon_url=${TF_VAR_language}&runtime_console=https://cloud.oracle.com/api-gateway/gateways/$TF_VAR_apigw_ocid/deployments/$APIGW_DEPLOYMENT_OCID&version=${GIT_BRANCH}&endpoint_url=${APIGW_URL}/app/dept&endpoint_git_path=src/terraform/apigw_existing.tf&spec_git_path=src/app/openapi_spec.yaml&spec_type=OpenAPI"
for APP_DIR in `app_dir_list`; do
if [ -f src/${APP_DIR}/openapi_spec.yaml ]; then
curl -k "https://${APIM_HOST}/ords/apim/rest/add_api?git_repo_url=${TF_VAR_git_url}&impl_name=${FIRST_LETTER_UPPERCASE}&icon_url=${TF_VAR_language}&runtime_console=https://cloud.oracle.com/api-gateway/gateways/$TF_VAR_apigw_ocid/deployments/$APIGW_DEPLOYMENT_OCID&version=${GIT_BRANCH}&endpoint_url=${APIGW_URL}/${APP_DIR}/dept&endpoint_git_path=src/terraform/apigw_existing.tf&spec_git_path=src/${APP_DIR}/openapi_spec.yaml&spec_type=OpenAPI"
fi
done
else
get_ui_url
if [ -f src/oke/ingress-app.yaml ]; then
Expand Down
40 changes: 25 additions & 15 deletions basis/bin/auto_env.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
#!/bin/bash
export BIN_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
export ROOT_DIR=${BIN_DIR%/*}
if [[ -z "${BIN_DIR}" ]]; then
export BIN_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
fi
if [[ -z "${PROJECT_DIR}" ]]; then
echo "Error: PROJECT_DIR not set"
exit
fi

# Target DIR
export TARGET_DIR=$PROJECT_DIR/target
if [ ! -d $TARGET_DIR ]; then
mkdir $TARGET_DIR
fi

# Shared BASH Functions
. $BIN_DIR/shared_bash_function.sh

if [ "$1" == "-no-auto" ]; then
return
fi

# Silent mode (default is not silent)
if [ "$1" == "-silent" ]; then
SILENT_MODE=true
Expand All @@ -20,7 +35,7 @@ fi
if [ "$TF_VAR_db_password" == "__TO_FILL__" ]; then
echo "Generating password for the database"
export TF_VAR_db_password=`python3 $BIN_DIR/gen_password.py`
sed -i "s&TF_VAR_db_password=\"__TO_FILL__\"&TF_VAR_db_password=\"$TF_VAR_db_password\"&" $ROOT_DIR/env.sh
sed -i "s&TF_VAR_db_password=\"__TO_FILL__\"&TF_VAR_db_password=\"$TF_VAR_db_password\"&" $PROJECT_DIR/env.sh
echo "Password stored in env.sh"
echo "> TF_VAR_db_password=$TF_VAR_db_password"
fi
Expand All @@ -44,11 +59,6 @@ if ! command -v jq &> /dev/null; then
exit 1
fi

export TARGET_DIR=$ROOT_DIR/target
if [ ! -d $TARGET_DIR ]; then
mkdir $TARGET_DIR
fi

#-- PRE terraform ----------------------------------------------------------
if [ "$OCI_STARTER_VARIABLES_SET" == "$OCI_STARTER_CREATION_DATE" ]; then
echo "Variables already set"
Expand Down Expand Up @@ -103,7 +113,7 @@ else
auto_echo TF_VAR_region=$TF_VAR_region

# Kubernetes and OCIR
if [ "$TF_VAR_deploy_strategy" == "kubernetes" ] || [ "$TF_VAR_deploy_strategy" == "function" ] || [ "$TF_VAR_deploy_strategy" == "container_instance" ] || [ -f $ROOT_DIR/src/terraform/oke.tf ]; then
if [ "$TF_VAR_deploy_strategy" == "kubernetes" ] || [ "$TF_VAR_deploy_strategy" == "function" ] || [ "$TF_VAR_deploy_strategy" == "container_instance" ] || [ -f $PROJECT_DIR/src/terraform/oke.tf ]; then
export TF_VAR_namespace=`oci os ns get | jq -r .data`
auto_echo TF_VAR_namespace=$TF_VAR_namespace
export [email protected]
Expand All @@ -113,12 +123,12 @@ else

export DOCKER_PREFIX=${TF_VAR_ocir}/${TF_VAR_namespace}
auto_echo DOCKER_PREFIX=$DOCKER_PREFIX
export KUBECONFIG=$ROOT_DIR/target/kubeconfig_starter
export KUBECONFIG=$TARGET_DIR/kubeconfig_starter
fi

# OpenAPI Spec
if [ -f $ROOT_DIR/src/app/openapi_spec.yaml ]; then
export TF_VAR_openapi_spec=$(cat $ROOT_DIR/src/app/openapi_spec.yaml)
if [ -f $PROJECT_DIR/src/app/openapi_spec.yaml ]; then
export TF_VAR_openapi_spec=$(cat $PROJECT_DIR/src/app/openapi_spec.yaml)
fi

if [ "$TF_VAR_deploy_strategy" == "hpc" ]; then
Expand All @@ -141,7 +151,7 @@ else
S1=${TF_VAR_git_url/git@gitlab.com:/https:\/\/gitlab.com\/}
export TF_VAR_git_url=${S1/.git/\/-\/blob\/}${GIT_BRANCH}
fi
cd $ROOT_DIR
cd $PROJECT_DIR
export GIT_RELATIVE_PATH=`git rev-parse --show-prefix`
cd -
export TF_VAR_git_url=${TF_VAR_git_url}/${GIT_RELATIVE_PATH}
Expand Down Expand Up @@ -215,13 +225,13 @@ if [ -f $STATE_FILE ]; then
get_attribute_from_tfstate "DB_NODE_IP" "starter_node_vnic" "private_ip_address"
fi

if [ "$TF_VAR_deploy_strategy" == "kubernetes" ] || [ -f $ROOT_DIR/src/terraform/oke.tf ]; then
if [ "$TF_VAR_deploy_strategy" == "kubernetes" ] || [ -f $PROJECT_DIR/src/terraform/oke.tf ]; then
# OKE
get_output_from_tfstate "OKE_OCID" "oke_ocid"
fi

# JMS
if [ -f $ROOT_DIR/src/terraform/jms.tf ]; then
if [ -f $PROJECT_DIR/src/terraform/jms.tf ]; then
if [ ! -f $TARGET_DIR/jms_agent_deploy.sh ]; then
get_output_from_tfstate "FLEET_OCID" "fleet_ocid"
get_output_from_tfstate "INSTALL_KEY_OCID" "install_key_ocid"
Expand Down
42 changes: 27 additions & 15 deletions basis/bin/build_all.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
#!/bin/bash
if [[ -z "${ROOT_DIR}" ]]; then
echo "Error: ROOT_DIR not set"
if [[ -z "${PROJECT_DIR}" ]]; then
echo "Error: PROJECT_DIR not set"
exit
fi
cd $ROOT_DIR
cd $PROJECT_DIR
SECONDS=0

. env.sh -no-auto
title "OCI Starter - Build"

# Build all
# Generate sshkeys if not part of a Common Resources project
if [ "$TF_VAR_ssh_private_path" == "" ]; then
. bin/sshkey_generate.sh
. $BIN_DIR/sshkey_generate.sh
fi
. env.sh
# Run Terraform
title "Terraform Apply"
src/terraform/apply.sh --auto-approve -no-color
exit_on_error

. env.sh
# Run config command on the DB directly (ex RAC)
if [ -f bin/deploy_db_node.sh ]; then
bin/deploy_db_node.sh
title "Deploy DB Node"
$BIN_DIR/deploy_db_node.sh
fi

# Build the DB tables (via Bastion)
if [ -d src/db ]; then
bin/deploy_bastion.sh
title "Deploy Bastion"
$BIN_DIR/deploy_bastion.sh
fi

# Init target/compute
Expand All @@ -32,25 +38,31 @@ if [ "$TF_VAR_deploy_strategy" == "compute" ]; then
cp src/compute/* target/compute/.
fi

if [ -f src/app/build_app.sh ]; then
src/app/build_app.sh
# Build all app* directories
for APP_DIR in `app_dir_list`; do
title "Build App $APP_DIR"
src/${APP_DIR}/build_app.sh
exit_on_error
fi
done

if [ -f src/ui/build_ui.sh ]; then
title "Build UI"
src/ui/build_ui.sh
exit_on_error
fi

# Deploy
title "Deploy $TF_VAR_deploy_strategy"
if [ "$TF_VAR_deploy_strategy" == "compute" ]; then
bin/deploy_compute.sh
$BIN_DIR/deploy_compute.sh
elif [ "$TF_VAR_deploy_strategy" == "kubernetes" ]; then
bin/oke_deploy.sh
$BIN_DIR/oke_deploy.sh
elif [ "$TF_VAR_deploy_strategy" == "container_instance" ]; then
bin/ci_deploy.sh
$BIN_DIR/ci_deploy.sh
fi

bin/add_api.sh
$BIN_DIR/add_api.sh

title "Done"
$BIN_DIR/done.sh

bin/done.sh
15 changes: 12 additions & 3 deletions basis/bin/build_common.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
# Build_common.sh
BIN_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
#!/bin/bash
if [[ -z "${BIN_DIR}" ]]; then
echo "Error: BIN_DIR not set"
exit
fi
if [[ -z "${PROJECT_DIR}" ]]; then
echo "Error: PROJECT_DIR not set"
exit
fi

# SCRIPT_DIR should be set by the calling scripts
APP_DIR=`echo ${SCRIPT_DIR} |sed -E "s#(.*)/(.*)#\2#"`
cd $SCRIPT_DIR

if [ -z "$TF_VAR_deploy_strategy" ]; then
. $BIN_DIR/../env.sh
. $PROJECT_DIR/env.sh
else
. $BIN_DIR/shared_bash_function.sh
fi
19 changes: 12 additions & 7 deletions basis/bin/destroy_all.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#!/bin/bash
if [[ -z "${ROOT_DIR}" ]]; then
echo "Error: ROOT_DIR not set"
if [[ -z "${PROJECT_DIR}" ]]; then
echo "Error: PROJECT_DIR not set"
exit
fi
cd $ROOT_DIR
cd $PROJECT_DIR
SECONDS=0

# Call the script with --auto-approve to destroy without prompt

echo "WARNING"
. env.sh -no-auto
title "OCI Starter - Destroy"
echo
echo "This will destroy all the resources created by Terraform."
echo "Warning: This will destroy all the resources created by Terraform."
echo
if [ "$1" != "--auto-approve" ]; then
read -p "Do you want to proceed? (yes/no) " yn
Expand All @@ -24,11 +26,14 @@ if [ "$1" != "--auto-approve" ]; then
fi

. env.sh
if [ -f $ROOT_DIR/src/terraform/oke.tf ]; then
if [ -f $PROJECT_DIR/src/terraform/oke.tf ]; then
title "OKE Destroy"
bin/oke_destroy.sh --auto-approve
elif [ "$TF_VAR_deploy_strategy" == "function" ]; then
# delete the UI website
title "Delete Object Storage files"
oci os object bulk-delete -bn ${TF_VAR_prefix}-public-bucket --force
fi

title "Terraform Destroy"
src/terraform/destroy.sh --auto-approve -no-color
echo "Destroy time: ${SECONDS} secs"
31 changes: 17 additions & 14 deletions basis/bin/done.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if [ ! -z "$UI_URL" ]; then
x=1
while [ $x -le 5 ]
do
curl $UI_URL/app/dept -L --retry 5 --retry-max-time 20 -D /tmp/result_json.log > /tmp/result.json
curl $UI_URL/app/dept -b /tmp/cookie.txt -c /tmp/cookie.txt -L --retry 5 --retry-max-time 20 -D /tmp/result_json.log > /tmp/result.json
if grep -q -i "deptno" /tmp/result.json; then
echo "OK"
break
Expand All @@ -38,22 +38,25 @@ if [ ! -z "$UI_URL" ]; then
x=$(( $x + 1 ))
done
if [ "$TF_VAR_ui_strategy" != "api" ]; then
curl $UI_URL/ -L --retry 5 --retry-max-time 20 -D /tmp/result_html.log > /tmp/result.html
rm /tmp/cookie.txt
curl $UI_URL/ -b /tmp/cookie.txt -c /tmp/cookie.txt -L --retry 5 --retry-max-time 20 -D /tmp/result_html.log > /tmp/result.html
else
echo "OCI Starter" > /tmp/result.html
fi
curl $UI_URL/app/info -L --retry 5 --retry-max-time 20 -D /tmp/result_info.log > /tmp/result.info
rm /tmp/cookie.txt
curl $UI_URL/app/info -b /tmp/cookie.txt -c /tmp/cookie.txt -L --retry 5 --retry-max-time 20 -D /tmp/result_info.log > /tmp/result.info
fi
if [ "$TF_VAR_ui_strategy" != "api" ]; then
echo - User Interface : $UI_URL/
echo - User Interface: $UI_URL/
fi
echo - Rest DB API : $UI_URL/app/dept
echo - Rest Info API : $UI_URL/app/info
if [ "$TF_VAR_language" == "php" ]; then
echo - PHP Page : $UI_URL/app/index.php
elif [ "$TF_VAR_language" == "java" ] && [ "$TF_VAR_java_framework" == "tomcat" ] ; then
echo - JSP Page : $UI_URL/app/index.jsp
elif [ "$TF_VAR_deploy_strategy" == "compute" ] && [ "$TF_VAR_ui_strategy" == "api" ]; then
for APP_DIR in `app_dir_list`; do
if [ -f $PROJECT_DIR/src/$APP_DIR/openapi_spec.yaml ]; then
python3 $BIN_DIR/openapi_list.py $PROJECT_DIR/src/$APP_DIR/openapi_spec.yaml $UI_URL
fi
# echo - Rest DB API : $UI_URL/$APP_DIR/dept
# echo - Rest Info API : $UI_URL/$APP_DIR/info
done
if [ "$TF_VAR_deploy_strategy" == "compute" ] && [ "$TF_VAR_ui_strategy" == "api" ]; then
export APIGW_URL=https://${APIGW_HOSTNAME}/${TF_VAR_prefix}
echo - API Gateway URL : $APIGW_URL/app/dept
fi
Expand All @@ -62,6 +65,6 @@ if [ ! -z "$UI_URL" ]; then
fi
fi

if [ -f $ROOT_DIR/src/after_done.sh ]; then
$ROOT_DIR/src/after_done.sh
fi
if [ -f $PROJECT_DIR/src/after_done.sh ]; then
$PROJECT_DIR/src/after_done.sh
fi
6 changes: 3 additions & 3 deletions basis/bin/gen_auth_token.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/bash
export BIN_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
export ROOT_DIR=${BIN_DIR%/*}
export PROJECT_DIR=${BIN_DIR%/*}

# Shared BASH Functions
. $BIN_DIR/shared_bash_function.sh

if grep -q 'TF_VAR_auth_token="__TO_FILL__"' $ROOT_DIR/env.sh; then
if grep -q 'TF_VAR_auth_token="__TO_FILL__"' $PROJECT_DIR/env.sh; then
echo "Generating a new AUTH_TOKEN"
get_user_details
oci iam auth-token create --description "OCI_STARTER_TOKEN" --user-id $TF_VAR_user_ocid > auth_token.log 2>&1
Expand All @@ -15,7 +15,7 @@ if grep -q 'TF_VAR_auth_token="__TO_FILL__"' $ROOT_DIR/env.sh; then
rm auth_token.log

if [ "$TF_VAR_auth_token" != "" ]; then
sed -i "s&TF_VAR_auth_token=\"__TO_FILL__\"&TF_VAR_auth_token=\"$TF_VAR_auth_token\"&" $ROOT_DIR/env.sh
sed -i "s&TF_VAR_auth_token=\"__TO_FILL__\"&TF_VAR_auth_token=\"$TF_VAR_auth_token\"&" $PROJECT_DIR/env.sh
echo "AUTH_TOKEN stored in env.sh"
echo "> TF_VAR_auth_token=$TF_VAR_auth_token"
fi
Expand Down
24 changes: 24 additions & 0 deletions basis/bin/openapi_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Usage: python openapi_list.py <filename>
# /app/dept
# /app/info
# Usage: python openapi_list.py <filename> <url_prefix>
# Rest DB API: $URL_PREFIX/app/dept
# Rest Info API: $URL_PREFIX/app/info

import yaml, sys

filename = sys.argv[1];
url_prefix = ""
if len(sys.argv)>2:
url_prefix = sys.argv[2];

with open(filename, "r") as stream:
try:
data = yaml.safe_load(stream)
for key, value in data["paths"].items():
if url_prefix != "":
print("- " + str(value["get"]["summary"]) +": " + url_prefix + str(key))
else:
print(str(key))
except yaml.YAMLError as exc:
print(exc)
Loading

0 comments on commit 546e376

Please sign in to comment.