├── jenkins_home
├── dsl-repo
│ ├── README.md
│ ├── config
│ │ └── common.groovy
│ ├── dsl
│ │ ├── Common
│ │ │ └── initial.groovy
│ │ └── Demo
│ │ │ └── Infrastructure_As_Code.groovy
│ └── pipeline
│ │ └── Demo
│ │ └── Infrastructure_As_Code.groovy
├── secrets
│ └── slave-to-master-security-kill-switch
├── terraform-repo
│ ├── aws_account
│ │ └── demo
│ │ │ └── us-east-1
│ │ │ └── Infrastructure_As_Code
│ │ │ ├── Gemfile
│ │ │ ├── operations
│ │ │ ├── spec
│ │ │ ├── .gitignore
│ │ │ ├── spec_helper.rb
│ │ │ ├── vpc_spec.rb
│ │ │ └── lamp_spec.rb
│ │ │ ├── Makefile
│ │ │ ├── Rakefile
│ │ │ ├── vpc.tf
│ │ │ ├── lamp.tf
│ │ │ └── variables.tf
│ ├── modules
│ │ ├── network
│ │ │ ├── subnet
│ │ │ │ ├── outputs.tf
│ │ │ │ ├── variables.tf
│ │ │ │ ├── subnet.tf
│ │ │ │ └── numbering.tf
│ │ │ ├── vpc
│ │ │ │ ├── variables.tf
│ │ │ │ ├── numbering.tf
│ │ │ │ ├── security_group.tf
│ │ │ │ ├── vpc.tf
│ │ │ │ └── subnets.tf
│ │ │ └── numbering
│ │ │ │ └── variables.tf
│ │ └── lamp
│ │ │ ├── variables.tf
│ │ │ ├── elb.tf
│ │ │ ├── security.tf
│ │ │ ├── cloudwatch.tf
│ │ │ └── asg.tf
│ ├── operations
│ │ ├── scripts
│ │ │ ├── lamp
│ │ │ │ └── init-variables
│ │ │ └── common
│ │ │ │ ├── init-backend
│ │ │ │ └── do-task
│ │ └── makefiles
│ │ │ ├── common
│ │ │ ├── keypair.mk
│ │ │ └── help.mk
│ │ │ └── Makefile
│ │ │ └── lamp
│ └── README.md
├── jenkins.CLI.xml
├── jenkins.security.UpdateSiteWarningsConfiguration.xml
├── javaposse.jobdsl.plugin.GlobalJobDslSecurityConfiguration.xml
├── Dockerfile
├── jobs
│ ├── Demo
│ │ ├── config.xml
│ │ └── jobs
│ │ │ └── Infrastructure_As_Code
│ │ │ └── config.xml
│ └── Seed
│ │ └── config.xml
├── plugins.txt
├── config.xml
├── scriptApproval.xml
└── users
│ └── devopsdays
│ └── config.xml
├── jenkins.container
├── .gitignore
└── README.md
/jenkins_home/dsl-repo/README.md:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/jenkins_home/secrets/slave-to-master-security-kill-switch:
--------------------------------------------------------------------------------
1 | false
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/aws_account/demo/us-east-1/Infrastructure_As_Code/Gemfile:
--------------------------------------------------------------------------------
1 | gem 'awspec'
2 |
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/aws_account/demo/us-east-1/Infrastructure_As_Code/operations:
--------------------------------------------------------------------------------
1 | ../../../../operations/
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/aws_account/demo/us-east-1/Infrastructure_As_Code/spec/.gitignore:
--------------------------------------------------------------------------------
1 | secrets.yml
2 |
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/aws_account/demo/us-east-1/Infrastructure_As_Code/Makefile:
--------------------------------------------------------------------------------
1 | ./operations/makefiles/Makefile/lamp
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/modules/network/subnet/outputs.tf:
--------------------------------------------------------------------------------
1 | output "subnet_id" {
2 | value = "${aws_subnet.main.id}"
3 | }
4 |
--------------------------------------------------------------------------------
/jenkins_home/jenkins.CLI.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | false
4 |
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/aws_account/demo/us-east-1/Infrastructure_As_Code/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | require 'awspec'
2 | Awsecrets.load
3 |
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/aws_account/demo/us-east-1/Infrastructure_As_Code/Rakefile:
--------------------------------------------------------------------------------
1 | require 'rspec/core/rake_task'
2 | RSpec::Core::RakeTask.new('spec')
3 | task :default => :spec
4 |
--------------------------------------------------------------------------------
/jenkins_home/jenkins.security.UpdateSiteWarningsConfiguration.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/jenkins_home/dsl-repo/config/common.groovy:
--------------------------------------------------------------------------------
1 | throttleNumber='1'
2 | numToKeepStr='10'
3 |
4 | phase_description='choose which phase you want to deploy\n doesn\'t matter when release build'
5 | version_description='choose which version you want to deploy\n keep none when release build'
6 |
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/modules/network/subnet/variables.tf:
--------------------------------------------------------------------------------
1 | variable "vpc_id" {}
2 | variable "name" {}
3 | variable "availability_zone" {}
4 | variable "cidr_block" {}
5 | variable "route_table_id" {}
6 |
7 | data "aws_vpc" "target" {
8 | id = "${var.vpc_id}"
9 | }
10 |
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/aws_account/demo/us-east-1/Infrastructure_As_Code/vpc.tf:
--------------------------------------------------------------------------------
1 |
2 | module "vpc" {
3 | source = "../../../../modules/network/vpc"
4 | name = "${var.common["name_prefix"]}-${var.common["phase"]}"
5 | phase = "${var.common["phase"]}"
6 | base_cidr_block = "${var.vpc["base_cidr_block"]}"
7 | }
8 |
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/operations/scripts/lamp/init-variables:
--------------------------------------------------------------------------------
1 | #!/bin/bash -e
2 |
3 | availability_zones=`aws ec2 describe-availability-zones | jq -r .AvailabilityZones[].ZoneName | head -3 | paste -sd "," -`
4 |
5 | cat < terraform.tfvars
6 | cidr = {
7 | availability_zones = "${availability_zones}"
8 | }
9 | EOF
10 |
--------------------------------------------------------------------------------
/jenkins_home/javaposse.jobdsl.plugin.GlobalJobDslSecurityConfiguration.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | false
5 |
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/modules/lamp/variables.tf:
--------------------------------------------------------------------------------
1 | variable "name" {}
2 | variable "vpc_id" {}
3 | variable "subnet_ids" {}
4 |
5 | variable "asg_availability_zones" {}
6 | variable "asg_max_size" {}
7 | variable "asg_min_size" {}
8 |
9 | variable "lc_image_id" {}
10 | variable "lc_instance_type" {}
11 | variable "lc_key_name" {}
12 |
13 | output "elb_dns_name" { value = "${ aws_elb.lamp.dns_name }" }
14 |
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/modules/network/subnet/subnet.tf:
--------------------------------------------------------------------------------
1 | resource "aws_subnet" "main" {
2 | availability_zone = "${var.availability_zone}"
3 | cidr_block = "${var.cidr_block}"
4 | vpc_id = "${var.vpc_id}"
5 |
6 | tags {
7 | Name = "${var.name}"
8 | }
9 | }
10 |
11 | resource "aws_route_table_association" "main" {
12 | subnet_id = "${aws_subnet.main.id}"
13 | route_table_id = "${var.route_table_id}"
14 | }
15 |
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/operations/scripts/common/init-backend:
--------------------------------------------------------------------------------
1 | #!/bin/bash -e
2 |
3 | REPO_NAME='terraform-repo'
4 | KEY=`pwd`
5 | KEY=`echo ${KEY##*$REPO_NAME/}`/terraform.tfstate
6 |
7 | if [ -f ".terraform/terraform.tfstate" ]; then
8 | :
9 | else
10 | terraform init \
11 | -backend-config "bucket=$TERRAFORM_BACKEND_S3_BUCKET" \
12 | -backend-config "key=$KEY" \
13 | -backend-config "region=$AWS_DEFAULT_REGION"
14 | fi
15 |
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/modules/network/vpc/variables.tf:
--------------------------------------------------------------------------------
1 | # variables
2 |
3 | variable "base_cidr_block" {}
4 | variable "name" {}
5 | variable "phase" {}
6 |
7 | # outputs
8 | output "id" { value = "${ aws_vpc.main.id }" }
9 | output "primary_subnet_id" { value = "${ module.primary_subnet.subnet_id }" }
10 | output "secondary_subnet_id" { value = "${ module.secondary_subnet.subnet_id }" }
11 | output "tertiary_subnet_id" { value = "${ module.tertiary_subnet.subnet_id }" }
12 |
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/modules/network/vpc/numbering.tf:
--------------------------------------------------------------------------------
1 | variable "region_numbers" {
2 | default = {
3 | us-east-1 = 1
4 | us-west-1 = 2
5 | us-west-2 = 3
6 | eu-west-1 = 4
7 | }
8 | }
9 |
10 | variable "az_numbers" {
11 | default = {
12 | a = 1
13 | b = 2
14 | c = 3
15 | d = 4
16 | e = 5
17 | f = 6
18 | g = 7
19 | h = 8
20 | i = 9
21 | j = 10
22 | k = 11
23 | l = 12
24 | m = 13
25 | n = 14
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/jenkins_home/dsl-repo/dsl/Common/initial.groovy:
--------------------------------------------------------------------------------
1 | import jenkins.model.Jenkins
2 |
3 | folder('Demo')
4 |
5 | // approve the pipeline groovy automaitcally
6 | def scriptApproval = Jenkins.instance.getExtensionList('org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval')[0]
7 |
8 | scriptApproval.approveSignature("new java.io.File java.lang.String")
9 | scriptApproval.approveSignature("method java.io.File exists")
10 | scriptApproval.approveSignature("method java.io.File isDirectory")
11 |
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/modules/network/numbering/variables.tf:
--------------------------------------------------------------------------------
1 | variable "region_numbers" {
2 | default = {
3 | us-east-1 = 1
4 | us-west-1 = 2
5 | us-west-2 = 3
6 | eu-west-1 = 4
7 | }
8 | }
9 |
10 | variable "az_numbers" {
11 | default = {
12 | a = 1
13 | b = 2
14 | c = 3
15 | d = 4
16 | e = 5
17 | f = 6
18 | g = 7
19 | h = 8
20 | i = 9
21 | j = 10
22 | k = 11
23 | l = 12
24 | m = 13
25 | n = 14
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/modules/network/subnet/numbering.tf:
--------------------------------------------------------------------------------
1 | variable "region_numbers" {
2 | default = {
3 | us-east-1 = 1
4 | us-west-1 = 2
5 | us-west-2 = 3
6 | eu-west-1 = 4
7 | }
8 | }
9 |
10 | variable "az_numbers" {
11 | default = {
12 | a = 1
13 | b = 2
14 | c = 3
15 | d = 4
16 | e = 5
17 | f = 6
18 | g = 7
19 | h = 8
20 | i = 9
21 | j = 10
22 | k = 11
23 | l = 12
24 | m = 13
25 | n = 14
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/modules/network/vpc/security_group.tf:
--------------------------------------------------------------------------------
1 | resource "aws_security_group" "main" {
2 | name = "${var.name}"
3 | description = "Open access within ${var.name} vpc"
4 | vpc_id = "${aws_vpc.main.id}"
5 |
6 | ingress {
7 | from_port = 0
8 | to_port = 0
9 | protocol = -1
10 | cidr_blocks = ["${var.base_cidr_block}"]
11 | }
12 |
13 | egress {
14 | from_port = 0
15 | to_port = 0
16 | protocol = "-1"
17 | cidr_blocks = ["0.0.0.0/0"]
18 | }
19 |
20 | tags {
21 | Name = "${var.name}"
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/operations/scripts/common/do-task:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | if [ "$#" -lt 2 ]; then
4 | echo not enough args
5 | exit 1
6 | fi
7 |
8 | red='\e[1;31m%s\e[0m\n'
9 | green='\e[1;32m%s\e[0m\n'
10 | yellow='\e[1;33m%s\e[0m\n'
11 | blue='\e[1;34m%s\e[0m\n'
12 | magenta='\e[1;35m%s\e[0m\n'
13 | cyan='\e[1;36m%s\e[0m\n'
14 |
15 |
16 | TEXT=$1
17 | shift
18 |
19 |
20 | printf "$blue" "❤ $TEXT"
21 |
22 | "$@"
23 | EXIT_CODE=$?
24 |
25 | if [ $EXIT_CODE -eq 0 ]
26 | then
27 | printf "$green" "✓ $TEXT - SUCCESS"
28 | else
29 | printf "$red" "✗ $TEXT - FAIL"
30 | fi
31 |
32 | echo
33 | exit $EXIT_CODE
34 |
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/operations/makefiles/common/keypair.mk:
--------------------------------------------------------------------------------
1 | $(DIR_KEY_PAIR)/: ; @mkdir -p $@
2 |
3 | $(DIR_KEY_PAIR)/$(AWS_EC2_KEY_NAME).pem: | $(DIR_KEY_PAIR)/
4 | @aws --region ${AWS_DEFAULT_REGION} ec2 create-key-pair \
5 | --key-name ${AWS_EC2_KEY_NAME} \
6 | --query 'KeyMaterial' \
7 | --output text \
8 | > $@
9 | @chmod 400 $@
10 |
11 | ## create ec2 key-pair
12 | create-keypair: $(DIR_KEY_PAIR)/$(AWS_EC2_KEY_NAME).pem
13 |
14 | ## delete ec2 key-pair
15 | delete-keypair:
16 | @aws --region ${AWS_DEFAULT_REGION} ec2 delete-key-pair --key-name ${AWS_EC2_KEY_NAME} || true
17 | @-rm -rf $(DIR_KEY_PAIR)/
18 |
19 | .PHONY: create-key-pair delete-key-pair
20 |
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/modules/network/vpc/vpc.tf:
--------------------------------------------------------------------------------
1 | resource "aws_vpc" "main" {
2 | cidr_block = "${var.base_cidr_block}"
3 | enable_dns_support = true
4 | enable_dns_hostnames = true
5 |
6 | tags {
7 | Name = "${var.name}"
8 | }
9 | }
10 |
11 | resource "aws_internet_gateway" "main" {
12 | vpc_id = "${aws_vpc.main.id}"
13 |
14 | tags {
15 | Name = "${var.name}-igw"
16 | }
17 | }
18 |
19 | resource "aws_route_table" "main" {
20 | vpc_id = "${aws_vpc.main.id}"
21 | route {
22 | cidr_block = "0.0.0.0/0"
23 | gateway_id = "${aws_internet_gateway.main.id}"
24 | }
25 |
26 | tags {
27 | Name = "${var.name}-default"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/modules/lamp/elb.tf:
--------------------------------------------------------------------------------
1 | resource "aws_elb" "lamp" {
2 | name = "lamp"
3 |
4 | cross_zone_load_balancing = true
5 |
6 | health_check {
7 | healthy_threshold = 2
8 | unhealthy_threshold = 2
9 | timeout = 5
10 | target = "HTTP:80/"
11 | interval = 10
12 | }
13 |
14 | idle_timeout = 60
15 |
16 | listener {
17 | instance_port = 80
18 | instance_protocol = "http"
19 | lb_port = 80
20 | lb_protocol = "http"
21 | }
22 |
23 | security_groups = [
24 | "${aws_security_group.lamp.id}",
25 | ]
26 |
27 | subnets = [ "${ split(",", var.subnet_ids) }" ]
28 |
29 | tags {
30 | Name = "${var.name}"
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/modules/lamp/security.tf:
--------------------------------------------------------------------------------
1 | resource "aws_security_group" "lamp" {
2 | name = "${var.name}"
3 | description = "Open access for external real user"
4 | vpc_id = "${var.vpc_id}"
5 |
6 | ingress {
7 | from_port = 80
8 | to_port = 80
9 | protocol = "tcp"
10 | cidr_blocks = ["0.0.0.0/0"]
11 | }
12 |
13 | ingress {
14 | from_port = 22
15 | to_port = 22
16 | protocol = "tcp"
17 | cidr_blocks = ["0.0.0.0/0"]
18 | }
19 |
20 | egress {
21 | from_port = 0
22 | to_port = 0
23 | protocol = "-1"
24 | cidr_blocks = ["0.0.0.0/0"]
25 | }
26 |
27 | tags {
28 | Name = "${var.name}"
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/aws_account/demo/us-east-1/Infrastructure_As_Code/lamp.tf:
--------------------------------------------------------------------------------
1 | module "lamp" {
2 |
3 | source = "../../../../modules/lamp"
4 |
5 | name = "${var.common["name_prefix"]}_${var.common["phase"]}"
6 | vpc_id = "${module.vpc.id}"
7 | subnet_ids = "${module.vpc.primary_subnet_id},${module.vpc.secondary_subnet_id},${module.vpc.tertiary_subnet_id}"
8 |
9 | asg_availability_zones = "${var.lamp_asg["availability_zones"]}"
10 | asg_max_size = "${var.lamp_asg["max_size"]}"
11 | asg_min_size = "${var.lamp_asg["min_size"]}"
12 |
13 | lc_image_id = "${var.lamp_lc["image_id"]}"
14 | lc_instance_type = "${var.lamp_lc["instance_type"]}"
15 | lc_key_name = "${var.lamp_lc["key_name"]}"
16 | }
17 |
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/operations/makefiles/common/help.mk:
--------------------------------------------------------------------------------
1 | ## display this help text
2 | help:
3 | $(info Available targets)
4 | @awk '/^[a-zA-Z\-\_0-9]+:/ { \
5 | nb = sub( /^## /, "", helpMsg ); \
6 | if(nb == 0) { \
7 | helpMsg = $$0; \
8 | nb = sub( /^[^:]*:.* ## /, "", helpMsg ); \
9 | } \
10 | if (nb) \
11 | print $$1 "\t" helpMsg; \
12 | } \
13 | { helpMsg = $$0 }' \
14 | $(MAKEFILE_LIST) | column -ts $$'\t' | \
15 | grep --color '^[^ ]*'
16 |
17 | .PHONY: help
18 |
--------------------------------------------------------------------------------
/jenkins_home/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM jenkins/jenkins:lts
2 |
3 | # install terraform
4 | USER root
5 | RUN wget https://releases.hashicorp.com/terraform/0.10.3/terraform_0.10.3_linux_amd64.zip && unzip terraform_0.10.3_linux_amd64.zip && mv terraform /usr/bin/ && chmod 755 /usr/bin/terraform && rm terraform_0.10.3_linux_amd64.zip
6 |
7 | # install build, test tool
8 | RUN apt-get update && apt-get install -y vim build-essential python-pip python-setuptools python-wheel groff jq ruby --no-install-recommends && rm -rf /var/lib/apt/lists/* && pip install --no-cache-dir awscli && gem install awspec bundler
9 |
10 | # install plugins
11 | USER jenkins
12 | COPY plugins.txt /usr/share/jenkins/ref/plugins.txt
13 | RUN /usr/local/bin/install-plugins.sh < /usr/share/jenkins/ref/plugins.txt
14 |
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/aws_account/demo/us-east-1/Infrastructure_As_Code/spec/vpc_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe vpc('devopsdays-demo') do
4 | it { should exist }
5 | end
6 |
7 | describe route_table('devopsdays-demo-default') do
8 | it { should exist }
9 | it { should have_route('172.20.0.0/16').target(gateway: 'local') }
10 | end
11 |
12 | describe security_group('devopsdays-demo') do
13 | its(:outbound) { should be_opened }
14 | its(:inbound) { should be_opened.for('172.20.0.0/16') }
15 | end
16 |
17 | describe internet_gateway('devopsdays-demo-igw') do
18 | it { should exist }
19 | end
20 |
21 | describe subnet('devopsdays-demo-a') do
22 | it { should exist }
23 | end
24 |
25 | describe subnet('devopsdays-demo-b') do
26 | it { should exist }
27 | end
28 |
29 | describe subnet('devopsdays-demo-c') do
30 | it { should exist }
31 | end
32 |
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/aws_account/demo/us-east-1/Infrastructure_As_Code/variables.tf:
--------------------------------------------------------------------------------
1 | provider "aws" {}
2 |
3 | terraform { backend "s3" {} }
4 |
5 | variable "common" {
6 | type = "map"
7 | default = {
8 | name_prefix = "devopsdays"
9 | phase = "demo"
10 | }
11 | }
12 |
13 | variable "vpc" {
14 | type = "map"
15 | default = {
16 | base_cidr_block = "172.20.0.0/16"
17 | }
18 | }
19 |
20 | variable "lamp_asg" {
21 | type = "map"
22 | default = {
23 | availability_zones = ""
24 | max_size = "5"
25 | min_size = "2"
26 | }
27 | }
28 |
29 | variable "lamp_lc" {
30 | type = "map"
31 | default = {
32 | image_id = "ami-ffd2d1e9"
33 | instance_type = "t2.large"
34 | key_name = "lamp"
35 | }
36 | }
37 |
38 | output "lamp_dns_name" { value = "${ module.lamp.elb_dns_name }" }
39 | output "image_id" { value = "${ var.lamp_lc["image_id"] }" }
40 |
--------------------------------------------------------------------------------
/jenkins_home/jobs/Demo/config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | All
9 | false
10 | false
11 |
12 |
13 |
14 |
15 | All
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/aws_account/demo/us-east-1/Infrastructure_As_Code/spec/lamp_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 | require 'json'
3 |
4 | terraform_output = './spec/terraform.output.json'
5 | tfvars = JSON.parse(File.read(terraform_output))
6 |
7 | describe elb('lamp') do
8 | it { should exist }
9 | it { should have_listener(protocol: 'HTTP', port: 80, instance_protocol: 'HTTP', instance_port: 80) }
10 | it { should have_security_group('devopsdays_demo') }
11 | it { should have_subnet('devopsdays-demo-a') }
12 | it { should have_subnet('devopsdays-demo-b') }
13 | it { should have_subnet('devopsdays-demo-c') }
14 | it { should belong_to_vpc('devopsdays-demo') }
15 | end
16 |
17 | describe autoscaling_group("devopsdays_demo-#{tfvars["image_id"]["value"]}") do
18 | it { should exist }
19 | it { should have_elb('lamp') }
20 | it { should have_launch_configuration("devopsdays_demo-#{tfvars["image_id"]["value"]}") }
21 | its(:min_size) { should eq 2 }
22 | its(:desired_capacity) { should eq 2 }
23 | end
24 |
--------------------------------------------------------------------------------
/jenkins_home/dsl-repo/pipeline/Demo/Infrastructure_As_Code.groovy:
--------------------------------------------------------------------------------
1 | // define pipeline global variable
2 | def job_info = [:]
3 |
4 | job_info['folder'] = 'Demo'
5 | job_info['name'] = env.JOB_BASE_NAME
6 |
7 | pipeline {
8 |
9 | agent any
10 |
11 | stages {
12 | stage('Build') {
13 | when { expression { version == 'none' } }
14 |
15 | steps {
16 | echo 'Building AMI...'
17 | deleteDir()
18 | }
19 | }
20 |
21 | stage('Deploy') {
22 | when { expression { version != 'none' } }
23 |
24 | steps {
25 | dir("${env.JENKINS_HOME}/terraform-repo/aws_account/${phase}/${env.AWS_DEFAULT_REGION}/${job_info['name']}"){
26 | sh "make deploy image_id=${version}"
27 | }
28 | }
29 | }
30 |
31 | stage('Testing') {
32 | when { expression { version != 'none' } }
33 |
34 | steps {
35 | dir("${env.JENKINS_HOME}/terraform-repo/aws_account/${phase}/${env.AWS_DEFAULT_REGION}/${job_info['name']}"){
36 | sh "make test"
37 | }
38 | }
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/README.md:
--------------------------------------------------------------------------------
1 | # Terraform
2 |
3 | This folder illustrate how to create AWS VPC and a simple web server with auto-scaling from scratch
4 |
5 | ## Folder Structure
6 |
7 | There are mainly three foler:
8 |
9 | terraform-repo/
10 | ├── README.md
11 | ├── aws_account
12 | │ └── demo
13 | ├── modules
14 | │ ├── lamp
15 | │ └── network
16 | └── operations
17 | ├── makefiles
18 | └── scripts
19 |
20 | - aws_account: Store the AWS resource want to create
21 | - modules: the commom module for reusing
22 | - operations: the common makefile, shell script for reusing
23 |
24 |
25 |
26 |
27 | ## Operation Command
28 |
29 | - **Don't forgot to swicth folder where terraform define cloud resource**
30 |
31 | ```
32 | ~$ cd ~/terraform-repo/aws_account/demo/us-east-1/Infrastructure_As_Code
33 | ```
34 |
35 | - Check the AWS cloud resource will be create/modify
36 |
37 | ```
38 | ~$ make plan
39 | ```
40 | - Create the AWS cloud resource
41 |
42 | ```
43 | ~$ make apply
44 | ```
45 |
46 | - Test the created AWS resource
47 |
48 | ```
49 | ~$ make test
50 | ```
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/modules/lamp/cloudwatch.tf:
--------------------------------------------------------------------------------
1 | resource "aws_cloudwatch_metric_alarm" "lamp_cpu_high" {
2 |
3 | alarm_name = "${var.name}-cpu-util-high"
4 | comparison_operator = "GreaterThanOrEqualToThreshold"
5 | evaluation_periods = "2"
6 | metric_name = "CPUUtilization"
7 | namespace = "AWS/EC2"
8 | period = "300"
9 | statistic = "Average"
10 | threshold = "70"
11 | alarm_description = "This metric monitors ec2 cpu for high utilization"
12 | alarm_actions = [
13 | "${aws_autoscaling_policy.lamp_scale_out.arn}"
14 | ]
15 | dimensions {
16 | AutoScalingGroupName = "${aws_autoscaling_group.lamp_asg.name}"
17 | }
18 | }
19 |
20 | resource "aws_cloudwatch_metric_alarm" "lamp_cpu_low" {
21 |
22 | alarm_name = "${var.name}-cpu-util-low"
23 | comparison_operator = "LessThanOrEqualToThreshold"
24 | evaluation_periods = "2"
25 | metric_name = "CPUUtilization"
26 | namespace = "AWS/EC2"
27 | period = "300"
28 | statistic = "Average"
29 | threshold = "30"
30 | alarm_description = "This metric monitors ec2 cpu for low utilization"
31 | alarm_actions = [
32 | "${aws_autoscaling_policy.lamp_scale_in.arn}"
33 | ]
34 | dimensions {
35 | AutoScalingGroupName = "${aws_autoscaling_group.lamp_asg.name}"
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/jenkins_home/plugins.txt:
--------------------------------------------------------------------------------
1 | ace-editor:1.1
2 | authentication-tokens:1.3
3 | bouncycastle-api:2.16.2
4 | branch-api:2.0.11
5 | build-user-vars-plugin:1.5
6 | cloudbees-folder:6.1.2
7 | credentials-binding:1.13
8 | credentials:2.1.14
9 | display-url-api:2.0
10 | docker-commons:1.8
11 | docker-workflow:1.12
12 | durable-task:1.14
13 | extensible-choice-parameter:1.4.1
14 | git-client:2.5.0
15 | git-server:1.7
16 | git:3.5.1
17 | github-api:1.86
18 | github-branch-source:2.2.3
19 | github:1.28.0
20 | handlebars:1.1.1
21 | icon-shim:2.0.3
22 | jackson2-api:2.7.3
23 | job-dsl:1.64
24 | jquery-detached:1.2.1
25 | junit:1.21
26 | mailer:1.20
27 | matrix-project:1.11
28 | momentjs:1.1.1
29 | pipeline-build-step:2.5.1
30 | pipeline-github-lib:1.0
31 | pipeline-graph-analysis:1.5
32 | pipeline-input-step:2.8
33 | pipeline-milestone-step:1.3.1
34 | pipeline-model-api:1.1.9
35 | pipeline-model-declarative-agent:1.1.1
36 | pipeline-model-definition:1.1.9
37 | pipeline-model-extensions:1.1.9
38 | pipeline-rest-api:2.9
39 | pipeline-stage-step:2.2
40 | pipeline-stage-tags-metadata:1.1.9
41 | pipeline-stage-view:2.9
42 | plain-credentials:1.4
43 | resource-disposer:0.7
44 | scm-api:2.2.1
45 | script-security:1.33
46 | ssh-credentials:1.13
47 | structs:1.10
48 | timestamper:1.8.8
49 | token-macro:2.3
50 | workflow-aggregator:2.5
51 | workflow-api:2.20
52 | workflow-basic-steps:2.6
53 | workflow-cps-global-lib:2.8
54 | workflow-cps:2.39
55 | workflow-durable-task-step:2.15
56 | workflow-job:2.12.2
57 | workflow-multibranch:2.16
58 | workflow-scm-step:2.6
59 | workflow-step-api:2.12
60 | workflow-support:2.14
61 | ws-cleanup:0.34
62 |
--------------------------------------------------------------------------------
/jenkins_home/dsl-repo/dsl/Demo/Infrastructure_As_Code.groovy:
--------------------------------------------------------------------------------
1 | import jenkins.model.Jenkins
2 |
3 | // define global variable
4 | def job_folder = 'Demo'
5 | def job_name = 'Infrastructure_As_Code'
6 |
7 | // load config file
8 | def config = new ConfigSlurper().parse(readFileFromWorkspace('config/common.groovy'))
9 |
10 | pipelineJob("${job_folder}/${job_name}") {
11 |
12 | properties {
13 | buildDiscarderProperty {
14 | strategy {
15 | logRotator {
16 | artifactDaysToKeepStr('')
17 | artifactNumToKeepStr('')
18 | daysToKeepStr('')
19 | numToKeepStr(config.numToKeepStr)
20 | }
21 | }
22 | }
23 |
24 | parametersDefinitionProperty {
25 | parameterDefinitions {
26 |
27 | choiceParameterDefinition {
28 | name('phase')
29 | choices ('demo')
30 | description(config.phase_description)
31 | }
32 |
33 | choiceParameterDefinition {
34 | name('version')
35 | choices ('ami-ffd2d1e9\nami-6d656316')
36 | description(config.version_description)
37 | }
38 | }
39 | }
40 | }
41 |
42 | definition {
43 | cps {
44 | script(readFileFromWorkspace("pipeline/${job_folder}/${job_name}.groovy"))
45 | }
46 | }
47 | }
48 |
49 | // approve the pipeline groovy automaitcally
50 | def groovyscript = readFileFromWorkspace("pipeline/${job_folder}/${job_name}.groovy")
51 | def scriptApproval = Jenkins.instance.getExtensionList('org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval')[0]
52 | scriptApproval.approveScript(scriptApproval.hash(groovyscript, 'groovy'))
53 |
--------------------------------------------------------------------------------
/jenkins_home/config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 2.60.2
5 | 2
6 | NORMAL
7 | true
8 |
9 | true
10 |
11 |
12 | true
13 | false
14 |
15 | false
16 |
17 | ${ITEM_ROOTDIR}/workspace
18 | ${ITEM_ROOTDIR}/builds
19 |
20 |
21 |
22 |
23 |
24 | 5
25 | 0
26 |
27 |
28 |
29 | all
30 | false
31 | false
32 |
33 |
34 |
35 | all
36 | 50000
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/jenkins_home/scriptApproval.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 4123293e609a6b2ffcf43da0556565a7ae10c103
5 | 6b7a84583a36e242ff9729fabec0e81f19cb199b
6 | 8b886849d001f79bc9772d78f51f33d280664676
7 | 9a5d10f70d717a4de4254b9355d62fd65f549d5b
8 | c9f8200c822e45ecab363164836fbdf2208a6480
9 | efb330409090f2ec91293b156b49b9ec20351754
10 |
11 |
12 | method java.io.File exists
13 | method java.io.File isDirectory
14 | new java.io.File java.lang.String
15 |
16 |
17 |
18 |
19 |
20 |
21 | - Seed
22 |
23 |
34 | groovy
35 |
36 |
37 |
38 |
39 | groovy
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/modules/network/vpc/subnets.tf:
--------------------------------------------------------------------------------
1 | data "aws_availability_zones" "all" {
2 | state = "available"
3 | }
4 |
5 | data "aws_availability_zone" "primary" {
6 | name = "${data.aws_availability_zones.all.names[0]}"
7 | }
8 |
9 | data "aws_availability_zone" "secondary" {
10 | name = "${data.aws_availability_zones.all.names[1]}"
11 | }
12 |
13 | data "aws_availability_zone" "tertiary" {
14 | name = "${data.aws_availability_zones.all.names[2]}"
15 | }
16 |
17 | data "aws_vpc" "target" {
18 | id = "${aws_vpc.main.id}"
19 | }
20 |
21 | module "primary_subnet" {
22 | name = "${var.name}-a"
23 | source = "../subnet"
24 | vpc_id = "${aws_vpc.main.id}"
25 | availability_zone = "${data.aws_availability_zones.all.names[0]}"
26 | cidr_block = "${cidrsubnet(data.aws_vpc.target.cidr_block, 2, lookup(var.az_numbers, data.aws_availability_zone.primary.name_suffix) - 1)}"
27 | route_table_id = "${aws_route_table.main.id}"
28 | }
29 |
30 | module "secondary_subnet" {
31 | name = "${var.name}-b"
32 | source = "../subnet"
33 | vpc_id = "${aws_vpc.main.id}"
34 | availability_zone = "${data.aws_availability_zones.all.names[1]}"
35 | cidr_block = "${cidrsubnet(data.aws_vpc.target.cidr_block, 2, lookup(var.az_numbers, data.aws_availability_zone.secondary.name_suffix) - 1)}"
36 | route_table_id = "${aws_route_table.main.id}"
37 | }
38 |
39 | module "tertiary_subnet" {
40 | name = "${var.name}-c"
41 | source = "../subnet"
42 | vpc_id = "${aws_vpc.main.id}"
43 | availability_zone = "${data.aws_availability_zones.all.names[2]}"
44 | cidr_block = "${cidrsubnet(data.aws_vpc.target.cidr_block, 2, lookup(var.az_numbers, data.aws_availability_zone.tertiary.name_suffix) - 1)}"
45 | route_table_id = "${aws_route_table.main.id}"
46 | }
47 |
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/operations/makefiles/Makefile/lamp:
--------------------------------------------------------------------------------
1 | SHELL += -eu
2 |
3 | BLUE := \033[0;34m
4 | GREEN := \033[0;32m
5 | RED := \033[0;31m
6 | NC := \033[0m
7 |
8 | export DIR_KEY_PAIR := .ssh
9 | export AWS_EC2_KEY_NAME := lamp
10 |
11 | include ./operations/makefiles/common/*.mk
12 |
13 | ## terraform apply
14 | apply: plan
15 | @echo "${BLUE}❤ terraform apply - commencing${NC}"
16 | terraform apply -target=module.vpc
17 | terraform apply -target=module.lamp
18 | @echo "${GREEN}✓ make $@ - success${NC}"
19 |
20 | ## deploy new ami
21 | deploy:
22 | @echo "${BLUE}❤ terraform apply - commencing${NC}"
23 | terraform apply -target=module.lamp -var 'lamp_lc={image_id="${image_id}"}'
24 | @echo "${GREEN}✓ make $@ - success${NC}"
25 |
26 | ## terraform destroy
27 | destroy: init
28 | terraform destroy
29 | @$(MAKE) delete-keypair
30 | @rm -f terraform.tfvars
31 |
32 | ## terraform get
33 | get: ; terraform get
34 |
35 | ## terraform initialization
36 | init: create-keypair terraform.tfvars
37 | @echo "${BLUE}❤ sync module - processing${NC}"
38 | terraform get
39 | @echo "${GREEN}✓ sync module - success${NC}"
40 | @echo "${BLUE}❤ initialize terraform backend - processing${NC}"
41 | @./operations/scripts/common/init-backend
42 | @echo "${GREEN}✓ initialize terraform backend - success${NC}"
43 |
44 | ## terraform output
45 | output:
46 | @terraform output -json
47 |
48 | ## terraform plan
49 | plan: init
50 | terraform validate
51 | @echo "${GREEN}✓ terraform validate - success${NC}"
52 | terraform plan
53 |
54 | ## terraform show
55 | show: ; terraform show
56 |
57 | ## test
58 | test:
59 | @terraform output -json > spec/terraform.output.json
60 | @bundle
61 | @bundle exec rake spec
62 |
63 | terraform.tfvars: ; @operations/scripts/lamp/init-variables
64 |
65 | .PHONY: apply destroy get init plan show
66 | .DEFAULT_GOAL := help
67 |
--------------------------------------------------------------------------------
/jenkins_home/terraform-repo/modules/lamp/asg.tf:
--------------------------------------------------------------------------------
1 | resource "aws_autoscaling_group" "lamp_asg" {
2 | lifecycle { create_before_destroy = true }
3 |
4 | # spread the app instances across the availability zones
5 | availability_zones = ["${split(",", var.asg_availability_zones)}"]
6 |
7 |
8 | # interpolate the LC into the ASG name so it always forces an update
9 | name = "${var.name}-${var.lc_image_id}"
10 | max_size = "${var.asg_max_size}"
11 | min_size = "${var.asg_min_size}"
12 | wait_for_elb_capacity = 2
13 | desired_capacity = 2
14 | health_check_grace_period = 300
15 | health_check_type = "ELB"
16 | launch_configuration = "${aws_launch_configuration.lamp_lc.id}"
17 | load_balancers = ["${aws_elb.lamp.id}"]
18 | vpc_zone_identifier = ["${split(",", var.subnet_ids)}"]
19 |
20 | tag {
21 | key = "Name"
22 | value = "${var.name}-${var.lc_image_id}"
23 | propagate_at_launch = true
24 | }
25 | }
26 |
27 | resource "aws_launch_configuration" "lamp_lc" {
28 | lifecycle { create_before_destroy = true }
29 |
30 | name = "${var.name}-${var.lc_image_id}"
31 | image_id = "${var.lc_image_id}"
32 | instance_type = "${var.lc_instance_type}"
33 | key_name = "${var.lc_key_name}"
34 | associate_public_ip_address = true
35 |
36 | root_block_device {
37 | "volume_type" = "gp2"
38 | "volume_size" = 100
39 | }
40 |
41 | # Our Security group to allow HTTP and SSH access
42 | security_groups = ["${aws_security_group.lamp.id}"]
43 |
44 | }
45 |
46 | resource "aws_autoscaling_policy" "lamp_scale_out" {
47 |
48 | name = "${var.name}-scale-out"
49 | scaling_adjustment = 1
50 | adjustment_type = "ChangeInCapacity"
51 | cooldown = 300
52 | autoscaling_group_name = "${aws_autoscaling_group.lamp_asg.name}"
53 | }
54 |
55 | resource "aws_autoscaling_policy" "lamp_scale_in" {
56 |
57 | name = "${var.name}-scale-in"
58 | scaling_adjustment = -1
59 | adjustment_type = "ChangeInCapacity"
60 | cooldown = 300
61 | autoscaling_group_name = "${aws_autoscaling_group.lamp_asg.name}"
62 | }
63 |
--------------------------------------------------------------------------------
/jenkins.container:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Exit on any individual command failure.
4 | set -e
5 |
6 | # Pretty colors.
7 | red='\033[0;31m'
8 | green='\033[0;32m'
9 | neutral='\033[0m'
10 |
11 | timestamp=$(date +%s)
12 |
13 | image=${IMAGE:-"smalltown/devopsdays_2017:jenkins"}
14 | project=${PROJECT:-"jenkins"}
15 | jenkins_home=${JENKINS_HOME:-"/var/jenkins_home"}
16 | container_id=${CONTAINER_ID:-$project-$timestamp}
17 | aws_access_key_id=${AWS_ACCESS_KEY_ID:-""}
18 | aws_secret_access_key=${AWS_SECRET_ACCESS_KEY:-""}
19 | aws_default_region=${AWS_DEFAULT_REGION:-""}
20 | terraform_backend_s3_bucket=${TERRAFORM_BACKEND_S3_BUCKET:-""}
21 | host_uid=`id -u`
22 | opts="--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
23 |
24 | # pull the latest docker image
25 | printf ${green}"Pull the image: "$image${neutral}"\n"
26 | docker pull $image
27 | printf "\n"
28 |
29 | # run the docker container
30 | printf ${green}"Starting Docker Container: "$image${neutral}:"\n"
31 | printf ${green}"Container ID: "$container_id${neutral}"\n"
32 | printf ${green}"AWS Default Region: "$AWS_DEFAULT_REGION${neutral}"\n"
33 | printf ${green}"AWS Access Key ID: "********${neutral}"\n"
34 | printf ${green}"AWS Secret Access Key: "********${neutral}"\n"
35 | printf ${green}"Terraform Backend S3 Bucket: "$TERRAFORM_BACKEND_S3_BUCKET${neutral}"\n"
36 |
37 | docker run --detach \
38 | --volume="$PWD/jenkins_home":"$jenkins_home":rw \
39 | --volume="/var/run/docker.sock:/var/run/docker.sock":ro \
40 | --volume="/tmp:/tmp":rw \
41 | --publish 80:8080 \
42 | --publish 50000:50000 \
43 | --name $container_id \
44 | --env "AWS_ACCESS_KEY_ID=$aws_access_key_id" \
45 | --env "AWS_SECRET_ACCESS_KEY=$aws_secret_access_key" \
46 | --env "AWS_DEFAULT_REGION=$aws_default_region" \
47 | --env "AWS_REGION=$aws_default_region" \
48 | --env "TERRAFORM_BACKEND_S3_BUCKET=$terraform_backend_s3_bucket" \
49 | --env "HOST_UID=$host_uid" \
50 | $opts $image
51 |
52 | printf "\n"
53 |
--------------------------------------------------------------------------------
/jenkins_home/jobs/Seed/config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | false
6 |
7 |
8 |
9 | -1
10 | 10
11 | -1
12 | -1
13 |
14 |
15 |
16 |
17 | true
18 | false
19 | false
20 | false
21 |
22 | false
23 |
24 |
25 | # clean old properties and script file
26 |
27 | rm -rf *
28 |
29 | # copy the latest properties and script file
30 | cp -rf /var/jenkins_home/dsl-repo/config ./
31 | cp -rf /var/jenkins_home/dsl-repo/dsl ./
32 | cp -rf /var/jenkins_home/dsl-repo/pipeline ./
33 |
34 |
35 |
36 | dsl/Common/initial.groovy
37 | dsl/Common/*.groovy
38 | dsl/*/*.groovy
39 | false
40 | false
41 | false
42 | true
43 | false
44 | false
45 | IGNORE
46 | IGNORE
47 | IGNORE
48 | JENKINS_ROOT
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/jenkins_home/users/devopsdays/config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | devopsdays
4 |
5 |
6 | {AQAAABAAAAAwr21dgbuuGfueZyFkA7zEH8RvLg2w6ycAYWZ9sL8OGdrMcwst8X3fqflyVo4cTz49jA/RqFwks1HA77jKFXsfEw==}
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | all
16 | false
17 | false
18 |
19 |
20 |
21 |
22 |
23 | default
24 |
25 |
26 |
27 |
28 |
29 | true
30 |
31 |
32 | #jbcrypt:$2a$10$SDekHKzZ2LyAzlzCisH5Eu6lbhkXnJ3BKcj/qilfytfH1d17ZLROK
33 |
34 |
35 | devopsdays@gmail.com
36 |
37 |
38 |
39 | authenticated
40 |
41 | 1504404150540
42 |
43 |
44 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | terraform.tfvars
2 | terraform.tfstate.backup
3 | .terraform
4 | .terraform.d
5 | terraform.output.json
6 | .ssh
7 |
8 | Gemfile.lock
9 | .gem
10 | .bundle
11 | .viminfo
12 | .rspec
13 |
14 | # xml config
15 | #jenkins_home/config.xml
16 | jenkins_home/github-plugin-configuration.xml
17 | jenkins_home/hudson.model.UpdateCenter.xml
18 | jenkins_home/hudson.plugins.git.GitTool.xml
19 | jenkins_home/hudson.plugins.git.GitSCM.xml
20 | jenkins_home/hudson.plugins.timestamper.TimestamperConfig.xml
21 | jenkins_home/hudson.plugins.throttleconcurrents.ThrottleJobProperty.xml
22 | jenkins_home/hudson.tasks.Mailer.xml
23 | jenkins_home/hudson.tasks.Shell.xml
24 | jenkins_home/hudson.triggers.SCMTrigger.xml
25 | jenkins_home/javaposse.jobdsl.plugin.ExecuteDslScripts.xml
26 | jenkins_home/jenkins.model.ArtifactManagerConfiguration.xml
27 | jenkins_home/jenkins.model.DownloadSettings.xml
28 | jenkins_home/jenkins.model.JenkinsLocationConfiguration.xml
29 | #jenkins_home/javaposse.jobdsl.plugin.GlobalJobDslSecurityConfiguration.xml
30 | #jenkins_home/jenkins.CLI.xml
31 | jenkins_home/jenkins.security.QueueItemAuthenticatorConfiguration.xml
32 | jenkins_home/jp.ikedam.jenkins.plugins.extensible_choice_parameter.ExtensibleChoiceParameterDefinition.xml
33 | jenkins_home/jp.ikedam.jenkins.plugins.extensible_choice_parameter.GlobalTextareaChoiceListProvider.xml
34 | jenkins_home/nodeMonitors.xml
35 | jenkins_home/org.jenkinsci.plugins.pipeline.modeldefinition.config.GlobalConfig.xml
36 | jenkins_home/org.jenkinsci.plugins.workflow.flow.FlowExecutionList.xml
37 | jenkins_home/queue.xml
38 | jenkins_home/queue.xml.bak
39 |
40 | # jenkins job
41 | lastStable
42 | lastSuccessful
43 | nextBuildNumber
44 | builds/
45 | *workspace*
46 |
47 | # others
48 | jenkins_home/.bash_history
49 | jenkins_home/.docker/
50 | jenkins_home/.gitconfig
51 | jenkins_home/.java/
52 | jenkins_home/.owner
53 | jenkins_home/.ssh/known_hosts
54 | jenkins_home/*.log
55 | jenkins_home/jenkins.install.InstallUtil.lastExecVersion
56 | jenkins_home/jenkins.install.UpgradeWizard.state
57 | jenkins_home/identity.key.enc
58 | jenkins_home/init.groovy.d
59 | jenkins_home/logs/
60 | jenkins_home/packer-repo@tmp/
61 | jenkins_home/plugins/
62 | jenkins_home/plugins/*.bak
63 | jenkins_home/secret.key
64 | jenkins_home/secret.key.not-so-secret
65 | jenkins_home/secrets/*
66 | !jenkins_home/secrets/slave-to-master-security-kill-switch
67 | jenkins_home/updates/
68 | jenkins_home/userContent/
69 | #jenkins_home/users/
70 | jenkins_home/war/
71 | jenkins_home/pipeline-lib-serving
72 | *@tmp
73 | .DS_Store
74 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DevOpsDays Taipei 2017 - Everything As Code
2 | This repository is for demonstrate below items:
3 |
4 | - Jenkins: Pipeline As Code
5 | - Terraform: Infrastructure As Code
6 | - CM: Provision As Code
7 | - Packer: Image As Code
8 | - Docker: Server As Code
9 | - Kubernetes: Orchestration As Code
10 | - Hubot: Chat As Code
11 |
12 | If anyone is interested about the ignore topic above, here is the [**Slide**](https://www.slideshare.net/smalltown20110306/coscup-2017-infrastructure-as-code) and [**GitHub Repository**](https://github.com/smalltown/coscup_2017) for reference ^^
13 |
14 | # There are three modules need to be setup...
15 |
16 | ## Prerequisite
17 |
18 | - Linux Based Machine
19 | - Docker
20 | - AWS Account
21 |
22 | ## Jenkins (power by container)
23 |
24 | - Export AWS access key ID, secret access key and region
25 |
26 | ```
27 | ~$ export AWS_ACCESS_KEY_ID =XXXXXX
28 | ~$ export AWS_SECRET_ACCESS_KEY =XXXXXX
29 | ~$ export AWS_DEFAULT_REGION=us-east-1
30 | ```
31 |
32 | - Create a AWS S3 bucket as Terraform as backend to store cloud resource state, then export the S3 bucket name
33 |
34 | ```
35 | ~$ export TERRAFORM_BACKEND_S3_BUCKET=${S3 Bucket Name}
36 |
37 | ```
38 |
39 | - Execute below command to launch Jenkins
40 |
41 | ```
42 | ~$ ./jenkins.container
43 |
44 | Pull the image: smalltown/devopsdays_2017:jenkins
45 | jenkins: Pulling from smalltown/devopsdays_2017
46 | 06b22ddb1913: Already exists
47 |
48 | ...
49 |
50 | Digest: sha256:3e8e2c1e3dac5d0df8f767c2f73bbbdfbf5872f528efb3ae2c0955e0534da9cf
51 | Status: Downloaded newer image for smalltown/ devopsdays_2017:jenkins
52 |
53 | Starting Docker Container: smalltown/devopsdays_2017:jenkins:
54 | Container ID: jenkins-1504540691
55 | AWS Default Region: us-east-1
56 | AWS Access Key ID: ********
57 | AWS Secret Access Key: ********
58 | Terraform Backend S3 Bucket: ${S3 Bucket Name}
59 | e682b9b8ba03d66cd7de01c51446627871a1f860b19ce33984f7a24090ab1854
60 | ```
61 |
62 | - Visit http://127.0.0.1 from the browser after several minutes
63 |
64 | - Login Jenkins by below account and password
65 | - Admin Account : devopsdays
66 | - Admin Password : devopsdays
67 |
68 | ## Terraform (power by Hashicorp)
69 |
70 | - Get the Jenkins container ID, e.g. here is e682b9b8ba03
71 |
72 | ```
73 | ~$ docker ps
74 |
75 | CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
76 | e682b9b8ba03 smalltown/devopsdays_2017:jenkins "/bin/tini -- /usr..." 10 minutes ago Up 10 minutes 0.0.0.0:50000->50000/tcp, 0.0.0.0:80->8080/tcp jenkins-1504540691
77 | ```
78 |
79 | - Enter the container
80 |
81 | ```
82 | ~$ docker exec -it e682b9b8ba03 bash
83 | ```
84 |
85 | - Switch to the Terraform repository folder
86 |
87 | ```
88 | ~$ cd ~/terraform-repo/aws_account/demo/us-east-1/Infrastructure_As_Code
89 | ```
90 |
91 | - Refer to [**The Document**](./jenkins_home/terraform-repo/README.md) for terraform operation
--------------------------------------------------------------------------------
/jenkins_home/jobs/Demo/jobs/Infrastructure_As_Code/config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | false
12 |
13 |
14 |
15 |
16 | phase
17 | choose which phase you want to deploy
18 | doesn't matter when release build
19 |
20 |
21 | demo
22 |
23 |
24 |
25 |
26 | version
27 | choose which version you want to deploy
28 | keep none when release build
29 |
30 |
31 | ami-ffd2d1e9
32 | ami-6d656316
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 | -1
41 | 10
42 | -1
43 | -1
44 |
45 |
46 |
47 |
48 |
90 | false
91 |
92 |
93 | false
94 |
--------------------------------------------------------------------------------