Skip to content

Commit

Permalink
Merge branch 'VKPR-104-create-sample-app-whoami-formula-in-cli' of ht…
Browse files Browse the repository at this point in the history
…tps://github.com/vertigobr/vkpr-cli into VKPR-104-create-sample-app-whoami-formula-in-cli
  • Loading branch information
HumbertoPeluso committed Aug 16, 2021
2 parents cec1ec1 + da3ee36 commit 5bc622f
Show file tree
Hide file tree
Showing 18 changed files with 120 additions and 88 deletions.
19 changes: 11 additions & 8 deletions vkpr/cert-manager/install/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@
"dockerImageBuilder": "ritclizup/rit-shell-bat-builder",
"inputs": [
{
"label": "Type your email to use to generate certificates: ",
"name": "input_email_cluster_issuer",
"label": "Type your email to use to generate certificates:",
"name": "email",
"required": true,
"tutorial": "<email>@<email>.com",
"type": "text"
"tutorial": "<email>@<domain>",
"type": "text",
"cache": {
"active": true,
"qty": 2,
"newLabel": "Type other email: "
}
},
{
"label": "Type your API Access Token from the Digital Ocean",
"name": "input_API_AT_cluster_issuer",
"name": "token",
"required": true,
"tutorial": "",
"type": "text"
"type": "CREDENTIAL_DIGITALOCEAN_TOKEN"
}
],
"template": "shell-bat",
Expand Down
80 changes: 59 additions & 21 deletions vkpr/cert-manager/install/src/unix/formula/formula.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,79 @@

runFormula() {
VKPR_HOME=~/.vkpr
VKPR_CERT_VALUES=$VKPR_HOME/values/cert-manager/cert-manager.yaml
VKPR_CERT_ISSUER=$VKPR_HOME/configs/cert-manager/cluster-issuer.yaml
mkdir -p $VKPR_HOME/configs/cert-manager/ $VKPR_HOME/values/cert-manager/
VKPR_CERT_VERSION="v1.5.0"

VKPR_CERT_VALUES=$VKPR_HOME/values/cert-manager.yaml
VKPR_CERT_ISSUER=$(dirname "$0")/utils/issuers.yaml
VKPR_CERT_TOKEN=$(dirname "$0")/utils/token-dns.yaml

VKPR_KUBECTL=$VKPR_HOME/bin/kubectl
VKPR_HELM=$VKPR_HOME/bin/helm
VKPR_YQ=$VKPR_HOME/bin/yq

VKPR_INPUT_ACCESS_TOKEN=$TOKEN
VKPR_INPUT_EMAIL="$EMAIL"

mkdir -p $VKPR_HOME/values/cert-manager/

install_crds
add_cluster_issuer
add_repo_certmanager
install_certmanager
add_token_dns
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_HOME/bin/helm repo add jetstack https://charts.jetstack.io
$VKPR_HOME/bin/helm repo update
$VKPR_HELM repo add jetstack https://charts.jetstack.io
$VKPR_HELM repo update
}

install_crds() {
echoColor "yellow" "Adicionando CRDS do cert-manager..."
$VKPR_HOME/bin/kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.4.2/cert-manager.crds.yaml
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
}

add_cluster_issuer() {
echoColor "yellow" "Adicionando Cluster Issuer do cert-manager..."
export VKPR_EMAIL_INPUT=$INPUT_EMAIL_CLUSTER_ISSUER
export VKPR_ACCESS_TOKEN_INPUT=$INPUT_API_AT_CLUSTER_ISSUER
. $(dirname "$0")/utils/cluster-issuer.sh $VKPR_EMAIL_INPUT $VKPR_ACCESS_TOKEN_INPUT $VKPR_CERT_ISSUER
$VKPR_HOME/bin/kubectl apply -f $VKPR_CERT_ISSUER
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
}

