Skip to content

Commit 899ff73

Browse files
committed
Infra
1 parent fa0309e commit 899ff73

11 files changed

+469
-0
lines changed

.github/workflows/create-cluster.yaml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Create a cluster
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
name:
6+
required: true
7+
description: "The name of the cluster"
8+
provider:
9+
required: true
10+
description: "The provider where the cluster is hosted"
11+
default: "civo"
12+
cluster:
13+
required: true
14+
description: "The type of the cluster"
15+
default: "ck-all"
16+
node-size:
17+
required: true
18+
description: "The size of the nodes"
19+
default: "small"
20+
min-node-count:
21+
required: true
22+
description: "The minnimun number of nodes (autoscaler might increase this number)"
23+
default: "1"
24+
jobs:
25+
deploy-app:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v3
29+
with:
30+
persist-credentials: false
31+
fetch-depth: 0
32+
- name: Create cluster
33+
run: |
34+
chmod +x scripts/create-cluster.sh
35+
./scripts/create-cluster.sh ${{ inputs.name }} ${{ inputs.provider }} ${{ inputs.cluster }} ${{ inputs.node-size }} ${{ inputs.min-node-count }}
36+
- name: Commit changes
37+
run: |
38+
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
39+
git config --local user.name "github-actions[bot]"
40+
git add .
41+
git commit -m "Create cluster ${{ inputs.name }}"
42+
- name: Push changes
43+
uses: ad-m/github-push-action@master
44+
with:
45+
github_token: ${{ secrets.GITHUB_TOKEN }}
46+
branch: ${{ github.ref }}

.github/workflows/delete-cluster.yaml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Delete the cluster
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
name:
6+
required: true
7+
description: "The name of the cluster"
8+
jobs:
9+
deploy-app:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
with:
14+
persist-credentials: false
15+
fetch-depth: 0
16+
- name: Create cluster
17+
run: |
18+
rm infra/${NAME}-cluster.yaml
19+
- name: Commit changes
20+
run: |
21+
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
22+
git config --local user.name "github-actions[bot]"
23+
git add .
24+
git commit -m "Create cluster ${{ inputs.name }}"
25+
- name: Push changes
26+
uses: ad-m/github-push-action@master
27+
with:
28+
github_token: ${{ secrets.GITHUB_TOKEN }}
29+
branch: ${{ github.ref }}
File renamed without changes.

crossplane/cluster-template.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
apiVersion: devopstoolkitseries.com/v1alpha1
3+
kind: ClusterClaim
4+
metadata:
5+
name: NAME
6+
namespace: infra
7+
spec:
8+
id: NAME
9+
compositionSelector:
10+
matchLabels:
11+
provider: PROVIDER
12+
cluster: CLUSTER
13+
parameters:
14+
nodeSize: SIZE
15+
minNodeCount: 1

port/cluster-blueprint.json

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"identifier": "cluster",
3+
"description": "This blueprint represents a Kubernetes Cluster",
4+
"title": "Cluster",
5+
"icon": "Cluster",
6+
"schema": {
7+
"properties": {
8+
"provider": {
9+
"type": "string",
10+
"title": "Provider",
11+
"default": "civo",
12+
"description": "The provider where the cluster is hosted",
13+
"enum": [
14+
"civo"
15+
]
16+
},
17+
"node-size": {
18+
"type": "string",
19+
"title": "Node Size",
20+
"default": "small",
21+
"description": "The size of the nodes",
22+
"enum": [
23+
"small",
24+
"medium",
25+
"large"
26+
]
27+
},
28+
"min-node-count": {
29+
"type": "number",
30+
"title": "Minimum number of nodes",
31+
"default": 1,
32+
"description": "The minimun number of nodes (autoscaler might increase this number)"
33+
}
34+
},
35+
"required": [
36+
"provider",
37+
"node-size",
38+
"min-node-count"
39+
]
40+
},
41+
"mirrorProperties": {},
42+
"calculationProperties": {
43+
"cluster": {
44+
"type": "string",
45+
"title": "Cluster",
46+
"calculation": "if .properties.provider == \"civo\" then \"ck-all\" end"
47+
}
48+
},
49+
"relations": {}
50+
}

port/cluster-create-action.json

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"identifier": "create-cluster",
3+
"title": "Create a cluster",
4+
"userInputs": {
5+
"properties": {
6+
"name": {
7+
"type": "string",
8+
"title": "Name",
9+
"description": "The name of the cluster"
10+
},
11+
"provider": {
12+
"type": "string",
13+
"title": "Provider",
14+
"default": "civo",
15+
"description": "The provider where the cluster is hosted",
16+
"enum": [
17+
"civo"
18+
]
19+
},
20+
"node-size": {
21+
"type": "string",
22+
"title": "Node Size",
23+
"default": "small",
24+
"description": "The size of the nodes",
25+
"enum": [
26+
"small",
27+
"medium",
28+
"large"
29+
]
30+
},
31+
"min-node-count": {
32+
"type": "string",
33+
"title": "Minimum number of nodes",
34+
"default": "1",
35+
"description": "The minimun number of nodes (autoscaler might increase this number)"
36+
}
37+
},
38+
"required": [
39+
"name",
40+
"provider",
41+
"node-size",
42+
"min-node-count"
43+
]
44+
},
45+
"invocationMethod": {
46+
"type": "GITHUB",
47+
"org": "vfarcic",
48+
"repo": "idp-demo",
49+
"workflow": "create-cluster.yaml",
50+
"omitPayload": true
51+
},
52+
"trigger": "CREATE",
53+
"description": "Create a new cluster."
54+
}

port/cluster-delete-action.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"identifier": "delete-cluster",
3+
"title": "Delete the cluster",
4+
"userInputs": {
5+
"properties": {
6+
"name": {
7+
"type": "string",
8+
"title": "Name",
9+
"description": "The name of the cluster"
10+
}
11+
},
12+
"required": [
13+
"name",
14+
]
15+
},
16+
"invocationMethod": {
17+
"type": "GITHUB",
18+
"org": "vfarcic",
19+
"repo": "idp-demo",
20+
"workflow": "create-cluster.yaml",
21+
"omitPayload": true
22+
},
23+
"trigger": "DELETE",
24+
"description": "Delete the cluster."
25+
}

scripts/create-cluster.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
NAME=$1
2+
PROVIDER=$2
3+
CLUSTER=$3
4+
NODE_SIZE=$4
5+
MIN_NODE_COUNT=$5
6+
7+
FILE_PATH=infra/${NAME}-cluster.yaml
8+
9+
cp crossplane/cluster-template.yaml $FILE_PATH
10+
yq --inplace ".metadata.name = \"${NAME}\"" $FILE_PATH
11+
yq --inplace ".spec.id = \"${NAME}\"" $FILE_PATH
12+
yq --inplace ".spec.compositionSelector.matchLabels.provider = \"${PROVIDER}\"" $FILE_PATH
13+
yq --inplace ".spec.compositionSelector.matchLabels.cluster = \"${CLUSTER}\"" $FILE_PATH
14+
yq --inplace ".spec.parameters.nodeSize = \"${NODE_SIZE}\"" $FILE_PATH
15+
yq --inplace ".spec.parameters.minNodeCount = ${MIN_NODE_COUNT}" $FILE_PATH

setup-infra.sh

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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

Comments
 (0)