From af638b5c5db9ab9de51125323fa863f1e99cab8d Mon Sep 17 00:00:00 2001 From: Andre Fernandes Date: Mon, 30 Aug 2021 09:39:47 -0300 Subject: [PATCH 01/32] small fixes to vkpr init (curl instead of git) --- LEIAME.md | 22 +++++++++++++++++++ vkpr/init/src/unix/formula/formula.sh | 31 +++++++++++++++++++++------ 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/LEIAME.md b/LEIAME.md index 958e5a90..d25eea59 100644 --- a/LEIAME.md +++ b/LEIAME.md @@ -13,3 +13,25 @@ When cloning this repo please add its folder as a workspace: ``` rit add workspace --name vkpr-formulas --path $(pwd) ``` + +Ritchie must be installed: + +``` +curl -fsSL https://commons-repo.ritchiecli.io/install.sh | bash +``` + +## Using containers + +You can use temporary containers to test your formulas in a clean environment: + +``` +docker run --rm -ti -v $(pwd):/opt centos +``` + +Install Ritchie in it and configure the workspace: + +``` +curl -fsSL https://commons-repo.ritchiecli.io/install.sh | sed -e 's/sudo//g' | bash +rit set formula-runner --runner=local +rit add workspace --name vkpr-formulas --path /opt +``` diff --git a/vkpr/init/src/unix/formula/formula.sh b/vkpr/init/src/unix/formula/formula.sh index 17d37ea0..a07c2704 100755 --- a/vkpr/init/src/unix/formula/formula.sh +++ b/vkpr/init/src/unix/formula/formula.sh @@ -32,8 +32,10 @@ runFormula() { installTool "jq" installTool "yq" installTool "k9s" - installGlobals + + installGlobals installBats + # if [ "$RIT_INPUT_BOOLEAN" = "true" ]; then # echoColor "blue" "I've already created formulas using Ritchie." # else @@ -76,17 +78,32 @@ installGlobals() { installBats(){ if [[ -f "$VKPR_HOME/bats/bin/bats" ]]; then - echoColor "yellow" "Tool $toolName already installed. Skipping." + echoColor "yellow" "Bats already installed. Skipping." else - echoColor "green" "intalling bats..." + echoColor "green" "intalling Bats..." mkdir -p /tmp/bats - git clone https://github.com/bats-core/bats-core.git /tmp/bats-core + # bats-core + curl -sL -o /tmp/bats-core.tar.gz https://github.com/bats-core/bats-core/archive/refs/tags/v1.4.1.tar.gz + tar -xzf /tmp/bats-core.tar.gz -C /tmp + mv /tmp/bats-core-1.4.1 /tmp/bats-core /tmp/bats-core/install.sh $VKPR_HOME/bats rm -r --force /tmp/bats-core + echoColor "green" "intalling bats add-ons..." - git clone https://github.com/bats-core/bats-support $VKPR_HOME/bats/bats-support - git clone https://github.com/bats-core/bats-assert $VKPR_HOME/bats/bats-assert - git clone https://github.com/bats-core/bats-file $VKPR_HOME/bats/bats-file + # bats-support + #git clone https://github.com/bats-core/bats-support $VKPR_HOME/bats/bats-support + curl -sL -o /tmp/bats-support.tar.gz https://github.com/bats-core/bats-support/archive/refs/tags/v0.3.0.tar.gz + tar -xzf /tmp/bats-support.tar.gz -C /tmp + mv /tmp/bats-support-0.3.0 $VKPR_HOME/bats/bats-support + # bats-assert + curl -sL -o /tmp/bats-assert.tar.gz https://github.com/bats-core/bats-assert/archive/refs/tags/v2.0.0.tar.gz + tar -xzf /tmp/bats-assert.tar.gz -C /tmp + mv /tmp/bats-assert-2.0.0 $VKPR_HOME/bats/bats-assert + # bats-file + curl -sL -o /tmp/bats-file.tar.gz https://github.com/bats-core/bats-file/archive/refs/tags/v0.3.0.tar.gz + tar -xzf /tmp/bats-file.tar.gz -C /tmp + mv /tmp/bats-file-0.3.0 $VKPR_HOME/bats/bats-file + echo "Bats add-ons installed" fi } From 32f9d96dafb8d28dc59cdddc8eb68f241dc156c7 Mon Sep 17 00:00:00 2001 From: HumbertoPeluso Date: Wed, 1 Sep 2021 15:05:22 -0300 Subject: [PATCH 02/32] whoami values precedence example --- .../install/src/unix/formula/formula.sh | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/vkpr/whoami/install/src/unix/formula/formula.sh b/vkpr/whoami/install/src/unix/formula/formula.sh index d5ac3c3f..9641e9f1 100755 --- a/vkpr/whoami/install/src/unix/formula/formula.sh +++ b/vkpr/whoami/install/src/unix/formula/formula.sh @@ -3,7 +3,7 @@ runFormula() { VKPR_WHOAMI_VALUES=$(dirname "$0")/utils/whoami.yaml - verifyExistingEnv 'SECURE' "${SECURE}" 'DOMAIN' "${DOMAIN}" + checkGlobalConfig $DOMAIN "whoami.localhost" "domain" addRepoWhoami installWhoami } @@ -17,4 +17,22 @@ installWhoami(){ echoColor "yellow" "Installing whoami..." $VKPR_YQ eval '.ingress.hosts[0].host = "'$VKPR_ENV_DOMAIN'" | .ingress.tls[0].hosts[0] = "'$VKPR_ENV_DOMAIN'"' "$VKPR_WHOAMI_VALUES" \ | $VKPR_HELM upgrade -i -f - whoami cowboysysop/whoami +} + +#$1=global variable; $2=default value of the global variable; $3=label from config file +checkGlobalConfig(){ + CONFIG_FILE=$VKPR_GLOBALS/global-config.yaml + file_label='.global.'$3 + if [ -f "$CONFIG_FILE" ] && [ $1 == $2 ] && [ $($VKPR_YQ eval $file_label $CONFIG_FILE) != "null" ]; then + echoColor "yellow" "Setting value from config file" + VKPR_ENV_DOMAIN=$($VKPR_YQ eval $file_label $CONFIG_FILE) + else + if [ $1 == $2 ]; then + echoColor "yellow" "Setting value from default value" + VKPR_ENV_DOMAIN=$1 + else + echoColor "yellow" "Setting value from user input" + VKPR_ENV_DOMAIN=$1 + fi + fi } \ No newline at end of file From ff9af7f38e427d7a66d9a84b726f9ff32b617e62 Mon Sep 17 00:00:00 2001 From: Jpeedroza Date: Thu, 2 Sep 2021 13:07:08 -0300 Subject: [PATCH 03/32] Created aws eks deploy formula --- vkpr/aws/eks/deploy/README.md | 13 +++++++ vkpr/aws/eks/deploy/build.sh | 11 ++++++ vkpr/aws/eks/deploy/config.json | 15 ++++++++ vkpr/aws/eks/deploy/metadata.json | 18 ++++++++++ vkpr/aws/eks/deploy/src/main.sh | 6 ++++ .../eks/deploy/src/unix/formula/formula.sh | 8 +++++ vkpr/aws/eks/destroy/README.md | 13 +++++++ vkpr/aws/eks/destroy/build.sh | 11 ++++++ vkpr/aws/eks/destroy/config.json | 15 ++++++++ vkpr/aws/eks/destroy/metadata.json | 18 ++++++++++ vkpr/aws/eks/destroy/src/main.sh | 6 ++++ .../eks/destroy/src/unix/formula/formula.sh | 8 +++++ vkpr/aws/eks/up/README.md | 13 +++++++ vkpr/aws/eks/up/build.sh | 11 ++++++ vkpr/aws/eks/up/config.json | 34 +++++++++++++++++++ vkpr/aws/eks/up/metadata.json | 18 ++++++++++ vkpr/aws/eks/up/src/main.sh | 17 ++++++++++ vkpr/aws/eks/up/src/unix/formula/formula.sh | 10 ++++++ 18 files changed, 245 insertions(+) create mode 100755 vkpr/aws/eks/deploy/README.md create mode 100755 vkpr/aws/eks/deploy/build.sh create mode 100755 vkpr/aws/eks/deploy/config.json create mode 100755 vkpr/aws/eks/deploy/metadata.json create mode 100755 vkpr/aws/eks/deploy/src/main.sh create mode 100755 vkpr/aws/eks/deploy/src/unix/formula/formula.sh create mode 100755 vkpr/aws/eks/destroy/README.md create mode 100755 vkpr/aws/eks/destroy/build.sh create mode 100755 vkpr/aws/eks/destroy/config.json create mode 100755 vkpr/aws/eks/destroy/metadata.json create mode 100755 vkpr/aws/eks/destroy/src/main.sh create mode 100755 vkpr/aws/eks/destroy/src/unix/formula/formula.sh create mode 100755 vkpr/aws/eks/up/README.md create mode 100755 vkpr/aws/eks/up/build.sh create mode 100755 vkpr/aws/eks/up/config.json create mode 100755 vkpr/aws/eks/up/metadata.json create mode 100755 vkpr/aws/eks/up/src/main.sh create mode 100755 vkpr/aws/eks/up/src/unix/formula/formula.sh diff --git a/vkpr/aws/eks/deploy/README.md b/vkpr/aws/eks/deploy/README.md new file mode 100755 index 00000000..79368789 --- /dev/null +++ b/vkpr/aws/eks/deploy/README.md @@ -0,0 +1,13 @@ +# Description + +Formula description + +## Command + +```bash +rit vkpr aws eks deploy +``` + +## Requirements + +## Demonstration diff --git a/vkpr/aws/eks/deploy/build.sh b/vkpr/aws/eks/deploy/build.sh new file mode 100755 index 00000000..3f067481 --- /dev/null +++ b/vkpr/aws/eks/deploy/build.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +BIN_FOLDER=bin +BINARY_NAME_UNIX=run.sh +ENTRY_POINT_UNIX=main.sh + +#bash-build: + mkdir -p $BIN_FOLDER + cp -r src/* $BIN_FOLDER + mv $BIN_FOLDER/$ENTRY_POINT_UNIX $BIN_FOLDER/$BINARY_NAME_UNIX + chmod +x $BIN_FOLDER/$BINARY_NAME_UNIX diff --git a/vkpr/aws/eks/deploy/config.json b/vkpr/aws/eks/deploy/config.json new file mode 100755 index 00000000..cfde09aa --- /dev/null +++ b/vkpr/aws/eks/deploy/config.json @@ -0,0 +1,15 @@ +{ + "dockerImageBuilder": "ritclizup/rit-shell-bat-builder", + "inputs": [ + { + "name": "gitlab_token", + "type": "CREDENTIAL_GITLAB_TOKEN" + }, + { + "name": "gitlab_username", + "type": "CREDENTIAL_GITLAB_USERNAME" + } + ], + "template": "shell-bat", + "templateRelease:": "2.16.2" +} \ No newline at end of file diff --git a/vkpr/aws/eks/deploy/metadata.json b/vkpr/aws/eks/deploy/metadata.json new file mode 100755 index 00000000..81ad3a2e --- /dev/null +++ b/vkpr/aws/eks/deploy/metadata.json @@ -0,0 +1,18 @@ +{ + "execution": [ + "local" + ], + "os": { + "deps": [], + "support": [ + "mac", + "linux" + ] + }, + "tags": [ + "vkpr", + "aws", + "eks", + "deploy" + ] +} diff --git a/vkpr/aws/eks/deploy/src/main.sh b/vkpr/aws/eks/deploy/src/main.sh new file mode 100755 index 00000000..736f5ce4 --- /dev/null +++ b/vkpr/aws/eks/deploy/src/main.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# shellcheck source=/dev/null +. "$(dirname "$0")"/unix/formula/formula.sh --source-only + +runFormula diff --git a/vkpr/aws/eks/deploy/src/unix/formula/formula.sh b/vkpr/aws/eks/deploy/src/unix/formula/formula.sh new file mode 100755 index 00000000..f1eccf1f --- /dev/null +++ b/vkpr/aws/eks/deploy/src/unix/formula/formula.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +runFormula() { + PROJECT_ID=$(curl https://gitlab.com/api/v4/users/$GITLAB_USERNAME/projects | jq '.[0] | .id') + PIPELINE_ID=$(curl https://gitlab.com/api/v4/projects/$PROJECT_ID/pipelines | jq '.[0] | .id') + DEPLOY_ID=$(curl -H "PRIVATE-TOKEN: $GITLAB_TOKEN" https://gitlab.com/api/v4/projects/$PROJECT_ID/jobs | jq '.[1] | .id') + curl -H "PRIVATE-TOKEN: $GITLAB_TOKEN" -X POST -s https://gitlab.com/api/v4/projects/$PROJECT_ID/jobs/$DEPLOY_ID/play > /dev/null +} \ No newline at end of file diff --git a/vkpr/aws/eks/destroy/README.md b/vkpr/aws/eks/destroy/README.md new file mode 100755 index 00000000..e7074f83 --- /dev/null +++ b/vkpr/aws/eks/destroy/README.md @@ -0,0 +1,13 @@ +# Description + +Formula description + +## Command + +```bash +rit vkpr aws eks destroy +``` + +## Requirements + +## Demonstration diff --git a/vkpr/aws/eks/destroy/build.sh b/vkpr/aws/eks/destroy/build.sh new file mode 100755 index 00000000..3f067481 --- /dev/null +++ b/vkpr/aws/eks/destroy/build.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +BIN_FOLDER=bin +BINARY_NAME_UNIX=run.sh +ENTRY_POINT_UNIX=main.sh + +#bash-build: + mkdir -p $BIN_FOLDER + cp -r src/* $BIN_FOLDER + mv $BIN_FOLDER/$ENTRY_POINT_UNIX $BIN_FOLDER/$BINARY_NAME_UNIX + chmod +x $BIN_FOLDER/$BINARY_NAME_UNIX diff --git a/vkpr/aws/eks/destroy/config.json b/vkpr/aws/eks/destroy/config.json new file mode 100755 index 00000000..cfde09aa --- /dev/null +++ b/vkpr/aws/eks/destroy/config.json @@ -0,0 +1,15 @@ +{ + "dockerImageBuilder": "ritclizup/rit-shell-bat-builder", + "inputs": [ + { + "name": "gitlab_token", + "type": "CREDENTIAL_GITLAB_TOKEN" + }, + { + "name": "gitlab_username", + "type": "CREDENTIAL_GITLAB_USERNAME" + } + ], + "template": "shell-bat", + "templateRelease:": "2.16.2" +} \ No newline at end of file diff --git a/vkpr/aws/eks/destroy/metadata.json b/vkpr/aws/eks/destroy/metadata.json new file mode 100755 index 00000000..b60a6c06 --- /dev/null +++ b/vkpr/aws/eks/destroy/metadata.json @@ -0,0 +1,18 @@ +{ + "execution": [ + "local" + ], + "os": { + "deps": [], + "support": [ + "mac", + "linux" + ] + }, + "tags": [ + "vkpr", + "aws", + "eks", + "destroy" + ] +} diff --git a/vkpr/aws/eks/destroy/src/main.sh b/vkpr/aws/eks/destroy/src/main.sh new file mode 100755 index 00000000..736f5ce4 --- /dev/null +++ b/vkpr/aws/eks/destroy/src/main.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# shellcheck source=/dev/null +. "$(dirname "$0")"/unix/formula/formula.sh --source-only + +runFormula diff --git a/vkpr/aws/eks/destroy/src/unix/formula/formula.sh b/vkpr/aws/eks/destroy/src/unix/formula/formula.sh new file mode 100755 index 00000000..b7e60474 --- /dev/null +++ b/vkpr/aws/eks/destroy/src/unix/formula/formula.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +runFormula() { + PROJECT_ID=$(curl https://gitlab.com/api/v4/users/$GITLAB_USERNAME/projects | jq '.[0] | .id') + PIPELINE_ID=$(curl https://gitlab.com/api/v4/projects/$PROJECT_ID/pipelines | jq '.[0] | .id') + DESTROY_ID=$(curl -H "PRIVATE-TOKEN: $GITLAB_TOKEN" https://gitlab.com/api/v4/projects/$PROJECT_ID/jobs | jq '.[0] | .id') + curl -H "PRIVATE-TOKEN: $GITLAB_TOKEN" -X POST -s https://gitlab.com/api/v4/projects/$PROJECT_ID/jobs/$DESTROY_ID/play > /dev/null +} \ No newline at end of file diff --git a/vkpr/aws/eks/up/README.md b/vkpr/aws/eks/up/README.md new file mode 100755 index 00000000..b77f7784 --- /dev/null +++ b/vkpr/aws/eks/up/README.md @@ -0,0 +1,13 @@ +# Description + +Formula description + +## Command + +```bash +rit vkpr aws eks up +``` + +## Requirements + +## Demonstration diff --git a/vkpr/aws/eks/up/build.sh b/vkpr/aws/eks/up/build.sh new file mode 100755 index 00000000..3f067481 --- /dev/null +++ b/vkpr/aws/eks/up/build.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +BIN_FOLDER=bin +BINARY_NAME_UNIX=run.sh +ENTRY_POINT_UNIX=main.sh + +#bash-build: + mkdir -p $BIN_FOLDER + cp -r src/* $BIN_FOLDER + mv $BIN_FOLDER/$ENTRY_POINT_UNIX $BIN_FOLDER/$BINARY_NAME_UNIX + chmod +x $BIN_FOLDER/$BINARY_NAME_UNIX diff --git a/vkpr/aws/eks/up/config.json b/vkpr/aws/eks/up/config.json new file mode 100755 index 00000000..df9345a5 --- /dev/null +++ b/vkpr/aws/eks/up/config.json @@ -0,0 +1,34 @@ +{ + "dockerImageBuilder": "ritclizup/rit-shell-bat-builder", + "inputs": [ + { + "name": "aws_access_key", + "type": "CREDENTIAL_AWS_ACCESSKEYID" + }, + { + "name": "aws_secret_key", + "type": "CREDENTIAL_AWS_SECRETACCESSKEY" + }, + { + "name": "aws_region", + "label": "Type your aws region: ", + "type": "text", + "default": "us-east-1", + "cache": { + "active": true, + "qty": 2, + "newLabel": "Type another region: " + } + }, + { + "name": "gitlab_token", + "type": "CREDENTIAL_GITLAB_TOKEN" + }, + { + "name": "gitlab_username", + "type": "CREDENTIAL_GITLAB_USERNAME" + } + ], + "template": "shell-bat", + "templateRelease:": "2.16.2" +} \ No newline at end of file diff --git a/vkpr/aws/eks/up/metadata.json b/vkpr/aws/eks/up/metadata.json new file mode 100755 index 00000000..b9615a24 --- /dev/null +++ b/vkpr/aws/eks/up/metadata.json @@ -0,0 +1,18 @@ +{ + "execution": [ + "local" + ], + "os": { + "deps": [], + "support": [ + "mac", + "linux" + ] + }, + "tags": [ + "vkpr", + "aws", + "eks", + "up" + ] +} diff --git a/vkpr/aws/eks/up/src/main.sh b/vkpr/aws/eks/up/src/main.sh new file mode 100755 index 00000000..9697102d --- /dev/null +++ b/vkpr/aws/eks/up/src/main.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +if [ ! -d ~/.vkpr/global ]; then + echo "Doesn't initializated the vkpr... Call again the function" + rit vkpr init + exit; +fi + +source ~/.vkpr/global/log.sh +source ~/.vkpr/global/var.sh +source ~/.vkpr/global/helper.sh +source ~/.vkpr/global/.env + +# shellcheck source=/dev/null +. "$(dirname "$0")"/unix/formula/formula.sh --source-only + +runFormula diff --git a/vkpr/aws/eks/up/src/unix/formula/formula.sh b/vkpr/aws/eks/up/src/unix/formula/formula.sh new file mode 100755 index 00000000..f4a6a388 --- /dev/null +++ b/vkpr/aws/eks/up/src/unix/formula/formula.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +runFormula() { + $VKPR_GLAB auth login -h "gitlab.com" -t "$GITLAB_TOKEN" + $VKPR_GLAB repo fork vkpr/aws-eks + $VKPR_GLAB variable set "AWS_ACCESS_KEY" -m -v "$AWS_ACCESS_KEY" -R $GITLAB_USERNAME/aws-eks + $VKPR_GLAB variable set "AWS_SECRET_KEY" -m -v "$AWS_SECRET_KEY" -R $GITLAB_USERNAME/aws-eks + $VKPR_GLAB variable set "AWS_REGION" -m -v "$AWS_REGION" -R $GITLAB_USERNAME/aws-eks + $VKPR_GLAB ci run -R $GITLAB_USERNAME/aws-eks +} From 0feb1b90ae768527ef50c2d25c824ced2ae2f0e1 Mon Sep 17 00:00:00 2001 From: Jpeedroza Date: Thu, 2 Sep 2021 13:22:46 -0300 Subject: [PATCH 04/32] Deleted unused variable --- vkpr/aws/eks/deploy/src/unix/formula/formula.sh | 1 - vkpr/aws/eks/destroy/src/unix/formula/formula.sh | 1 - 2 files changed, 2 deletions(-) diff --git a/vkpr/aws/eks/deploy/src/unix/formula/formula.sh b/vkpr/aws/eks/deploy/src/unix/formula/formula.sh index f1eccf1f..e826e265 100755 --- a/vkpr/aws/eks/deploy/src/unix/formula/formula.sh +++ b/vkpr/aws/eks/deploy/src/unix/formula/formula.sh @@ -2,7 +2,6 @@ runFormula() { PROJECT_ID=$(curl https://gitlab.com/api/v4/users/$GITLAB_USERNAME/projects | jq '.[0] | .id') - PIPELINE_ID=$(curl https://gitlab.com/api/v4/projects/$PROJECT_ID/pipelines | jq '.[0] | .id') DEPLOY_ID=$(curl -H "PRIVATE-TOKEN: $GITLAB_TOKEN" https://gitlab.com/api/v4/projects/$PROJECT_ID/jobs | jq '.[1] | .id') curl -H "PRIVATE-TOKEN: $GITLAB_TOKEN" -X POST -s https://gitlab.com/api/v4/projects/$PROJECT_ID/jobs/$DEPLOY_ID/play > /dev/null } \ No newline at end of file diff --git a/vkpr/aws/eks/destroy/src/unix/formula/formula.sh b/vkpr/aws/eks/destroy/src/unix/formula/formula.sh index b7e60474..f6404f91 100755 --- a/vkpr/aws/eks/destroy/src/unix/formula/formula.sh +++ b/vkpr/aws/eks/destroy/src/unix/formula/formula.sh @@ -2,7 +2,6 @@ runFormula() { PROJECT_ID=$(curl https://gitlab.com/api/v4/users/$GITLAB_USERNAME/projects | jq '.[0] | .id') - PIPELINE_ID=$(curl https://gitlab.com/api/v4/projects/$PROJECT_ID/pipelines | jq '.[0] | .id') DESTROY_ID=$(curl -H "PRIVATE-TOKEN: $GITLAB_TOKEN" https://gitlab.com/api/v4/projects/$PROJECT_ID/jobs | jq '.[0] | .id') curl -H "PRIVATE-TOKEN: $GITLAB_TOKEN" -X POST -s https://gitlab.com/api/v4/projects/$PROJECT_ID/jobs/$DESTROY_ID/play > /dev/null } \ No newline at end of file From 1fe36abbfb862b7c329359d4009705fe4532647c Mon Sep 17 00:00:00 2001 From: Jpeedroza Date: Fri, 3 Sep 2021 09:33:01 -0300 Subject: [PATCH 05/32] Created an interval to check if the build was concluded --- vkpr/aws/eks/deploy/src/main.sh | 11 +++++++++++ vkpr/aws/eks/deploy/src/unix/formula/formula.sh | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/vkpr/aws/eks/deploy/src/main.sh b/vkpr/aws/eks/deploy/src/main.sh index 736f5ce4..24e26cf6 100755 --- a/vkpr/aws/eks/deploy/src/main.sh +++ b/vkpr/aws/eks/deploy/src/main.sh @@ -1,5 +1,16 @@ #!/bin/bash +if [ ! -d ~/.vkpr/global ]; then + echo "Doesn't initializated the vkpr... Call again the function" + rit vkpr init + exit; +fi + +source ~/.vkpr/global/log.sh +source ~/.vkpr/global/var.sh +source ~/.vkpr/global/.env +source ~/.vkpr/global/helper.sh + # shellcheck source=/dev/null . "$(dirname "$0")"/unix/formula/formula.sh --source-only diff --git a/vkpr/aws/eks/deploy/src/unix/formula/formula.sh b/vkpr/aws/eks/deploy/src/unix/formula/formula.sh index e826e265..01dadc0b 100755 --- a/vkpr/aws/eks/deploy/src/unix/formula/formula.sh +++ b/vkpr/aws/eks/deploy/src/unix/formula/formula.sh @@ -2,6 +2,14 @@ runFormula() { PROJECT_ID=$(curl https://gitlab.com/api/v4/users/$GITLAB_USERNAME/projects | jq '.[0] | .id') + BUILD_COMPLETE=$(curl -H "PRIVATE-TOKEN: $GITLAB_TOKEN" https://gitlab.com/api/v4/projects/$PROJECT_ID/jobs | jq '.[2] | .status') + SECONDS=0 + while [[ $BUILD_COMPLETE != '"success"' ]]; do + echoColor "yellow" "Pipeline still executing, await more... ${SECONDS}s passed" + sleep 30 + let "SECONDS+30" + BUILD_COMPLETE=$(curl -H "PRIVATE-TOKEN: $GITLAB_TOKEN" https://gitlab.com/api/v4/projects/$PROJECT_ID/jobs | jq '.[2] | .status') + done DEPLOY_ID=$(curl -H "PRIVATE-TOKEN: $GITLAB_TOKEN" https://gitlab.com/api/v4/projects/$PROJECT_ID/jobs | jq '.[1] | .id') curl -H "PRIVATE-TOKEN: $GITLAB_TOKEN" -X POST -s https://gitlab.com/api/v4/projects/$PROJECT_ID/jobs/$DEPLOY_ID/play > /dev/null } \ No newline at end of file From 95a241d285fa3ce9f2deb6f02214c57e6e337737 Mon Sep 17 00:00:00 2001 From: Jpeedroza Date: Fri, 3 Sep 2021 09:43:35 -0300 Subject: [PATCH 06/32] Install glab script in vkpr init --- vkpr/init/src/unix/formula/formula.sh | 12 ++++++++++++ vkpr/init/src/utils/var.sh | 1 + 2 files changed, 13 insertions(+) diff --git a/vkpr/init/src/unix/formula/formula.sh b/vkpr/init/src/unix/formula/formula.sh index 17d37ea0..d15c9d58 100755 --- a/vkpr/init/src/unix/formula/formula.sh +++ b/vkpr/init/src/unix/formula/formula.sh @@ -26,6 +26,7 @@ runFormula() { mkdir -p $VKPR_HOME/bats installArkade + installGlab installTool "kubectl" installTool "helm" installTool "k3d" @@ -69,6 +70,17 @@ installArkade() { fi } +installGlab() { + if [[ -f "$VKPR_HOME/bin/glab" ]]; then + echoColor "yellow" "Glab already installed. Skipping." + else + echoColor "green" "Installing Glab..." + curl -sLS https://j.mp/glab-cli > /tmp/glab.sh + chmod +x /tmp/glab.sh + /tmp/glab.sh $VKPR_HOME/bin + fi +} + installGlobals() { mkdir -p $VKPR_GLOBALS createPackagesFiles diff --git a/vkpr/init/src/utils/var.sh b/vkpr/init/src/utils/var.sh index 1198661c..6a716d23 100644 --- a/vkpr/init/src/utils/var.sh +++ b/vkpr/init/src/utils/var.sh @@ -3,6 +3,7 @@ VKPR_HOME=~/.vkpr VKPR_GLOBALS=$VKPR_HOME/global +VKPR_GLAB=$VKPR_HOME/bin/glab VKPR_K3D=$VKPR_HOME/bin/k3d VKPR_ARKADE=$VKPR_HOME/bin/arkade VKPR_KUBECTL=$VKPR_HOME/bin/kubectl From e0bab53c425864d1769148c8a0851be43e655aa5 Mon Sep 17 00:00:00 2001 From: Andre Fernandes Date: Wed, 8 Sep 2021 12:26:50 -0300 Subject: [PATCH 07/32] VKPR-136 #comment external-dns tests and fixes --- vkpr-test/TESTS.md | 60 +++++++++ vkpr-test/common-setup.bash | 11 ++ vkpr-test/dnslog.j2 | 6 + vkpr-test/exposed-service.yml | 43 +++++++ vkpr-test/externaldns-test.bats | 114 ++++++++++++++++++ vkpr/external-dns/install/aws/README.md | 13 ++ vkpr/external-dns/install/{ => aws}/build.sh | 4 + vkpr/external-dns/install/aws/config.json | 6 + vkpr/external-dns/install/aws/help.json | 4 + vkpr/external-dns/install/aws/metadata.json | 18 +++ .../install/{ => aws}/set_umask.sh | 0 vkpr/external-dns/install/aws/src/main.sh | 6 + .../install/aws/src/unix/formula/formula.sh | 35 ++++++ vkpr/external-dns/install/config.json | 23 ---- vkpr/external-dns/install/{ => do}/README.md | 2 +- vkpr/external-dns/install/do/build.sh | 15 +++ vkpr/external-dns/install/do/config.json | 13 ++ vkpr/external-dns/install/do/help.json | 4 + .../install/{ => do}/metadata.json | 8 +- vkpr/external-dns/install/do/set_umask.sh | 3 + vkpr/external-dns/install/do/src/main.sh | 8 ++ .../{ => do}/src/unix/formula/formula.sh | 25 +--- .../{ => do}/src/utils/external-dns.yaml | 2 +- vkpr/external-dns/install/pdns/README.md | 13 ++ vkpr/external-dns/install/pdns/build.sh | 15 +++ vkpr/external-dns/install/pdns/config.json | 22 ++++ vkpr/external-dns/install/pdns/help.json | 4 + vkpr/external-dns/install/pdns/metadata.json | 18 +++ vkpr/external-dns/install/pdns/set_umask.sh | 3 + vkpr/external-dns/install/pdns/src/main.sh | 8 ++ .../install/pdns/src/unix/formula/formula.sh | 34 ++++++ .../install/pdns/src/utils/external-dns.yaml | 11 ++ vkpr/external-dns/install/src/main.sh | 17 --- vkpr/external-dns/remove/src/main.sh | 6 +- .../remove/src/unix/formula/formula.sh | 2 +- vkpr/postgres/install/src/main.bat | 3 - 36 files changed, 508 insertions(+), 71 deletions(-) create mode 100644 vkpr-test/TESTS.md create mode 100644 vkpr-test/dnslog.j2 create mode 100644 vkpr-test/exposed-service.yml create mode 100644 vkpr-test/externaldns-test.bats create mode 100755 vkpr/external-dns/install/aws/README.md rename vkpr/external-dns/install/{ => aws}/build.sh (91%) mode change 100644 => 100755 create mode 100755 vkpr/external-dns/install/aws/config.json create mode 100644 vkpr/external-dns/install/aws/help.json create mode 100755 vkpr/external-dns/install/aws/metadata.json rename vkpr/external-dns/install/{ => aws}/set_umask.sh (100%) mode change 100644 => 100755 create mode 100755 vkpr/external-dns/install/aws/src/main.sh create mode 100755 vkpr/external-dns/install/aws/src/unix/formula/formula.sh delete mode 100644 vkpr/external-dns/install/config.json rename vkpr/external-dns/install/{ => do}/README.md (74%) mode change 100644 => 100755 create mode 100755 vkpr/external-dns/install/do/build.sh create mode 100755 vkpr/external-dns/install/do/config.json create mode 100644 vkpr/external-dns/install/do/help.json rename vkpr/external-dns/install/{ => do}/metadata.json (64%) mode change 100644 => 100755 create mode 100755 vkpr/external-dns/install/do/set_umask.sh create mode 100755 vkpr/external-dns/install/do/src/main.sh rename vkpr/external-dns/install/{ => do}/src/unix/formula/formula.sh (67%) rename vkpr/external-dns/install/{ => do}/src/utils/external-dns.yaml (84%) create mode 100755 vkpr/external-dns/install/pdns/README.md create mode 100755 vkpr/external-dns/install/pdns/build.sh create mode 100755 vkpr/external-dns/install/pdns/config.json create mode 100644 vkpr/external-dns/install/pdns/help.json create mode 100755 vkpr/external-dns/install/pdns/metadata.json create mode 100755 vkpr/external-dns/install/pdns/set_umask.sh create mode 100755 vkpr/external-dns/install/pdns/src/main.sh create mode 100755 vkpr/external-dns/install/pdns/src/unix/formula/formula.sh create mode 100644 vkpr/external-dns/install/pdns/src/utils/external-dns.yaml delete mode 100644 vkpr/external-dns/install/src/main.sh delete mode 100755 vkpr/postgres/install/src/main.bat diff --git a/vkpr-test/TESTS.md b/vkpr-test/TESTS.md new file mode 100644 index 00000000..99ae2cc1 --- /dev/null +++ b/vkpr-test/TESTS.md @@ -0,0 +1,60 @@ +# TESTS + +Automated BATS tests for VKPR formulas. + +## BATS in VKPR + +Tests written using [BATS](https://bats-core.readthedocs.io/en/stable/index.html). + +BATS itself is installed by `vkpr init` formula. + +A few points: + +- BATS supports `setup` and `teardown` operations defined in each `.bats` file (invoked before and after **each test** in that file). +- BATS also supports `setup_file` and `teardown_file` operations defined in each `.bats` file (invoked **once** before and after each file). +- VKPR tests also rely on a shared `common_setup.bash` that is invoked by all `setup_file` operations (by convention), to implement "smart" warm-ups and caches for all tests + +A typical `bats` file is like this: + +```sh +VKPR_HOME=~/.vkpr + +setup_file() { + load 'common-setup' + _common_setup + # here goes 'once per file' setup code +} + +setup() { + load $VKPR_HOME/bats/bats-support/load.bash + load $VKPR_HOME/bats/bats-assert/load.bash + # here goes 'once per test' setup code +} + +# here goes all tests +@test "this is a test" { + # here is some test code +} +``` + +## Running individual tests + +You can run individual tests quickly (for a TDD approach) by disabling teardown and specifying the test file: + +``` +VKPR_TEST_SKIP_TEARDOWN=true ~/.vkpr/bats/bin/bats ingress-test.bats +``` + +or to disable only the "common" teardown (cluster destruction): + +``` +VKPR_TEST_SKIP_COMMON_TEARDOWN=true ~/.vkpr/bats/bin/bats ingress-test.bats +``` + +## Running all tests + +You can run all tests by running BATS against the tests folder: + +``` +~/.vkpr/bats/bin/bats vkpr-tests +``` diff --git a/vkpr-test/common-setup.bash b/vkpr-test/common-setup.bash index 81cffba0..814a4898 100644 --- a/vkpr-test/common-setup.bash +++ b/vkpr-test/common-setup.bash @@ -12,3 +12,14 @@ _common_setup() { fi fi } + +_common_teardown() { + if [ "$VKPR_TEST_SKIP_TEARDOWN" == "true" ]; then + echo "common_teardown: skipping common-teardown due to VKPR_TEST_SKIP_TEARDOWN=true" >&3 + elif [ "$VKPR_TEST_SKIP_COMMON_TEARDOWN" == "true" ]; then + echo "common_teardown: skipping common-teardown due to VKPR_TEST_SKIP_COMMON_TEARDOWN=true" >&3 + else + echo "common_teardown: killing vkpr cluster...." >&3 + rit vkpr infra down + fi +} diff --git a/vkpr-test/dnslog.j2 b/vkpr-test/dnslog.j2 new file mode 100644 index 00000000..95c567e0 --- /dev/null +++ b/vkpr-test/dnslog.j2 @@ -0,0 +1,6 @@ +log-dns-details=yes +log-dns-queries=yes +loglevel=6 +cache-ttl=0 +zone-cache-refresh-interval=0 +zone-metadata-cache-ttl=0 diff --git a/vkpr-test/exposed-service.yml b/vkpr-test/exposed-service.yml new file mode 100644 index 00000000..38fce301 --- /dev/null +++ b/vkpr-test/exposed-service.yml @@ -0,0 +1,43 @@ +# nginx service with external-dns annotations +# +# generated with the commands below: +# +# kubectl run nginx --image=nginx --port=80 --dry-run=client -o yaml +# kubectl expose pod nginx --port=8000 --target-port=80 --type=LoadBalancer --dry-run=client -o yaml +# +apiVersion: v1 +kind: Pod +metadata: + labels: + run: nginx + name: nginx +spec: + containers: + - image: nginx + name: nginx + ports: + - containerPort: 80 + resources: {} + dnsPolicy: ClusterFirst + restartPolicy: Always +status: {} + +--- + +apiVersion: v1 +kind: Service +metadata: + labels: + run: nginx + name: nginx + annotations: + external-dns.alpha.kubernetes.io/ttl: "10" + external-dns.alpha.kubernetes.io/hostname: nginx.example.com. +spec: + ports: + - port: 8000 + protocol: TCP + targetPort: 80 + selector: + run: nginx + type: LoadBalancer diff --git a/vkpr-test/externaldns-test.bats b/vkpr-test/externaldns-test.bats new file mode 100644 index 00000000..867f24dc --- /dev/null +++ b/vkpr-test/externaldns-test.bats @@ -0,0 +1,114 @@ +# +# External-DNS Tests +# +# We are starting a local PowerDNS authoritative server and creating a new "example.com" domain during setup. +# Mora bout this in https://doc.powerdns.com/authoritative/PowerDNS-Authoritative.pdf. +# +VKPR_HOME=~/.vkpr + +setup_file() { + load 'common-setup' + _common_setup + if [ "$VKPR_TEST_SKIP_SETUP" == "true" ]; then + echo "setup: skipping setup due to VKPR_TEST_SKIP_SETUP=true" >&3 + else + echo "setup: starting powerdns..." >&3 + startPowerDNS + echo "setup: installing externaldns...." >&3 + rit vkpr external-dns install pdns --apiurl=http://host.k3d.internal + # expose test service + echo "setup: creating and exposing annotated service...." >&3 + kubectl apply -f $BATS_TEST_DIRNAME/exposed-service.yml + # wait for all to be ready + kubectl wait --for=condition=ready --timeout=1m pod --all + #sleep 20 + fi +} + +setup() { + load $VKPR_HOME/bats/bats-support/load.bash + load $VKPR_HOME/bats/bats-assert/load.bash +} + +@test "tests name resolution of k3d host internal alias (host.k3d.internal)" { + run get_host_ip +} + +@test "dig test of powerdns container 'local.example.com'" { + # ensures powerdns has been initialized correctly + run dig_local + assert_output '127.0.0.1' +} + +dig_local(){ + dig @localhost -4 -r -p 8553 local.example.com +short +} + +@test "testing if external-dns dealt with exposed annotated service" { + # service + external_ip=$(kubectl get svc nginx --template="{{range .status.loadBalancer.ingress}}{{.ip}}{{end}}") + trim "$external_ip" + external_ip="$TRIMMED" + echo "external_ip=$external_ip" >&3 + refute [ -z "$external_ip" ] + run dig_exposed_service + assert_output "$external_ip" +} + +dig_exposed_service(){ + dig @localhost -4 -r -p 8553 nginx.example.com +short +} + +get_host_ip() { + kubectl run --rm=true -i busybox --image=busybox --restart=Never \ + --command -- ping -c1 -n host.k3d.internal | head -n1 | sed 's/.*(\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\)).*/\1/g' +} + +startPowerDNS() { + # define log/cache cfg (IMPORTANTE zerar os tempos de cache) + cp $BATS_TEST_DIRNAME/dnslog.j2 /tmp/dnslog.j2 + # start powerdns + docker run -d --name pdns \ + -p 8553:53/tcp -p 8553:53/udp -p 8081:8081 \ + -e PDNS_AUTH_API_KEY=mykey \ + -e TEMPLATE_FILES="dnslog" \ + -v /tmp/dnslog.j2:/etc/powerdns/templates.d/dnslog.j2:ro \ + powerdns/pdns-auth-45 + # creates dns zone + docker exec pdns pdnsutil create-zone example.com + docker exec pdns pdnsutil set-kind example.com native + docker exec pdns pdnsutil set-meta example.com SOA-EDIT INCEPTION-INCREMENT + docker exec pdns pdnsutil increase-serial example.com + docker exec pdns pdnsutil add-record example.com local A 60 "127.0.0.1" + + # creates rit powerdns credential + rit set credential --provider='powerdns' --fields="apikey" --values="mykey" +} + +stopPowerDNS() { + docker stop pdns + docker rm pdns +} + +teardown_file() { + if [ "$VKPR_TEST_SKIP_TEARDOWN" == "true" ]; then + echo "teardown: skipping teardown due to VKPR_TEST_SKIP_TEARDOWN=true" >&3 + else + echo "teardown: removing annotated service...." >&3 + kubectl delete --ignore-not-found=true -f $BATS_TEST_DIRNAME/exposed-service.yml + echo "teardown: stopping power-dns...." >&3 + stopPowerDNS + echo "teardown: uninstalling external-dns...." >&3 + rit vkpr external-dns remove + fi + _common_teardown +} + +trim() { + local var="$*" + # remove leading whitespace characters + var="${var#"${var%%[![:space:]]*}"}" + # remove trailing whitespace characters + var="${var%"${var##*[![:space:]]}"}" + TRIMMED="$var" +} diff --git a/vkpr/external-dns/install/aws/README.md b/vkpr/external-dns/install/aws/README.md new file mode 100755 index 00000000..cc6ffbfa --- /dev/null +++ b/vkpr/external-dns/install/aws/README.md @@ -0,0 +1,13 @@ +# Description + +Formula description + +## Command + +```bash +rit vkpr external-dns install aws +``` + +## Requirements + +## Demonstration diff --git a/vkpr/external-dns/install/build.sh b/vkpr/external-dns/install/aws/build.sh old mode 100644 new mode 100755 similarity index 91% rename from vkpr/external-dns/install/build.sh rename to vkpr/external-dns/install/aws/build.sh index 3f067481..e0c86872 --- a/vkpr/external-dns/install/build.sh +++ b/vkpr/external-dns/install/aws/build.sh @@ -9,3 +9,7 @@ ENTRY_POINT_UNIX=main.sh cp -r src/* $BIN_FOLDER mv $BIN_FOLDER/$ENTRY_POINT_UNIX $BIN_FOLDER/$BINARY_NAME_UNIX chmod +x $BIN_FOLDER/$BINARY_NAME_UNIX + +#bat-build: + +#docker: diff --git a/vkpr/external-dns/install/aws/config.json b/vkpr/external-dns/install/aws/config.json new file mode 100755 index 00000000..c3d6c6c2 --- /dev/null +++ b/vkpr/external-dns/install/aws/config.json @@ -0,0 +1,6 @@ +{ + "dockerImageBuilder": "ritclizup/rit-shell-bat-builder", + "inputs": [], + "template": "shell-bat", + "templateRelease:": "2.16.2" +} diff --git a/vkpr/external-dns/install/aws/help.json b/vkpr/external-dns/install/aws/help.json new file mode 100644 index 00000000..4e9a4925 --- /dev/null +++ b/vkpr/external-dns/install/aws/help.json @@ -0,0 +1,4 @@ +{ + "short": "Install external-dns (aws provider)", + "long": "Install the external-dns in the Kubernetes cluster configured against a PowerDNS server." +} \ No newline at end of file diff --git a/vkpr/external-dns/install/aws/metadata.json b/vkpr/external-dns/install/aws/metadata.json new file mode 100755 index 00000000..9cee5d7f --- /dev/null +++ b/vkpr/external-dns/install/aws/metadata.json @@ -0,0 +1,18 @@ +{ + "execution": [ + "local" + ], + "os": { + "deps": [], + "support": [ + "mac", + "linux" + ] + }, + "tags": [ + "vkpr", + "external-dns", + "install", + "aws" + ] +} diff --git a/vkpr/external-dns/install/set_umask.sh b/vkpr/external-dns/install/aws/set_umask.sh old mode 100644 new mode 100755 similarity index 100% rename from vkpr/external-dns/install/set_umask.sh rename to vkpr/external-dns/install/aws/set_umask.sh diff --git a/vkpr/external-dns/install/aws/src/main.sh b/vkpr/external-dns/install/aws/src/main.sh new file mode 100755 index 00000000..736f5ce4 --- /dev/null +++ b/vkpr/external-dns/install/aws/src/main.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# shellcheck source=/dev/null +. "$(dirname "$0")"/unix/formula/formula.sh --source-only + +runFormula diff --git a/vkpr/external-dns/install/aws/src/unix/formula/formula.sh b/vkpr/external-dns/install/aws/src/unix/formula/formula.sh new file mode 100755 index 00000000..8ac25f1f --- /dev/null +++ b/vkpr/external-dns/install/aws/src/unix/formula/formula.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +runFormula() { + echo "Hello World!" + echoColor "green" "My name is $RIT_INPUT_TEXT." + + if [ "$RIT_INPUT_BOOLEAN" = "true" ]; then + echoColor "blue" "I've already created formulas using Ritchie." + else + echoColor "red" "I'm excited in creating new formulas using Ritchie." + fi + + echoColor "yellow" "Today, I want to automate $RIT_INPUT_LIST." + echoColor "cyan" "My secret is $RIT_INPUT_PASSWORD." +} + +echoColor() { + case $1 in + red) + echo "$(printf '\033[31m')$2$(printf '\033[0m')" + ;; + green) + echo "$(printf '\033[32m')$2$(printf '\033[0m')" + ;; + yellow) + echo "$(printf '\033[33m')$2$(printf '\033[0m')" + ;; + blue) + echo "$(printf '\033[34m')$2$(printf '\033[0m')" + ;; + cyan) + echo "$(printf '\033[36m')$2$(printf '\033[0m')" + ;; + esac +} diff --git a/vkpr/external-dns/install/config.json b/vkpr/external-dns/install/config.json deleted file mode 100644 index ba57c02e..00000000 --- a/vkpr/external-dns/install/config.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "dockerImageBuilder": "ritclizup/rit-shell-bat-builder", - "inputs": [ - { - "default": "DIGITALOCEAN", - "items": [ - "DIGITALOCEAN", - "AWS" - ], - "label": "What is your cloud provider? ", - "name": "provider", - "required": true, - "type": "text" - }, - { - "name": "token", - "type": "CREDENTIAL_DIGITALOCEAN_APITOKEN" - } - ], - "template": "shell-bat", - "templateRelease:": "2.16.2" -} - diff --git a/vkpr/external-dns/install/README.md b/vkpr/external-dns/install/do/README.md old mode 100644 new mode 100755 similarity index 74% rename from vkpr/external-dns/install/README.md rename to vkpr/external-dns/install/do/README.md index 68b1eb53..a802ddb8 --- a/vkpr/external-dns/install/README.md +++ b/vkpr/external-dns/install/do/README.md @@ -5,7 +5,7 @@ Formula description ## Command ```bash -rit vkpr external-dns install +rit vkpr external-dns install do ``` ## Requirements diff --git a/vkpr/external-dns/install/do/build.sh b/vkpr/external-dns/install/do/build.sh new file mode 100755 index 00000000..e0c86872 --- /dev/null +++ b/vkpr/external-dns/install/do/build.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +BIN_FOLDER=bin +BINARY_NAME_UNIX=run.sh +ENTRY_POINT_UNIX=main.sh + +#bash-build: + mkdir -p $BIN_FOLDER + cp -r src/* $BIN_FOLDER + mv $BIN_FOLDER/$ENTRY_POINT_UNIX $BIN_FOLDER/$BINARY_NAME_UNIX + chmod +x $BIN_FOLDER/$BINARY_NAME_UNIX + +#bat-build: + +#docker: diff --git a/vkpr/external-dns/install/do/config.json b/vkpr/external-dns/install/do/config.json new file mode 100755 index 00000000..f35a5d6c --- /dev/null +++ b/vkpr/external-dns/install/do/config.json @@ -0,0 +1,13 @@ +{ + "dockerImageBuilder": "ritclizup/rit-shell-bat-builder", + "inputs": [ + { + "name": "token", + "required": false, + "type": "CREDENTIAL_DIGITALOCEAN_TOKEN" + } + ], + "template": "shell-bat", + "templateRelease:": "2.16.2" +} + diff --git a/vkpr/external-dns/install/do/help.json b/vkpr/external-dns/install/do/help.json new file mode 100644 index 00000000..73c7c613 --- /dev/null +++ b/vkpr/external-dns/install/do/help.json @@ -0,0 +1,4 @@ +{ + "short": "Install external-dns (digitalocean provider)", + "long": "Install the external-dns in the Kubernetes cluster configured against a PowerDNS server." +} \ No newline at end of file diff --git a/vkpr/external-dns/install/metadata.json b/vkpr/external-dns/install/do/metadata.json old mode 100644 new mode 100755 similarity index 64% rename from vkpr/external-dns/install/metadata.json rename to vkpr/external-dns/install/do/metadata.json index 89a145bb..c0574368 --- a/vkpr/external-dns/install/metadata.json +++ b/vkpr/external-dns/install/do/metadata.json @@ -1,7 +1,6 @@ { "execution": [ - "local", - "docker" + "local" ], "os": { "deps": [], @@ -11,6 +10,9 @@ ] }, "tags": [ - "vkpr", "external-dns", "install" + "vkpr", + "external-dns", + "install", + "do" ] } diff --git a/vkpr/external-dns/install/do/set_umask.sh b/vkpr/external-dns/install/do/set_umask.sh new file mode 100755 index 00000000..091c13d6 --- /dev/null +++ b/vkpr/external-dns/install/do/set_umask.sh @@ -0,0 +1,3 @@ +#!/bin/sh +umask 0011 +$1 diff --git a/vkpr/external-dns/install/do/src/main.sh b/vkpr/external-dns/install/do/src/main.sh new file mode 100755 index 00000000..20e7f416 --- /dev/null +++ b/vkpr/external-dns/install/do/src/main.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# shellcheck source=/dev/null +. "$(dirname "$0")"/unix/formula/formula.sh --source-only + +source ~/.vkpr/global/log.sh + +runFormula diff --git a/vkpr/external-dns/install/src/unix/formula/formula.sh b/vkpr/external-dns/install/do/src/unix/formula/formula.sh similarity index 67% rename from vkpr/external-dns/install/src/unix/formula/formula.sh rename to vkpr/external-dns/install/do/src/unix/formula/formula.sh index 2bd17d0f..5a51a67b 100755 --- a/vkpr/external-dns/install/src/unix/formula/formula.sh +++ b/vkpr/external-dns/install/do/src/unix/formula/formula.sh @@ -1,13 +1,10 @@ #!/bin/sh runFormula() { - echoColor "yellow" "Instalando external-dns..." - VKPR_EXTERNAL_DNS_LOCAL=$VKPR_HOME/values/external-dns - VKPR_EXTERNAL_DNS_VALUES=$VKPR_EXTERNAL_DNS_LOCAL/external-dns.yaml - mkdir -p $VKPR_EXTERNAL_DNS_LOCAL + echoColor "yellow" "Instalando external-dns with DigitalOcean DNS..." VKPR_EXTERNAL_DNS_VALUES=$(dirname "$0")/utils/external-dns.yaml - getProvider $PROVIDER + getProviderCreds add_repo_external_dns install_external_dns } @@ -18,10 +15,12 @@ add_repo_external_dns() { } install_external_dns() { - $VKPR_HOME/bin/helm upgrade -i vkpr -f $VKPR_EXTERNAL_DNS_VALUES bitnami/external-dns + $VKPR_HOME/bin/helm upgrade -i external-dns \ + --set digitalocean.apiToken=$TOKEN \ + -f $VKPR_EXTERNAL_DNS_VALUES bitnami/external-dns } -get_credentials() { +getProviderCreds(){ # CREDENTIAL INPUT NOT WORKING IN SHELL FORMULA # PARSING FILE DIRECTLY AND IGNORING INPUT ("-r" is important!!!) #VKPR_ACCESS_TOKEN_INPUT=$(jq -r .credential.token ~/.rit/credentials/default/digitalocean) @@ -35,15 +34,3 @@ get_credentials() { echoColor "red" "Please check https://cert-manager.io/docs/configuration/acme/dns01/digitalocean/" fi } - -getProvider(){ - case $1 in - DIGITALOCEAN) - get_credentials - ;; - AWS) - echoColor "yellow" "AWS is a working in progress." - exit 0 - ;; - esac -} \ No newline at end of file diff --git a/vkpr/external-dns/install/src/utils/external-dns.yaml b/vkpr/external-dns/install/do/src/utils/external-dns.yaml similarity index 84% rename from vkpr/external-dns/install/src/utils/external-dns.yaml rename to vkpr/external-dns/install/do/src/utils/external-dns.yaml index 5f40f555..db520ed2 100644 --- a/vkpr/external-dns/install/src/utils/external-dns.yaml +++ b/vkpr/external-dns/install/do/src/utils/external-dns.yaml @@ -6,4 +6,4 @@ sources: provider: digitalocean interval: "1m" digitalocean: - apiToken: $Token \ No newline at end of file + apiToken: $TOKEN diff --git a/vkpr/external-dns/install/pdns/README.md b/vkpr/external-dns/install/pdns/README.md new file mode 100755 index 00000000..56fc1385 --- /dev/null +++ b/vkpr/external-dns/install/pdns/README.md @@ -0,0 +1,13 @@ +# Description + +Formula description + +## Command + +```bash +rit vkpr external-dns install pdns +``` + +## Requirements + +## Demonstration diff --git a/vkpr/external-dns/install/pdns/build.sh b/vkpr/external-dns/install/pdns/build.sh new file mode 100755 index 00000000..e0c86872 --- /dev/null +++ b/vkpr/external-dns/install/pdns/build.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +BIN_FOLDER=bin +BINARY_NAME_UNIX=run.sh +ENTRY_POINT_UNIX=main.sh + +#bash-build: + mkdir -p $BIN_FOLDER + cp -r src/* $BIN_FOLDER + mv $BIN_FOLDER/$ENTRY_POINT_UNIX $BIN_FOLDER/$BINARY_NAME_UNIX + chmod +x $BIN_FOLDER/$BINARY_NAME_UNIX + +#bat-build: + +#docker: diff --git a/vkpr/external-dns/install/pdns/config.json b/vkpr/external-dns/install/pdns/config.json new file mode 100755 index 00000000..28be2c7f --- /dev/null +++ b/vkpr/external-dns/install/pdns/config.json @@ -0,0 +1,22 @@ +{ + "dockerImageBuilder": "ritclizup/rit-shell-bat-builder", + "inputs": [ + { + "label": "What is the powerdns server apiurl endpoint?", + "name": "apiurl", + "required": true, + "type": "text", + "cache": { + "active": true, + "qty": 5, + "newLabel": "Type another url:" + } + }, + { + "name": "apikey", + "type": "CREDENTIAL_POWERDNS_APIKEY" + } + ], + "template": "shell-bat", + "templateRelease:": "2.16.2" +} diff --git a/vkpr/external-dns/install/pdns/help.json b/vkpr/external-dns/install/pdns/help.json new file mode 100644 index 00000000..e08b452d --- /dev/null +++ b/vkpr/external-dns/install/pdns/help.json @@ -0,0 +1,4 @@ +{ + "short": "Install external-dns (powerdns provider)", + "long": "Install the external-dns in the Kubernetes cluster configured against a PowerDNS server." +} \ No newline at end of file diff --git a/vkpr/external-dns/install/pdns/metadata.json b/vkpr/external-dns/install/pdns/metadata.json new file mode 100755 index 00000000..6ec3ef0a --- /dev/null +++ b/vkpr/external-dns/install/pdns/metadata.json @@ -0,0 +1,18 @@ +{ + "execution": [ + "local" + ], + "os": { + "deps": [], + "support": [ + "mac", + "linux" + ] + }, + "tags": [ + "vkpr", + "external-dns", + "install", + "pdns" + ] +} diff --git a/vkpr/external-dns/install/pdns/set_umask.sh b/vkpr/external-dns/install/pdns/set_umask.sh new file mode 100755 index 00000000..091c13d6 --- /dev/null +++ b/vkpr/external-dns/install/pdns/set_umask.sh @@ -0,0 +1,3 @@ +#!/bin/sh +umask 0011 +$1 diff --git a/vkpr/external-dns/install/pdns/src/main.sh b/vkpr/external-dns/install/pdns/src/main.sh new file mode 100755 index 00000000..20e7f416 --- /dev/null +++ b/vkpr/external-dns/install/pdns/src/main.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# shellcheck source=/dev/null +. "$(dirname "$0")"/unix/formula/formula.sh --source-only + +source ~/.vkpr/global/log.sh + +runFormula diff --git a/vkpr/external-dns/install/pdns/src/unix/formula/formula.sh b/vkpr/external-dns/install/pdns/src/unix/formula/formula.sh new file mode 100755 index 00000000..ae14c794 --- /dev/null +++ b/vkpr/external-dns/install/pdns/src/unix/formula/formula.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +runFormula() { + echoColor "yellow" "Installing external-dns with powerdns..." + VKPR_EXTERNAL_DNS_VALUES=$(dirname "$0")/utils/external-dns.yaml + + getProviderCreds + add_repo_external_dns + install_external_dns +} + +add_repo_external_dns() { + $VKPR_HOME/bin/helm repo add bitnami https://charts.bitnami.com/bitnami + $VKPR_HOME/bin/helm repo update +} + +install_external_dns() { + $VKPR_HOME/bin/helm upgrade -i vkpr-external-dns \ + --set pdns.apiKey=$APIKEY \ + --set pdns.apiUrl=$APIURL \ + -f $VKPR_EXTERNAL_DNS_VALUES bitnami/external-dns +} + +getProviderCreds(){ + if [ -z "$APIKEY" ]; then + echo "yellow" "No powerdns apikey found in rit credentials. Falling back to PDNS_APIKEY env variable." + APIKEY="$PDNS_APIKEY" + fi + if [ -z "$APIKEY" ]; then + echoColor "red" "No powerdns apikey found in both rit credentials or PDNS_APIKEY env variable." + echoColor "red" "External-dns will fail to manage records unless you provide the powerdns apikey." + echoColor "red" "Please check https://github.com/kubernetes-sigs/external-dns/blob/master/docs/tutorials/pdns.md" + fi +} diff --git a/vkpr/external-dns/install/pdns/src/utils/external-dns.yaml b/vkpr/external-dns/install/pdns/src/utils/external-dns.yaml new file mode 100644 index 00000000..42bd1211 --- /dev/null +++ b/vkpr/external-dns/install/pdns/src/utils/external-dns.yaml @@ -0,0 +1,11 @@ +rbac: + create: true +sources: + - ingress + - service +provider: pdns +interval: "1m" +pdns: + apiUrl: $APIURL + apiPort: 8081 + apiKey: $APIKEY diff --git a/vkpr/external-dns/install/src/main.sh b/vkpr/external-dns/install/src/main.sh deleted file mode 100644 index 24e26cf6..00000000 --- a/vkpr/external-dns/install/src/main.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -if [ ! -d ~/.vkpr/global ]; then - echo "Doesn't initializated the vkpr... Call again the function" - rit vkpr init - exit; -fi - -source ~/.vkpr/global/log.sh -source ~/.vkpr/global/var.sh -source ~/.vkpr/global/.env -source ~/.vkpr/global/helper.sh - -# shellcheck source=/dev/null -. "$(dirname "$0")"/unix/formula/formula.sh --source-only - -runFormula diff --git a/vkpr/external-dns/remove/src/main.sh b/vkpr/external-dns/remove/src/main.sh index 24e26cf6..ccdaf5f6 100755 --- a/vkpr/external-dns/remove/src/main.sh +++ b/vkpr/external-dns/remove/src/main.sh @@ -7,9 +7,9 @@ if [ ! -d ~/.vkpr/global ]; then fi source ~/.vkpr/global/log.sh -source ~/.vkpr/global/var.sh -source ~/.vkpr/global/.env -source ~/.vkpr/global/helper.sh +#source ~/.vkpr/global/var.sh +#source ~/.vkpr/global/.env +#source ~/.vkpr/global/helper.sh # shellcheck source=/dev/null . "$(dirname "$0")"/unix/formula/formula.sh --source-only diff --git a/vkpr/external-dns/remove/src/unix/formula/formula.sh b/vkpr/external-dns/remove/src/unix/formula/formula.sh index c6c2a288..964b7f18 100755 --- a/vkpr/external-dns/remove/src/unix/formula/formula.sh +++ b/vkpr/external-dns/remove/src/unix/formula/formula.sh @@ -3,5 +3,5 @@ runFormula() { echoColor "yellow" "Removendo external-dns..." rm -rf $VKPR_HOME/values/external-dns - helm delete vkpr + helm delete external-dns } diff --git a/vkpr/postgres/install/src/main.bat b/vkpr/postgres/install/src/main.bat deleted file mode 100755 index 4100614f..00000000 --- a/vkpr/postgres/install/src/main.bat +++ /dev/null @@ -1,3 +0,0 @@ -@echo off - -call windows\formula\formula.bat runFormula From 45f6e6c5329e46b6d931709435501122924594a3 Mon Sep 17 00:00:00 2001 From: Andre Fernandes Date: Wed, 8 Sep 2021 13:03:31 -0300 Subject: [PATCH 08/32] external-dns test small fix --- vkpr/external-dns/install/pdns/src/unix/formula/formula.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vkpr/external-dns/install/pdns/src/unix/formula/formula.sh b/vkpr/external-dns/install/pdns/src/unix/formula/formula.sh index ae14c794..3656f39f 100755 --- a/vkpr/external-dns/install/pdns/src/unix/formula/formula.sh +++ b/vkpr/external-dns/install/pdns/src/unix/formula/formula.sh @@ -15,7 +15,7 @@ add_repo_external_dns() { } install_external_dns() { - $VKPR_HOME/bin/helm upgrade -i vkpr-external-dns \ + $VKPR_HOME/bin/helm upgrade -i external-dns \ --set pdns.apiKey=$APIKEY \ --set pdns.apiUrl=$APIURL \ -f $VKPR_EXTERNAL_DNS_VALUES bitnami/external-dns From a6f362dbb611803ee1961cf2f93a3a31f0f7276f Mon Sep 17 00:00:00 2001 From: HumbertoPeluso Date: Wed, 8 Sep 2021 13:55:34 -0300 Subject: [PATCH 09/32] v1.0.6 Commit --- vkpr-test/cert-manager-test.bats | 44 +++++++++++++++++++ .../install/src/utils/issuers.yaml | 4 +- 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 vkpr-test/cert-manager-test.bats diff --git a/vkpr-test/cert-manager-test.bats b/vkpr-test/cert-manager-test.bats new file mode 100644 index 00000000..3a31d392 --- /dev/null +++ b/vkpr-test/cert-manager-test.bats @@ -0,0 +1,44 @@ +VKPR_HOME=~/.vkpr + +setup_file() { + load 'common-setup' + _common_setup + if [ "$VKPR_TEST_SKIP_SETUP" == "true" ]; then + echo "setup: skipping setup due to VKPR_TEST_SKIP_SETUP=true" >&3 + else + echo "setup: installing cert-manager...." >&3 + rit vkpr cert-manager install --email test@test.com + kubectl wait --for=condition=ready --timeout=1m pod --all + sleep 2 + + echo "setup: installing whoami to create a certificate...." >&3 + rit vkpr whoami install --domain whoami.vkpr-dev.vertigo.com.br --secure true + kubectl wait --for=condition=ready --timeout=1m pod --all + sleep 2 + fi +} + +setup() { + load $VKPR_HOME/bats/bats-support/load.bash + load $VKPR_HOME/bats/bats-assert/load.bash +} + +@test "curl to https://whoami.vkpr-dev.vertigo.com.br:8001 must return a letsencrypt certificate" { + #command that tests whether ingress is running + run "$(curl -vik --resolve whoami.vkpr-dev.vertigo.com.br:8001:127.0.0.1 https://whoami.vkpr-dev.vertigo.com.br:8001)" + actual="${lines[1]}" + trim "$actual" + actual="$TRIMMED" + expected="<>" + assert_equal "$actual" "$expected" +} + + +trim() { + local var="$*" + # remove leading whitespace characters + var="${var#"${var%%[![:space:]]*}"}" + # remove trailing whitespace characters + var="${var%"${var##*[![:space:]]}"}" + TRIMMED="$var" +} diff --git a/vkpr/cert-manager/install/src/utils/issuers.yaml b/vkpr/cert-manager/install/src/utils/issuers.yaml index 09b9587b..9bdb51c0 100755 --- a/vkpr/cert-manager/install/src/utils/issuers.yaml +++ b/vkpr/cert-manager/install/src/utils/issuers.yaml @@ -6,7 +6,7 @@ metadata: spec: acme: email: user@example.com - server: https://acme-staging-v02.api.letsencrypt.org/directory + server: https://host.k3d.internal/acme/acme/directory privateKeySecretRef: name: letsencrypt-staging-key solvers: @@ -25,7 +25,7 @@ metadata: spec: acme: email: user@example.com - server: https://acme-v02.api.letsencrypt.org/directory + server: https://host.k3d.internal/acme/acme/directory privateKeySecretRef: name: letsencrypt-production-key solvers: From 22854767fb6956fd4311dacae2773456e95b306f Mon Sep 17 00:00:00 2001 From: HumbertoPeluso Date: Wed, 8 Sep 2021 14:05:15 -0300 Subject: [PATCH 10/32] turn back server values --- vkpr/cert-manager/install/src/utils/issuers.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vkpr/cert-manager/install/src/utils/issuers.yaml b/vkpr/cert-manager/install/src/utils/issuers.yaml index 9bdb51c0..f1bce943 100755 --- a/vkpr/cert-manager/install/src/utils/issuers.yaml +++ b/vkpr/cert-manager/install/src/utils/issuers.yaml @@ -6,7 +6,7 @@ metadata: spec: acme: email: user@example.com - server: https://host.k3d.internal/acme/acme/directory + server: https://acme-staging-v02.api.letsencrypt.org/directory privateKeySecretRef: name: letsencrypt-staging-key solvers: @@ -25,7 +25,7 @@ metadata: spec: acme: email: user@example.com - server: https://host.k3d.internal/acme/acme/directory + server: https://acme-v02.api.letsencrypt.org/directory privateKeySecretRef: name: letsencrypt-production-key solvers: @@ -34,4 +34,4 @@ spec: digitalocean: tokenSecretRef: name: digitalocean-dns - key: access-token + key: access-token \ No newline at end of file From ccb002d7afc55ddbec2cddc1973194b8958b4fd5 Mon Sep 17 00:00:00 2001 From: Jpeedroza Date: Wed, 8 Sep 2021 14:34:16 -0300 Subject: [PATCH 11/32] Created test to check availability of whoami --- vkpr-test/whoami.bats | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 vkpr-test/whoami.bats diff --git a/vkpr-test/whoami.bats b/vkpr-test/whoami.bats new file mode 100644 index 00000000..d62425c5 --- /dev/null +++ b/vkpr-test/whoami.bats @@ -0,0 +1,50 @@ + +VKPR_HOME=~/.vkpr + +setup_file() { + load 'common-setup' + _common_setup + if [ "$VKPR_TEST_SKIP_SETUP" == "true" ]; then + echo "setup: skipping setup due to VKPR_TEST_SKIP_SETUP=true" >&3 + else + echo "setup: installing ingress...." >&3 + rit vkpr ingress install + kubectl wait --for=condition=ready --timeout=1m pod --all + echo "setup: installing whoami...." >&3 + rit vkpr whoami install --default + kubectl wait --for=condition=ready --timeout=1m pod --all + sleep 20 + fi +} + +setup() { + load $VKPR_HOME/bats/bats-support/load.bash + load $VKPR_HOME/bats/bats-assert/load.bash +} + +@test "Curl to Whoami and must return Hostname" { + run curlWhoami + actual="${lines[3]}" + expected=$(podName) + assert_equal "$actual" "$expected" +} + +teardown_file() { + if [ "$VKPR_TEST_SKIP_TEARDOWN" == "true" ]; then + echo "teardown: skipping teardown due to VKPR_TEST_SKIP_TEARDOWN=true" >&3 + else + echo "teardown: uninstalling ingress...." >&3 + rit vkpr ingress remove + rit vkpr infra down + fi +} + +podName(){ + local pod=$($VKPR_HOME/bin/kubectl get po -o name | grep whoami | cut -d "/" -f 2) + echo "Hostname: ${pod}" +} + +curlWhoami(){ + curl -k -H "Host: whoami.localhost" https://127.0.0.1:8001 | sed 's/<\/*[^>]*>//g' + sleep 5 +} \ No newline at end of file From cd26afce2c7e0f43b7f904fe5f08bef0106d9312 Mon Sep 17 00:00:00 2001 From: Andre Fernandes Date: Thu, 9 Sep 2021 08:32:25 -0300 Subject: [PATCH 12/32] VKPR-141 #close #comment infra start done --- vkpr/infra/start/README.md | 13 ++++ vkpr/infra/start/build.sh | 15 +++++ vkpr/infra/start/config.json | 29 +++++++++ vkpr/infra/start/metadata.json | 17 +++++ vkpr/infra/start/set_umask.sh | 3 + vkpr/infra/start/src/main.sh | 9 +++ vkpr/infra/start/src/unix/formula/formula.sh | 67 ++++++++++++++++++++ vkpr/infra/up/src/main.sh | 4 +- vkpr/infra/up/src/unix/formula/formula.sh | 61 +----------------- 9 files changed, 156 insertions(+), 62 deletions(-) create mode 100755 vkpr/infra/start/README.md create mode 100755 vkpr/infra/start/build.sh create mode 100755 vkpr/infra/start/config.json create mode 100755 vkpr/infra/start/metadata.json create mode 100755 vkpr/infra/start/set_umask.sh create mode 100755 vkpr/infra/start/src/main.sh create mode 100755 vkpr/infra/start/src/unix/formula/formula.sh diff --git a/vkpr/infra/start/README.md b/vkpr/infra/start/README.md new file mode 100755 index 00000000..096edc46 --- /dev/null +++ b/vkpr/infra/start/README.md @@ -0,0 +1,13 @@ +# Description + +Formula description + +## Command + +```bash +rit vkpr infra start +``` + +## Requirements + +## Demonstration diff --git a/vkpr/infra/start/build.sh b/vkpr/infra/start/build.sh new file mode 100755 index 00000000..e0c86872 --- /dev/null +++ b/vkpr/infra/start/build.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +BIN_FOLDER=bin +BINARY_NAME_UNIX=run.sh +ENTRY_POINT_UNIX=main.sh + +#bash-build: + mkdir -p $BIN_FOLDER + cp -r src/* $BIN_FOLDER + mv $BIN_FOLDER/$ENTRY_POINT_UNIX $BIN_FOLDER/$BINARY_NAME_UNIX + chmod +x $BIN_FOLDER/$BINARY_NAME_UNIX + +#bat-build: + +#docker: diff --git a/vkpr/infra/start/config.json b/vkpr/infra/start/config.json new file mode 100755 index 00000000..ef8ecbff --- /dev/null +++ b/vkpr/infra/start/config.json @@ -0,0 +1,29 @@ +{ + "dockerImageBuilder": "ritclizup/rit-shell-bat-builder", + "inputs": [ + { + "default": "8000", + "label": "Type the HTTP listening port: ", + "name": "http_port", + "type": "text" + }, + { + "default": "8001", + "label": "Type the HTTP listening port: ", + "name": "https_port", + "type": "text" + }, + { + "default": "false", + "items": [ + "false", + "true" + ], + "label": "Enable Traefik ingress controller? ", + "name": "enable_traefik", + "type": "bool" + } + ], + "template": "shell-bat", + "templateRelease:": "2.16.2" +} diff --git a/vkpr/infra/start/metadata.json b/vkpr/infra/start/metadata.json new file mode 100755 index 00000000..3d96be03 --- /dev/null +++ b/vkpr/infra/start/metadata.json @@ -0,0 +1,17 @@ +{ + "execution": [ + "local" + ], + "os": { + "deps": [], + "support": [ + "mac", + "linux" + ] + }, + "tags": [ + "vkpr", + "infra", + "start" + ] +} diff --git a/vkpr/infra/start/set_umask.sh b/vkpr/infra/start/set_umask.sh new file mode 100755 index 00000000..091c13d6 --- /dev/null +++ b/vkpr/infra/start/set_umask.sh @@ -0,0 +1,3 @@ +#!/bin/sh +umask 0011 +$1 diff --git a/vkpr/infra/start/src/main.sh b/vkpr/infra/start/src/main.sh new file mode 100755 index 00000000..add369f0 --- /dev/null +++ b/vkpr/infra/start/src/main.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# shellcheck source=/dev/null +. "$(dirname "$0")"/unix/formula/formula.sh --source-only + +source ~/.vkpr/global/log.sh +source ~/.vkpr/global/var.sh + +runFormula diff --git a/vkpr/infra/start/src/unix/formula/formula.sh b/vkpr/infra/start/src/unix/formula/formula.sh new file mode 100755 index 00000000..1a7c2631 --- /dev/null +++ b/vkpr/infra/start/src/unix/formula/formula.sh @@ -0,0 +1,67 @@ +#!/bin/sh + +runFormula() { + echo "VKPR local infra start routine" + echo "==============================" + echoColor "yellow" "Ports used:" + echo "Kubernetes API: " + echo "Ingress controller (load balancer): " + echo "Local registry: 5000" + echo "Docker Hub registry mirror (cache): 5001" + echoColor "yellow" "Volumes used:" + echo "Two local unamed docker volumes" + + # TODO: test dependencies + + # VKPR home is "~/.vkpr" + # starts local registry and mirror + configRegistry + startRegistry + # starts kubernetes using registries + startCluster +} + +configRegistry() { + #HOST_IP="172.17.0.1" # linux native + HOST_IP="host.k3d.internal" + cat > $VKPR_HOME/config/registry.yaml << EOF +mirrors: + "docker.io": + endpoint: + - "http://$HOST_IP:5001" +EOF +} + +startCluster() { + # traefik flag + if [ "$ENABLE_TRAEFIK" == "true" ]; then TRAEFIK_FLAG=""; else TRAEFIK_FLAG="--k3s-server-arg '--no-deploy=traefik'"; fi + # local registry + if ! $(k3d cluster list | grep -q "vkpr-local"); then + k3d cluster create vkpr-local \ + -p "$HTTP_PORT:80@loadbalancer" \ + -p "$HTTPS_PORT:443@loadbalancer" \ + $TRAEFIK_FLAG \ + --registry-use k3d-registry.localhost \ + --registry-config $VKPR_HOME/config/registry.yaml + else + echoColor "yellow" "Cluster vkpr-local already started, skipping." + fi + # use cluster + $VKPR_HOME/bin/kubectl config use-context k3d-vkpr-local + $VKPR_HOME/bin/kubectl cluster-info +} + +startRegistry() { + # local registry + if ! $(k3d registry list | grep -q "k3d-registry\.localhost"); then + k3d registry create registry.localhost -p 5000 + else + echoColor "yellow" "Registry already started, skipping." + fi + # docker hub mirror + if ! $(k3d registry list | grep -q "k3d-mirror\.localhost"); then + k3d registry create mirror.localhost -i vertigo/registry-mirror -p 5001 + else + echoColor "yellow" "Mirror already started, skipping." + fi +} diff --git a/vkpr/infra/up/src/main.sh b/vkpr/infra/up/src/main.sh index 24e26cf6..8468f137 100755 --- a/vkpr/infra/up/src/main.sh +++ b/vkpr/infra/up/src/main.sh @@ -8,8 +8,8 @@ fi source ~/.vkpr/global/log.sh source ~/.vkpr/global/var.sh -source ~/.vkpr/global/.env -source ~/.vkpr/global/helper.sh +#source ~/.vkpr/global/.env +#source ~/.vkpr/global/helper.sh # shellcheck source=/dev/null . "$(dirname "$0")"/unix/formula/formula.sh --source-only diff --git a/vkpr/infra/up/src/unix/formula/formula.sh b/vkpr/infra/up/src/unix/formula/formula.sh index 5b2ac28f..00b16565 100755 --- a/vkpr/infra/up/src/unix/formula/formula.sh +++ b/vkpr/infra/up/src/unix/formula/formula.sh @@ -1,65 +1,6 @@ #!/bin/sh runFormula() { - echo "VKPR local infra start routine" - echo "==============================" - echoColor "yellow" "Ports used:" - echo "Kubernetes API: " - echo "Ingress controller (load balancer): " - echo "Local registry: 5000" - echo "Docker Hub registry mirror (cache): 5001" - echoColor "yellow" "Volumes used:" - echo "Two local unamed docker volumes" - - # TODO: test dependencies - - # VKPR home is "~/.vkpr" - # starts local registry and mirror - configRegistry - startRegistry - # starts kubernetes using registries - startCluster -} - -configRegistry() { - #HOST_IP="172.17.0.1" # linux native - HOST_IP="host.k3d.internal" - cat > $VKPR_HOME/config/registry.yaml << EOF -mirrors: - "docker.io": - endpoint: - - "http://$HOST_IP:5001" -EOF + rit vkpr infra start --default } -startCluster() { - # local registry - if ! $(k3d cluster list | grep -q "vkpr-local"); then - k3d cluster create vkpr-local \ - -p "8000:80@loadbalancer" \ - -p "8001:443@loadbalancer" \ - --k3s-server-arg '--no-deploy=traefik' \ - --registry-use k3d-registry.localhost \ - --registry-config $VKPR_HOME/config/registry.yaml - else - echoColor "yellow" "Cluster vkpr-local already started, skipping." - fi - # use cluster - $VKPR_HOME/bin/kubectl config use-context k3d-vkpr-local - $VKPR_HOME/bin/kubectl cluster-info -} - -startRegistry() { - # local registry - if ! $(k3d registry list | grep -q "k3d-registry\.localhost"); then - k3d registry create registry.localhost -p 5000 - else - echoColor "yellow" "Registry already started, skipping." - fi - # docker hub mirror - if ! $(k3d registry list | grep -q "k3d-mirror\.localhost"); then - k3d registry create mirror.localhost -i vertigo/registry-mirror -p 5001 - else - echoColor "yellow" "Mirror already started, skipping." - fi -} From 782f4e52350bcc62d539c2b73911394a17a04874 Mon Sep 17 00:00:00 2001 From: Andre Fernandes Date: Thu, 9 Sep 2021 09:16:37 -0300 Subject: [PATCH 13/32] fix traefik flag error --- vkpr/infra/start/src/unix/formula/formula.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/vkpr/infra/start/src/unix/formula/formula.sh b/vkpr/infra/start/src/unix/formula/formula.sh index 1a7c2631..f0018870 100755 --- a/vkpr/infra/start/src/unix/formula/formula.sh +++ b/vkpr/infra/start/src/unix/formula/formula.sh @@ -34,13 +34,20 @@ EOF startCluster() { # traefik flag - if [ "$ENABLE_TRAEFIK" == "true" ]; then TRAEFIK_FLAG=""; else TRAEFIK_FLAG="--k3s-server-arg '--no-deploy=traefik'"; fi + TRAEFIK_FLAG="" + if [ "$ENABLE_TRAEFIK" == "true" ]; then + echo "startCluster: Traefik is enabled" + else + echo "startCluster: Traefik is disabled" + TRAEFIK_FLAG="--no-deploy=traefik" + fi + echo "startCluster: TRAEFIK_FLAG=$TRAEFIK_FLAG" # local registry if ! $(k3d cluster list | grep -q "vkpr-local"); then k3d cluster create vkpr-local \ -p "$HTTP_PORT:80@loadbalancer" \ -p "$HTTPS_PORT:443@loadbalancer" \ - $TRAEFIK_FLAG \ + --k3s-server-arg "$TRAEFIK_FLAG" \ --registry-use k3d-registry.localhost \ --registry-config $VKPR_HOME/config/registry.yaml else From ae927f4b1346e39e521205271b9c135a0d5699f2 Mon Sep 17 00:00:00 2001 From: Jpeedroza Date: Thu, 9 Sep 2021 13:31:44 -0300 Subject: [PATCH 14/32] Change init and globals set --- vkpr/cert-manager/install/src/main.sh | 13 ++++--------- vkpr/cert-manager/remove/src/main.sh | 13 ++++--------- vkpr/create/formula/src/main.sh | 13 ++++--------- vkpr/external-dns/install/src/main.sh | 13 ++++--------- vkpr/external-dns/remove/src/main.sh | 13 ++++--------- vkpr/globals/set/src/main.sh | 13 +++++-------- vkpr/infra/down/src/main.sh | 13 ++++--------- vkpr/infra/up/src/main.sh | 13 ++++--------- vkpr/ingress/install/src/main.sh | 13 ++++--------- vkpr/ingress/remove/src/main.sh | 13 ++++--------- vkpr/init/src/utils/helper.sh | 6 +++--- vkpr/init/src/utils/var.sh | 1 + vkpr/keycloak/install/src/main.sh | 8 ++++---- vkpr/keycloak/remove/src/main.sh | 8 ++++---- vkpr/postgres/install/src/main.bat | 3 --- vkpr/postgres/install/src/main.sh | 6 ++++++ vkpr/postgres/remove/src/main.bat | 3 --- vkpr/postgres/remove/src/main.sh | 6 ++++++ vkpr/template/config/src/main.bat | 3 --- vkpr/template/config/src/main.sh | 13 ++++--------- vkpr/template/config/src/unix/formula/formula.sh | 2 +- vkpr/whoami/install/src/main.sh | 13 ++++--------- vkpr/whoami/remove/src/main.sh | 6 ++++++ 23 files changed, 80 insertions(+), 128 deletions(-) delete mode 100755 vkpr/postgres/install/src/main.bat delete mode 100755 vkpr/postgres/remove/src/main.bat delete mode 100755 vkpr/template/config/src/main.bat diff --git a/vkpr/cert-manager/install/src/main.sh b/vkpr/cert-manager/install/src/main.sh index 24e26cf6..cf647088 100755 --- a/vkpr/cert-manager/install/src/main.sh +++ b/vkpr/cert-manager/install/src/main.sh @@ -1,15 +1,10 @@ #!/bin/bash -if [ ! -d ~/.vkpr/global ]; then - echo "Doesn't initializated the vkpr... Call again the function" - rit vkpr init - exit; -fi +VKPR_SCRIPTS=~/.vkpr/src -source ~/.vkpr/global/log.sh -source ~/.vkpr/global/var.sh -source ~/.vkpr/global/.env -source ~/.vkpr/global/helper.sh +source $VKPR_SCRIPTS/log.sh +source $VKPR_SCRIPTS/var.sh +source $VKPR_SCRIPTS/helper.sh # shellcheck source=/dev/null . "$(dirname "$0")"/unix/formula/formula.sh --source-only diff --git a/vkpr/cert-manager/remove/src/main.sh b/vkpr/cert-manager/remove/src/main.sh index 24e26cf6..cf647088 100755 --- a/vkpr/cert-manager/remove/src/main.sh +++ b/vkpr/cert-manager/remove/src/main.sh @@ -1,15 +1,10 @@ #!/bin/bash -if [ ! -d ~/.vkpr/global ]; then - echo "Doesn't initializated the vkpr... Call again the function" - rit vkpr init - exit; -fi +VKPR_SCRIPTS=~/.vkpr/src -source ~/.vkpr/global/log.sh -source ~/.vkpr/global/var.sh -source ~/.vkpr/global/.env -source ~/.vkpr/global/helper.sh +source $VKPR_SCRIPTS/log.sh +source $VKPR_SCRIPTS/var.sh +source $VKPR_SCRIPTS/helper.sh # shellcheck source=/dev/null . "$(dirname "$0")"/unix/formula/formula.sh --source-only diff --git a/vkpr/create/formula/src/main.sh b/vkpr/create/formula/src/main.sh index 24e26cf6..cf647088 100755 --- a/vkpr/create/formula/src/main.sh +++ b/vkpr/create/formula/src/main.sh @@ -1,15 +1,10 @@ #!/bin/bash -if [ ! -d ~/.vkpr/global ]; then - echo "Doesn't initializated the vkpr... Call again the function" - rit vkpr init - exit; -fi +VKPR_SCRIPTS=~/.vkpr/src -source ~/.vkpr/global/log.sh -source ~/.vkpr/global/var.sh -source ~/.vkpr/global/.env -source ~/.vkpr/global/helper.sh +source $VKPR_SCRIPTS/log.sh +source $VKPR_SCRIPTS/var.sh +source $VKPR_SCRIPTS/helper.sh # shellcheck source=/dev/null . "$(dirname "$0")"/unix/formula/formula.sh --source-only diff --git a/vkpr/external-dns/install/src/main.sh b/vkpr/external-dns/install/src/main.sh index 24e26cf6..cf647088 100644 --- a/vkpr/external-dns/install/src/main.sh +++ b/vkpr/external-dns/install/src/main.sh @@ -1,15 +1,10 @@ #!/bin/bash -if [ ! -d ~/.vkpr/global ]; then - echo "Doesn't initializated the vkpr... Call again the function" - rit vkpr init - exit; -fi +VKPR_SCRIPTS=~/.vkpr/src -source ~/.vkpr/global/log.sh -source ~/.vkpr/global/var.sh -source ~/.vkpr/global/.env -source ~/.vkpr/global/helper.sh +source $VKPR_SCRIPTS/log.sh +source $VKPR_SCRIPTS/var.sh +source $VKPR_SCRIPTS/helper.sh # shellcheck source=/dev/null . "$(dirname "$0")"/unix/formula/formula.sh --source-only diff --git a/vkpr/external-dns/remove/src/main.sh b/vkpr/external-dns/remove/src/main.sh index 24e26cf6..cf647088 100755 --- a/vkpr/external-dns/remove/src/main.sh +++ b/vkpr/external-dns/remove/src/main.sh @@ -1,15 +1,10 @@ #!/bin/bash -if [ ! -d ~/.vkpr/global ]; then - echo "Doesn't initializated the vkpr... Call again the function" - rit vkpr init - exit; -fi +VKPR_SCRIPTS=~/.vkpr/src -source ~/.vkpr/global/log.sh -source ~/.vkpr/global/var.sh -source ~/.vkpr/global/.env -source ~/.vkpr/global/helper.sh +source $VKPR_SCRIPTS/log.sh +source $VKPR_SCRIPTS/var.sh +source $VKPR_SCRIPTS/helper.sh # shellcheck source=/dev/null . "$(dirname "$0")"/unix/formula/formula.sh --source-only diff --git a/vkpr/globals/set/src/main.sh b/vkpr/globals/set/src/main.sh index 994db848..8a7d61d5 100755 --- a/vkpr/globals/set/src/main.sh +++ b/vkpr/globals/set/src/main.sh @@ -1,13 +1,10 @@ #!/bin/bash -if [ ! -d $CURRENT_PWD/global ]; then - echo "Doesn't initializated the vkpr... Call again the function" - rit vkpr init - exit; -fi - -source $CURRENT_PWD/global/log.sh -source $CURRENT_PWD/global/var.sh +VKPR_SCRIPTS=~/.vkpr/src + +source $VKPR_SCRIPTS/log.sh +source $VKPR_SCRIPTS/var.sh +source $VKPR_SCRIPTS/helper.sh # shellcheck source=/dev/null . "$(dirname "$0")"/unix/formula/formula.sh --source-only diff --git a/vkpr/infra/down/src/main.sh b/vkpr/infra/down/src/main.sh index 24e26cf6..cf647088 100755 --- a/vkpr/infra/down/src/main.sh +++ b/vkpr/infra/down/src/main.sh @@ -1,15 +1,10 @@ #!/bin/bash -if [ ! -d ~/.vkpr/global ]; then - echo "Doesn't initializated the vkpr... Call again the function" - rit vkpr init - exit; -fi +VKPR_SCRIPTS=~/.vkpr/src -source ~/.vkpr/global/log.sh -source ~/.vkpr/global/var.sh -source ~/.vkpr/global/.env -source ~/.vkpr/global/helper.sh +source $VKPR_SCRIPTS/log.sh +source $VKPR_SCRIPTS/var.sh +source $VKPR_SCRIPTS/helper.sh # shellcheck source=/dev/null . "$(dirname "$0")"/unix/formula/formula.sh --source-only diff --git a/vkpr/infra/up/src/main.sh b/vkpr/infra/up/src/main.sh index 24e26cf6..cf647088 100755 --- a/vkpr/infra/up/src/main.sh +++ b/vkpr/infra/up/src/main.sh @@ -1,15 +1,10 @@ #!/bin/bash -if [ ! -d ~/.vkpr/global ]; then - echo "Doesn't initializated the vkpr... Call again the function" - rit vkpr init - exit; -fi +VKPR_SCRIPTS=~/.vkpr/src -source ~/.vkpr/global/log.sh -source ~/.vkpr/global/var.sh -source ~/.vkpr/global/.env -source ~/.vkpr/global/helper.sh +source $VKPR_SCRIPTS/log.sh +source $VKPR_SCRIPTS/var.sh +source $VKPR_SCRIPTS/helper.sh # shellcheck source=/dev/null . "$(dirname "$0")"/unix/formula/formula.sh --source-only diff --git a/vkpr/ingress/install/src/main.sh b/vkpr/ingress/install/src/main.sh index 24e26cf6..cf647088 100755 --- a/vkpr/ingress/install/src/main.sh +++ b/vkpr/ingress/install/src/main.sh @@ -1,15 +1,10 @@ #!/bin/bash -if [ ! -d ~/.vkpr/global ]; then - echo "Doesn't initializated the vkpr... Call again the function" - rit vkpr init - exit; -fi +VKPR_SCRIPTS=~/.vkpr/src -source ~/.vkpr/global/log.sh -source ~/.vkpr/global/var.sh -source ~/.vkpr/global/.env -source ~/.vkpr/global/helper.sh +source $VKPR_SCRIPTS/log.sh +source $VKPR_SCRIPTS/var.sh +source $VKPR_SCRIPTS/helper.sh # shellcheck source=/dev/null . "$(dirname "$0")"/unix/formula/formula.sh --source-only diff --git a/vkpr/ingress/remove/src/main.sh b/vkpr/ingress/remove/src/main.sh index 24e26cf6..cf647088 100755 --- a/vkpr/ingress/remove/src/main.sh +++ b/vkpr/ingress/remove/src/main.sh @@ -1,15 +1,10 @@ #!/bin/bash -if [ ! -d ~/.vkpr/global ]; then - echo "Doesn't initializated the vkpr... Call again the function" - rit vkpr init - exit; -fi +VKPR_SCRIPTS=~/.vkpr/src -source ~/.vkpr/global/log.sh -source ~/.vkpr/global/var.sh -source ~/.vkpr/global/.env -source ~/.vkpr/global/helper.sh +source $VKPR_SCRIPTS/log.sh +source $VKPR_SCRIPTS/var.sh +source $VKPR_SCRIPTS/helper.sh # shellcheck source=/dev/null . "$(dirname "$0")"/unix/formula/formula.sh --source-only diff --git a/vkpr/init/src/utils/helper.sh b/vkpr/init/src/utils/helper.sh index a1d4f45c..4fd9a2b5 100644 --- a/vkpr/init/src/utils/helper.sh +++ b/vkpr/init/src/utils/helper.sh @@ -3,12 +3,12 @@ # Create a variable by Global Scope # $1: Global variable / $2: Default value of the global variable / $3: Label from config file / $4: Name of env checkGlobalConfig(){ - CONFIG_FILE=~/.vkpr/global-config.yaml + VALUES_FILE=~/.vkpr/global-values.yaml FILE_LABEL=".global.$3" local NAME_ENV=VKPR_ENV_$4 - if [ -f "$CONFIG_FILE" ] && [ $1 == $2 ] && [ $($VKPR_YQ eval $FILE_LABEL $CONFIG_FILE) != "null" ]; then + if [ -f "$VALUES_FILE" ] && [ $1 == $2 ] && [ $($VKPR_YQ eval $FILE_LABEL $VALUES_FILE) != "null" ]; then echoColor "yellow" "Setting value from config file" - eval $NAME_ENV=$($VKPR_YQ eval $FILE_LABEL $CONFIG_FILE) + eval $NAME_ENV=$($VKPR_YQ eval $FILE_LABEL $VALUES_FILE) else if [ $1 == $2 ]; then echoColor "yellow" "Setting value from default value" diff --git a/vkpr/init/src/utils/var.sh b/vkpr/init/src/utils/var.sh index e6831282..68c3b45b 100644 --- a/vkpr/init/src/utils/var.sh +++ b/vkpr/init/src/utils/var.sh @@ -1,6 +1,7 @@ #!/bin/bash VKPR_HOME=~/.vkpr +VKPR_GLOBAL=$VKPR_HOME/global-values.yaml VKPR_K3D=$VKPR_HOME/bin/k3d VKPR_ARKADE=$VKPR_HOME/bin/arkade diff --git a/vkpr/keycloak/install/src/main.sh b/vkpr/keycloak/install/src/main.sh index b417dc84..cf647088 100755 --- a/vkpr/keycloak/install/src/main.sh +++ b/vkpr/keycloak/install/src/main.sh @@ -1,10 +1,10 @@ #!/bin/bash -VKPR_GLOBALS=~/.vkpr/global +VKPR_SCRIPTS=~/.vkpr/src -source $VKPR_GLOBALS/log.sh -source $VKPR_GLOBALS/var.sh -source $VKPR_GLOBALS/helper.sh +source $VKPR_SCRIPTS/log.sh +source $VKPR_SCRIPTS/var.sh +source $VKPR_SCRIPTS/helper.sh # shellcheck source=/dev/null . "$(dirname "$0")"/unix/formula/formula.sh --source-only diff --git a/vkpr/keycloak/remove/src/main.sh b/vkpr/keycloak/remove/src/main.sh index b417dc84..cf647088 100755 --- a/vkpr/keycloak/remove/src/main.sh +++ b/vkpr/keycloak/remove/src/main.sh @@ -1,10 +1,10 @@ #!/bin/bash -VKPR_GLOBALS=~/.vkpr/global +VKPR_SCRIPTS=~/.vkpr/src -source $VKPR_GLOBALS/log.sh -source $VKPR_GLOBALS/var.sh -source $VKPR_GLOBALS/helper.sh +source $VKPR_SCRIPTS/log.sh +source $VKPR_SCRIPTS/var.sh +source $VKPR_SCRIPTS/helper.sh # shellcheck source=/dev/null . "$(dirname "$0")"/unix/formula/formula.sh --source-only diff --git a/vkpr/postgres/install/src/main.bat b/vkpr/postgres/install/src/main.bat deleted file mode 100755 index 4100614f..00000000 --- a/vkpr/postgres/install/src/main.bat +++ /dev/null @@ -1,3 +0,0 @@ -@echo off - -call windows\formula\formula.bat runFormula diff --git a/vkpr/postgres/install/src/main.sh b/vkpr/postgres/install/src/main.sh index 736f5ce4..cf647088 100755 --- a/vkpr/postgres/install/src/main.sh +++ b/vkpr/postgres/install/src/main.sh @@ -1,5 +1,11 @@ #!/bin/bash +VKPR_SCRIPTS=~/.vkpr/src + +source $VKPR_SCRIPTS/log.sh +source $VKPR_SCRIPTS/var.sh +source $VKPR_SCRIPTS/helper.sh + # shellcheck source=/dev/null . "$(dirname "$0")"/unix/formula/formula.sh --source-only diff --git a/vkpr/postgres/remove/src/main.bat b/vkpr/postgres/remove/src/main.bat deleted file mode 100755 index 4100614f..00000000 --- a/vkpr/postgres/remove/src/main.bat +++ /dev/null @@ -1,3 +0,0 @@ -@echo off - -call windows\formula\formula.bat runFormula diff --git a/vkpr/postgres/remove/src/main.sh b/vkpr/postgres/remove/src/main.sh index 736f5ce4..cf647088 100755 --- a/vkpr/postgres/remove/src/main.sh +++ b/vkpr/postgres/remove/src/main.sh @@ -1,5 +1,11 @@ #!/bin/bash +VKPR_SCRIPTS=~/.vkpr/src + +source $VKPR_SCRIPTS/log.sh +source $VKPR_SCRIPTS/var.sh +source $VKPR_SCRIPTS/helper.sh + # shellcheck source=/dev/null . "$(dirname "$0")"/unix/formula/formula.sh --source-only diff --git a/vkpr/template/config/src/main.bat b/vkpr/template/config/src/main.bat deleted file mode 100755 index 4100614f..00000000 --- a/vkpr/template/config/src/main.bat +++ /dev/null @@ -1,3 +0,0 @@ -@echo off - -call windows\formula\formula.bat runFormula diff --git a/vkpr/template/config/src/main.sh b/vkpr/template/config/src/main.sh index 9697102d..cf647088 100755 --- a/vkpr/template/config/src/main.sh +++ b/vkpr/template/config/src/main.sh @@ -1,15 +1,10 @@ #!/bin/bash -if [ ! -d ~/.vkpr/global ]; then - echo "Doesn't initializated the vkpr... Call again the function" - rit vkpr init - exit; -fi +VKPR_SCRIPTS=~/.vkpr/src -source ~/.vkpr/global/log.sh -source ~/.vkpr/global/var.sh -source ~/.vkpr/global/helper.sh -source ~/.vkpr/global/.env +source $VKPR_SCRIPTS/log.sh +source $VKPR_SCRIPTS/var.sh +source $VKPR_SCRIPTS/helper.sh # shellcheck source=/dev/null . "$(dirname "$0")"/unix/formula/formula.sh --source-only diff --git a/vkpr/template/config/src/unix/formula/formula.sh b/vkpr/template/config/src/unix/formula/formula.sh index d3fb2e44..3b3ed109 100755 --- a/vkpr/template/config/src/unix/formula/formula.sh +++ b/vkpr/template/config/src/unix/formula/formula.sh @@ -6,5 +6,5 @@ runFormula() { } outputGlobalTemplate(){ - $VKPR_YQ eval $VKPR_GLOBALS/global-values.yaml + $VKPR_YQ eval $VKPR_HOME/global-values.yaml } diff --git a/vkpr/whoami/install/src/main.sh b/vkpr/whoami/install/src/main.sh index 9697102d..cf647088 100755 --- a/vkpr/whoami/install/src/main.sh +++ b/vkpr/whoami/install/src/main.sh @@ -1,15 +1,10 @@ #!/bin/bash -if [ ! -d ~/.vkpr/global ]; then - echo "Doesn't initializated the vkpr... Call again the function" - rit vkpr init - exit; -fi +VKPR_SCRIPTS=~/.vkpr/src -source ~/.vkpr/global/log.sh -source ~/.vkpr/global/var.sh -source ~/.vkpr/global/helper.sh -source ~/.vkpr/global/.env +source $VKPR_SCRIPTS/log.sh +source $VKPR_SCRIPTS/var.sh +source $VKPR_SCRIPTS/helper.sh # shellcheck source=/dev/null . "$(dirname "$0")"/unix/formula/formula.sh --source-only diff --git a/vkpr/whoami/remove/src/main.sh b/vkpr/whoami/remove/src/main.sh index 736f5ce4..cf647088 100755 --- a/vkpr/whoami/remove/src/main.sh +++ b/vkpr/whoami/remove/src/main.sh @@ -1,5 +1,11 @@ #!/bin/bash +VKPR_SCRIPTS=~/.vkpr/src + +source $VKPR_SCRIPTS/log.sh +source $VKPR_SCRIPTS/var.sh +source $VKPR_SCRIPTS/helper.sh + # shellcheck source=/dev/null . "$(dirname "$0")"/unix/formula/formula.sh --source-only From 9560e5080413045e61c2fc781859a0e3619f59c1 Mon Sep 17 00:00:00 2001 From: Jpeedroza Date: Thu, 9 Sep 2021 13:33:18 -0300 Subject: [PATCH 15/32] Update the function to create globals --- vkpr/init/src/unix/formula/formula.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/vkpr/init/src/unix/formula/formula.sh b/vkpr/init/src/unix/formula/formula.sh index 710a7d21..56c2e9f5 100755 --- a/vkpr/init/src/unix/formula/formula.sh +++ b/vkpr/init/src/unix/formula/formula.sh @@ -18,10 +18,12 @@ runFormula() { echo "VKPR initialization" VKPR_HOME=~/.vkpr - VKPR_GLOBALS=$VKPR_HOME/global + VKPR_SCRIPTS=$VKPR_HOME/src + mkdir -p $VKPR_HOME/bin mkdir -p $VKPR_HOME/config mkdir -p $VKPR_HOME/bats + mkdir -p $VKPR_HOME/src installArkade installTool "kubectl" @@ -60,7 +62,6 @@ installArkade() { } installGlobals() { - mkdir -p $VKPR_GLOBALS createPackagesFiles } @@ -81,10 +82,11 @@ installBats(){ } createPackagesFiles() { - touch global-values.yaml - cp $(dirname "$0")/utils/*.sh $VKPR_GLOBALS + touch $VKPR_HOME/global-values.yaml + cp $(dirname "$0")/utils/*.sh $VKPR_SCRIPTS } + echoColor() { case $1 in red) @@ -102,5 +104,7 @@ echoColor() { cyan) echo "$(printf '\033[36m')$2$(printf '\033[0m')" ;; + bold) + echo "$(printf '\033[1m')$2$(printf '\033[0m')" esac } \ No newline at end of file From f204efea78acd69538423844dacb8853be99a67b Mon Sep 17 00:00:00 2001 From: jpeedroza Date: Thu, 9 Sep 2021 14:03:23 -0300 Subject: [PATCH 16/32] Updated the config yaml --- .../install/src/utils/keycloak-db.yaml | 40 +++++++++---------- vkpr/keycloak/install/src/utils/keycloak.yaml | 33 ++++++++------- 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/vkpr/keycloak/install/src/utils/keycloak-db.yaml b/vkpr/keycloak/install/src/utils/keycloak-db.yaml index b6cfbb9e..32d38e69 100644 --- a/vkpr/keycloak/install/src/utils/keycloak-db.yaml +++ b/vkpr/keycloak/install/src/utils/keycloak-db.yaml @@ -1,28 +1,28 @@ +auth: + adminUser: "" + adminPassword: "" + managementPassword: "senha" +containerPorts: + http: 8080 + https: 8443 +service: + type: ClusterIP +ingress: + enabled: true + certManager: false + hostname: keycloak.localhost + ingressClassName: "nginx" + path: / + tls: false +rbac: + create: true postgresql: enabled: false + persistence: + enabled: false externalDatabase: host: "" port: "" user: "" password: "" database: "" -ingress: - enabled: true - annotations: - kubernetes.io/ingress.class: nginx - certManager: false - hostname: login.localhost - path: "/" - tls: true -readinessProbe: - enabled: false -rbac: - create: true -auth: - adminUser: "" - adminPassword: "" -proxyAddressForwarding: true -extraEnv: | - - name: JAVA_OPTS - value: >- - -Dkeycloak.migration.file=/realm/realm.json diff --git a/vkpr/keycloak/install/src/utils/keycloak.yaml b/vkpr/keycloak/install/src/utils/keycloak.yaml index a21135dc..934ed309 100644 --- a/vkpr/keycloak/install/src/utils/keycloak.yaml +++ b/vkpr/keycloak/install/src/utils/keycloak.yaml @@ -1,18 +1,21 @@ -ingress: - enabled: false - annotations: - kubernetes.io/ingress.class: nginx - path: "/" - tls: true -readinessProbe: - enabled: false -rbac: - create: true auth: adminUser: "" adminPassword: "" -proxyAddressForwarding: true -extraEnv: | - - name: JAVA_OPTS - value: >- - -Dkeycloak.migration.file=/realm/realm.json + managementPassword: "senha" +containerPorts: + http: 8080 + https: 8443 +service: + type: ClusterIP +ingress: + enabled: true + certManager: false + hostname: keycloak.localhost + ingressClassName: "nginx" + path: / + tls: false +rbac: + create: true +postgresql: + persistence: + enabled: false From 1138df46600b0076ba791d4935e7d8b41ea038eb Mon Sep 17 00:00:00 2001 From: jpeedroza Date: Thu, 9 Sep 2021 15:58:19 -0300 Subject: [PATCH 17/32] Created test to keycloak --- vkpr-test/keycloak-test.bats | 60 ++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 vkpr-test/keycloak-test.bats diff --git a/vkpr-test/keycloak-test.bats b/vkpr-test/keycloak-test.bats new file mode 100644 index 00000000..7da1e92e --- /dev/null +++ b/vkpr-test/keycloak-test.bats @@ -0,0 +1,60 @@ + +VKPR_HOME=~/.vkpr + +setup_file() { + load 'common-setup' + _common_setup + if [ "$VKPR_TEST_SKIP_SETUP" == "true" ]; then + echo "setup: skipping setup due to VKPR_TEST_SKIP_SETUP=true" >&3 + else + echo "setup: installing ingress...." >&3 + rit vkpr ingress install + kubectl wait --for=condition=ready --timeout=1m pod --all + echo "setup: installing keycloak...." >&3 + rit vkpr keycloak install --default + kubectl wait --for=condition=ready --timeout=1m pod --all + sleep 2 + fi +} + +setup() { + load $VKPR_HOME/bats/bats-support/load.bash + load $VKPR_HOME/bats/bats-assert/load.bash +} + +@test "Check if keycloak is up" { + run curlKeycloak + actual="${lines[3]}" + trim "$actual" + actual="$TRIMMED" + expected='"realm":"master"' + assert_equal "$actual" "$expected" +} + +teardown_file() { + if [ "$VKPR_TEST_SKIP_TEARDOWN" == "true" ]; then + echo "teardown: skipping teardown due to VKPR_TEST_SKIP_TEARDOWN=true" >&3 + else + echo "teardown: uninstalling ingress...." >&3 + rit vkpr keycloak remove + sleep 5 + rit vkpr ingress remove + sleep 5 + rit vkpr infra down + sleep 5 + fi +} + +curlKeycloak(){ + content=$(curl -H "Host: keycloak.localhost" http://127.0.0.1:8000/auth/realms/master) + echo ${content:1:16} +} + +trim() { + local var="$*" + # remove leading whitespace characters + var="${var#"${var%%[![:space:]]*}"}" + # remove trailing whitespace characters + var="${var%"${var##*[![:space:]]}"}" + TRIMMED="$var" +} \ No newline at end of file From d04f3c1583b443921003fe1e4935ee20893e70aa Mon Sep 17 00:00:00 2001 From: Andre Fernandes Date: Thu, 9 Sep 2021 16:16:56 -0300 Subject: [PATCH 18/32] novas formulas de cert-manager (do e custom-acme) --- .../install/custom-acme/README.md | 13 +++++ .../install/{ => custom-acme}/build.sh | 6 ++- .../install/{ => custom-acme}/config.json | 5 -- .../install/custom-acme/metadata.json | 18 +++++++ .../install/custom-acme/set_umask.sh | 3 ++ .../install/custom-acme/src/main.sh | 9 ++++ .../custom-acme/src/unix/formula/formula.sh | 52 +++++++++++++++++++ .../custom-acme/src/utils/cert-manager.yaml | 15 ++++++ .../custom-acme/src/utils/issuers.yaml | 15 ++++++ vkpr/cert-manager/install/{ => do}/README.md | 2 +- vkpr/cert-manager/install/do/build.sh | 15 ++++++ vkpr/cert-manager/install/do/config.json | 34 ++++++++++++ vkpr/cert-manager/install/do/help.json | 4 ++ .../install/{ => do}/metadata.json | 5 +- vkpr/cert-manager/install/do/set_umask.sh | 3 ++ .../cert-manager/install/{ => do}/src/main.sh | 16 +++--- .../{ => do}/src/unix/formula/formula.sh | 3 +- .../do/src/utils/cert-manager-custom-ca.yaml | 15 ++++++ .../{ => do}/src/utils/cert-manager.yaml | 0 .../install/{ => do}/src/utils/issuers.yaml | 0 .../install/{ => do}/src/utils/token-dns.yaml | 0 .../remove/src/unix/formula/formula.sh | 4 +- 22 files changed, 216 insertions(+), 21 deletions(-) create mode 100755 vkpr/cert-manager/install/custom-acme/README.md rename vkpr/cert-manager/install/{ => custom-acme}/build.sh (76%) rename vkpr/cert-manager/install/{ => custom-acme}/config.json (77%) create mode 100755 vkpr/cert-manager/install/custom-acme/metadata.json create mode 100755 vkpr/cert-manager/install/custom-acme/set_umask.sh create mode 100755 vkpr/cert-manager/install/custom-acme/src/main.sh create mode 100755 vkpr/cert-manager/install/custom-acme/src/unix/formula/formula.sh create mode 100644 vkpr/cert-manager/install/custom-acme/src/utils/cert-manager.yaml create mode 100755 vkpr/cert-manager/install/custom-acme/src/utils/issuers.yaml rename vkpr/cert-manager/install/{ => do}/README.md (74%) create mode 100755 vkpr/cert-manager/install/do/build.sh create mode 100755 vkpr/cert-manager/install/do/config.json create mode 100644 vkpr/cert-manager/install/do/help.json rename vkpr/cert-manager/install/{ => do}/metadata.json (86%) create mode 100755 vkpr/cert-manager/install/do/set_umask.sh rename vkpr/cert-manager/install/{ => do}/src/main.sh (60%) rename vkpr/cert-manager/install/{ => do}/src/unix/formula/formula.sh (96%) create mode 100644 vkpr/cert-manager/install/do/src/utils/cert-manager-custom-ca.yaml rename vkpr/cert-manager/install/{ => do}/src/utils/cert-manager.yaml (100%) rename vkpr/cert-manager/install/{ => do}/src/utils/issuers.yaml (100%) rename vkpr/cert-manager/install/{ => do}/src/utils/token-dns.yaml (100%) diff --git a/vkpr/cert-manager/install/custom-acme/README.md b/vkpr/cert-manager/install/custom-acme/README.md new file mode 100755 index 00000000..ca91539f --- /dev/null +++ b/vkpr/cert-manager/install/custom-acme/README.md @@ -0,0 +1,13 @@ +# Description + +Formula description + +## Command + +```bash +rit vkpr cert-manager install custom-acme +``` + +## Requirements + +## Demonstration diff --git a/vkpr/cert-manager/install/build.sh b/vkpr/cert-manager/install/custom-acme/build.sh similarity index 76% rename from vkpr/cert-manager/install/build.sh rename to vkpr/cert-manager/install/custom-acme/build.sh index cfabf0a0..e0c86872 100755 --- a/vkpr/cert-manager/install/build.sh +++ b/vkpr/cert-manager/install/custom-acme/build.sh @@ -8,4 +8,8 @@ ENTRY_POINT_UNIX=main.sh mkdir -p $BIN_FOLDER cp -r src/* $BIN_FOLDER mv $BIN_FOLDER/$ENTRY_POINT_UNIX $BIN_FOLDER/$BINARY_NAME_UNIX - chmod +x $BIN_FOLDER/$BINARY_NAME_UNIX \ No newline at end of file + chmod +x $BIN_FOLDER/$BINARY_NAME_UNIX + +#bat-build: + +#docker: diff --git a/vkpr/cert-manager/install/config.json b/vkpr/cert-manager/install/custom-acme/config.json similarity index 77% rename from vkpr/cert-manager/install/config.json rename to vkpr/cert-manager/install/custom-acme/config.json index 7bea1f28..b069508b 100755 --- a/vkpr/cert-manager/install/config.json +++ b/vkpr/cert-manager/install/custom-acme/config.json @@ -11,11 +11,6 @@ "qty": 2, "newLabel": "Type other email: " } - }, - { - "name": "token", - "required": true, - "type": "CREDENTIAL_DIGITALOCEAN_TOKEN" } ], "template": "shell-bat", diff --git a/vkpr/cert-manager/install/custom-acme/metadata.json b/vkpr/cert-manager/install/custom-acme/metadata.json new file mode 100755 index 00000000..0f05be18 --- /dev/null +++ b/vkpr/cert-manager/install/custom-acme/metadata.json @@ -0,0 +1,18 @@ +{ + "execution": [ + "local" + ], + "os": { + "deps": [], + "support": [ + "mac", + "linux" + ] + }, + "tags": [ + "vkpr", + "cert-manager", + "install", + "custom-acme" + ] +} diff --git a/vkpr/cert-manager/install/custom-acme/set_umask.sh b/vkpr/cert-manager/install/custom-acme/set_umask.sh new file mode 100755 index 00000000..091c13d6 --- /dev/null +++ b/vkpr/cert-manager/install/custom-acme/set_umask.sh @@ -0,0 +1,3 @@ +#!/bin/sh +umask 0011 +$1 diff --git a/vkpr/cert-manager/install/custom-acme/src/main.sh b/vkpr/cert-manager/install/custom-acme/src/main.sh new file mode 100755 index 00000000..add369f0 --- /dev/null +++ b/vkpr/cert-manager/install/custom-acme/src/main.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# shellcheck source=/dev/null +. "$(dirname "$0")"/unix/formula/formula.sh --source-only + +source ~/.vkpr/global/log.sh +source ~/.vkpr/global/var.sh + +runFormula diff --git a/vkpr/cert-manager/install/custom-acme/src/unix/formula/formula.sh b/vkpr/cert-manager/install/custom-acme/src/unix/formula/formula.sh new file mode 100755 index 00000000..35fcea4d --- /dev/null +++ b/vkpr/cert-manager/install/custom-acme/src/unix/formula/formula.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +runFormula() { + VKPR_CERT_VERSION="v1.5.3" + + VKPR_CERT_VALUES=$VKPR_HOME/values/cert-manager.yaml + VKPR_CERT_ISSUER=$(dirname "$0")/utils/issuers.yaml + VKPR_INPUT_EMAIL="$EMAIL" + + mkdir -p $VKPR_HOME/values/cert-manager/ + + install_crds + add_repo_certmanager + install_certmanager + add_issuer +} + +install_crds() { + echoColor "yellow" "Installing cert-manager CRDS beforehand..." + $VKPR_KUBECTL apply -f "https://github.com/jetstack/cert-manager/releases/download/$VKPR_CERT_VERSION/cert-manager.crds.yaml" +} + +add_repo_certmanager() { + $VKPR_HELM repo add jetstack https://charts.jetstack.io + $VKPR_HELM repo update +} + +install_certmanager() { + echoColor "yellow" "Installing cert-manager..." + get_cert_values + # namespace cert-manager mandatory + $VKPR_HELM upgrade -i -f $VKPR_CERT_VALUES \ + -n cert-manager --create-namespace \ + --version "$VKPR_CERT_VERSION" \ + cert-manager jetstack/cert-manager +} + +get_cert_values() { + # checking local values + if [ ! -f "$VKPR_CERT_VALUES" ]; then + VKPR_CERT_VALUES=$(dirname "$0")/utils/cert-manager.yaml + echoColor "yellow" "Reading cert-manager values from formula default file" + else + echoColor "green" "Reading cert-manager values from project local file '.vkpr/values/cert-manager.yaml'" + fi +} + +add_issuer() { + echoColor "yellow" "Installing Issuers and/or ClusterIssuers..." + $VKPR_YQ eval '.spec.acme.email = strenv(VKPR_INPUT_EMAIL)' "$VKPR_CERT_ISSUER" \ + | $VKPR_KUBECTL apply -f - +} diff --git a/vkpr/cert-manager/install/custom-acme/src/utils/cert-manager.yaml b/vkpr/cert-manager/install/custom-acme/src/utils/cert-manager.yaml new file mode 100644 index 00000000..ba0224c7 --- /dev/null +++ b/vkpr/cert-manager/install/custom-acme/src/utils/cert-manager.yaml @@ -0,0 +1,15 @@ +installCRDs: false +ingressShim: + defaultIssuerName: stepissuer + defaultIssuerKind: ClusterIssuer + defaultIssuerGroup: cert-manager.io +prometheus: + enabled: false +volumes: + - name: custom-ca + secret: + secretName: custom-ca-secret +volumeMounts: + - name: custom-ca + mountPath: "/etc/ssl/certs" + readOnly: true diff --git a/vkpr/cert-manager/install/custom-acme/src/utils/issuers.yaml b/vkpr/cert-manager/install/custom-acme/src/utils/issuers.yaml new file mode 100755 index 00000000..00d52932 --- /dev/null +++ b/vkpr/cert-manager/install/custom-acme/src/utils/issuers.yaml @@ -0,0 +1,15 @@ +apiVersion: cert-manager.io/v1 +kind: ClusterIssuer +metadata: + name: stepissuer + namespace: cert-manager +spec: + acme: + email: user@example.com + server: https://host.k3d.internal:9000/acme/acme/directory + privateKeySecretRef: + name: stepissuer-key + solvers: + - http01: + ingress: + class: nginx diff --git a/vkpr/cert-manager/install/README.md b/vkpr/cert-manager/install/do/README.md similarity index 74% rename from vkpr/cert-manager/install/README.md rename to vkpr/cert-manager/install/do/README.md index 84322983..5c4240aa 100755 --- a/vkpr/cert-manager/install/README.md +++ b/vkpr/cert-manager/install/do/README.md @@ -5,7 +5,7 @@ Formula description ## Command ```bash -rit vkpr cert-manager install +rit vkpr cert-manager install do ``` ## Requirements diff --git a/vkpr/cert-manager/install/do/build.sh b/vkpr/cert-manager/install/do/build.sh new file mode 100755 index 00000000..e0c86872 --- /dev/null +++ b/vkpr/cert-manager/install/do/build.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +BIN_FOLDER=bin +BINARY_NAME_UNIX=run.sh +ENTRY_POINT_UNIX=main.sh + +#bash-build: + mkdir -p $BIN_FOLDER + cp -r src/* $BIN_FOLDER + mv $BIN_FOLDER/$ENTRY_POINT_UNIX $BIN_FOLDER/$BINARY_NAME_UNIX + chmod +x $BIN_FOLDER/$BINARY_NAME_UNIX + +#bat-build: + +#docker: diff --git a/vkpr/cert-manager/install/do/config.json b/vkpr/cert-manager/install/do/config.json new file mode 100755 index 00000000..116abbbe --- /dev/null +++ b/vkpr/cert-manager/install/do/config.json @@ -0,0 +1,34 @@ +{ + "inputs": [ + { + "label": "Type your email to use to generate certificates:", + "name": "email", + "required": true, + "tutorial": "@", + "type": "text", + "cache": { + "active": true, + "qty": 2, + "newLabel": "Type other email: " + } + }, + { + "default": "letsencrypt-staging", + "items": [ + "letsencrypt-staging", + "letsencrypt-production" + ], + "label": "What is the default cluster issuer? ", + "name": "issuer", + "required": true, + "type": "text" + }, + { + "name": "token", + "required": true, + "type": "CREDENTIAL_DIGITALOCEAN_TOKEN" + } + ], + "template": "shell-bat", + "templateRelease:": "2.16.2" +} \ No newline at end of file diff --git a/vkpr/cert-manager/install/do/help.json b/vkpr/cert-manager/install/do/help.json new file mode 100644 index 00000000..5070b594 --- /dev/null +++ b/vkpr/cert-manager/install/do/help.json @@ -0,0 +1,4 @@ +{ + "short": "Install cert-manager", + "long": "Install the cert-manager in the Kubernetes cluster." +} \ No newline at end of file diff --git a/vkpr/cert-manager/install/metadata.json b/vkpr/cert-manager/install/do/metadata.json similarity index 86% rename from vkpr/cert-manager/install/metadata.json rename to vkpr/cert-manager/install/do/metadata.json index b0fa888c..327e084d 100755 --- a/vkpr/cert-manager/install/metadata.json +++ b/vkpr/cert-manager/install/do/metadata.json @@ -12,6 +12,7 @@ "tags": [ "vkpr", "cert-manager", - "install" + "install", + "do" ] -} \ No newline at end of file +} diff --git a/vkpr/cert-manager/install/do/set_umask.sh b/vkpr/cert-manager/install/do/set_umask.sh new file mode 100755 index 00000000..091c13d6 --- /dev/null +++ b/vkpr/cert-manager/install/do/set_umask.sh @@ -0,0 +1,3 @@ +#!/bin/sh +umask 0011 +$1 diff --git a/vkpr/cert-manager/install/src/main.sh b/vkpr/cert-manager/install/do/src/main.sh similarity index 60% rename from vkpr/cert-manager/install/src/main.sh rename to vkpr/cert-manager/install/do/src/main.sh index 24e26cf6..87512597 100755 --- a/vkpr/cert-manager/install/src/main.sh +++ b/vkpr/cert-manager/install/do/src/main.sh @@ -1,17 +1,15 @@ #!/bin/bash -if [ ! -d ~/.vkpr/global ]; then - echo "Doesn't initializated the vkpr... Call again the function" - rit vkpr init - exit; -fi +# shellcheck source=/dev/null +. "$(dirname "$0")"/unix/formula/formula.sh --source-only source ~/.vkpr/global/log.sh source ~/.vkpr/global/var.sh -source ~/.vkpr/global/.env -source ~/.vkpr/global/helper.sh -# shellcheck source=/dev/null -. "$(dirname "$0")"/unix/formula/formula.sh --source-only +# TODO: detectar se já fez init +if [ ! -d ~/.vkpr/global ]; then + echo "Din't initialize the vkpr cli. Please run `vkpr init`" + exit; +fi runFormula diff --git a/vkpr/cert-manager/install/src/unix/formula/formula.sh b/vkpr/cert-manager/install/do/src/unix/formula/formula.sh similarity index 96% rename from vkpr/cert-manager/install/src/unix/formula/formula.sh rename to vkpr/cert-manager/install/do/src/unix/formula/formula.sh index 2f75c6f8..51fd4800 100755 --- a/vkpr/cert-manager/install/src/unix/formula/formula.sh +++ b/vkpr/cert-manager/install/do/src/unix/formula/formula.sh @@ -1,7 +1,7 @@ #!/bin/sh runFormula() { - VKPR_CERT_VERSION="v1.5.0" + VKPR_CERT_VERSION="v1.5.3" VKPR_CERT_VALUES=$VKPR_HOME/values/cert-manager.yaml VKPR_CERT_ISSUER=$(dirname "$0")/utils/issuers.yaml @@ -34,6 +34,7 @@ install_certmanager() { # namespace cert-manager mandatory $VKPR_HELM upgrade -i -f $VKPR_CERT_VALUES \ -n cert-manager --create-namespace \ + --set ingressShim.defaultIssuerName="$ISSUER" \ --version "$VKPR_CERT_VERSION" \ cert-manager jetstack/cert-manager } diff --git a/vkpr/cert-manager/install/do/src/utils/cert-manager-custom-ca.yaml b/vkpr/cert-manager/install/do/src/utils/cert-manager-custom-ca.yaml new file mode 100644 index 00000000..ba0224c7 --- /dev/null +++ b/vkpr/cert-manager/install/do/src/utils/cert-manager-custom-ca.yaml @@ -0,0 +1,15 @@ +installCRDs: false +ingressShim: + defaultIssuerName: stepissuer + defaultIssuerKind: ClusterIssuer + defaultIssuerGroup: cert-manager.io +prometheus: + enabled: false +volumes: + - name: custom-ca + secret: + secretName: custom-ca-secret +volumeMounts: + - name: custom-ca + mountPath: "/etc/ssl/certs" + readOnly: true diff --git a/vkpr/cert-manager/install/src/utils/cert-manager.yaml b/vkpr/cert-manager/install/do/src/utils/cert-manager.yaml similarity index 100% rename from vkpr/cert-manager/install/src/utils/cert-manager.yaml rename to vkpr/cert-manager/install/do/src/utils/cert-manager.yaml diff --git a/vkpr/cert-manager/install/src/utils/issuers.yaml b/vkpr/cert-manager/install/do/src/utils/issuers.yaml similarity index 100% rename from vkpr/cert-manager/install/src/utils/issuers.yaml rename to vkpr/cert-manager/install/do/src/utils/issuers.yaml diff --git a/vkpr/cert-manager/install/src/utils/token-dns.yaml b/vkpr/cert-manager/install/do/src/utils/token-dns.yaml similarity index 100% rename from vkpr/cert-manager/install/src/utils/token-dns.yaml rename to vkpr/cert-manager/install/do/src/utils/token-dns.yaml diff --git a/vkpr/cert-manager/remove/src/unix/formula/formula.sh b/vkpr/cert-manager/remove/src/unix/formula/formula.sh index 1a1e6bb1..33738609 100755 --- a/vkpr/cert-manager/remove/src/unix/formula/formula.sh +++ b/vkpr/cert-manager/remove/src/unix/formula/formula.sh @@ -3,7 +3,7 @@ runFormula() { echoColor "yellow" "Removing cert-manager..." rm -rf $VKPR_HOME/configs/cert-manager/ $VKPR_HOME/values/cert-manager/ - $VKPR_KUBECTL delete clusterissuer letsencrypt-staging + #$VKPR_KUBECTL delete clusterissuer letsencrypt-staging $VKPR_HELM uninstall cert-manager -n cert-manager - $VKPR_KUBECTL delete ns cert-manager + #$VKPR_KUBECTL delete ns cert-manager } From 8d8e5422de21cce33dd8e2e797649ecfe0c83ef2 Mon Sep 17 00:00:00 2001 From: Jpeedroza Date: Fri, 10 Sep 2021 11:40:16 -0300 Subject: [PATCH 19/32] Merged test branches --- vkpr-test/postgres.bats | 41 +++++++++++++++++++++++++++++++++ vkpr-test/whoami.bats | 50 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 vkpr-test/postgres.bats create mode 100644 vkpr-test/whoami.bats diff --git a/vkpr-test/postgres.bats b/vkpr-test/postgres.bats new file mode 100644 index 00000000..99098417 --- /dev/null +++ b/vkpr-test/postgres.bats @@ -0,0 +1,41 @@ + +VKPR_HOME=~/.vkpr + +setup_file() { + load 'common-setup' + _common_setup + if [ "$VKPR_TEST_SKIP_SETUP" == "true" ]; then + echo "setup: skipping setup due to VKPR_TEST_SKIP_SETUP=true" >&3 + else + echo "setup: installing postgres...." >&3 + rit vkpr postgres install + kubectl wait --for=condition=ready --timeout=1m pod --all + sleep 2 + fi +} + +setup() { + load $VKPR_HOME/bats/bats-support/load.bash + load $VKPR_HOME/bats/bats-assert/load.bash +} + +@test "Ping in DB and must show if is accepting connections" { + run ping_db + actual="${lines[0]}" + expected="postgres-postgresql:5432 - accepting connections" + assert_equal "$actual" "$expected" +} + +teardown_file() { + if [ "$VKPR_TEST_SKIP_TEARDOWN" == "true" ]; then + echo "teardown: skipping teardown due to VKPR_TEST_SKIP_TEARDOWN=true" >&3 + else + echo "teardown: uninstalling postgres...." >&3 + rit vkpr postgres remove + rit vkpr infra down + fi +} + +ping_db(){ + $VKPR_HOME/bin/kubectl run test-db --rm -it --restart='Never' --image docker.io/bitnami/postgresql:11.13.0-debian-10-r12 --env="PGUSER=postgres" --env="PGPASSWORD=123" --env="PGHOST=postgres-postgresql" --env="PGPORT=5432" --command -- pg_isready +} \ No newline at end of file diff --git a/vkpr-test/whoami.bats b/vkpr-test/whoami.bats new file mode 100644 index 00000000..d62425c5 --- /dev/null +++ b/vkpr-test/whoami.bats @@ -0,0 +1,50 @@ + +VKPR_HOME=~/.vkpr + +setup_file() { + load 'common-setup' + _common_setup + if [ "$VKPR_TEST_SKIP_SETUP" == "true" ]; then + echo "setup: skipping setup due to VKPR_TEST_SKIP_SETUP=true" >&3 + else + echo "setup: installing ingress...." >&3 + rit vkpr ingress install + kubectl wait --for=condition=ready --timeout=1m pod --all + echo "setup: installing whoami...." >&3 + rit vkpr whoami install --default + kubectl wait --for=condition=ready --timeout=1m pod --all + sleep 20 + fi +} + +setup() { + load $VKPR_HOME/bats/bats-support/load.bash + load $VKPR_HOME/bats/bats-assert/load.bash +} + +@test "Curl to Whoami and must return Hostname" { + run curlWhoami + actual="${lines[3]}" + expected=$(podName) + assert_equal "$actual" "$expected" +} + +teardown_file() { + if [ "$VKPR_TEST_SKIP_TEARDOWN" == "true" ]; then + echo "teardown: skipping teardown due to VKPR_TEST_SKIP_TEARDOWN=true" >&3 + else + echo "teardown: uninstalling ingress...." >&3 + rit vkpr ingress remove + rit vkpr infra down + fi +} + +podName(){ + local pod=$($VKPR_HOME/bin/kubectl get po -o name | grep whoami | cut -d "/" -f 2) + echo "Hostname: ${pod}" +} + +curlWhoami(){ + curl -k -H "Host: whoami.localhost" https://127.0.0.1:8001 | sed 's/<\/*[^>]*>//g' + sleep 5 +} \ No newline at end of file From f92bb0acd255ebf5ce4e96ce7d6de9ef389bcaa7 Mon Sep 17 00:00:00 2001 From: Jpeedroza Date: Fri, 10 Sep 2021 15:28:29 -0300 Subject: [PATCH 20/32] Whoami refactored code and formula documentation update --- vkpr/whoami/install/README.md | 45 ++++++++++++++++--- .../install/src/unix/formula/formula.sh | 7 +-- vkpr/whoami/install/src/utils/whoami.yaml | 4 +- vkpr/whoami/remove/README.md | 12 +++-- vkpr/whoami/remove/build.sh | 2 - .../whoami/remove/src/unix/formula/formula.sh | 31 +++---------- 6 files changed, 57 insertions(+), 44 deletions(-) diff --git a/vkpr/whoami/install/README.md b/vkpr/whoami/install/README.md index 4b91f82e..a82308d0 100755 --- a/vkpr/whoami/install/README.md +++ b/vkpr/whoami/install/README.md @@ -1,13 +1,48 @@ # Description -Formula description +Install whoami into cluster. Uses [whoami](https://artifacthub.io/packages/helm/cowboysysop/whoami) Helm chart. -## Command +## Commands + +Interactive inputs: + +```bash +vkpr whoami install +``` + +Non-interactive: + +```bash +vkpr whoami install --domain="whoami.localhost" \ + --secure=false +``` + +Non-interactive without setting values: + +```bash +vkpr whoami install --default +``` + +## Parameters ```bash -rit vkpr whoami install + --domain= Define the domain of whoami. Default: whoami.localhost + --secure= Define https on the whoami. Default: false + --default= Set all values with default. +``` + +## Globals File Parameters + +```yaml +global: + whoami: + domain: + secure: ``` -## Requirements +### Content installed on the Cluster -## Demonstration +- Deployment +- Service +- Ingress +- Secret (certificate) diff --git a/vkpr/whoami/install/src/unix/formula/formula.sh b/vkpr/whoami/install/src/unix/formula/formula.sh index d5ac3c3f..9821ef0b 100755 --- a/vkpr/whoami/install/src/unix/formula/formula.sh +++ b/vkpr/whoami/install/src/unix/formula/formula.sh @@ -3,7 +3,8 @@ runFormula() { VKPR_WHOAMI_VALUES=$(dirname "$0")/utils/whoami.yaml - verifyExistingEnv 'SECURE' "${SECURE}" 'DOMAIN' "${DOMAIN}" + checkGlobalConfig $DOMAIN "whoami.localhost" "whoami.domain" "WHOAMI_DOMAIN" + checkGlobalConfig $SECURE "false" "whoami.secure" "WHOAMI_SECURE" # Unused Variable TODO: See if is secure and then enable the cert-manager and TLS addRepoWhoami installWhoami } @@ -15,6 +16,6 @@ addRepoWhoami(){ installWhoami(){ echoColor "yellow" "Installing whoami..." - $VKPR_YQ eval '.ingress.hosts[0].host = "'$VKPR_ENV_DOMAIN'" | .ingress.tls[0].hosts[0] = "'$VKPR_ENV_DOMAIN'"' "$VKPR_WHOAMI_VALUES" \ - | $VKPR_HELM upgrade -i -f - whoami cowboysysop/whoami + $VKPR_YQ eval '.ingress.hosts[0].host = "'$VKPR_ENV_WHOAMI_DOMAIN'" | .ingress.tls[0].hosts[0] = "'$VKPR_ENV_WHOAMI_DOMAIN'"' "$VKPR_WHOAMI_VALUES" \ + | $VKPR_HELM upgrade -i -f - vkpr-whoami cowboysysop/whoami } \ No newline at end of file diff --git a/vkpr/whoami/install/src/utils/whoami.yaml b/vkpr/whoami/install/src/utils/whoami.yaml index e0ab3960..0eb982af 100644 --- a/vkpr/whoami/install/src/utils/whoami.yaml +++ b/vkpr/whoami/install/src/utils/whoami.yaml @@ -4,10 +4,10 @@ ingress: kubernetes.io/ingress.class: nginx kubernetes.io/tls-acme: "true" hosts: - - host: domain + - host: "" paths: ["/"] pathType: Prefix tls: - hosts: - - domain + - "" secretName: whoami-cert diff --git a/vkpr/whoami/remove/README.md b/vkpr/whoami/remove/README.md index 3d34af7e..5666c5d3 100755 --- a/vkpr/whoami/remove/README.md +++ b/vkpr/whoami/remove/README.md @@ -1,13 +1,11 @@ # Description -Formula description +Uninstall all the contet of whoami from the cluster. -## Command +## Commands + +Non-interactive: ```bash -rit vkpr whoami remove +vkpr whoami remove ``` - -## Requirements - -## Demonstration diff --git a/vkpr/whoami/remove/build.sh b/vkpr/whoami/remove/build.sh index 341574b7..cfabf0a0 100755 --- a/vkpr/whoami/remove/build.sh +++ b/vkpr/whoami/remove/build.sh @@ -2,9 +2,7 @@ BIN_FOLDER=bin BINARY_NAME_UNIX=run.sh -#BINARY_NAME_WINDOWS=run.bat ENTRY_POINT_UNIX=main.sh -#ENTRY_POINT_WINDOWS=main.bat #bash-build: mkdir -p $BIN_FOLDER diff --git a/vkpr/whoami/remove/src/unix/formula/formula.sh b/vkpr/whoami/remove/src/unix/formula/formula.sh index e355e18b..cacfa5d6 100755 --- a/vkpr/whoami/remove/src/unix/formula/formula.sh +++ b/vkpr/whoami/remove/src/unix/formula/formula.sh @@ -1,33 +1,14 @@ #!/bin/sh runFormula() { - VKPR_HOME=~/.vkpr - uninstallWhoami } uninstallWhoami(){ echoColor "yellow" "Removendo Whoami..." - $VKPR_HOME/bin/helm uninstall whoami - $VKPR_HOME/bin/kubectl delete secret whoami-cert -} - -echoColor() { - case $1 in - red) - echo "$(printf '\033[31m')$2$(printf '\033[0m')" - ;; - green) - echo "$(printf '\033[32m')$2$(printf '\033[0m')" - ;; - yellow) - echo "$(printf '\033[33m')$2$(printf '\033[0m')" - ;; - blue) - echo "$(printf '\033[34m')$2$(printf '\033[0m')" - ;; - cyan) - echo "$(printf '\033[36m')$2$(printf '\033[0m')" - ;; - esac -} + $VKPR_HELM uninstall vkpr-whoami + EXISTING_CERT=$($VKPR_KUBECTL get secret/vkpr-whoami-cert -o name --ignore-not-found | cut -d "/" -f2) + if [[ $EXISTING_CERT = "vkpr-whoami-cert" ]]; then + $VKPR_KUBECTL delete secret vkpr-whoami-cert + fi +} \ No newline at end of file From 8516a60046436f9c3cacfbdf826c4bfc0464a4c0 Mon Sep 17 00:00:00 2001 From: Jpeedroza Date: Fri, 10 Sep 2021 15:28:53 -0300 Subject: [PATCH 21/32] Template refactored code and formula documentation update --- vkpr/template/config/README.md | 12 +++++------- vkpr/template/config/build.sh | 4 ---- vkpr/template/config/config.json | 3 +-- vkpr/template/config/set_umask.sh | 3 --- vkpr/template/config/src/unix/formula/formula.sh | 6 +++++- 5 files changed, 11 insertions(+), 17 deletions(-) delete mode 100755 vkpr/template/config/set_umask.sh diff --git a/vkpr/template/config/README.md b/vkpr/template/config/README.md index 15d02cf2..5f8ad7cf 100755 --- a/vkpr/template/config/README.md +++ b/vkpr/template/config/README.md @@ -1,13 +1,11 @@ # Description -Formula description +Show the values setted on the global-values. -## Command +## Commands + +Non-interactive: ```bash -rit vkpr template config +vkpr template config ``` - -## Requirements - -## Demonstration diff --git a/vkpr/template/config/build.sh b/vkpr/template/config/build.sh index e0c86872..3f067481 100755 --- a/vkpr/template/config/build.sh +++ b/vkpr/template/config/build.sh @@ -9,7 +9,3 @@ ENTRY_POINT_UNIX=main.sh cp -r src/* $BIN_FOLDER mv $BIN_FOLDER/$ENTRY_POINT_UNIX $BIN_FOLDER/$BINARY_NAME_UNIX chmod +x $BIN_FOLDER/$BINARY_NAME_UNIX - -#bat-build: - -#docker: diff --git a/vkpr/template/config/config.json b/vkpr/template/config/config.json index c3d6c6c2..257f1ebe 100755 --- a/vkpr/template/config/config.json +++ b/vkpr/template/config/config.json @@ -1,6 +1,5 @@ { - "dockerImageBuilder": "ritclizup/rit-shell-bat-builder", "inputs": [], "template": "shell-bat", "templateRelease:": "2.16.2" -} +} \ No newline at end of file diff --git a/vkpr/template/config/set_umask.sh b/vkpr/template/config/set_umask.sh deleted file mode 100755 index 091c13d6..00000000 --- a/vkpr/template/config/set_umask.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -umask 0011 -$1 diff --git a/vkpr/template/config/src/unix/formula/formula.sh b/vkpr/template/config/src/unix/formula/formula.sh index 3b3ed109..e88229d2 100755 --- a/vkpr/template/config/src/unix/formula/formula.sh +++ b/vkpr/template/config/src/unix/formula/formula.sh @@ -6,5 +6,9 @@ runFormula() { } outputGlobalTemplate(){ - $VKPR_YQ eval $VKPR_HOME/global-values.yaml + if [[ ! -s $VKPR_GLOBAL ]]; then + echoColor "red" "Doesnt have any values in global config file." + else + $VKPR_YQ eval $VKPR_GLOBAL + fi } From e6686498cc60c9ea356b79fc1cab9ef43eb53f03 Mon Sep 17 00:00:00 2001 From: Jpeedroza Date: Fri, 10 Sep 2021 15:29:14 -0300 Subject: [PATCH 22/32] Postgres refactored code and formula documentation update --- vkpr/postgres/install/README.md | 22 ++++++++++--- vkpr/postgres/install/build.sh | 6 +--- vkpr/postgres/install/config.json | 3 +- vkpr/postgres/install/metadata.json | 2 +- vkpr/postgres/install/set_umask.sh | 3 -- .../install/src/unix/formula/formula.sh | 27 ++-------------- vkpr/postgres/remove/README.md | 12 +++---- vkpr/postgres/remove/build.sh | 6 +--- vkpr/postgres/remove/config.json | 3 +- vkpr/postgres/remove/set_umask.sh | 3 -- .../remove/src/unix/formula/formula.sh | 32 +++---------------- 11 files changed, 33 insertions(+), 86 deletions(-) delete mode 100755 vkpr/postgres/install/set_umask.sh delete mode 100755 vkpr/postgres/remove/set_umask.sh diff --git a/vkpr/postgres/install/README.md b/vkpr/postgres/install/README.md index 4c6bfe34..af7a7775 100755 --- a/vkpr/postgres/install/README.md +++ b/vkpr/postgres/install/README.md @@ -1,13 +1,25 @@ # Description -Formula description +Install Postgres into cluster. Uses [postgresql](https://artifacthub.io/packages/helm/bitnami/postgresql) Helm chart. -## Command +## Commands + +Interactive input: + +```bash +vkpr postgres install +``` + +Non-interactive: ```bash -rit vkpr postgres install +rit set credential --provider="postgres" --fields="password" --values="" +vkpr postgres install ``` -## Requirements +### Content installed on the Cluster -## Demonstration +- Statefulset +- Service +- Secret +- PV and PVC diff --git a/vkpr/postgres/install/build.sh b/vkpr/postgres/install/build.sh index e0c86872..cfabf0a0 100755 --- a/vkpr/postgres/install/build.sh +++ b/vkpr/postgres/install/build.sh @@ -8,8 +8,4 @@ ENTRY_POINT_UNIX=main.sh mkdir -p $BIN_FOLDER cp -r src/* $BIN_FOLDER mv $BIN_FOLDER/$ENTRY_POINT_UNIX $BIN_FOLDER/$BINARY_NAME_UNIX - chmod +x $BIN_FOLDER/$BINARY_NAME_UNIX - -#bat-build: - -#docker: + chmod +x $BIN_FOLDER/$BINARY_NAME_UNIX \ No newline at end of file diff --git a/vkpr/postgres/install/config.json b/vkpr/postgres/install/config.json index 8031960a..12a31fb5 100755 --- a/vkpr/postgres/install/config.json +++ b/vkpr/postgres/install/config.json @@ -1,5 +1,4 @@ { - "dockerImageBuilder": "ritclizup/rit-shell-bat-builder", "inputs": [ { "name": "password", @@ -8,4 +7,4 @@ ], "template": "shell-bat", "templateRelease:": "2.16.2" -} +} \ No newline at end of file diff --git a/vkpr/postgres/install/metadata.json b/vkpr/postgres/install/metadata.json index 2f65cdef..1201cdd2 100755 --- a/vkpr/postgres/install/metadata.json +++ b/vkpr/postgres/install/metadata.json @@ -14,4 +14,4 @@ "postgres", "install" ] -} +} \ No newline at end of file diff --git a/vkpr/postgres/install/set_umask.sh b/vkpr/postgres/install/set_umask.sh deleted file mode 100755 index 091c13d6..00000000 --- a/vkpr/postgres/install/set_umask.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -umask 0011 -$1 diff --git a/vkpr/postgres/install/src/unix/formula/formula.sh b/vkpr/postgres/install/src/unix/formula/formula.sh index bb7bf63a..1024d5e0 100755 --- a/vkpr/postgres/install/src/unix/formula/formula.sh +++ b/vkpr/postgres/install/src/unix/formula/formula.sh @@ -1,13 +1,10 @@ #!/bin/sh runFormula() { - VKPR_HOME=~/.vkpr - VKPR_HELM=$VKPR_HOME/bin/helm VKPR_POSTGRES_VALUES=$(dirname "$0")/utils/postgres.yaml addRepoPostgres installPostgres - } addRepoPostgres(){ @@ -17,25 +14,5 @@ addRepoPostgres(){ installPostgres(){ echoColor "yellow" "Installing postgres..." - $VKPR_HELM upgrade -i --set global.postgresql.postgresqlPassword=$PASSWORD postgres bitnami/postgresql -} - -echoColor() { - case $1 in - red) - echo "$(printf '\033[31m')$2$(printf '\033[0m')" - ;; - green) - echo "$(printf '\033[32m')$2$(printf '\033[0m')" - ;; - yellow) - echo "$(printf '\033[33m')$2$(printf '\033[0m')" - ;; - blue) - echo "$(printf '\033[34m')$2$(printf '\033[0m')" - ;; - cyan) - echo "$(printf '\033[36m')$2$(printf '\033[0m')" - ;; - esac -} + $VKPR_HELM upgrade -i --set global.postgresql.postgresqlPassword=$PASSWORD vkpr-postgres bitnami/postgresql +} \ No newline at end of file diff --git a/vkpr/postgres/remove/README.md b/vkpr/postgres/remove/README.md index f3c18fa3..a56c15ca 100755 --- a/vkpr/postgres/remove/README.md +++ b/vkpr/postgres/remove/README.md @@ -1,13 +1,11 @@ # Description -Formula description +Uninstall all the contet of Postgres from the cluster. -## Command +## Commands + +Non-interactive: ```bash -rit vkpr postgres remove +vkpr postgres remove ``` - -## Requirements - -## Demonstration diff --git a/vkpr/postgres/remove/build.sh b/vkpr/postgres/remove/build.sh index e0c86872..cfabf0a0 100755 --- a/vkpr/postgres/remove/build.sh +++ b/vkpr/postgres/remove/build.sh @@ -8,8 +8,4 @@ ENTRY_POINT_UNIX=main.sh mkdir -p $BIN_FOLDER cp -r src/* $BIN_FOLDER mv $BIN_FOLDER/$ENTRY_POINT_UNIX $BIN_FOLDER/$BINARY_NAME_UNIX - chmod +x $BIN_FOLDER/$BINARY_NAME_UNIX - -#bat-build: - -#docker: + chmod +x $BIN_FOLDER/$BINARY_NAME_UNIX \ No newline at end of file diff --git a/vkpr/postgres/remove/config.json b/vkpr/postgres/remove/config.json index c3d6c6c2..257f1ebe 100755 --- a/vkpr/postgres/remove/config.json +++ b/vkpr/postgres/remove/config.json @@ -1,6 +1,5 @@ { - "dockerImageBuilder": "ritclizup/rit-shell-bat-builder", "inputs": [], "template": "shell-bat", "templateRelease:": "2.16.2" -} +} \ No newline at end of file diff --git a/vkpr/postgres/remove/set_umask.sh b/vkpr/postgres/remove/set_umask.sh deleted file mode 100755 index 091c13d6..00000000 --- a/vkpr/postgres/remove/set_umask.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -umask 0011 -$1 diff --git a/vkpr/postgres/remove/src/unix/formula/formula.sh b/vkpr/postgres/remove/src/unix/formula/formula.sh index 322eecac..a7429f83 100755 --- a/vkpr/postgres/remove/src/unix/formula/formula.sh +++ b/vkpr/postgres/remove/src/unix/formula/formula.sh @@ -1,40 +1,16 @@ #!/bin/sh runFormula() { - VKPR_HOME=~/.vkpr - VKPR_HELM=$VKPR_HOME/bin/helm - removePostgres removePVC - } removePostgres(){ echoColor "green" "Removing Postgres..." - $VKPR_HELM uninstall postgres + $VKPR_HELM uninstall vkpr-postgres } removePVC(){ - echoColor "green" "Removing PVC..." - kubectl delete pvc -l app.kubernetes.io/instance=postgres -} - -echoColor() { - case $1 in - red) - echo "$(printf '\033[31m')$2$(printf '\033[0m')" - ;; - green) - echo "$(printf '\033[32m')$2$(printf '\033[0m')" - ;; - yellow) - echo "$(printf '\033[33m')$2$(printf '\033[0m')" - ;; - blue) - echo "$(printf '\033[34m')$2$(printf '\033[0m')" - ;; - cyan) - echo "$(printf '\033[36m')$2$(printf '\033[0m')" - ;; - esac -} + echoColor "green" "Removing PVC..." + $VKPR_KUBECTL delete pvc -l app.kubernetes.io/instance=vkpr-postgres +} \ No newline at end of file From 4143ef9e7080b38b0e7b625ca2171b810051c2eb Mon Sep 17 00:00:00 2001 From: Jpeedroza Date: Fri, 10 Sep 2021 15:29:36 -0300 Subject: [PATCH 23/32] Keycloak refactored code and formula documentation update --- vkpr/keycloak/install/README.md | 65 +++++++++++++++++-- .../install/src/unix/formula/formula.sh | 12 ++-- vkpr/keycloak/remove/README.md | 12 ++-- .../remove/src/unix/formula/formula.sh | 2 +- 4 files changed, 72 insertions(+), 19 deletions(-) diff --git a/vkpr/keycloak/install/README.md b/vkpr/keycloak/install/README.md index cdbb929b..3c1ac3d1 100755 --- a/vkpr/keycloak/install/README.md +++ b/vkpr/keycloak/install/README.md @@ -1,6 +1,61 @@ -# Globals file +# Description -.global.keycloak.domain -.global.keycloak.secure -.global.keycloak.admin_user -.global.keycloak.admin_password +Install keycloak into cluster. Uses [keycloak](https://artifacthub.io/packages/helm/bitnami/keycloak) Helm chart. + +## Commands + +Interactive inputs: + +```bash +vkpr keycloak install +``` + +Non-interactive: + +```bash +vkpr keycloak install --domain="keycloak.localhost" \ + --secure=false \ + --admin_user="admin" \ + --admin_password="vkpr123" +``` + +Non-interactive without setting values: + +```bash +vkpr keycloak install --default +``` + +## Parameters + +```bash + --domain= Define the domain of whoami. Default: keycloak.localhost + --secure= Define https on the keycloak. Default: false + --admin_user= Define RBAC Admin user on the keycloak. Default: admin + --admin_password= Define RBAC Admin password keycloak. Default: vkpr123 + --default= Set all values with default. +``` + +**Note:** Require credential of Password Postgres to create the postgres + +## Globals File Parameters + +```yaml +global: + keycloak: + domain: + secure: + admin_user: + admin_password: +``` + +### Content installed on the Cluster + +- Statefulset +- Service +- Ingress +- Secret (certificate) +- ConfigMap +- Job +- Role +- RoleBinding +- ServiceAccount diff --git a/vkpr/keycloak/install/src/unix/formula/formula.sh b/vkpr/keycloak/install/src/unix/formula/formula.sh index 3689b450..061159bd 100755 --- a/vkpr/keycloak/install/src/unix/formula/formula.sh +++ b/vkpr/keycloak/install/src/unix/formula/formula.sh @@ -21,10 +21,10 @@ addRepoKeycloak(){ } verifyExistingPostgres(){ - EXISTING_POSTGRES=$($VKPR_KUBECTL get po/postgres-postgresql-0 -o name --ignore-not-found | cut -d "/" -f2) - if [[ $EXISTING_POSTGRES = "postgres-postgresql-0" ]]; then - POSTGRES=$($VKPR_KUBECTL wait --for=condition=Ready po/postgres-postgresql-0 -o name | cut -d "/" -f2) - if [[ $POSTGRES = "postgres-postgresql-0" ]]; then + EXISTING_POSTGRES=$($VKPR_KUBECTL get po/vkpr-postgres-postgresql-0 -o name --ignore-not-found | cut -d "/" -f2) + if [[ $EXISTING_POSTGRES = "vkpr-postgres-postgresql-0" ]]; then + POSTGRES=$($VKPR_KUBECTL wait --for=condition=Ready po/vkpr-postgres-postgresql-0 -o name | cut -d "/" -f2) + if [[ $POSTGRES = "vkpr-postgres-postgresql-0" ]]; then echo "true" return fi @@ -36,7 +36,7 @@ settingKeycloak(){ $VKPR_YQ eval '.ingress.hosts[0].host = "'$VKPR_ENV_KEYCLOAK_DOMAIN'" | .ingress.tls[0].hosts[0] = "'$VKPR_ENV_KEYCLOAK_DOMAIN'" | .auth.adminUser = "'$VKPR_ENV_KEYCLOAK_ADMIN_USER'" | .auth.adminPassword = "'$VKPR_ENV_KEYCLOAK_ADMIN_PASSWORD'"' "$VKPR_KEYCLOAK_YAML" \ - | $VKPR_HELM upgrade -i -f - keycloak bitnami/keycloak + | $VKPR_HELM upgrade -i -f - vkpr-keycloak bitnami/keycloak } settingKeycloakDB(){ @@ -45,7 +45,7 @@ settingKeycloakDB(){ .externalDatabase.user = "'$PG_USER'" | .externalDatabase.password = "'$PG_PASSWORD'" | .externalDatabase.database = "'$PG_DATABASE_NAME'" | .auth.adminUser = "'$VKPR_ENV_KEYCLOAK_ADMIN_USER'" | .auth.adminPassword = "'$VKPR_ENV_KEYCLOAK_ADMIN_PASSWORD'"' "$VKPR_KEYCLOAK_YAML" \ - | $VKPR_HELM upgrade -i -f - keycloak bitnami/keycloak + | $VKPR_HELM upgrade -i -f - vkpr-keycloak bitnami/keycloak } installKeycloak(){ diff --git a/vkpr/keycloak/remove/README.md b/vkpr/keycloak/remove/README.md index d698d195..78dd5e68 100644 --- a/vkpr/keycloak/remove/README.md +++ b/vkpr/keycloak/remove/README.md @@ -1,13 +1,11 @@ # Description -Formula description +Uninstall all the contet of Keycloak from the cluster. -## Command +## Commands + +Non-interactive: ```bash -rit vkpr keycloak remove +vkpr keycloak remove ``` - -## Requirements - -## Demonstration diff --git a/vkpr/keycloak/remove/src/unix/formula/formula.sh b/vkpr/keycloak/remove/src/unix/formula/formula.sh index ebaf6883..3f554bff 100755 --- a/vkpr/keycloak/remove/src/unix/formula/formula.sh +++ b/vkpr/keycloak/remove/src/unix/formula/formula.sh @@ -2,5 +2,5 @@ runFormula() { echoColor "green" "Removing keycloak..." - $VKPR_HELM uninstall keycloak + $VKPR_HELM uninstall vkpr-keycloak } \ No newline at end of file From 35b6e640e0cc59a874198ef17cda725e97bb3381 Mon Sep 17 00:00:00 2001 From: Jpeedroza Date: Fri, 10 Sep 2021 15:29:47 -0300 Subject: [PATCH 24/32] Init refactored code and formula documentation update --- vkpr/init/README.md | 15 +++++---------- vkpr/init/build.sh | 10 +--------- vkpr/init/config.json | 3 +-- vkpr/init/metadata.json | 5 +++-- vkpr/init/src/utils/global-values.yaml | 2 -- 5 files changed, 10 insertions(+), 25 deletions(-) diff --git a/vkpr/init/README.md b/vkpr/init/README.md index ba9b96ea..65402bef 100755 --- a/vkpr/init/README.md +++ b/vkpr/init/README.md @@ -1,16 +1,11 @@ # Description -Formula description +Initializate all necessary tools to run the VKPR. -## Command +## Commands + +Non-interactive: ```bash -rit vkpr init +vkpr init ``` - -## Requirements - -None. - -## Demonstration - diff --git a/vkpr/init/build.sh b/vkpr/init/build.sh index 4f5571d0..cfabf0a0 100755 --- a/vkpr/init/build.sh +++ b/vkpr/init/build.sh @@ -2,18 +2,10 @@ BIN_FOLDER=bin BINARY_NAME_UNIX=run.sh -#BINARY_NAME_WINDOWS=run.bat ENTRY_POINT_UNIX=main.sh -#ENTRY_POINT_WINDOWS=main.bat #bash-build: mkdir -p $BIN_FOLDER cp -r src/* $BIN_FOLDER mv $BIN_FOLDER/$ENTRY_POINT_UNIX $BIN_FOLDER/$BINARY_NAME_UNIX - chmod +x $BIN_FOLDER/$BINARY_NAME_UNIX - -#bat-build: -# mv $BIN_FOLDER/$ENTRY_POINT_WINDOWS $BIN_FOLDER/$BINARY_NAME_WINDOWS - -#docker: -# cp Dockerfile set_umask.sh $BIN_FOLDER + chmod +x $BIN_FOLDER/$BINARY_NAME_UNIX \ No newline at end of file diff --git a/vkpr/init/config.json b/vkpr/init/config.json index 67926700..1de9a971 100755 --- a/vkpr/init/config.json +++ b/vkpr/init/config.json @@ -1,6 +1,5 @@ { - "dockerImageBuilder": "ritclizup/rit-shell-bat-builder", "inputs": [], "template": "shell-bat", "templateRelease:": "2.16.1" -} +} \ No newline at end of file diff --git a/vkpr/init/metadata.json b/vkpr/init/metadata.json index ee99c903..9ca544c1 100755 --- a/vkpr/init/metadata.json +++ b/vkpr/init/metadata.json @@ -10,6 +10,7 @@ ] }, "tags": [ - "vkpr", "init" + "vkpr", + "init" ] -} +} \ No newline at end of file diff --git a/vkpr/init/src/utils/global-values.yaml b/vkpr/init/src/utils/global-values.yaml index eb24a5dc..e69de29b 100644 --- a/vkpr/init/src/utils/global-values.yaml +++ b/vkpr/init/src/utils/global-values.yaml @@ -1,2 +0,0 @@ -global: - domain: vkpr-dev.vertigo.com.br \ No newline at end of file From b6958315b4a95fe277784d3b63d35a49b2c75923 Mon Sep 17 00:00:00 2001 From: Jpeedroza Date: Fri, 10 Sep 2021 15:30:06 -0300 Subject: [PATCH 25/32] Ingress refactored code and formula documentation update --- vkpr/ingress/install/README.md | 20 ++++++++++++------- vkpr/ingress/install/config.json | 3 +-- vkpr/ingress/install/metadata.json | 6 ++++-- vkpr/ingress/install/set_umask.sh | 3 --- .../install/src/unix/formula/formula.sh | 2 +- vkpr/ingress/remove/README.md | 12 +++++------ vkpr/ingress/remove/config.json | 3 +-- vkpr/ingress/remove/metadata.json | 6 ++++-- vkpr/ingress/remove/set_umask.sh | 3 --- 9 files changed, 29 insertions(+), 29 deletions(-) delete mode 100755 vkpr/ingress/install/set_umask.sh delete mode 100755 vkpr/ingress/remove/set_umask.sh diff --git a/vkpr/ingress/install/README.md b/vkpr/ingress/install/README.md index a6c01191..aacca424 100755 --- a/vkpr/ingress/install/README.md +++ b/vkpr/ingress/install/README.md @@ -1,10 +1,6 @@ # Description -Install ingress controller into cluster. Uses [ingress-nginx](https://artifacthub.io/packages/helm/ingress-nginx/ingress-nginx) Helm chart. - -Requires these global definitions: - -- domain +Install nginx-ingress controller into cluster. Uses [ingress-nginx](https://artifacthub.io/packages/helm/ingress-nginx/ingress-nginx) Helm chart. ## Command @@ -12,6 +8,16 @@ Requires these global definitions: rit vkpr ingress install ``` -## Requirements +### Content installed on the Cluster -## Demonstration +- Deployment +- Service +- Daemonset +- Secret (certificate) +- ConfigMap +- Job +- ClusterRole +- Role +- RoleBinding +- ServiceAccount +- ValidatingWebhookConfiguration diff --git a/vkpr/ingress/install/config.json b/vkpr/ingress/install/config.json index c3d6c6c2..257f1ebe 100755 --- a/vkpr/ingress/install/config.json +++ b/vkpr/ingress/install/config.json @@ -1,6 +1,5 @@ { - "dockerImageBuilder": "ritclizup/rit-shell-bat-builder", "inputs": [], "template": "shell-bat", "templateRelease:": "2.16.2" -} +} \ No newline at end of file diff --git a/vkpr/ingress/install/metadata.json b/vkpr/ingress/install/metadata.json index bced356b..db5546f2 100755 --- a/vkpr/ingress/install/metadata.json +++ b/vkpr/ingress/install/metadata.json @@ -10,6 +10,8 @@ ] }, "tags": [ - "vkpr", "ingress", "install" + "vkpr", + "ingress", + "install" ] -} +} \ No newline at end of file diff --git a/vkpr/ingress/install/set_umask.sh b/vkpr/ingress/install/set_umask.sh deleted file mode 100755 index 091c13d6..00000000 --- a/vkpr/ingress/install/set_umask.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -umask 0011 -$1 diff --git a/vkpr/ingress/install/src/unix/formula/formula.sh b/vkpr/ingress/install/src/unix/formula/formula.sh index 014c02e3..f6385d3f 100755 --- a/vkpr/ingress/install/src/unix/formula/formula.sh +++ b/vkpr/ingress/install/src/unix/formula/formula.sh @@ -2,5 +2,5 @@ runFormula() { echo "VKPR Ingress install" - $VKPR_HOME/bin/arkade install ingress-nginx + $VKPR_ARKADE install ingress-nginx } diff --git a/vkpr/ingress/remove/README.md b/vkpr/ingress/remove/README.md index 058d7780..252878e5 100755 --- a/vkpr/ingress/remove/README.md +++ b/vkpr/ingress/remove/README.md @@ -1,13 +1,11 @@ # Description -Formula description +Uninstall all the contet of nginx-ingress controller from the cluster. -## Command +## Commands + +Non-interactive: ```bash -rit vkpr ingress remove +vkpr ingress remove ``` - -## Requirements - -## Demonstration diff --git a/vkpr/ingress/remove/config.json b/vkpr/ingress/remove/config.json index c3d6c6c2..257f1ebe 100755 --- a/vkpr/ingress/remove/config.json +++ b/vkpr/ingress/remove/config.json @@ -1,6 +1,5 @@ { - "dockerImageBuilder": "ritclizup/rit-shell-bat-builder", "inputs": [], "template": "shell-bat", "templateRelease:": "2.16.2" -} +} \ No newline at end of file diff --git a/vkpr/ingress/remove/metadata.json b/vkpr/ingress/remove/metadata.json index 5c101857..9e4d1a42 100755 --- a/vkpr/ingress/remove/metadata.json +++ b/vkpr/ingress/remove/metadata.json @@ -11,6 +11,8 @@ ] }, "tags": [ - "vkpr", "ingress", "remove" + "vkpr", + "ingress", + "remove" ] -} +} \ No newline at end of file diff --git a/vkpr/ingress/remove/set_umask.sh b/vkpr/ingress/remove/set_umask.sh deleted file mode 100755 index 091c13d6..00000000 --- a/vkpr/ingress/remove/set_umask.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -umask 0011 -$1 From 0b03acd2140b37eb7c01cc652e1b64b9279d2194 Mon Sep 17 00:00:00 2001 From: Jpeedroza Date: Fri, 10 Sep 2021 15:30:20 -0300 Subject: [PATCH 26/32] Infra refactored code and formula documentation update --- vkpr/infra/down/README.md | 12 +++++------ vkpr/infra/down/config.json | 3 +-- vkpr/infra/down/metadata.json | 6 ++++-- vkpr/infra/down/set_umask.sh | 3 --- vkpr/infra/down/src/unix/formula/formula.sh | 2 +- vkpr/infra/up/README.md | 13 +++++++----- vkpr/infra/up/build.sh | 10 +--------- vkpr/infra/up/config.json | 3 +-- vkpr/infra/up/metadata.json | 6 ++++-- vkpr/infra/up/set_umask.sh | 3 --- vkpr/infra/up/src/unix/formula/formula.sh | 22 +++++++++++---------- 11 files changed, 37 insertions(+), 46 deletions(-) delete mode 100755 vkpr/infra/down/set_umask.sh delete mode 100755 vkpr/infra/up/set_umask.sh diff --git a/vkpr/infra/down/README.md b/vkpr/infra/down/README.md index 83079fba..52d0c0df 100755 --- a/vkpr/infra/down/README.md +++ b/vkpr/infra/down/README.md @@ -1,13 +1,11 @@ # Description -Formula description +Drop all the cluster. -## Command +## Commands + +Non-interactive: ```bash -rit vkpr infra down +vkpr infra down ``` - -## Requirements - -## Demonstration diff --git a/vkpr/infra/down/config.json b/vkpr/infra/down/config.json index c3d6c6c2..257f1ebe 100755 --- a/vkpr/infra/down/config.json +++ b/vkpr/infra/down/config.json @@ -1,6 +1,5 @@ { - "dockerImageBuilder": "ritclizup/rit-shell-bat-builder", "inputs": [], "template": "shell-bat", "templateRelease:": "2.16.2" -} +} \ No newline at end of file diff --git a/vkpr/infra/down/metadata.json b/vkpr/infra/down/metadata.json index a70d96dc..7477114d 100755 --- a/vkpr/infra/down/metadata.json +++ b/vkpr/infra/down/metadata.json @@ -10,6 +10,8 @@ ] }, "tags": [ - "vkpr", "infra", "down" + "vkpr", + "infra", + "down" ] -} +} \ No newline at end of file diff --git a/vkpr/infra/down/set_umask.sh b/vkpr/infra/down/set_umask.sh deleted file mode 100755 index 091c13d6..00000000 --- a/vkpr/infra/down/set_umask.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -umask 0011 -$1 diff --git a/vkpr/infra/down/src/unix/formula/formula.sh b/vkpr/infra/down/src/unix/formula/formula.sh index 11af07ec..64c1c986 100755 --- a/vkpr/infra/down/src/unix/formula/formula.sh +++ b/vkpr/infra/down/src/unix/formula/formula.sh @@ -8,7 +8,7 @@ runFormula() { stopCluster() { # local registry - if $(k3d cluster list | grep -q "vkpr-local"); then + if $($VKPR_K3D cluster list | grep -q "vkpr-local"); then $VKPR_K3D cluster delete vkpr-local else echoColor "red" "Cluster vkpr-local not running, skipping." diff --git a/vkpr/infra/up/README.md b/vkpr/infra/up/README.md index ff298468..21bca46b 100755 --- a/vkpr/infra/up/README.md +++ b/vkpr/infra/up/README.md @@ -1,13 +1,16 @@ # Description -Formula description +Create a k3d cluster to test the applications. -## Command +## Commands + +Non-interactive: ```bash -rit vkpr infra up +vkpr infra up ``` -## Requirements +### Ports -## Demonstration +- 8000: http +- 8001: https diff --git a/vkpr/infra/up/build.sh b/vkpr/infra/up/build.sh index 4f5571d0..cfabf0a0 100755 --- a/vkpr/infra/up/build.sh +++ b/vkpr/infra/up/build.sh @@ -2,18 +2,10 @@ BIN_FOLDER=bin BINARY_NAME_UNIX=run.sh -#BINARY_NAME_WINDOWS=run.bat ENTRY_POINT_UNIX=main.sh -#ENTRY_POINT_WINDOWS=main.bat #bash-build: mkdir -p $BIN_FOLDER cp -r src/* $BIN_FOLDER mv $BIN_FOLDER/$ENTRY_POINT_UNIX $BIN_FOLDER/$BINARY_NAME_UNIX - chmod +x $BIN_FOLDER/$BINARY_NAME_UNIX - -#bat-build: -# mv $BIN_FOLDER/$ENTRY_POINT_WINDOWS $BIN_FOLDER/$BINARY_NAME_WINDOWS - -#docker: -# cp Dockerfile set_umask.sh $BIN_FOLDER + chmod +x $BIN_FOLDER/$BINARY_NAME_UNIX \ No newline at end of file diff --git a/vkpr/infra/up/config.json b/vkpr/infra/up/config.json index c3d6c6c2..257f1ebe 100755 --- a/vkpr/infra/up/config.json +++ b/vkpr/infra/up/config.json @@ -1,6 +1,5 @@ { - "dockerImageBuilder": "ritclizup/rit-shell-bat-builder", "inputs": [], "template": "shell-bat", "templateRelease:": "2.16.2" -} +} \ No newline at end of file diff --git a/vkpr/infra/up/metadata.json b/vkpr/infra/up/metadata.json index 5b106e3a..14fccb10 100755 --- a/vkpr/infra/up/metadata.json +++ b/vkpr/infra/up/metadata.json @@ -10,6 +10,8 @@ ] }, "tags": [ - "vkpr", "infra", "up" + "vkpr", + "infra", + "up" ] -} +} \ No newline at end of file diff --git a/vkpr/infra/up/set_umask.sh b/vkpr/infra/up/set_umask.sh deleted file mode 100755 index 091c13d6..00000000 --- a/vkpr/infra/up/set_umask.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -umask 0011 -$1 diff --git a/vkpr/infra/up/src/unix/formula/formula.sh b/vkpr/infra/up/src/unix/formula/formula.sh index 5b2ac28f..2849d11c 100755 --- a/vkpr/infra/up/src/unix/formula/formula.sh +++ b/vkpr/infra/up/src/unix/formula/formula.sh @@ -11,6 +11,8 @@ runFormula() { echoColor "yellow" "Volumes used:" echo "Two local unamed docker volumes" + VKPR_CONFIG_REGISTRY=$VKPR_HOME/config/registry.yaml + # TODO: test dependencies # VKPR home is "~/.vkpr" @@ -24,7 +26,7 @@ runFormula() { configRegistry() { #HOST_IP="172.17.0.1" # linux native HOST_IP="host.k3d.internal" - cat > $VKPR_HOME/config/registry.yaml << EOF + cat > $VKPR_CONFIG_REGISTRY << EOF mirrors: "docker.io": endpoint: @@ -34,31 +36,31 @@ EOF startCluster() { # local registry - if ! $(k3d cluster list | grep -q "vkpr-local"); then - k3d cluster create vkpr-local \ + if ! $($VKPR_K3D cluster list | grep -q "vkpr-local"); then + $VKPR_K3D cluster create vkpr-local \ -p "8000:80@loadbalancer" \ -p "8001:443@loadbalancer" \ --k3s-server-arg '--no-deploy=traefik' \ --registry-use k3d-registry.localhost \ - --registry-config $VKPR_HOME/config/registry.yaml + --registry-config $VKPR_CONFIG_REGISTRY else echoColor "yellow" "Cluster vkpr-local already started, skipping." fi # use cluster - $VKPR_HOME/bin/kubectl config use-context k3d-vkpr-local - $VKPR_HOME/bin/kubectl cluster-info + $VKPR_KUBECTL config use-context k3d-vkpr-local + $VKPR_KUBECTL cluster-info } startRegistry() { # local registry - if ! $(k3d registry list | grep -q "k3d-registry\.localhost"); then - k3d registry create registry.localhost -p 5000 + if ! $($VKPR_K3D registry list | grep -q "k3d-registry\.localhost"); then + $VKPR_K3D registry create registry.localhost -p 5000 else echoColor "yellow" "Registry already started, skipping." fi # docker hub mirror - if ! $(k3d registry list | grep -q "k3d-mirror\.localhost"); then - k3d registry create mirror.localhost -i vertigo/registry-mirror -p 5001 + if ! $($VKPR_K3D registry list | grep -q "k3d-mirror\.localhost"); then + $VKPR_K3D registry create mirror.localhost -i vertigo/registry-mirror -p 5001 else echoColor "yellow" "Mirror already started, skipping." fi From b6840de61e1bddb24ea351ada791837ba0bcaaee Mon Sep 17 00:00:00 2001 From: Jpeedroza Date: Fri, 10 Sep 2021 15:30:35 -0300 Subject: [PATCH 27/32] External-dns refactored code and formula documentation update --- vkpr/external-dns/install/README.md | 46 +++++++++++++++++-- vkpr/external-dns/install/set_umask.sh | 3 -- .../install/src/unix/formula/formula.sh | 2 +- vkpr/external-dns/remove/README.md | 12 ++--- vkpr/external-dns/remove/config.json | 3 +- vkpr/external-dns/remove/metadata.json | 6 ++- vkpr/external-dns/remove/set_umask.sh | 3 -- .../remove/src/unix/formula/formula.sh | 3 +- 8 files changed, 53 insertions(+), 25 deletions(-) delete mode 100644 vkpr/external-dns/install/set_umask.sh delete mode 100755 vkpr/external-dns/remove/set_umask.sh diff --git a/vkpr/external-dns/install/README.md b/vkpr/external-dns/install/README.md index 68b1eb53..727319ca 100644 --- a/vkpr/external-dns/install/README.md +++ b/vkpr/external-dns/install/README.md @@ -1,13 +1,49 @@ # Description -Formula description +Install external-dns into cluster. Uses [external-dns](https://artifacthub.io/packages/helm/bitnami/external-dns) Helm chart. -## Command +## Commands + +Interactive inputs: + +```bash +vkpr external-dns install +``` + +Non-interactive: + +```bash +rit set credential --provider="digitalocean" --fields="token" --values="" +vkpr external-dns install --provider="digitalocean" +``` + +Non-interactive without setting values: + +```bash +vkpr external-dns install --default +``` + +## Parameters ```bash -rit vkpr external-dns install + --provider= Define the provider from external-dns. Default: digitalocean + --default= Set all values with default. +``` + +## Globals File Parameters + +```yaml +global: + external-dns: + provider: ``` -## Requirements +### Content installed on the Cluster -## Demonstration +- Deployment +- Service +- Secret (certificate) +- Job +- ServiceAccount +- ClusterRole +- ClusterRoleBinding diff --git a/vkpr/external-dns/install/set_umask.sh b/vkpr/external-dns/install/set_umask.sh deleted file mode 100644 index 091c13d6..00000000 --- a/vkpr/external-dns/install/set_umask.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -umask 0011 -$1 diff --git a/vkpr/external-dns/install/src/unix/formula/formula.sh b/vkpr/external-dns/install/src/unix/formula/formula.sh index 2bd17d0f..a5b1400d 100755 --- a/vkpr/external-dns/install/src/unix/formula/formula.sh +++ b/vkpr/external-dns/install/src/unix/formula/formula.sh @@ -18,7 +18,7 @@ add_repo_external_dns() { } install_external_dns() { - $VKPR_HOME/bin/helm upgrade -i vkpr -f $VKPR_EXTERNAL_DNS_VALUES bitnami/external-dns + $VKPR_HOME/bin/helm upgrade -i vkpr-external-dns -f $VKPR_EXTERNAL_DNS_VALUES bitnami/external-dns } get_credentials() { diff --git a/vkpr/external-dns/remove/README.md b/vkpr/external-dns/remove/README.md index 68b1eb53..7b082fa0 100755 --- a/vkpr/external-dns/remove/README.md +++ b/vkpr/external-dns/remove/README.md @@ -1,13 +1,11 @@ # Description -Formula description +Uninstall all the contet of external-dns from the cluster. -## Command +## Commands + +Non-interactive: ```bash -rit vkpr external-dns install +vkpr external-dns remove ``` - -## Requirements - -## Demonstration diff --git a/vkpr/external-dns/remove/config.json b/vkpr/external-dns/remove/config.json index c3d6c6c2..257f1ebe 100755 --- a/vkpr/external-dns/remove/config.json +++ b/vkpr/external-dns/remove/config.json @@ -1,6 +1,5 @@ { - "dockerImageBuilder": "ritclizup/rit-shell-bat-builder", "inputs": [], "template": "shell-bat", "templateRelease:": "2.16.2" -} +} \ No newline at end of file diff --git a/vkpr/external-dns/remove/metadata.json b/vkpr/external-dns/remove/metadata.json index 89a145bb..1ff70eaa 100755 --- a/vkpr/external-dns/remove/metadata.json +++ b/vkpr/external-dns/remove/metadata.json @@ -11,6 +11,8 @@ ] }, "tags": [ - "vkpr", "external-dns", "install" + "vkpr", + "external-dns", + "install" ] -} +} \ No newline at end of file diff --git a/vkpr/external-dns/remove/set_umask.sh b/vkpr/external-dns/remove/set_umask.sh deleted file mode 100755 index 091c13d6..00000000 --- a/vkpr/external-dns/remove/set_umask.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -umask 0011 -$1 diff --git a/vkpr/external-dns/remove/src/unix/formula/formula.sh b/vkpr/external-dns/remove/src/unix/formula/formula.sh index c6c2a288..3b88bd21 100755 --- a/vkpr/external-dns/remove/src/unix/formula/formula.sh +++ b/vkpr/external-dns/remove/src/unix/formula/formula.sh @@ -2,6 +2,5 @@ runFormula() { echoColor "yellow" "Removendo external-dns..." - rm -rf $VKPR_HOME/values/external-dns - helm delete vkpr + $VKPR_HELM uninstall vkpr-external-dns } From 429b0a578166bfacb65a3b865d4d574ec8128e89 Mon Sep 17 00:00:00 2001 From: Jpeedroza Date: Fri, 10 Sep 2021 15:30:55 -0300 Subject: [PATCH 28/32] Create Formula refactored code and formula documentation update --- vkpr/create/formula/README.md | 7 +------ vkpr/create/formula/config.json | 3 +-- vkpr/create/formula/metadata.json | 6 ++++-- vkpr/create/formula/set_umask.sh | 3 --- vkpr/create/formula/src/unix/formula/formula.sh | 3 +++ 5 files changed, 9 insertions(+), 13 deletions(-) delete mode 100755 vkpr/create/formula/set_umask.sh diff --git a/vkpr/create/formula/README.md b/vkpr/create/formula/README.md index 248d36a4..549280e1 100755 --- a/vkpr/create/formula/README.md +++ b/vkpr/create/formula/README.md @@ -7,6 +7,7 @@ Files/folders removed: - build.bat - Dockerfile - Makefile +- set_umask.sh - src/windows/ - src/main.bat @@ -29,9 +30,3 @@ Non-interactive: ```bash vkpr create formula --vkpr_formula="vkpr object verb" ``` - - -## Requirements - -## Demonstration - diff --git a/vkpr/create/formula/config.json b/vkpr/create/formula/config.json index 6930fdda..ae8faaf1 100755 --- a/vkpr/create/formula/config.json +++ b/vkpr/create/formula/config.json @@ -1,5 +1,4 @@ { - "dockerImageBuilder": "ritclizup/rit-shell-bat-builder", "inputs": [ { "label": "Enter the new formula command (must begin with 'vkpr'): ", @@ -33,4 +32,4 @@ ], "template": "shell-bat", "templateRelease:": "2.16.2" -} +} \ No newline at end of file diff --git a/vkpr/create/formula/metadata.json b/vkpr/create/formula/metadata.json index 183c4922..44011cf7 100755 --- a/vkpr/create/formula/metadata.json +++ b/vkpr/create/formula/metadata.json @@ -10,6 +10,8 @@ ] }, "tags": [ - "vkpr", "create", "formula" + "vkpr", + "create", + "formula" ] -} +} \ No newline at end of file diff --git a/vkpr/create/formula/set_umask.sh b/vkpr/create/formula/set_umask.sh deleted file mode 100755 index 091c13d6..00000000 --- a/vkpr/create/formula/set_umask.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -umask 0011 -$1 diff --git a/vkpr/create/formula/src/unix/formula/formula.sh b/vkpr/create/formula/src/unix/formula/formula.sh index 444495a3..3b5cbb56 100755 --- a/vkpr/create/formula/src/unix/formula/formula.sh +++ b/vkpr/create/formula/src/unix/formula/formula.sh @@ -36,10 +36,13 @@ cleanupFormula() { echoColor "red" "cleanupFormula: This is not a formula path (no 'config.json' file), bailing out." exit 1 fi + # create file + touch "$formulaPath/help.json" # delete files rm -f "$formulaPath/build.bat" rm -f "$formulaPath/Dockerfile" rm -f "$formulaPath/Makefile" + rm -f "$formulaPath/set_umask.sh" rm -Rf "$formulaPath/src/windows" # change files sed -i.bak '/BINARY_NAME_WINDOWS/d' "$formulaPath/build.sh" # sao duas From e68a79a6251e6647a109d16ec3fc133223aa423b Mon Sep 17 00:00:00 2001 From: Jpeedroza Date: Fri, 10 Sep 2021 15:31:10 -0300 Subject: [PATCH 29/32] Cert-manager refactored code and formula documentation update --- vkpr/cert-manager/install/README.md | 39 ++++++++++++++++--- .../install/src/unix/formula/formula.sh | 2 +- vkpr/cert-manager/remove/README.md | 12 +++--- .../remove/src/unix/formula/formula.sh | 2 +- 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/vkpr/cert-manager/install/README.md b/vkpr/cert-manager/install/README.md index 84322983..67e70c25 100755 --- a/vkpr/cert-manager/install/README.md +++ b/vkpr/cert-manager/install/README.md @@ -1,13 +1,42 @@ # Description -Formula description +Install cert-manager into cluster. Uses [cert-manager](https://artifacthub.io/packages/helm/cert-manager/cert-manager) Helm chart. -## Command +## Commands + +Interactive inputs: + +```bash +vkpr cert-manager install +``` + +Non-interactive: + +```bash +rit set credential --provider="digitalocean" --fields="token" --values="" +vkpr cert-manager install --email="your-email@your-provider.com" +``` + +## Parameters ```bash -rit vkpr cert-manager install + --email= Define the email to use on Lets Encrypt. Default: none +``` + +## Globals File Parameters + +```yaml +global: + cert-manager: + email: ``` -## Requirements +### Content installed on the Cluster -## Demonstration +- Deployment +- Service +- Secret (certificate) +- ServiceAccount +- MutatingWebhookConfiguration +- ValidatingWebhookConfiguration +- CRDS diff --git a/vkpr/cert-manager/install/src/unix/formula/formula.sh b/vkpr/cert-manager/install/src/unix/formula/formula.sh index 2f75c6f8..7c2a1499 100755 --- a/vkpr/cert-manager/install/src/unix/formula/formula.sh +++ b/vkpr/cert-manager/install/src/unix/formula/formula.sh @@ -35,7 +35,7 @@ install_certmanager() { $VKPR_HELM upgrade -i -f $VKPR_CERT_VALUES \ -n cert-manager --create-namespace \ --version "$VKPR_CERT_VERSION" \ - cert-manager jetstack/cert-manager + vkpr-cert-manager jetstack/cert-manager } get_cert_values() { diff --git a/vkpr/cert-manager/remove/README.md b/vkpr/cert-manager/remove/README.md index 9033c37a..cc1d4375 100755 --- a/vkpr/cert-manager/remove/README.md +++ b/vkpr/cert-manager/remove/README.md @@ -1,13 +1,11 @@ # Description -Formula description +Uninstall all the content of cert-manager from the cluster. (Doesnt uninstall the crds) -## Command +## Commands + +Non-interactive: ```bash -rit vkpr cert-manager remove +vkpr cert-manager remove ``` - -## Requirements - -## Demonstration diff --git a/vkpr/cert-manager/remove/src/unix/formula/formula.sh b/vkpr/cert-manager/remove/src/unix/formula/formula.sh index 1a1e6bb1..89b5960a 100755 --- a/vkpr/cert-manager/remove/src/unix/formula/formula.sh +++ b/vkpr/cert-manager/remove/src/unix/formula/formula.sh @@ -4,6 +4,6 @@ runFormula() { echoColor "yellow" "Removing cert-manager..." rm -rf $VKPR_HOME/configs/cert-manager/ $VKPR_HOME/values/cert-manager/ $VKPR_KUBECTL delete clusterissuer letsencrypt-staging - $VKPR_HELM uninstall cert-manager -n cert-manager + $VKPR_HELM uninstall vkpr-cert-manager -n cert-manager $VKPR_KUBECTL delete ns cert-manager } From ba42af04f7f2bf35c233182215eb5f45b1358e5b Mon Sep 17 00:00:00 2001 From: Jpeedroza Date: Fri, 10 Sep 2021 15:35:41 -0300 Subject: [PATCH 30/32] AWS EKS formula documentation and helpers update --- vkpr/aws/eks/deploy/README.md | 17 ++++++++++----- vkpr/aws/eks/deploy/config.json | 1 - vkpr/aws/eks/deploy/help.json | 4 ++++ vkpr/aws/eks/deploy/src/main.sh | 13 ++++-------- vkpr/aws/eks/destroy/README.md | 12 +++++------ vkpr/aws/eks/destroy/config.json | 1 - vkpr/aws/eks/destroy/help.json | 4 ++++ vkpr/aws/eks/destroy/src/main.sh | 6 ++++++ vkpr/aws/eks/help.json | 4 ++++ vkpr/aws/eks/up/README.md | 36 +++++++++++++++++++++++++++----- vkpr/aws/eks/up/config.json | 1 - vkpr/aws/eks/up/help.json | 4 ++++ vkpr/aws/eks/up/metadata.json | 2 +- vkpr/aws/eks/up/src/main.sh | 13 ++++-------- 14 files changed, 79 insertions(+), 39 deletions(-) create mode 100644 vkpr/aws/eks/deploy/help.json create mode 100644 vkpr/aws/eks/destroy/help.json create mode 100644 vkpr/aws/eks/help.json create mode 100644 vkpr/aws/eks/up/help.json diff --git a/vkpr/aws/eks/deploy/README.md b/vkpr/aws/eks/deploy/README.md index 79368789..dfe3a995 100755 --- a/vkpr/aws/eks/deploy/README.md +++ b/vkpr/aws/eks/deploy/README.md @@ -1,13 +1,20 @@ # Description -Formula description +Create a Cluster EKS in AWS with [Gitops Terraform Module](https://gitlab.com/vkpr/terraform-aws-eks). -## Command +## Commands + +Interactive inputs: ```bash -rit vkpr aws eks deploy +vkpr aws eks deploy ``` -## Requirements +Non-interactive: + +```bash +rit set credential --fields="token,username" --provider="gitlab" --values="," +vkpr aws eks deploy +``` -## Demonstration +**Note**: If you set the credentials of gitlab in formula `vkpr aws eks up`, you dont need to set again. diff --git a/vkpr/aws/eks/deploy/config.json b/vkpr/aws/eks/deploy/config.json index cfde09aa..a9881c6c 100755 --- a/vkpr/aws/eks/deploy/config.json +++ b/vkpr/aws/eks/deploy/config.json @@ -1,5 +1,4 @@ { - "dockerImageBuilder": "ritclizup/rit-shell-bat-builder", "inputs": [ { "name": "gitlab_token", diff --git a/vkpr/aws/eks/deploy/help.json b/vkpr/aws/eks/deploy/help.json new file mode 100644 index 00000000..32769eaf --- /dev/null +++ b/vkpr/aws/eks/deploy/help.json @@ -0,0 +1,4 @@ +{ + "short": "Deploy AWS EKS with Gitops", + "long": "Deploy the AWS EKS by your Gitlab CI Pipeline. The KUBECONFIG will be in the Artifacts on the pipeline." +} \ No newline at end of file diff --git a/vkpr/aws/eks/deploy/src/main.sh b/vkpr/aws/eks/deploy/src/main.sh index 24e26cf6..cf647088 100755 --- a/vkpr/aws/eks/deploy/src/main.sh +++ b/vkpr/aws/eks/deploy/src/main.sh @@ -1,15 +1,10 @@ #!/bin/bash -if [ ! -d ~/.vkpr/global ]; then - echo "Doesn't initializated the vkpr... Call again the function" - rit vkpr init - exit; -fi +VKPR_SCRIPTS=~/.vkpr/src -source ~/.vkpr/global/log.sh -source ~/.vkpr/global/var.sh -source ~/.vkpr/global/.env -source ~/.vkpr/global/helper.sh +source $VKPR_SCRIPTS/log.sh +source $VKPR_SCRIPTS/var.sh +source $VKPR_SCRIPTS/helper.sh # shellcheck source=/dev/null . "$(dirname "$0")"/unix/formula/formula.sh --source-only diff --git a/vkpr/aws/eks/destroy/README.md b/vkpr/aws/eks/destroy/README.md index e7074f83..41a28b7b 100755 --- a/vkpr/aws/eks/destroy/README.md +++ b/vkpr/aws/eks/destroy/README.md @@ -1,13 +1,11 @@ # Description -Formula description +Destroy the EKS in AWS. -## Command +## Commands + +Non-interactive: ```bash -rit vkpr aws eks destroy +vkpr aws eks destroy ``` - -## Requirements - -## Demonstration diff --git a/vkpr/aws/eks/destroy/config.json b/vkpr/aws/eks/destroy/config.json index cfde09aa..a9881c6c 100755 --- a/vkpr/aws/eks/destroy/config.json +++ b/vkpr/aws/eks/destroy/config.json @@ -1,5 +1,4 @@ { - "dockerImageBuilder": "ritclizup/rit-shell-bat-builder", "inputs": [ { "name": "gitlab_token", diff --git a/vkpr/aws/eks/destroy/help.json b/vkpr/aws/eks/destroy/help.json new file mode 100644 index 00000000..f2eec87e --- /dev/null +++ b/vkpr/aws/eks/destroy/help.json @@ -0,0 +1,4 @@ +{ + "short": "Destroy the AWS EKS", + "long": "Destroy the AWS EKS by your Gitlab CI Pipeline." +} \ No newline at end of file diff --git a/vkpr/aws/eks/destroy/src/main.sh b/vkpr/aws/eks/destroy/src/main.sh index 736f5ce4..cf647088 100755 --- a/vkpr/aws/eks/destroy/src/main.sh +++ b/vkpr/aws/eks/destroy/src/main.sh @@ -1,5 +1,11 @@ #!/bin/bash +VKPR_SCRIPTS=~/.vkpr/src + +source $VKPR_SCRIPTS/log.sh +source $VKPR_SCRIPTS/var.sh +source $VKPR_SCRIPTS/helper.sh + # shellcheck source=/dev/null . "$(dirname "$0")"/unix/formula/formula.sh --source-only diff --git a/vkpr/aws/eks/help.json b/vkpr/aws/eks/help.json new file mode 100644 index 00000000..ede3bab7 --- /dev/null +++ b/vkpr/aws/eks/help.json @@ -0,0 +1,4 @@ +{ + "short": "Manage AWS EKS", + "long": "Amazon Elastic Kubernetes Service (Amazon EKS) gives you the flexibility to start, run, and scale Kubernetes applications in the AWS Cloud or on-premises." +} \ No newline at end of file diff --git a/vkpr/aws/eks/up/README.md b/vkpr/aws/eks/up/README.md index b77f7784..f3fce5f2 100755 --- a/vkpr/aws/eks/up/README.md +++ b/vkpr/aws/eks/up/README.md @@ -1,13 +1,39 @@ # Description -Formula description +Fork the project from [Gitops EKS](https://gitlab.com/vkpr/aws-eks) and run the pipeline to build the terraform config. -## Command +## Commands + +Interactive inputs: ```bash -rit vkpr aws eks up +vkpr aws eks up ``` -## Requirements +Non-interactive: + +```bash +rit set credential --fields="accesskeyid,secretaccesskey" --provider="aws" --values="," +rit set credential --fields="token,username" --provider="gitlab" --values="," +vkpr aws eks up --aws_region="us-east-1" +``` + +```bash +vkpr aws eks up --default +``` -## Demonstration +## Parameters + +```bash + --aws_region= Define the region to create the EKS. Default: us-east-1 + --default= Set all values with default. +``` + +## Globals File Parameters + +```yaml +global: + aws: + eks: + aws_region: +``` diff --git a/vkpr/aws/eks/up/config.json b/vkpr/aws/eks/up/config.json index df9345a5..7bf24fd5 100755 --- a/vkpr/aws/eks/up/config.json +++ b/vkpr/aws/eks/up/config.json @@ -1,5 +1,4 @@ { - "dockerImageBuilder": "ritclizup/rit-shell-bat-builder", "inputs": [ { "name": "aws_access_key", diff --git a/vkpr/aws/eks/up/help.json b/vkpr/aws/eks/up/help.json new file mode 100644 index 00000000..7f8de3bd --- /dev/null +++ b/vkpr/aws/eks/up/help.json @@ -0,0 +1,4 @@ +{ + "short": "Build AWS EKS with Gitops", + "long": "Build the terraform module in your Gitlab CI Pipeline forked by a AWS EKS project." +} \ No newline at end of file diff --git a/vkpr/aws/eks/up/metadata.json b/vkpr/aws/eks/up/metadata.json index b9615a24..deaea978 100755 --- a/vkpr/aws/eks/up/metadata.json +++ b/vkpr/aws/eks/up/metadata.json @@ -15,4 +15,4 @@ "eks", "up" ] -} +} \ No newline at end of file diff --git a/vkpr/aws/eks/up/src/main.sh b/vkpr/aws/eks/up/src/main.sh index 9697102d..cf647088 100755 --- a/vkpr/aws/eks/up/src/main.sh +++ b/vkpr/aws/eks/up/src/main.sh @@ -1,15 +1,10 @@ #!/bin/bash -if [ ! -d ~/.vkpr/global ]; then - echo "Doesn't initializated the vkpr... Call again the function" - rit vkpr init - exit; -fi +VKPR_SCRIPTS=~/.vkpr/src -source ~/.vkpr/global/log.sh -source ~/.vkpr/global/var.sh -source ~/.vkpr/global/helper.sh -source ~/.vkpr/global/.env +source $VKPR_SCRIPTS/log.sh +source $VKPR_SCRIPTS/var.sh +source $VKPR_SCRIPTS/helper.sh # shellcheck source=/dev/null . "$(dirname "$0")"/unix/formula/formula.sh --source-only From 65e3585b0e97b820dd2a2f50e4010d3f9f063ca8 Mon Sep 17 00:00:00 2001 From: Jpeedroza Date: Fri, 10 Sep 2021 15:37:25 -0300 Subject: [PATCH 31/32] Deleted vkpr globals due to lack of use and purpose --- vkpr/globals/help.json | 4 --- vkpr/globals/set/README.md | 13 -------- vkpr/globals/set/build.sh | 12 -------- vkpr/globals/set/config.json | 27 ----------------- vkpr/globals/set/help.json | 4 --- vkpr/globals/set/metadata.json | 17 ----------- vkpr/globals/set/src/main.sh | 12 -------- vkpr/globals/set/src/unix/formula/formula.sh | 31 -------------------- 8 files changed, 120 deletions(-) delete mode 100644 vkpr/globals/help.json delete mode 100755 vkpr/globals/set/README.md delete mode 100755 vkpr/globals/set/build.sh delete mode 100755 vkpr/globals/set/config.json delete mode 100644 vkpr/globals/set/help.json delete mode 100755 vkpr/globals/set/metadata.json delete mode 100755 vkpr/globals/set/src/main.sh delete mode 100755 vkpr/globals/set/src/unix/formula/formula.sh diff --git a/vkpr/globals/help.json b/vkpr/globals/help.json deleted file mode 100644 index b9f57e07..00000000 --- a/vkpr/globals/help.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "short": "Manage Globals", - "long": "Manage Globals" -} \ No newline at end of file diff --git a/vkpr/globals/set/README.md b/vkpr/globals/set/README.md deleted file mode 100755 index 4cee78e1..00000000 --- a/vkpr/globals/set/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Description - -Formula description - -## Command - -```bash -rit vkpr globals set -``` - -## Requirements - -## Demonstration diff --git a/vkpr/globals/set/build.sh b/vkpr/globals/set/build.sh deleted file mode 100755 index ce55095f..00000000 --- a/vkpr/globals/set/build.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -BIN_FOLDER=bin -BINARY_NAME_UNIX=run.sh -ENTRY_POINT_UNIX=main.sh - -#bash-build: - mkdir -p $BIN_FOLDER - cp -r src/* $BIN_FOLDER - mv $BIN_FOLDER/$ENTRY_POINT_UNIX $BIN_FOLDER/$BINARY_NAME_UNIX - chmod +x $BIN_FOLDER/$BINARY_NAME_UNIX - diff --git a/vkpr/globals/set/config.json b/vkpr/globals/set/config.json deleted file mode 100755 index f293e841..00000000 --- a/vkpr/globals/set/config.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "inputs": [ - { - "label": "Type of global:", - "name": "global_type", - "required": true, - "type": "text", - "items": [ - "credential", - "file" - ], - "default": "file" - }, - { - "label": "Type the env name:", - "name": "name", - "type": "text" - }, - { - "label": "Type the env content:", - "name": "content", - "type": "text" - } - ], - "template": "shell-bat", - "templateRelease:": "2.16.2" -} \ No newline at end of file diff --git a/vkpr/globals/set/help.json b/vkpr/globals/set/help.json deleted file mode 100644 index 44b760be..00000000 --- a/vkpr/globals/set/help.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "short": "Set a new variable", - "long": "Set a new variable by the methods credential or env" -} \ No newline at end of file diff --git a/vkpr/globals/set/metadata.json b/vkpr/globals/set/metadata.json deleted file mode 100755 index 2e588971..00000000 --- a/vkpr/globals/set/metadata.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "execution": [ - "local" - ], - "os": { - "deps": [], - "support": [ - "mac", - "linux" - ] - }, - "tags": [ - "vkpr", - "globals", - "set" - ] -} diff --git a/vkpr/globals/set/src/main.sh b/vkpr/globals/set/src/main.sh deleted file mode 100755 index 8a7d61d5..00000000 --- a/vkpr/globals/set/src/main.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -VKPR_SCRIPTS=~/.vkpr/src - -source $VKPR_SCRIPTS/log.sh -source $VKPR_SCRIPTS/var.sh -source $VKPR_SCRIPTS/helper.sh - -# shellcheck source=/dev/null -. "$(dirname "$0")"/unix/formula/formula.sh --source-only - -runFormula \ No newline at end of file diff --git a/vkpr/globals/set/src/unix/formula/formula.sh b/vkpr/globals/set/src/unix/formula/formula.sh deleted file mode 100755 index a5fb0cb4..00000000 --- a/vkpr/globals/set/src/unix/formula/formula.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -runFormula() { - VKPR_GLOBAL_TYPE=$GLOBAL_TYPE - VKPR_GLOBAL_NAME=$(echo "$NAME" | tr '[a-z]' '[A-Z]') - VKPR_GLOBAL_CONTENT=$CONTENT - - case $VKPR_GLOBAL_TYPE in - credential) - createEnvCredential - ;; - file) - createEnvFile - ;; - esac -} - -createEnvCredential() { - read -p "$(echoColor "bold" "$(echoColor "green" "?")") $(echoColor "bold" "Type of provider : (vkpr)")" VKPR_GLOBAL_PROVIDER - VKPR_GLOBAL_PROVIDER=${VKPR_GLOBAL_PROVIDER:-vkpr} - rit set credential --provider=$VKPR_GLOBAL_PROVIDER --fields="$VKPR_GLOBAL_NAME" --values="$VKPR_GLOBAL_CONTENT" -} - -createEnvFile() { - if [ ! -d $VKPR_GLOBALS ]; then - mkdir -p $VKPR_GLOBALS - fi - if [ ! -z $VKPR_GLOBAL_NAME ]; then - printf "VKPR_ENV_$VKPR_GLOBAL_NAME=$VKPR_GLOBAL_CONTENT\n" >> $VKPR_GLOBALS/.env - fi -} \ No newline at end of file From 72a584070e3f079291ae0dc9b48ed70e5bee97a3 Mon Sep 17 00:00:00 2001 From: HumbertoPeluso Date: Fri, 10 Sep 2021 21:16:27 -0300 Subject: [PATCH 32/32] cert-manager test in bats --- vkpr-test/cert-manager-test.bats | 57 +++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/vkpr-test/cert-manager-test.bats b/vkpr-test/cert-manager-test.bats index 3a31d392..373ceeb9 100644 --- a/vkpr-test/cert-manager-test.bats +++ b/vkpr-test/cert-manager-test.bats @@ -1,20 +1,53 @@ VKPR_HOME=~/.vkpr setup_file() { - load 'common-setup' - _common_setup + #load 'common-setup' + #_common_setup if [ "$VKPR_TEST_SKIP_SETUP" == "true" ]; then echo "setup: skipping setup due to VKPR_TEST_SKIP_SETUP=true" >&3 else + echo "setup: starting private ACME server..." >&3 + DOCKER0_IP=$(ifconfig docker0 | grep "inet " | awk '{printf $2}'0) + docker run --rm -d --name step \ + -p 9000:9000 \ + --add-host "host.k3d.internal:$DOCKER0_IP" \ + -e "DOCKER_STEPCA_INIT_NAME=Smallstep" \ + -e "DOCKER_STEPCA_INIT_DNS_NAMES=host.k3d.internal,localhost,step,$(hostname -f)" \ + smallstep/step-ca + sleep 20 + docker exec step step ca provisioner add acme --type ACME + docker kill -s 1 step + + #docker logs -f step + + echo "setup: copying root_ca.crt from ACME server..." >&3 + docker cp step:/home/step/certs/root_ca.crt /tmp/ + chmod +r /tmp/root_ca.crt + + echo "setup: initialising infra. Cluster running on port 80 , 443 is manadatory for this test." >&3 + rit vkpr infra start --http_port 80 --https_port 443 + kubectl wait --all-namespaces --for=condition=ready --timeout=20m pod --all + sleep 2 + + echo "setup: Copying root_ca.crt to cert-manager namespace.." >&3 + kubectl create namespace cert-manager + kubectl create secret generic custom-ca-secret -n cert-manager \ + --from-file=ca-certificates.crt=/tmp/root_ca.crt + echo "setup: installing cert-manager...." >&3 - rit vkpr cert-manager install --email test@test.com - kubectl wait --for=condition=ready --timeout=1m pod --all + rit vkpr cert-manager install custom-acme --email eu@aqui.com + kubectl wait --all-namespaces --for=condition=ready --timeout=5m pod --all sleep 2 - echo "setup: installing whoami to create a certificate...." >&3 - rit vkpr whoami install --domain whoami.vkpr-dev.vertigo.com.br --secure true - kubectl wait --for=condition=ready --timeout=1m pod --all + echo "setup: instaling ingress..." >&3 + rit vkpr ingress install + kubectl wait --all-namespaces --for=condition=ready --timeout=5m pod --all sleep 2 + + echo "setup: installing whoami to create a certificate...." >&3 + rit vkpr whoami install --domain "host.k3d.internal" + kubectl wait --all-namespaces --for=condition=ready --timeout=5m pod --all + sleep 1m fi } @@ -23,14 +56,14 @@ setup() { load $VKPR_HOME/bats/bats-assert/load.bash } -@test "curl to https://whoami.vkpr-dev.vertigo.com.br:8001 must return a letsencrypt certificate" { - #command that tests whether ingress is running - run "$(curl -vik --resolve whoami.vkpr-dev.vertigo.com.br:8001:127.0.0.1 https://whoami.vkpr-dev.vertigo.com.br:8001)" - actual="${lines[1]}" +@test "curl to https://host.k3d.internal must return a Smallstep certificate" { + run "$(curl -vvv -k --resolve host.k3d.internal:443:127.0.0.1 https://host.k3d.internal 2>&1 | awk 'BEGIN { cert=0 } /^\* Server certificate:/ { cert=1 } /^\*/ { if (cert) print }')" + actual="${lines[4]}" trim "$actual" actual="$TRIMMED" - expected="<>" + expected="* issuer: O=Smallstep; CN=Smallstep Intermediate CA" assert_equal "$actual" "$expected" + }