-
Notifications
You must be signed in to change notification settings - Fork 28
/
setup.yml
72 lines (64 loc) · 2.57 KB
/
setup.yml
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
version: '1.0'
steps:
check_env:
title: Check environment for required variables
image: bash:4.4.23
commands:
- echo 'Checking for CLUSTER_NAME, AWS_ACCESS_KEY_ID, and AWS_SECRET_ACCESS_KEY...'
- bash -c '[[ -z $CLUSTER_NAME || -z $AWS_ACCESS_KEY_ID || -z $AWS_SECRET_ACCESS_KEY ]] && exit 1 || true'
- cf_export K8S_NAME="eks-$CLUSTER_NAME"
load_tfstate:
title: Attempt to load Terraform statefile from Codefresh context
image: codefresh/cli:0.8.54
commands:
- apk add --update make bash
- make codefresh-load-tfstate || echo "Skipping."
setup_eks_cluster:
title: Setup EKS cluster using Terraform
image: hashicorp/terraform:0.11.7
commands:
- apk add --update make bash
- set +e; make setup; cf_export RC=$?
save_tfstate:
title: Save Terraform statefile to Codefresh context
image: codefresh/cli:0.8.54
commands:
- apk add --update make bash
- make codefresh-save-tfstate
- exit ${{RC}}
create_kubernetes_resources:
title: Create additional Kubernetes resources
image: lachlanevenson/k8s-kubectl:v1.10.4
commands:
- rm -f heptio-authenticator-aws
- wget https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-06-05/bin/linux/amd64/heptio-authenticator-aws
- chmod +x heptio-authenticator-aws
- cp heptio-authenticator-aws /usr/local/bin
- export KUBECONFIG="$(pwd)/kubernetes/kubeconfig.yaml"
- cd kubernetes/
- kubectl apply -f config-map-aws-auth.yaml
- kubectl apply -f service-account.yaml
- kubectl apply -f role-binding.yaml
init_helm:
title: Initialiaze Helm in the cluster
image: lachlanevenson/k8s-helm:v2.9.1
commands:
- cp heptio-authenticator-aws /usr/local/bin
- export KUBECONFIG="$(pwd)/kubernetes/kubeconfig.yaml"
- helm init --service-account admin-user
get_token:
title: Extract token from Kubernetes secret
image: lachlanevenson/k8s-kubectl:v1.10.4
commands:
- cp heptio-authenticator-aws /usr/local/bin
- export KUBECONFIG="$(pwd)/kubernetes/kubeconfig.yaml"
- export SECRET_ID="$(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')"
- cf_export K8S_TOKEN=$(kubectl -n kube-system get secret $SECRET_ID -o jsonpath='{.data.token}')
add_cluster:
title: Add EKS cluster to Codefresh account
image: byrnedo/alpine-curl:0.1.5
commands:
- apk add --update make bash jq
- export K8S_CA="$(cat kubernetes/kubeca.txt)"
- export K8S_HOST="$(cat kubernetes/kubehost.txt)"
- make codefresh-add-cluster