Skip to content

Commit

Permalink
(feat): Add Gitlab CI/CD pipeline for chaos-exporter (#39)
Browse files Browse the repository at this point in the history
* (feat): Add gitlab CI/CD pipeline for chaos-exporter

Signed-off-by: Udit Gaurav <[email protected]>
  • Loading branch information
uditgaurav authored and Karthik Satchitanand committed Jan 2, 2020
1 parent 7b781af commit f6d84f2
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 1 deletion.
73 changes: 73 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
stages:
- setup
- build
- test
- push
- cleanup

ClusterSetup:
stage: setup
tags:
- setup
script:
- chmod 755 ./build/gitlab/stages/1-cluster-setup/gcp
- ./build/gitlab/stages/1-cluster-setup/gcp

artifacts:
when: always
paths:
- .kube/

Build:

stage: build
tags:
- build
script:

- export COMMIT=${CI_COMMIT_SHORT_SHA}
- export GOPATH=$HOME/go
- export GOROOT=/usr/local/go
- export PATH=$HOME/go/bin:$PATH
- mkdir -p $HOME/go/src/github.com/${REPONAME}/${IMAGENAME}
- rsync -az --delete ${CI_PROJECT_DIR}/ ${GOPATH}/src/github.com/${REPONAME}/${IMAGENAME}/ #CI_PROJECT_DIR is full path where project is cloned
- go env
- cd ~/go/src/github.com/${REPONAME}/${IMAGENAME}
- make godeps
# bdd testing dependencies - ginkgo and gomega
- make bdddeps
# Build
- make build

Test:

stage: test
tags:
- test
script:
- cd ~/go/src/github.com/${REPONAME}/${IMAGENAME}
- make test

Push:

stage: push
tags:
- push
script:
- make dockerops

ClusterCleanup:

when: always
stage: cleanup
tags:
- cleanup
script:
- chmod 755 ./build/gitlab/stages/2-cluster-cleanup/cluster-cleanup
- ./build/gitlab/stages/2-cluster-cleanup/cluster-cleanup

artifacts:
when: always
paths:
- .kube/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ bdddeps:
@go get -u github.com/onsi/ginkgo
@go get -u github.com/onsi/gomega
kubectl create -f https://raw.githubusercontent.com/litmuschaos/chaos-operator/master/deploy/chaos_crds.yaml
kubectl create ns litmus
kubectl create ns litmus
36 changes: 36 additions & 0 deletions build/gitlab/stages/1-cluster-setup/gcp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

set -e

path=$(pwd)
echo $SDK_TOKEN > key.json
gcloud auth activate-service-account --key-file=key.json
gcloud config set project ${PROJECT_NAME}
export GOOGLE_APPLICATION_CREDENTIALS="$path/key.json"

truncate -s 0 ~/logs/vpc
truncate -s 0 ~/logs/clusters

git clone https://github.com/mayadata-io/litmus.git
cd litmus/k8s/gcp/k8s-installer/

# Create VPC
echo "CREATING VPC"
ansible-playbook create-vpc.yml --extra-vars "project=${PROJECT_NAME}"

# Create k8s cluster
echo "CREATING CLUSTER"
ansible-playbook create-k8s-cluster.yml -vv --extra-vars "project=${PROJECT_NAME} nodes=1 k8s_version=1.11.1"

mkdir $path/.kube
cat ~/.kube/config > $path/.kube/config
cat ~/.kube/config > $path/.kube/admin.conf
cat ~/logs/clusters > $path/.kube/clusters
cat ~/logs/vpc > $path/.kube/vpc

# Export VPC network name
VPC=`cat $path/.kube/vpc`
echo $VPC
echo "Checking Cluster availability"
ansible-playbook check-cluster-availability.yml --extra-vars "nodes=1"
kubectl get nodes
31 changes: 31 additions & 0 deletions build/gitlab/stages/2-cluster-cleanup/cluster-cleanup
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

set -e

path=$(pwd)
echo $SDK_TOKEN > key.json
gcloud auth activate-service-account --key-file=key.json
gcloud config set project ${PROJECT_NAME}
export GOOGLE_APPLICATION_CREDENTIALS="$path/key.json"

cp $path/.kube/clusters ~/logs
cp $path/.kube/vpc ~/logs
git clone https://github.com/mayadata-io/litmus.git
cd litmus/k8s/gcp/k8s-installer/
echo "************************** Cluster cleanup started **************************"

# Fetching cluster name
cluster_name=$(cat ~/logs/clusters)

# Delete k8s cluster
ansible-playbook delete-k8s-cluster.yml

# Export VPC network name
VPC=`cat $path/.kube/vpc`
echo $VPC

# Delete VPC
ansible-playbook delete-vpc.yml --extra-vars "project=${PROJECT-NAME}"

echo $cluster_name
rm -rf litmus

0 comments on commit f6d84f2

Please sign in to comment.