diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..dfdb8b771 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.sh text eol=lf diff --git a/.github/resource/azure-credential-setup-wls-aks.sh b/.github/resource/azure-credential-setup-wls-aks.sh new file mode 100644 index 000000000..153c462e1 --- /dev/null +++ b/.github/resource/azure-credential-setup-wls-aks.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +set -Eeuo pipefail + +echo "Execute azure-credential-setup.sh - Start------------------------------------------" + +## Create Azure Credentials +SERVICE_PRINCIPAL_NAME_WLS_AKS="sp-${REPO_NAME}-wls-aks-$(date +%s)" +echo "Creating Azure Service Principal with name: $SERVICE_PRINCIPAL_NAME_WLS_AKS" +SUBSCRIPTION_ID=$(az account show --query id -o tsv| tr -d '\r\n') + +AZURE_CREDENTIALS=$(az ad sp create-for-rbac --name ${SERVICE_PRINCIPAL_NAME_WLS_AKS} --role="Contributor" --scopes="/subscriptions/${SUBSCRIPTION_ID}" --sdk-auth --only-show-errors) +SP_ID=$( az ad sp list --display-name $SERVICE_PRINCIPAL_NAME --query \[0\].id -o tsv | tr -d '\r\n') +az role assignment create --assignee ${SP_ID} --scope="/subscriptions/${SUBSCRIPTION_ID}" --role "User Access Administrator" + +## Set the Azure Credentials as a secret in the repository +gh secret set "AZURE_CREDENTIALS" -b"${AZURE_CREDENTIALS}" +gh variable set "SERVICE_PRINCIPAL_NAME_WLS_AKS" -b"${SERVICE_PRINCIPAL_NAME_WLS_AKS}" + +echo "Execute azure-credential-setup.sh - End--------------------------------------------" diff --git a/.github/resource/azure-credential-setup-wls-vm.sh b/.github/resource/azure-credential-setup-wls-vm.sh new file mode 100644 index 000000000..19ab631ac --- /dev/null +++ b/.github/resource/azure-credential-setup-wls-vm.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +set -Eeuo pipefail + +echo "Execute azure-credential-setup.sh - Start------------------------------------------" + +## Create Azure Credentials +SERVICE_PRINCIPAL_NAME_WLS_VM="sp-${REPO_NAME}-$(date +%s)" +echo "Creating Azure Service Principal with name: $SERVICE_PRINCIPAL_NAME_WLS_VM" +SUBSCRIPTION_ID=$(az account show --query id -o tsv| tr -d '\r\n') + +SERVICE_PRINCIPAL=$(az ad sp create-for-rbac --name ${SERVICE_PRINCIPAL_NAME_WLS_VM} --role="Contributor" --scopes="/subscriptions/${SUBSCRIPTION_ID}" --sdk-auth --only-show-errors | base64 ${w0}) +AZURE_CREDENTIALS=$(echo $SERVICE_PRINCIPAL | base64 -d) + +## Set the Azure Credentials as a secret in the repository +gh secret set "AZURE_CREDENTIALS" -b"${AZURE_CREDENTIALS}" +gh variable set "SERVICE_PRINCIPAL_NAME_WLS_VM" -b"${SERVICE_PRINCIPAL_NAME_WLS_VM}" + +echo "Execute azure-credential-setup.sh - End--------------------------------------------" diff --git a/.github/resource/azure-credential-teardown-wls-aks.sh b/.github/resource/azure-credential-teardown-wls-aks.sh new file mode 100644 index 000000000..2d75810d5 --- /dev/null +++ b/.github/resource/azure-credential-teardown-wls-aks.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -Eeuo pipefail + +echo "Execute azure-credential-teardown.sh - Start------------------------------------------" + +gh secret delete "AZURE_CREDENTIALS" +SERVICE_PRINCIPAL_NAME_WLS_AKS=$(gh variable get "SERVICE_PRINCIPAL_NAME_WLS_AKS") +az ad sp delete --id $(az ad sp list --display-name $SERVICE_PRINCIPAL_NAME_WLS_AKS --query "[].appId" -o tsv| tr -d '\r\n') + +echo "Execute azure-credential-teardown.sh - End--------------------------------------------" diff --git a/.github/resource/azure-credential-teardown-wls-vm.sh b/.github/resource/azure-credential-teardown-wls-vm.sh new file mode 100644 index 000000000..c0fd78802 --- /dev/null +++ b/.github/resource/azure-credential-teardown-wls-vm.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -Eeuo pipefail + +echo "Execute azure-credential-teardown.sh - Start------------------------------------------" + +gh secret delete "AZURE_CREDENTIALS" +SERVICE_PRINCIPAL_NAME_WLS_VM=$(gh variable get "SERVICE_PRINCIPAL_NAME_WLS_VM") +az ad sp delete --id $(az ad sp list --display-name $SERVICE_PRINCIPAL_NAME_WLS_VM --query "[].appId" -o tsv| tr -d '\r\n') + +echo "Execute azure-credential-teardown.sh - End--------------------------------------------" diff --git a/.github/resource/credentials-params-setup.sh b/.github/resource/credentials-params-setup.sh new file mode 100644 index 000000000..3faf23912 --- /dev/null +++ b/.github/resource/credentials-params-setup.sh @@ -0,0 +1,61 @@ +#!/usr/bin/env bash +set -Eeuo pipefail + +# ANSI color codes +RED='\033[0;31m' +NC='\033[0m' # No Color + +echo "setup-credentials.sh - Start" + +# Function to print error messages in red +print_error() { + local message=$1 + echo -e "${RED}Error: ${message}${NC}" +} + +check_parameters() { + echo "Checking parameters..." + local has_empty_value=0 + + while IFS= read -r line; do + name=$(echo "$line" | yq -r '.name') + value=$(echo "$line" | yq -r '.value') + + if [ -z "$value" ] || [ "$value" == "null" ]; then + print_error "The parameter '$name' has an empty/null value. Please provide a valid value." + has_empty_value=1 + break + else + echo "Name: $name, Value: $value" + fi + done < <(yq eval -o=json '.[]' "$param_file" | jq -c '.') + + echo "return $has_empty_value" + return $has_empty_value +} + +# Function to set values from YAML +set_values() { + echo "Setting values..." + yq eval -o=json '.[]' "$param_file" | jq -c '.' | while read -r line; do + name=$(echo "$line" | jq -r '.name') + value=$(echo "$line" | jq -r '.value') + gh secret set "$name" -b"${value}" + done +} + +# Main script execution +main() { + if check_parameters; then + echo "All parameters are valid." + set_values + else + echo "Parameter check failed. Exiting." + exit 1 + fi + + echo "setup-credentials.sh - Finish" +} + +# Run the main function +main diff --git a/.github/resource/credentials-params-teardown.sh b/.github/resource/credentials-params-teardown.sh new file mode 100644 index 000000000..0cc3d479f --- /dev/null +++ b/.github/resource/credentials-params-teardown.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -Eeuo pipefail + +echo "teardown-credentials.sh - Start" + +# remove param the json +yq eval -o=json '.[]' "$param_file" | jq -c '.' | while read -r line; do + name=$(echo "$line" | jq -r '.name') + value=$(echo "$line" | jq -r '.value') + gh secret remove "$name" +done + +echo "teardown-credentials.sh - Finish" diff --git a/.github/resource/credentials-params-wls-aks.yaml b/.github/resource/credentials-params-wls-aks.yaml new file mode 100644 index 000000000..c5c5784e8 --- /dev/null +++ b/.github/resource/credentials-params-wls-aks.yaml @@ -0,0 +1,23 @@ +# This file contains the parameters for the credentials used in the workflows. +- name: ORC_SSOUSER + value: "" + description: "Oracle single sign-on userid." +- name: ORC_SSOPSW + value: "" + description: "Password for Oracle single sign-on userid." +- name: WDT_RUNTIMEPSW + value: "" + description: "Password for WebLogic Server and Runtime Deployment Tooling encryption." +- name: WLS_PSW + value: ${WDT_RUNTIMEPSW} + description: "Password for WebLogic Server and Runtime Deployment Tooling encryption." +# parameters for the credentials used in the workflows with default values. +- name: WLS_USERNAME + value: "weblogic" + description: "WebLogic Server user name." +- name: DB_PASSWORD + value: "Secret123!" + description: "Password for the database" +- name: LOCATION + value: "eastus" + description: "Location of the resource group" diff --git a/.github/resource/credentials-params-wls-vm.yaml b/.github/resource/credentials-params-wls-vm.yaml new file mode 100644 index 000000000..33dc568f8 --- /dev/null +++ b/.github/resource/credentials-params-wls-vm.yaml @@ -0,0 +1,35 @@ +# This file contains the parameters for the credentials used in the workflows. +- name: OTN_USERID + value: "" + description: Oracle single sign-on userid. +- name: OTN_PASSWORD + value: "" + description: Password for Oracle single sign-on userid. +- name: WLS_PSW + value: "" + description: Password for WebLogic Server. +# Git credentials +- name: USER_EMAIL + value: "" + description: User Email of GitHub acount to access GitHub repository. +- name: USER_NAME + value: "" + description: User name of GitHub account +- name: GIT_TOKEN + value: "" + description: GitHub token to access GitHub repository. +# parameters for the credentials used in the workflows with default values. +- name: LOCATION + value: "eastus" + description: Location of the resource group +# Optional parameters: +# if you want to use optional parameters, please uncomment the following lines +#- name: ELK_URI +# value: "" +# description: URI (hostname:port) for Elastic server, leave blank if you don't want to integrate ELK. +#- name: ELK_USER_NAME +# value: "" +# description: Account password for Elastic server, leave blank if you don't want to integrate ELK. +#- name: ELK_PSW +# value: "" +# description: Account password for Elastic server, leave blank if you don't want to integrate ELK. diff --git a/.github/resource/pre-check.sh b/.github/resource/pre-check.sh new file mode 100644 index 000000000..deb1e4320 --- /dev/null +++ b/.github/resource/pre-check.sh @@ -0,0 +1,65 @@ +# Check environment and tools required to run the script + +# ANSI color codes +GREEN='\033[0;32m' +NC='\033[0m' # No Color + +## Check if the required tools are installed and logged in +echo -e "${GREEN}To run this script, you need to have the following tools installed:${NC}" +echo -e "${GREEN}1. yq${NC}" +echo -e "${GREEN}2. Github CLI (gh)${NC}" +echo -e "${GREEN}3. Azure CLI (az)${NC}" +echo -e "${GREEN}And you need to be logged in to GitHub CLI (gh), and Azure CLI (az).${NC}" + +echo "Checking if the required tools are installed..." +echo "Checking progress started..." + +if ! command -v yq &> /dev/null; then + echo "Check required tools and environment failed." + echo "yq is not installed. Please install it to proceed." + exit 1 +fi +echo "1/6...yq is installed." + +if ! command -v jq &> /dev/null; then + echo "Check required tools and environment failed." + echo "jq is not installed. Please install it to proceed." + exit 1 +fi +echo "2/6...jq is installed." + +# Check gh installed +if ! command -v gh &> /dev/null; then + echo "Check required tools and environment failed." + echo "GitHub CLI (gh) is not installed. Please install it to proceed." + exit 1 +fi +echo "3/6...GitHub CLI (gh) is installed." + + +# Check if the GitHub CLI (gh) is logged in +if ! gh auth status &> /dev/null; then + echo "Check required tools and environment failed." + echo "You are not logged in to GitHub CLI (gh). Please log in with `gh auth login` to proceed." + exit 1 +fi +echo "4/6...You are logged in to GitHub CLI (gh)." + +# check if az is installed +if ! command -v az &> /dev/null; then + echo "Check required tools and environment failed." + echo "Azure CLI (az) is not installed. Please install it to proceed." + exit 1 +fi +echo "5/6...Azure CLI (az) is installed." + + +# check if az is logged in +if ! az account show &> /dev/null; then + echo "Check required tools and environment failed." + echo "You are not logged in to Azure CLI (az). Please log in with command `az login` to proceed." + exit 1 +fi +echo "6/6...You are logged in to Azure CLI (az)." + +echo "Checking progress completed..." diff --git a/.github/workflows/setup-for-wls-aks.sh b/.github/workflows/setup-for-wls-aks.sh new file mode 100644 index 000000000..50a147246 --- /dev/null +++ b/.github/workflows/setup-for-wls-aks.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +################################################ +# This script is invoked by a human who: +# - has done az login. +# - can create repository secrets in the github repo from which this file was cloned. +# - has the gh client >= 2.0.0 installed. +# - has yq 4.x installed. +# +# This script initializes the repo from which this file is was cloned +# with the necessary secrets to run the workflows. +# Steps to run the Script: +# 1. Run az login. +# 2. Run gh auth login. +# 3. Clone the repository. +# 4. Prepare the .github/resource/credentials-params-wls-aks.yaml file with the required parameters. +# 5. Run the script with the following command: +# ``` +# cd .github/workflows +# bash setup-for-wls-aks.sh +# ``` +# 6. The script will set the required secrets in the repository. +# 7. Check the repository secrets to verify that the secrets are set. +################################################ + +set -Eeuo pipefail + +source ../resource/pre-check.sh +## Set environment variables +export param_file="../resource/credentials-params-wls-aks.yaml" +source ../resource/credentials-params-setup.sh +source ../resource/azure-credential-setup-wls-aks.sh diff --git a/.github/workflows/setup-for-wls-vm.sh b/.github/workflows/setup-for-wls-vm.sh new file mode 100644 index 000000000..1cb3d71eb --- /dev/null +++ b/.github/workflows/setup-for-wls-vm.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +################################################ +# This script is invoked by a human who: +# - has done az login. +# - can create repository secrets in the github repo from which this file was cloned. +# - has the gh client >= 2.0.0 installed. +# - has yq 4.x installed. +# +# This script initializes the repo from which this file is was cloned +# with the necessary secrets to run the workflows. +# Steps to run the Script: +# 1. Run az login. +# 2. Run gh auth login. +# 3. Clone the repository. +# 4. Prepare the .github/resource/credentials-params-wls-vm.yaml file with the required parameters. +# 5. Run the script with the following command: +# ``` +# cd .github/workflows +# bash setup-for-wls-vm.sh +# ``` +# 6. The script will set the required secrets in the repository. +# 7. Check the repository secrets to verify that the secrets are set. +################################################ + +set -Eeuo pipefail + +source ../resource/pre-check.sh +## Set environment variables +export param_file="../resource/credentials-params-wls-vm.yaml" +source ../resource/credentials-params-setup.sh +source ../resource/azure-credential-setup-wls-vm.sh diff --git a/.github/workflows/setupForWlsAks.sh b/.github/workflows/setupForWlsAks.sh deleted file mode 100755 index 8b436a3c5..000000000 --- a/.github/workflows/setupForWlsAks.sh +++ /dev/null @@ -1,194 +0,0 @@ -#!/usr/bin/env bash -################################################ -# This script is invoked by a human who: -# - has done az login. -# - can create repository secrets in the github repo from which this file was cloned. -# - has the gh client >= 2.0.0 installed. -# -# This script initializes the repo from which this file is was cloned -# with the necessary secrets to run the workflows. -# -# Script design taken from https://github.com/microsoft/NubesGen. -# -################################################ - -################################################ -# Set environment variables - the main variables you might want to configure. -# -AKS_REPO_USER_NAME=oracle -DB_PASSWORD="Secret123!" -# Three letters to disambiguate names. -DISAMBIG_PREFIX= -# The location of the resource group. For example `eastus`. Leave blank to use your default location. -LOCATION= -ORC_SSOPSW= -ORC_SSOUSER= -OWNER_REPONAME= -SLEEP_VALUE=30s -WDT_RUNTIMEPSW= -WLS_PSW=${WDT_RUNTIMEPSW} -WLS_USERNAME=weblogic - -# End set environment variables -################################################ - - -set -Eeuo pipefail -trap cleanup SIGINT SIGTERM ERR EXIT - -cleanup() { - trap - SIGINT SIGTERM ERR EXIT - # script cleanup here -} - -setup_colors() { - if [[ -t 2 ]] && [[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]]; then - NOFORMAT='\033[0m' RED='\033[0;31m' GREEN='\033[0;32m' ORANGE='\033[0;33m' BLUE='\033[0;34m' PURPLE='\033[0;35m' CYAN='\033[0;36m' YELLOW='\033[1;33m' - else - NOFORMAT='' RED='' GREEN='' ORANGE='' BLUE='' PURPLE='' CYAN='' YELLOW='' - fi -} - -msg() { - echo >&2 -e "${1-}" -} - -setup_colors - -read -r -p "Enter a disambiguation prefix (try initials with a sequence number, such as ejb01): " DISAMBIG_PREFIX - -if [ "$DISAMBIG_PREFIX" == '' ] ; then - msg "${RED}You must enter a disambiguation prefix." - exit 1; -fi - -# get ORC_SSOUSER if not set at the beginning of this file -if [ "$ORC_SSOUSER" == '' ] ; then - read -r -p "Enter Oracle single sign-on userid: " ORC_SSOUSER -fi - -# get ORC_SSOPSW if not set at the beginning of this file -if [ "$ORC_SSOPSW" == '' ] ; then - read -s -r -p "Enter password for preceding Oracle single sign-on userid: " ORC_SSOPSW -fi - -read -s -r -p "Enter password for WebLogic Server and Runtime Deployment Tooling encryption: " WDT_RUNTIMEPSW -WLS_PSW=${WDT_RUNTIMEPSW} - - -# get OWNER_REPONAME if not set at the beginning of this file -if [ "$OWNER_REPONAME" == '' ] ; then - read -r -p "Enter owner/reponame (blank for upsteam of current fork): " OWNER_REPONAME -fi - -if [ -z "${OWNER_REPONAME}" ] ; then - GH_FLAGS="" -else - GH_FLAGS="--repo ${OWNER_REPONAME}" -fi - -DISAMBIG_PREFIX=${DISAMBIG_PREFIX}`date +%m%d` -SERVICE_PRINCIPAL_NAME=${DISAMBIG_PREFIX}sp - -# get default location if not set at the beginning of this file -if [ "$LOCATION" == '' ] ; then - { - az config get defaults.location --only-show-errors > /dev/null 2>&1 - LOCATION_DEFAULTS_SETUP=$? - } || { - LOCATION_DEFAULTS_SETUP=0 - } - # if no default location is set, fallback to "eastus" - if [ "$LOCATION_DEFAULTS_SETUP" -eq 1 ]; then - LOCATION=eastus - else - LOCATION=$(az config get defaults.location --only-show-errors | jq -r .value) - fi -fi - -# Check AZ CLI status -msg "${GREEN}(1/6) Checking Azure CLI status...${NOFORMAT}" -{ - az > /dev/null -} || { - msg "${RED}Azure CLI is not installed." - msg "${GREEN}Go to https://aka.ms/nubesgen-install-az-cli to install Azure CLI." - exit 1; -} -{ - az account show > /dev/null -} || { - msg "${RED}You are not authenticated with Azure CLI." - msg "${GREEN}Run \"az login\" to authenticate." - exit 1; -} - -msg "${YELLOW}Azure CLI is installed and configured!" - -# Check GitHub CLI status -msg "${GREEN}(2/6) Checking GitHub CLI status...${NOFORMAT}" -USE_GITHUB_CLI=false -{ - gh auth status && USE_GITHUB_CLI=true && msg "${YELLOW}GitHub CLI is installed and configured!" -} || { - msg "${YELLOW}Cannot use the GitHub CLI. ${GREEN}No worries! ${YELLOW}We'll set up the GitHub secrets manually." - USE_GITHUB_CLI=false -} - -# Execute commands -msg "${GREEN}(3/6) Create Azure credentials ${SERVICE_PRINCIPAL_NAME}" -SUBSCRIPTION_ID=$(az account show --query id --output tsv --only-show-errors) - -### AZ ACTION CREATE - -AZURE_CREDENTIALS=$(az ad sp create-for-rbac --name ${SERVICE_PRINCIPAL_NAME} --role="Contributor" --scopes="/subscriptions/${SUBSCRIPTION_ID}" --sdk-auth --only-show-errors) -SP_ID=$( az ad sp list --display-name $SERVICE_PRINCIPAL_NAME --query \[0\].id -o tsv) -az role assignment create --assignee ${SP_ID} --scope="/subscriptions/${SUBSCRIPTION_ID}" --role "User Access Administrator" - -msg "${GREEN}(6/6) Create secrets in GitHub" -if $USE_GITHUB_CLI; then - { - msg "${GREEN}Using the GitHub CLI to set secrets.${NOFORMAT}" - gh ${GH_FLAGS} secret set AKS_REPO_USER_NAME -b"${AKS_REPO_USER_NAME}" - gh ${GH_FLAGS} secret set AZURE_CREDENTIALS -b"${AZURE_CREDENTIALS}" - msg "${YELLOW}\"AZURE_CREDENTIALS\"" - msg "${GREEN}${AZURE_CREDENTIALS}" - gh ${GH_FLAGS} secret set DB_PASSWORD -b"${DB_PASSWORD}" - gh ${GH_FLAGS} secret set ORC_SSOPSW -b"${ORC_SSOPSW}" - gh ${GH_FLAGS} secret set ORC_SSOUSER -b"${ORC_SSOUSER}" - gh ${GH_FLAGS} secret set WDT_RUNTIMEPSW -b"${WDT_RUNTIMEPSW}" - gh ${GH_FLAGS} secret set WLS_PSW -b"${WLS_PSW}" - gh ${GH_FLAGS} secret set WLS_USERNAME -b"${WLS_USERNAME}" - msg "${YELLOW}\"DISAMBIG_PREFIX\"" - msg "${GREEN}${DISAMBIG_PREFIX}" - } || { - USE_GITHUB_CLI=false - } -fi -if [ $USE_GITHUB_CLI == false ]; then - msg "${NOFORMAT}======================MANUAL SETUP======================================" - msg "${GREEN}Using your Web browser to set up secrets..." - msg "${NOFORMAT}Go to the GitHub repository you want to configure." - msg "${NOFORMAT}In the \"settings\", go to the \"secrets\" tab and the following secrets:" - msg "(in ${YELLOW}yellow the secret name and${NOFORMAT} in ${GREEN}green the secret value)" - msg "${YELLOW}\"AKS_REPO_USER_NAME\"" - msg "${GREEN}${AKS_REPO_USER_NAME}" - msg "${YELLOW}\"AZURE_CREDENTIALS\"" - msg "${GREEN}${AZURE_CREDENTIALS}" - msg "${YELLOW}\"DB_PASSWORD\"" - msg "${GREEN}${DB_PASSWORD}" - msg "${YELLOW}\"ORC_SSOPSW\"" - msg "${GREEN}${ORC_SSOPSW}" - msg "${YELLOW}\"ORC_SSOUSER\"" - msg "${GREEN}${ORC_SSOUSER}" - msg "${YELLOW}\"WDT_RUNTIMEPSW\"" - msg "${GREEN}${WDT_RUNTIMEPSW}" - msg "${YELLOW}\"WLS_PSW\"" - msg "${GREEN}${WLS_PSW}" - msg "${YELLOW}\"WLS_USERNAME\"" - msg "${GREEN}${WLS_USERNAME}" - msg "${YELLOW}\"DISAMBIG_PREFIX\"" - msg "${GREEN}${DISAMBIG_PREFIX}" - msg "${NOFORMAT}========================================================================" -fi -msg "${GREEN}Secrets configured" diff --git a/.github/workflows/setupForWlsVm.sh b/.github/workflows/setupForWlsVm.sh deleted file mode 100755 index 0cec4059d..000000000 --- a/.github/workflows/setupForWlsVm.sh +++ /dev/null @@ -1,235 +0,0 @@ -#!/usr/bin/env bash -################################################ -# This script is invoked by a human who: -# - has done az login. -# - can create repository secrets in the github repo from which this file was cloned. -# - has the gh client >= 2.0.0 installed. -# -# This script initializes the repo from which this file is was cloned -# with the necessary secrets to run the workflows. -# -# Script design taken from https://github.com/microsoft/NubesGen. -# -################################################ - -################################################ -# Set environment variables - the main variables you might want to configure. -# -AKS_REPO_USER_NAME=oracle -# Three letters to disambiguate names. -DISAMBIG_PREFIX= -# URI (hostname:port) for Elastic server, leave blank if you don't want to integrate ELK. -ELK_URI= -# Account name for Elastic server, leave blank if you don't want to integrate ELK. -ELK_USER_NAME= -# Account password for Elastic server, leave blank if you don't want to integrate ELK. -ELK_PSW= -# The location of the resource group. For example `eastus`. Leave blank to use your default location. -LOCATION= -# Oracle single sign-on userid. -OTN_USERID= -# Password for preceding Oracle single sign-on userid. -OTN_PASSWORD= -# User Email of GitHub acount to access GitHub repository. -USER_EMAIL= -# User name for preceding GitHub account. -USER_NAME= -# Personal token for preceding GitHub account. -GIT_TOKEN= -WLS_PSW= - -# End set environment variables -################################################ - - -set -Eeuo pipefail -trap cleanup SIGINT SIGTERM ERR EXIT - -cleanup() { - trap - SIGINT SIGTERM ERR EXIT - # script cleanup here -} - -setup_colors() { - if [[ -t 2 ]] && [[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]]; then - NOFORMAT='\033[0m' RED='\033[0;31m' GREEN='\033[0;32m' ORANGE='\033[0;33m' BLUE='\033[0;34m' PURPLE='\033[0;35m' CYAN='\033[0;36m' YELLOW='\033[1;33m' - else - NOFORMAT='' RED='' GREEN='' ORANGE='' BLUE='' PURPLE='' CYAN='' YELLOW='' - fi -} - -msg() { - echo >&2 -e "${1-}" -} - -setup_colors - -read -r -p "Enter a disambiguation prefix (try initials with a sequence number, such as ejb01): " DISAMBIG_PREFIX -read -r -p "Enter owner/reponame (blank for upsteam of current fork): " OWNER_REPONAME - -if [ "$DISAMBIG_PREFIX" == '' ] ; then - msg "${RED}You must enter a disambiguation prefix." - exit 1; -fi - -if [ -z "${OWNER_REPONAME}" ] ; then - GH_FLAGS="" -else - GH_FLAGS="--repo ${OWNER_REPONAME}" -fi - -# get OTN_USERID if not set at the beginning of this file -if [ "$OTN_USERID" == '' ] ; then - read -r -p "Enter Oracle single sign-on userid: " OTN_USERID -fi - -# get OTN_PASSWORD if not set at the beginning of this file -if [ "$OTN_PASSWORD" == '' ] ; then - read -s -r -p "Enter password for preceding Oracle single sign-on userid: " OTN_PASSWORD -fi - -# get USER_EMAIL if not set at the beginning of this file -if [ "$USER_EMAIL" == '' ] ; then - read -r -p "Enter user Email of GitHub acount to access GitHub repository: " USER_EMAIL -fi - -# get USER_NAME if not set at the beginning of this file -if [ "$USER_NAME" == '' ] ; then - read -r -p "Enter user name of GitHub account: " USER_NAME -fi - -# get GIT_TOKEN if not set at the beginning of this file -if [ "$GIT_TOKEN" == '' ] ; then - read -s -r -p "Enter personal token of GitHub account: " GIT_TOKEN -fi - -read -s -r -p "Enter password for WebLogic Server: " WLS_PSW - -# get ELK_URI if not set at the beginning of this file -if [ "$ELK_URI" == '' ] ; then - read -r -p "Enter URI (hostname:port) for Elastic server, leave blank if you don't want to integrate ELK.: " ELK_URI -fi - -# get ELK_USER_NAME if not set at the beginning of this file -if [ "$ELK_USER_NAME" == '' ] ; then - read -r -p "Enter account name for Elastic server, leave blank if you don't want to integrate ELK.: " ELK_USER_NAME -fi - -# get ELK_USER_NAME if not set at the beginning of this file -if [ "$ELK_PSW" == '' ] ; then - read -s -r -p "Enter account password for Elastic server, leave blank if you don't want to integrate ELK.: " ELK_PSW -fi - -DISAMBIG_PREFIX=${DISAMBIG_PREFIX}`date +%m%d` -SERVICE_PRINCIPAL_NAME=${DISAMBIG_PREFIX}sp - -# get default location if not set at the beginning of this file -if [ "$LOCATION" == '' ] ; then - { - az config get defaults.location --only-show-errors > /dev/null 2>&1 - LOCATION_DEFAULTS_SETUP=$? - } || { - LOCATION_DEFAULTS_SETUP=0 - } - # if no default location is set, fallback to "eastus" - if [ "$LOCATION_DEFAULTS_SETUP" -eq 1 ]; then - LOCATION=eastus - else - LOCATION=$(az config get defaults.location --only-show-errors | jq -r .value) - fi -fi - -# Check AZ CLI status -msg "${GREEN}(1/6) Checking Azure CLI status...${NOFORMAT}" -{ - az > /dev/null -} || { - msg "${RED}Azure CLI is not installed." - msg "${GREEN}Go to https://aka.ms/nubesgen-install-az-cli to install Azure CLI." - exit 1; -} -{ - az account show > /dev/null -} || { - msg "${RED}You are not authenticated with Azure CLI." - msg "${GREEN}Run \"az login\" to authenticate." - exit 1; -} - -msg "${YELLOW}Azure CLI is installed and configured!" - -# Check GitHub CLI status -msg "${GREEN}(2/6) Checking GitHub CLI status...${NOFORMAT}" -USE_GITHUB_CLI=false -{ - gh auth status && USE_GITHUB_CLI=true && msg "${YELLOW}GitHub CLI is installed and configured!" -} || { - msg "${YELLOW}Cannot use the GitHub CLI. ${GREEN}No worries! ${YELLOW}We'll set up the GitHub secrets manually." - USE_GITHUB_CLI=false -} - -# Execute commands -msg "${GREEN}(3/6) Create service principal and Azure credentials ${SERVICE_PRINCIPAL_NAME}" -SUBSCRIPTION_ID=$(az account show --query id --output tsv --only-show-errors) - -### AZ ACTION CREATE -# Explicitely disable line wrapping for non MacOS -w0=-w0 -if [[ $OSTYPE == 'darwin'* ]]; then - w0= -fi - -SERVICE_PRINCIPAL=$(az ad sp create-for-rbac --name ${SERVICE_PRINCIPAL_NAME} --role="Contributor" --scopes="/subscriptions/${SUBSCRIPTION_ID}" --sdk-auth --only-show-errors | base64 ${w0}) -AZURE_CREDENTIALS=$(echo $SERVICE_PRINCIPAL | base64 -d) - -msg "${GREEN}(6/6) Create secrets in GitHub" -if $USE_GITHUB_CLI; then - { - msg "${GREEN}Using the GitHub CLI to set secrets.${NOFORMAT}" - gh ${GH_FLAGS} secret set AZURE_CREDENTIALS -b"${AZURE_CREDENTIALS}" - msg "${YELLOW}\"AZURE_CREDENTIALS\"" - msg "${GREEN}${AZURE_CREDENTIALS}" - gh ${GH_FLAGS} secret set ELK_PSW -b"${ELK_PSW}" - gh ${GH_FLAGS} secret set ELK_URI -b"${ELK_URI}" - gh ${GH_FLAGS} secret set ELK_USER_NAME -b"${ELK_USER_NAME}" - gh ${GH_FLAGS} secret set GIT_TOKEN -b"${GIT_TOKEN}" - gh ${GH_FLAGS} secret set OTN_PASSWORD -b"${OTN_PASSWORD}" - gh ${GH_FLAGS} secret set OTN_USERID -b"${OTN_USERID}" - gh ${GH_FLAGS} secret set USER_EMAIL -b"${USER_EMAIL}" - gh ${GH_FLAGS} secret set USER_NAME -b"${USER_NAME}" - gh ${GH_FLAGS} secret set WLS_PSW -b"${WLS_PSW}" - } || { - USE_GITHUB_CLI=false - } -fi -if [ $USE_GITHUB_CLI == false ]; then - msg "${NOFORMAT}======================MANUAL SETUP======================================" - msg "${GREEN}Using your Web browser to set up secrets..." - msg "${NOFORMAT}Go to the GitHub repository you want to configure." - msg "${NOFORMAT}In the \"settings\", go to the \"secrets\" tab and the following secrets:" - msg "(in ${YELLOW}yellow the secret name and${NOFORMAT} in ${GREEN}green the secret value)" - msg "${YELLOW}\"AZURE_CREDENTIALS\"" - msg "${GREEN}${AZURE_CREDENTIALS}" - msg "${YELLOW}\"OTN_USERID\"" - msg "${GREEN}${OTN_USERID}" - msg "${YELLOW}\"OTN_PASSWORD\"" - msg "${GREEN}${OTN_PASSWORD}" - msg "${YELLOW}\"USER_EMAIL\"" - msg "${GREEN}${USER_EMAIL}" - msg "${YELLOW}\"USER_NAME\"" - msg "${GREEN}${USER_NAME}" - msg "${YELLOW}\"GIT_TOKEN\"" - msg "${GREEN}${GIT_TOKEN}" - msg "${YELLOW}\"ELK_URI\"" - msg "${GREEN}${ELK_URI}" - msg "${YELLOW}\"ELK_USER_NAME\"" - msg "${GREEN}${ELK_USER_NAME}" - msg "${YELLOW}\"ELK_PSW\"" - msg "${GREEN}${ELK_PSW}" - msg "${YELLOW}\"WLS_PSW\"" - msg "${GREEN}${WLS_PSW}" - msg "${YELLOW}\"DISAMBIG_PREFIX\"" - msg "${GREEN}${DISAMBIG_PREFIX}" - msg "${NOFORMAT}========================================================================" -fi -msg "${GREEN}Secrets configured" diff --git a/.github/workflows/teardown-for-wls-aks.sh b/.github/workflows/teardown-for-wls-aks.sh new file mode 100644 index 000000000..25fada69b --- /dev/null +++ b/.github/workflows/teardown-for-wls-aks.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +################################################ +# This script is invoked by a human who: +# - can remove repository secrets in the github repo from which this file was cloned. +# - has the gh client >= 2.0.0 installed. +# - has yq 4.x installed. +# +# This script initializes the repo from which this file is was cloned +# with the necessary secrets to run the workflows. +# Steps to run the Script: +# 1. Run gh auth login. +# 2. Clone the repository. +# 3. Run the script with the following command: +# ``` +# cd .github/workflows +# bash teardown-for-wls-aks.sh +# ``` +# 4. The script will remove the required secrets in the repository. +# 5. Check the repository secrets to verify that the secrets are removed. +################################################ + +set -Eeuo pipefail + +source ../resource/pre-check.sh +## Set environment variables +export param_file="../resource/credentials-params-wls-aks.yaml" +source ../resource/credentials-params-teardown.sh +source ../resource/azure-credential-teardown-wls-aks.sh diff --git a/.github/workflows/teardown-for-wls-vm.sh b/.github/workflows/teardown-for-wls-vm.sh new file mode 100644 index 000000000..f05889971 --- /dev/null +++ b/.github/workflows/teardown-for-wls-vm.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +################################################ +# This script is invoked by a human who: +# - can remove repository secrets in the github repo from which this file was cloned. +# - has the gh client >= 2.0.0 installed. +# - has yq 4.x installed. +# +# This script initializes the repo from which this file is was cloned +# with the necessary secrets to run the workflows. +# Steps to run the Script: +# 1. Run gh auth login. +# 2. Clone the repository. +# 3. Run the script with the following command: +# ``` +# cd .github/workflows +# bash teardown-for-wls-vm.sh +# ``` +# 4. The script will remove the required secrets in the repository. +# 5. Check the repository secrets to verify that the secrets are removed. +################################################ + +set -Eeuo pipefail + +source ../resource/pre-check.sh +## Set environment variables +export param_file="../resource/credentials-params-wls-vm.yaml" +source ../resource/credentials-params-teardown.sh +source ../resource/azure-credential-teardown-wls-vm.sh diff --git a/.github/workflows/teardownForWlsAks.sh b/.github/workflows/teardownForWlsAks.sh deleted file mode 100644 index 9c9201e7b..000000000 --- a/.github/workflows/teardownForWlsAks.sh +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/env bash -################################################ -# This script is invoked by a human who: -# - has invoked the setupForWlsAks.sh script -# -# This script removes the secrets and deletes the azure resources created in -# setupForWlsAks.sh. -# -# Script design taken from https://github.com/microsoft/NubesGen. -# -################################################ - - -set -Eeuo pipefail -trap cleanup SIGINT SIGTERM ERR EXIT - -cleanup() { - trap - SIGINT SIGTERM ERR EXIT - # script cleanup here -} - -setup_colors() { - if [[ -t 2 ]] && [[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]]; then - NOFORMAT='\033[0m' RED='\033[0;31m' GREEN='\033[0;32m' ORANGE='\033[0;33m' BLUE='\033[0;34m' PURPLE='\033[0;35m' CYAN='\033[0;36m' YELLOW='\033[1;33m' - else - NOFORMAT='' RED='' GREEN='' ORANGE='' BLUE='' PURPLE='' CYAN='' YELLOW='' - fi -} - -msg() { - echo >&2 -e "${1-}" -} - -setup_colors - -read -r -p "Enter disambiguation prefix: " DISAMBIG_PREFIX -read -r -p "Enter owner/reponame (blank for upsteam of current fork): " OWNER_REPONAME - -if [ -z "${OWNER_REPONAME}" ] ; then - GH_FLAGS="" -else - GH_FLAGS="--repo ${OWNER_REPONAME}" -fi - -SERVICE_PRINCIPAL_NAME=${DISAMBIG_PREFIX}sp -# Execute commands -msg "${GREEN}(1/4) Delete service principal ${SERVICE_PRINCIPAL_NAME}" -SUBSCRIPTION_ID=$(az account show --query id --output tsv --only-show-errors) -SP_OBJECT_ID_ARRAY=$(az ad sp list --display-name ${SERVICE_PRINCIPAL_NAME} --query "[0].id") || true -# remove whitespace -SP_OBJECT_ID_ARRAY=$(echo ${SP_OBJECT_ID_ARRAY} | xargs) || true -SP_OBJECT_ID_ARRAY=${SP_OBJECT_ID_ARRAY//[/} -SP_OBJECT_ID=${SP_OBJECT_ID_ARRAY//]/} -az role assignment delete --yes --assignee ${SP_OBJECT_ID} || true -az ad sp delete --id ${SP_OBJECT_ID} || true - -# Check GitHub CLI status -msg "${GREEN}(3/4) Checking GitHub CLI status...${NOFORMAT}" -USE_GITHUB_CLI=false -{ - gh auth status && USE_GITHUB_CLI=true && msg "${YELLOW}GitHub CLI is installed and configured!" -} || { - msg "${YELLOW}Cannot use the GitHub CLI. ${GREEN}No worries! ${YELLOW}We'll set up the GitHub secrets manually." - USE_GITHUB_CLI=false -} - -msg "${GREEN}(4/4) Removing secrets...${NOFORMAT}" -if $USE_GITHUB_CLI; then - { - msg "${GREEN}Using the GitHub CLI to remove secrets.${NOFORMAT}" - gh ${GH_FLAGS} secret remove AKS_REPO_USER_NAME - gh ${GH_FLAGS} secret remove AZURE_CREDENTIALS - gh ${GH_FLAGS} secret remove DB_PASSWORD - gh ${GH_FLAGS} secret remove ORC_SSOPSW - gh ${GH_FLAGS} secret remove ORC_SSOUSER - gh ${GH_FLAGS} secret remove WDT_RUNTIMEPSW - gh ${GH_FLAGS} secret remove WLS_PSW - gh ${GH_FLAGS} secret remove WLS_USERNAME - } || { - USE_GITHUB_CLI=false - } -fi -if [ $USE_GITHUB_CLI == false ]; then - msg "${NOFORMAT}======================MANUAL REMOVAL======================================" - msg "${GREEN}Using your Web browser to remove secrets..." - msg "${NOFORMAT}Go to the GitHub repository you want to configure." - msg "${NOFORMAT}In the \"settings\", go to the \"secrets\" tab and remove the following secrets:" - msg "(in ${YELLOW}yellow the secret name)" - msg "${YELLOW}\"AKS_REPO_USER_NAME\"" - msg "${YELLOW}\"AZURE_CREDENTIALS\"" - msg "${YELLOW}\"DB_PASSWORD\"" - msg "${YELLOW}\"ORC_SSOPSW\"" - msg "${YELLOW}\"ORC_SSOUSER\"" - msg "${YELLOW}\"WDT_RUNTIMEPSW\"" - msg "${YELLOW}\"WLS_PSW\"" - msg "${YELLOW}\"WLS_USERNAME\"" - msg "${NOFORMAT}========================================================================" -fi -msg "${GREEN}Secrets removed" diff --git a/.github/workflows/teardownForWlsVm.sh b/.github/workflows/teardownForWlsVm.sh deleted file mode 100644 index 6226c1010..000000000 --- a/.github/workflows/teardownForWlsVm.sh +++ /dev/null @@ -1,103 +0,0 @@ -#!/usr/bin/env bash -################################################ -# This script is invoked by a human who: -# - has invoked the setupForWlsAks.sh script -# -# This script removes the secrets and deletes the azure resources created in -# setupForWlsAks.sh. -# -# Script design taken from https://github.com/microsoft/NubesGen. -# -################################################ - - -set -Eeuo pipefail -trap cleanup SIGINT SIGTERM ERR EXIT - -cleanup() { - trap - SIGINT SIGTERM ERR EXIT - # script cleanup here -} - -setup_colors() { - if [[ -t 2 ]] && [[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]]; then - NOFORMAT='\033[0m' RED='\033[0;31m' GREEN='\033[0;32m' ORANGE='\033[0;33m' BLUE='\033[0;34m' PURPLE='\033[0;35m' CYAN='\033[0;36m' YELLOW='\033[1;33m' - else - NOFORMAT='' RED='' GREEN='' ORANGE='' BLUE='' PURPLE='' CYAN='' YELLOW='' - fi -} - -msg() { - echo >&2 -e "${1-}" -} - -setup_colors - -read -r -p "Enter disambiguation prefix: " DISAMBIG_PREFIX -read -r -p "Enter owner/reponame (blank for upsteam of current fork): " OWNER_REPONAME - -if [ -z "${OWNER_REPONAME}" ] ; then - GH_FLAGS="" -else - GH_FLAGS="--repo ${OWNER_REPONAME}" -fi - -SERVICE_PRINCIPAL_NAME=${DISAMBIG_PREFIX}sp - -# Execute commands -msg "${GREEN}(1/4) Delete service principal ${SERVICE_PRINCIPAL_NAME}" -SUBSCRIPTION_ID=$(az account show --query id --output tsv --only-show-errors) -SP_OBJECT_ID_ARRAY=$(az ad sp list --display-name ${SERVICE_PRINCIPAL_NAME} --query "[].objectId") || true -# remove whitespace -SP_OBJECT_ID_ARRAY=$(echo ${SP_OBJECT_ID_ARRAY} | xargs) || true -SP_OBJECT_ID_ARRAY=${SP_OBJECT_ID_ARRAY//[/} -SP_OBJECT_ID=${SP_OBJECT_ID_ARRAY//]/} -az ad sp delete --id ${SP_OBJECT_ID} || true - -# Check GitHub CLI status -msg "${GREEN}(3/4) Checking GitHub CLI status...${NOFORMAT}" -USE_GITHUB_CLI=false -{ - gh auth status && USE_GITHUB_CLI=true && msg "${YELLOW}GitHub CLI is installed and configured!" -} || { - msg "${YELLOW}Cannot use the GitHub CLI. ${GREEN}No worries! ${YELLOW}We'll set up the GitHub secrets manually." - USE_GITHUB_CLI=false -} - -msg "${GREEN}(4/4) Removing secrets...${NOFORMAT}" -if $USE_GITHUB_CLI; then - { - msg "${GREEN}Using the GitHub CLI to remove secrets.${NOFORMAT}" - gh ${GH_FLAGS} secret remove AZURE_CREDENTIALS - gh ${GH_FLAGS} secret remove ELK_PSW - gh ${GH_FLAGS} secret remove ELK_URI - gh ${GH_FLAGS} secret remove ELK_USER_NAME - gh ${GH_FLAGS} secret remove GIT_TOKEN - gh ${GH_FLAGS} secret remove OTN_PASSWORD - gh ${GH_FLAGS} secret remove OTN_USERID - gh ${GH_FLAGS} secret remove USER_EMAIL - gh ${GH_FLAGS} secret remove USER_NAME - gh ${GH_FLAGS} secret remove WLS_PSW - } || { - USE_GITHUB_CLI=false - } -fi -if [ $USE_GITHUB_CLI == false ]; then - msg "${NOFORMAT}======================MANUAL REMOVAL======================================" - msg "${GREEN}Using your Web browser to remove secrets..." - msg "${NOFORMAT}Go to the GitHub repository you want to configure." - msg "${NOFORMAT}In the \"settings\", go to the \"secrets\" tab and remove the following secrets:" - msg "(in ${YELLOW}yellow the secret name)" - msg "${YELLOW}\"AZURE_CREDENTIALS\"" - msg "${YELLOW}\"ELK_PSW\"" - msg "${YELLOW}\"ELK_URI\"" - msg "${YELLOW}\"ELK_USER_NAME\"" - msg "${YELLOW}\"GIT_TOKEN\"" - msg "${YELLOW}\"OTN_PASSWORD\"" - msg "${YELLOW}\"OTN_USERID\"" - msg "${YELLOW}\"USER_EMAIL\"" - msg "${YELLOW}\"USER_NAME\"" - msg "${YELLOW}\"WLS_PSW\"" - msg "${NOFORMAT}========================================================================" -fi -msg "${GREEN}Secrets removed"