install_certmanager() {
echoColor "yellow" "Instalando o cert-manager..."
if [[ ! -e $VKPR_CERT_VALUES ]]; then
echoColor "red" "Não identificado nenhum values para a aplicacão, será utilizado um values padrão"
. $(dirname $0)/utils/cert-manager.sh $VKPR_CERT_VALUES
add_token_dns() {
# detect OS for proper base64 args
BASE64_ARGS=""
if [[ "$OSTYPE" != "darwin"* ]]; then
BASE64_ARGS="-w0"
fi
$VKPR_HOME/bin/helm upgrade -i -f $VKPR_CERT_VALUES cert-manager jetstack/cert-manager
if [ -z "$VKPR_INPUT_ACCESS_TOKEN" ]; then
echo "red" "No token available, skipping digitalocean-dns secret deployment."
else
# replaces token in VKPR_CERT_TOKEN template
echoColor "yellow" "Adding the Token..."
VKPR_INPUT_ACCESS_TOKEN_BASE64=$(echo "$VKPR_INPUT_ACCESS_TOKEN" | base64 $BASE64_ARGS) \
$VKPR_YQ eval '.data.access-token = strenv(VKPR_INPUT_ACCESS_TOKEN_BASE64) | .data.access-token style = "double"' "$VKPR_CERT_TOKEN" \
| $VKPR_KUBECTL apply -f -
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 -
}

echoColor() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
printf \
"installCRDs: false
installCRDs: false
ingressShim:
defaultIssuerName: letsencrypt-staging
defaultIssuerKind: ClusterIssuer
defaultIssuerGroup: cert-manager.io" > $1
defaultIssuerGroup: cert-manager.io
prometheus:
enabled: false
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
#!/bin/sh
printf \
"apiVersion: cert-manager.io/v1
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: letsencrypt-staging
namespace: cert-manager
spec:
acme:
email: $1
email: [email protected]
server: https://acme-staging-v02.api.letsencrypt.org/directory
privateKeySecretRef:
name: acme-staging-issuer-account-key
name: letsencrypt-staging-key
solvers:
- dns01:
- selector: {}
dns01:
digitalocean:
tokenSecretRef:
name: digitalocean-dns
key: $2
key: access-token
---
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: letsencrypt-production
namespace: cert-manager
spec:
acme:
# Change this email address to yours
email: $1
email: [email protected]
server: https://acme-v02.api.letsencrypt.org/directory
privateKeySecretRef:
name: acme-production-issuer-account-key
name: letsencrypt-production-key
solvers:
- dns01:
- selector: {}
dns01:
digitalocean:
tokenSecretRef:
name: digitalocean-dns
key: $2" > $3
key: access-token
7 changes: 7 additions & 0 deletions vkpr/cert-manager/install/src/utils/token-dns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: Secret
metadata:
name: digitalocean-dns
namespace: cert-manager
data:
access-token: $token
5 changes: 3 additions & 2 deletions vkpr/cert-manager/remove/src/unix/formula/formula.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

runFormula() {
VKPR_HOME=~/.vkpr
echoColor "yellow" "Removendo Cert-manager do cluster..."
echoColor "yellow" "Removing cert-manager..."
rm -rf $VKPR_HOME/configs/cert-manager/ $VKPR_HOME/values/cert-manager/
$VKPR_HOME/bin/helm uninstall cert-manager
$VKPR_HOME/bin/kubectl delete clusterissuer letsencrypt-staging
$VKPR_HOME/bin/helm uninstall cert-manager -n cert-manager
$VKPR_HOME/bin/kubectl delete ns cert-manager
}

Expand Down
5 changes: 3 additions & 2 deletions vkpr/infra/up/src/unix/formula/formula.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ startCluster() {
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
Expand All @@ -51,13 +52,13 @@ startCluster() {

startRegistry() {
# local registry
if ! $(k3d registry list | grep -q "k3d-mirror.localhost"); then
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-registry.localhost"); then
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."
Expand Down
4 changes: 2 additions & 2 deletions vkpr/whoami/help.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"short": "Add the Whoami to the cluster.",
"long": "Add a Pod and dependences containing a Whoami App in the cluster."
"short": "Manage whoami",
"long": "Whoami is a Tiny Go webserver that prints OS information and HTTP request to output"
}
2 changes: 0 additions & 2 deletions vkpr/whoami/install/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion vkpr/whoami/install/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"dockerImageBuilder": "ritclizup/rit-shell-bat-builder",
"inputs": [
{
"default": "whoami.localhost",
Expand Down
4 changes: 2 additions & 2 deletions vkpr/whoami/install/help.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"short": "Install the Whoami to the cluster.",
"long": "Install the Pod and dependences containing a Whoami App in the cluster."
"short": "Install whoami",
"long": "Install the whoami in the cluster by a Helm Chart."
}
3 changes: 0 additions & 3 deletions vkpr/whoami/install/set_umask.sh

This file was deleted.

26 changes: 8 additions & 18 deletions vkpr/whoami/install/src/unix/formula/formula.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
#!/bin/sh

runFormula() {
echoColor "yellow" "Instalando Whoami..."
VKPR_HOME=~/.vkpr
VKPR_HELM=$VKPR_HOME/bin/helm
VKPR_WHOAMI_VALUES=$(dirname "$0")/utils/whoami.yaml

addRepoWhoami
installWhoami
}

addRepoWhoami(){
helm repo add cowboysysop https://cowboysysop.github.io/charts/
}

verifyHasIngress(){
INGRESS=$($VKPR_HOME/bin/kubectl wait --for=condition=available deploy ingress-nginx-controller -o name | cut -d "/" -f2)
if [[ ! $INGRESS = "ingress-nginx-controller" ]]; then
local res=$?
echo $res
fi
$VKPR_HELM repo add cowboysysop https://cowboysysop.github.io/charts/
$VKPR_HELM repo update
}

installWhoami(){
if [[ ! -n $(verifyHasIngress) ]]; then
$VKPR_HOME/bin/yq eval '.ingress.hosts[0].host = "'$DOMAIN'" | .ingress.tls[0].hosts[0] = "'$DOMAIN'"' "$VKPR_WHOAMI_VALUES" \
| helm upgrade -i -f - whoami cowboysysop/whoami
else
echoColor "red" "Não há ingress instalado, para utilizar o Whoami no localhost deve-se subir o ingress."
helm upgrade -i whoami cowboysysop/whoami
fi
echoColor "yellow" "Installing whoami..."
$VKPR_HOME/bin/yq eval '.ingress.hosts[0].host = "'$DOMAIN'" | .ingress.tls[0].hosts[0] = "'$DOMAIN'"' "$VKPR_WHOAMI_VALUES" \
| $VKPR_HELM upgrade -i -f - whoami cowboysysop/whoami
}

echoColor() {
Expand All @@ -48,4 +38,4 @@ echoColor() {
echo "$(printf '\033[36m')$2$(printf '\033[0m')"
;;
esac
}
}
4 changes: 2 additions & 2 deletions vkpr/whoami/install/src/utils/whoami.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ ingress:
annotations:
kubernetes.io/ingress.class: nginx
kubernetes.io/tls-acme: "true"
pathType: Prefix
hosts:
- host: domain
paths: ["/"]
pathType: Prefix
tls:
- hosts:
- domain
secretName: whoami-cert
secretName: whoami-cert
1 change: 0 additions & 1 deletion vkpr/whoami/remove/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"dockerImageBuilder": "ritclizup/rit-shell-bat-builder",
"inputs": [],
"template": "shell-bat",
"templateRelease:": "2.16.2"
Expand Down
4 changes: 2 additions & 2 deletions vkpr/whoami/remove/help.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"short": "Remove the Whoami from the cluster.",
"long": "Remove all the content about the Whoami App in the cluster."
"short": "Remove whoami",
"long": "Remove the whoami and its dependencies from the cluster"
}
3 changes: 0 additions & 3 deletions vkpr/whoami/remove/set_umask.sh

This file was deleted.

7 changes: 4 additions & 3 deletions vkpr/whoami/remove/src/unix/formula/formula.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#!/bin/sh

runFormula() {
echoColor "yellow" "Removendo Whoami..."
VKPR_HOME=~/.vkpr
rm -rf $VKPR_HOME/values/whoami

uninstallWhoami
}

uninstallWhoami(){
helm uninstall whoami
echoColor "yellow" "Removendo Whoami..."
$VKPR_HOME/bin/helm uninstall whoami
$VKPR_HOME/bin/kubectl delete secret whoami-cert
}

echoColor() {
Expand Down

0 comments on commit 5bc622f

Please sign in to comment.