-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
executable file
·146 lines (121 loc) · 4.51 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env bash
bold=$(tput bold)
normal=$(tput sgr0)
set -e
echo "${bold}[Dependencies]${normal}"
echo "Making sure dependencies are installed..."
if ! docker ps; then
echo "Docker doesn't appear to be running, exiting ❌"
exit 1
fi
if which terragrunt; then
echo "Terragrunt installed ✅"
else
read -p "Terragrunt is not installed — do you want to install it? (y/N) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]
then
brew install terragrunt
else
exit 1
fi
fi
if which kubectl; then
echo "Kubectl installed ✅"
else
read -p "Kubectl is not installed — do you want to install it? (y/N) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]
then
brew install kubectl
else
exit 1
fi
fi
if which helm; then
echo "Helm installed ✅"
else
read -p "Helm is not installed — do you want to install it? (y/N) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]
then
brew install helm
else
exit 1
fi
fi
echo "Checking whether there is an installed kubeconfig file..."
echo "Kubeconfig properly installed ✅"
echo "Installing NGINX ingress..."
pushd infrastructure/modules/nginx-ingress
if terragrunt apply --terragrunt-non-interactive -auto-approve 2>/dev/null; then
echo "NGINX ingress installed ✅"
else
echo "Failed to install NGINX ingress ❌"
exit 1
fi
popd
echo "Waiting for NGINX load balancer to get initialized..."
while ! LB_IPV4=$(kubectl get svc -n nginx-ingress nginx-ingress-ingress-nginx-controller --output jsonpath='{.status.loadBalancer.ingress[0].ip}'); do sleep 1; done
echo "NGINX load balancer initialized (IPv4 address: $LB_IPV4) ✅"
echo "Configuring parameters..."
echo "${bold}[GitHub Personal Access Token]${normal}"
echo "Create a Personal access token (PAT) with \`write:packages\`+\`read:packages\` permissions (https://github.com/settings/tokens)"
read -p "Enter your PAT: " GITHUB_PAT
read -p "Enter the GitHub username you used to generate the PAT: " GITHUB_USERNAME
echo "Logging in to GitHub package registry..."
echo $GITHUB_PAT | docker login ghcr.io --username "$GITHUB_USERNAME" --password-stdin
echo "Done ✅"
echo "${bold}[Email]${normal}"
echo "An email is required by LetsEncrypt in order to send warnings about certificates about to expire"
read -p "Enter your email address: " ACME_EMAIL
echo "${bold}[Domain name]${normal}"
echo "Next we configure DNS settings so that requests to your selected domain name will resolve to the IPv4 address for the NGINX load balancer"
echo "Create an A record in your DNS settings with value ${bold}@${normal} and value ${bold}$LB_IPV4${normal}"
echo "${bold}Note:${normal} You can use a subdomain by setting the value to ${bold}mysubdomain${normal}, but make sure to include that subdomain in the value entered below"
read -p "Enter your domain name: " DOMAIN_NAME
echo 'Verifying DNS settings...'
DIG_RES=$(dig "$DOMAIN_NAME" +short)
if [ "$DIG_RES" = "$LB_IPV4" ]; then
echo "Record for "$DOMAIN_NAME": "$DIG_RES" ✅"
else
read -p "Record for "$DOMAIN_NAME": "$DIG_RES" (wanted $LB_IPV4) ❌ Proceed anyway? (y/N)" -n 1 -r
echo ""
if ! [[ $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi
echo "Setting the domain name in the Terraform configuration..."
sed -i -e "s/\ domain.*=.*/ domain = \"$DOMAIN_NAME\"/" infrastructure/root.hcl
echo "Done ✅"
echo "Setting the GitHub and email settings in the Terraform vars file..."
cat <<EOT >infrastructure/terraform.tfvars
# The personal access token (PAT) you created in your GitHub repo settings
github_pat = "$GITHUB_PAT"
# The Username of the GitHub personal access token, in order to be able to access the GitHub package registry
github_username = "$GITHUB_USERNAME"
# An email that will be registered with LetsEncrypt for your TLS certificates
acme_email = "$ACME_EMAIL"
EOT
echo "Done ✅"
echo "Installing all remaining terraform modules"
pushd infrastructure
if terragrunt run-all apply --terragrunt-non-interactive 2>/dev/null; then
echo "NGINX ingress installed ✅"
else
echo "Failed to install NGINX ingress ❌"
exit 1
fi
popd
GITHUB_USERNAME_LOWERCASE=$(echo "$GITHUB_USERNAME" | awk '{print tolower($0)}')
GITHUB_REPO=$(basename `git rev-parse --show-toplevel`)
echo "Building, pushing & deploying API"
pushd api
API_TAG=ghcr.io/$GITHUB_USERNAME_LOWERCASE/$GITHUB_REPO/nodejs-api:initial
docker buildx build --push --platform linux/amd64,linux/arm64 -t "$API_TAG" .
helm upgrade --install nodejs-api --wait --set "image.repository=$API_TAG" ./charts
popd
echo "---"
echo "All done! ✅"
echo "Access Grafana at $DOMAIN_NAME/grafana"
echo "Access API at $DOMAIN_NAME/api"