Files
infra-hideyoshi.com/deploy.sh
Vitor Hideyoshi Nakazone Batista 2b92706be0 Implements Better Deployment System (#4) (#5)
* Initial Work of Better Deployment Script

* Checks if .secret is Present on Test Setup

* Implements Custom Routing per Profile

* Rewriting Setup Tools - Adds Postgres and Redis

* Rewriting Setup Tools - Adds Frontend

* Rewriting Setup Tools - Adds Backend

* Rewriting Setup Tools - Adds CertManager

* Rewriting Setup Tools - Adds Frontend

* Adds Nginx-Ingress and Fixes Staging Environment

* Updates CertManager and Nginx-Ingress

* Implements New Setup Process


Initial Adjustments to CI/CD


Adjusts CI/CD


test

* Adds CI/CD for Prod Environment
2023-07-10 06:14:42 -03:00

118 lines
2.9 KiB
Bash
Executable File

#!/bin/bash
function check_k3s_installation() {
if [ ! -f /usr/local/bin/k3s ]; then
curl -sfL https://get.k3s.io | sh -
sudo chmod 644 /etc/rancher/k3s/k3s.yaml;
fi
}
function start_cert_manager() {
kubectl apply -f ./deployment/cert-manager/cert-manager.yaml;
kubectl wait --for=condition=available \
--timeout=600s \
deployment.apps/cert-manager \
deployment.apps/cert-manager-cainjector \
deployment.apps/cert-manager-webhook \
-n cert-manager;
}
function application_deploy() {
kubectl apply -f ./deployment/portfolio-namespace.yaml;
kubectl apply -f \
./deployment/cert-manager/cert-manager-certificate.yaml;
kubectl apply -f ./deployment/postgres;
kubectl wait --for=condition=available \
--timeout=600s \
deployment.apps/postgres-deployment \
-n portfolio;
kubectl apply -f ./deployment/redis;
kubectl wait --for=condition=available \
--timeout=600s \
deployment.apps/redis-deployment \
-n portfolio;
kubectl apply -f ./deployment/frontend;
kubectl wait --for=condition=available \
--timeout=600s \
deployment.apps/frontend-deployment \
-n portfolio;
kubectl apply -f ./deployment/backend;
kubectl wait --for=condition=available \
--timeout=600s \
deployment.apps/backend-deployment \
-n portfolio;
kubectl apply -f \
./deployment/nginx-ingress/nginx-ingress-root.yaml;
kubectl apply -f \
./deployment/nginx-ingress/nginx-ingress-api.yaml;
}
function main() {
if [[ $1 == "--test" || $1 == "-t" ]]; then
function kubectl {
minikube kubectl -- $@
}
minikube start --driver kvm2;
minikube addons enable ingress-dns;
minikube addons enable ingress;
start_cert_manager
kubectl apply -f \
./deployment/cert-manager/cert-manager-issuer-dev.yaml;
application_deploy
echo "http://$(/usr/bin/minikube ip)";
elif [[ $1 == "--staging" || $1 == "-s" ]]; then
check_k3s_installation
kubectl apply -f ./deployment/nginx-ingress/nginx-ingress.yaml;
kubectl wait --namespace ingress-nginx \
--for=condition=ready pod \
--selector=app.kubernetes.io/component=controller \
--timeout=120s;
start_cert_manager
kubectl apply -f ./deployment/cert-manager/cert-manager-issuer.yaml;
application_deploy
else
check_k3s_installation
kubectl apply -f ./deployment/nginx-ingress/nginx-ingress.yaml;
kubectl wait --namespace ingress-nginx \
--for=condition=ready pod \
--selector=app.kubernetes.io/component=controller \
--timeout=120s;
start_cert_manager
kubectl apply -f ./deployment/cert-manager/cert-manager-issuer.yaml;
application_deploy
fi
exit 0;
}
main $1