|
| 1 | +#!/bin/sh |
| 2 | +set -e |
| 3 | + |
| 4 | +gum style \ |
| 5 | + --foreground 212 --border-foreground 212 --border double \ |
| 6 | + --margin "1 2" --padding "2 4" \ |
| 7 | + 'Setup for the |
| 8 | +"TODO:" |
| 9 | +video.' |
| 10 | + |
| 11 | +gum confirm ' |
| 12 | +Are you ready to start? |
| 13 | +Feel free to say "No" and inspect the script if you prefer setting up resources manually. |
| 14 | +' || exit 0 |
| 15 | + |
| 16 | +################ |
| 17 | +# Requirements # |
| 18 | +################ |
| 19 | + |
| 20 | +echo " |
| 21 | +## You will need following tools installed: |
| 22 | +|Name |Required |More info | |
| 23 | +|----------------|---------------------|---------------------------------------------------| |
| 24 | +|Charm Gum |Yes |'https://github.com/charmbracelet/gum#installation'| |
| 25 | +|kubectl |Yes |'https://kubernetes.io/docs/tasks/tools/#kubectl' | |
| 26 | +|helm |Yes |'https://helm.sh/docs/intro/install/' | |
| 27 | +|jq |Yes |'https://stedolan.github.io/jq/download' | |
| 28 | +|yq |Yes |'https://github.com/mikefarah/yq#install' | |
| 29 | +" | gum format |
| 30 | + |
| 31 | +gum confirm " |
| 32 | +Do you have those tools installed? |
| 33 | +" || exit 0 |
| 34 | + |
| 35 | +############## |
| 36 | +# Crossplane # |
| 37 | +############## |
| 38 | + |
| 39 | +kubectl apply --filename crossplane-config/config-kubernetes.yaml |
| 40 | + |
| 41 | +kubectl apply --filename crossplane-config/provider-civo.yaml |
| 42 | + |
| 43 | +kubectl wait --for=condition=healthy provider.pkg.crossplane.io --all --timeout=300s |
| 44 | + |
| 45 | +CIVO_TOKEN=$(gum input --placeholder "Please enter Civo (https://civo.com) token." --password --value "$CIVO_TOKEN") |
| 46 | + |
| 47 | +CIVO_TOKEN_ENCODED=$(echo $CIVO_TOKEN | base64) |
| 48 | + |
| 49 | +echo "apiVersion: v1 |
| 50 | +kind: Secret |
| 51 | +metadata: |
| 52 | + name: civo-creds |
| 53 | +type: Opaque |
| 54 | +data: |
| 55 | + credentials: $CIVO_TOKEN_ENCODED" \ |
| 56 | + | kubectl --namespace crossplane-system apply --filename - |
| 57 | + |
| 58 | +kubectl apply --filename crossplane-config/provider-config-civo.yaml |
| 59 | + |
| 60 | +########### |
| 61 | +# Argo CD # |
| 62 | +########### |
| 63 | + |
| 64 | +kubectl create namespace infra |
| 65 | + |
| 66 | +# Install `yq` from https://github.com/mikefarah/yq if you do not have it already |
| 67 | +yq --inplace ".server.ingress.hosts[0] = \"argocd.$INGRESS_HOST.nip.io\"" argocd/helm-values.yaml |
| 68 | + |
| 69 | +helm upgrade --install argocd argo-cd --repo https://argoproj.github.io/argo-helm --namespace argocd --create-namespace --values argocd/helm-values.yaml --wait |
| 70 | + |
| 71 | +kubectl apply --filename argocd/project.yaml |
| 72 | + |
| 73 | +yq --inplace ".spec.source.repoURL = \"https://github.com/$GITHUB_ORG/idp-demo\"" argocd/apps.yaml |
| 74 | + |
| 75 | +yq --inplace ".spec.source.repoURL = \"https://github.com/${GITHUB_ORG}/idp-demo.git\"" argocd/cluster-template.yaml |
| 76 | + |
| 77 | +kubectl apply --filename argocd/apps.yaml |
| 78 | + |
| 79 | +######## |
| 80 | +# Port # |
| 81 | +######## |
| 82 | + |
| 83 | +cat port/cluster-create-action.json \ |
| 84 | + | jq ".invocationMethod.org = \"$GITHUB_ORG\"" \ |
| 85 | + | tee port/cluster-create-action.json.tmp |
| 86 | + |
| 87 | +mv port/cluster-create-action.json.tmp port/cluster-create-action.json |
| 88 | + |
| 89 | +cat port/cluster-delete-action.json \ |
| 90 | + | jq ".invocationMethod.org = \"$GITHUB_ORG\"" \ |
| 91 | + | tee port/cluster-delete-action.json.tmp |
| 92 | + |
| 93 | +mv port/cluster-delete-action.json.tmp port/cluster-delete-action.json |
| 94 | + |
| 95 | +######## |
| 96 | +# Repo # |
| 97 | +######## |
| 98 | + |
| 99 | +git add . |
| 100 | + |
| 101 | +git commit -m "Infrastructure setup" |
| 102 | + |
| 103 | +git push |
0 commit comments