/gitops-labs-1

LAB GitOps - Jennkins-x + EKS - Terraform

Primary LanguageHCL

DevOps Challenge

Status: under development

Todo:

  • VPC
  • EKS Module
  • EBS Storage
  • EKS Dashboard / EKS Heapster
  • ECR - Container Registry
  • Jenkins-x Module
  • Jenkins-x Apps Module
  • Helm Charts API / WEB
  • Skaffold config API / WEB
  • RDS
  • Terraform Remote State S3 and Locking DynamoDB
Run Vagrant devops-box
$ git clone https://github.com/petersonwsantos/gitops-labs-1.git
$ cd gitops-labs-1
Run Vagrant devops-box
$ vagrant up && vagrant ssh
Configure AWS cli
#configure awscli
$ aws configure
Configure Terraform variables
$ cd /vagrant

$ cp terraform.tfvars.example terraform.tfvars

# configure variables
$ vi terraform.tfvars
Terraform - Create Infrastructure

Jenkins X icon

# Create bucket S3
$ aws s3api create-bucket \
  --bucket $(cat terraform.tfvars | grep ^'bucket_backend ' | awk '{print $3}' | sed 's/\"//g') \
  --region $(cat terraform.tfvars | grep ^'region '         | awk '{print $3}' | sed 's/\"//g')

$ aws s3api put-bucket-versioning \
  --bucket $(cat terraform.tfvars | grep ^'bucket_backend ' | awk '{print $3}' | sed 's/\"//g')  \
  --versioning-configuration "Status=Enabled"

# Download modules and initialize S3 backend
$ terraform init \
    -backend-config="region=$(cat terraform.tfvars | grep ^'region '        | awk '{print $3}' | sed 's/\"//g')" \
    -backend-config="bucket=$(cat terraform.tfvars | grep ^'bucket_backend '| awk '{print $3}' | sed 's/\"//g')"  \
    -backend-config="key=$(cat terraform.tfvars    | grep ^'key_backend '   | awk '{print $3}' | sed 's/\"//g')"

# Create infrastructure
$ terraform plan -out=apply.me && terraform apply apply.me
Create Environments
# Configure token
$ bash -c "$(terraform output -module=jx token)"

# Open  http://your_jenkins_url/configure and
# configure the field "Jenkins URL" with "http://your_jenkins_url"

# create environments
$ bash -c "$(terraform output -module=jx env_staging)"
$ bash -c "$(terraform output -module=jx env_production)"
Import Applications
# Import applications
$ bash -c "$(terraform output -module=jx_app_api import_app)"
$ bash -c "$(terraform output -module=jx_app_web import_app)"
Jenkins-x Flow

Jenkins X icon

Demo - Creating a new feature
# STEP 1 - DEVELOPER XXXXXXXXXXXXXXXXXXXXXXXXXX

# Clone app repo
$ cd web

# Create an issue
$ jx create issue -t 'feature version'

# Create new branch for PR
$ git checkout -b feature_version

# Code a feature
$ vi routes/index.js

# Push file and connect commit with issue #1
$ git add routes/index.js
$ git commit -m 'add feature ver -  fixes #1'
$ git push origin feature_version

# Create PR with hub or manually in Github page
$ hub pull-request

# STEP 2 - PRODUCT OWNER (or similar) XXXXXXXXXXXXXXXXXXXXXXXXXX

Automatically is created a pipeline for this PR and preview environment.

Approve Pull Request ?

-> If Yes - new release will be automatically created.

-> If no  - finish process.

# STEP 3 - DEPLOY RELEASE XXXXXXXXXXXXXXXXXXXXXXXXXX

# Promote release in Production environment
$ jx promote --app='web' --version='0.0.10' --env='production' --batch-mode=true

# Rollback version
$ jx promote --app='web' --version='0.0.9' --env='production' --batch-mode=true
Delete
# Step 1 - Delete Jenkins-X and ELBs(*)
# This command must be executed first, because the ELBs
#  created by Kubernetes (services / ingress) make it
#  impossible for Terraform to destroy the VPC.
$ terraform destroy -target=null_resource.jx_installation --force

# Step 2
$ terraform destroy --force

.

.

Sources of study and credits: