SlideShare a Scribd company logo
1 of 27
Download to read offline
Delivering Go.CD
with Terraform and Docker
http://www.google.com/about/datacenters/gallery/#/all/2
About me
Jorrit Salverda
Principle something at Travix
I automate...
● builds
● deployments
● infrastructure
What is Go.CD?
resource "google_compute_instance" "gocd_demo_agent" {
name = "gocd-demo-agent"
machine_type = "n1-standard-2"
zone = "${var.google_region}"
disk {
image = "container-vm"
auto_delete = "true"
}
And Terraform?
Containers...
● bundle dependencies
● allow content-agnostic manipulation
● deploy very fast
● run anywhere
Why Docker?
Live demo
What’s next?
● Monitoring
● Ship logs
● Volume plugins
● Shrink container image
● Run on Kubernetes
● Windows agents for .net builds
Thanks
jsalverda@travix.com
@jorritsalverda
Docker images
● travix/gocd-server
● travix/gocd-haproxy
● travix/gocd-agent
Appendix
Terraform - variables
variable "google_project" {
default = "google-project-name"
}
variable "google_region" {
default = "europe-west1-b"
}
Terraform - providers
provider "google" {
account_file = "${file("google-service-account-key.json")}"
project = "${var.google_project}"
region = "${var.google_region}"
}
provider "aws" {
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret_key}"
region = "${var.aws_region}"
}
Terraform - persistent disks
resource "google_compute_disk" "gocd_demo_server_persistent_data" {
name = "gocd-demo-server-persistent-data"
zone = "${var.google_region}"
type = "pd-ssd"
size = "200"
}
Terraform - compute instances
resource "google_compute_instance" "gocd_demo_server" {
name = "gocd-demo-server"
machine_type = "n1-standard-2"
zone = "${var.google_region}"
disk { image = "container-vm" }
...
Terraform - compute instances
...
network_interface {
network = "private-dev"
access_config { // Ephemeral IP }
}
metadata {
startup-script = "${file("bootstrap/gocd-demo-server-startup.sh")}"
google-container-manifest = "${file("bootstrap/gocd-demo-server-containers.yml")}"
}
}
Terraform - outputs
output "output_google_compute_instance_gocd_demo_server_internal_ip_address" {
value = "${google_compute_instance.gocd_demo_server.network_interface.0.address}"
}
output "output_google_compute_instance_gocd_demo_server_external_ip_address" {
value = "${google_compute_instance.gocd_demo_server.network_interface.0.access_config.
0.nat_ip}"
}
Dockerfile travix/gocd-server
FROM travix/base-debian-git-jre7:latest
MAINTAINER Travix
# build time environment variables
ENV GO_VERSION=15.2.0-2248 
USER_NAME=go 
USER_ID=999 
GROUP_NAME=go 
GROUP_ID=999
Dockerfile travix/gocd-server
# install go server
RUN groupadd -r -g $GROUP_ID $GROUP_NAME 
&& useradd -r -g $GROUP_NAME -u $USER_ID -d /var/go $USER_NAME 
&& curl -fSL "http://download.go.cd/gocd-deb/go-server-$GO_VERSION.deb" 
-o go-server.deb 
&& dpkg -i go-server.deb 
&& rm -rf go-server.db 
&& sed -i -e "s/DAEMON=Y/DAEMON=N/" /etc/default/go-server
Dockerfile travix/gocd-server
# runtime environment variables
ENV SERVER_MEM=512m 
SERVER_MAX_MEM=1024m 
SERVER_MIN_PERM_GEN=128m 
SERVER_MAX_PERM_GEN=256m 
AGENT_KEY=""
# expose ports
EXPOSE 8153 8154
Dockerfile travix/gocd-server
# define default command
CMD groupmod -g ${GROUP_ID} ${GROUP_NAME}; 
usermod -g ${GROUP_ID} -u ${USER_ID} ${USER_NAME}; 
chown -R ${USER_NAME}:${GROUP_NAME} /var/lib/go-server /var/log/go-server /etc/go; 
(/bin/su - ${USER_NAME} -c "/usr/share/go-server/server.sh &"); 
until curl -s -o /dev/null 'http://localhost:8153'; 
do sleep 1; 
done; 
/bin/su - ${USER_NAME} -c "exec tail -F /var/log/go-server/*"
Startup script
#! /bin/bash
# create users for mounting local directories as container volumes
sudo groupadd -r -g 999 go
sudo useradd -r -g go -u 999 go
sudo groupadd -r -g 998 haproxy
sudo useradd -r -g haproxy -u 998 haproxy
# mount local ssd
sudo mkdir -p /mnt/gocd-server-local-ssd
sudo /usr/share/google/safe_format_and_mount -m "mkfs.ext4 -F" /dev/disk/by-id/google-
local-ssd-0 /mnt/gocd-server-local-ssd
sudo resize2fs /dev/disk/by-id/google-local-ssd-0
Kubelet manifest - container
version: v1
kind: Pod
metadata:
name: gocd-server
spec:
containers:
- name: gocd-server
image: travix/gocd-server:latest
imagePullPolicy: Always
Kubelet manifest - volumes
volumeMounts:
- mountPath: /var/lib/go-server/db/h2db
name: gocd-server-db
- mountPath: /etc/go
name: gocd-server-config
volumes:
- name: gocd-server-db
hostPath:
Path: /mnt/gocd-server-persistent-disk/db
- name: gocd-server-config
hostPath:
Path: /mnt/gocd-server-persistent-disk/config
Kubelet manifest - ports
ports:
- name: server-http
containerPort: 8153
hostPort: 8153
protocol: TCP
- name: server-https
containerPort: 8154
hostPort: 8154
protocol: TCP
Kubelet manifest - environment vars
env:
- name: "AGENT_KEY"
value: "secret-key-for-autoregistration"
- name: "SERVER_MEM"
value: "4096m"
- name: "SERVER_MAX_MEM"
value: "4096m"
- name: "SERVER_MIN_PERM_GEN"
value: "1024m"
- name: "SERVER_MAX_PERM_GEN"
value: "1024m"

More Related Content

What's hot

Docker in production service discovery with consul - road to opscon 2015
Docker in production  service discovery with consul - road to opscon 2015Docker in production  service discovery with consul - road to opscon 2015
Docker in production service discovery with consul - road to opscon 2015
Giovanni Toraldo
 

What's hot (20)

2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
 
Docker for Java Developers
Docker for Java DevelopersDocker for Java Developers
Docker for Java Developers
 
Kubernetes Boston — Custom High Availability of Kubernetes
Kubernetes Boston — Custom High Availability of KubernetesKubernetes Boston — Custom High Availability of Kubernetes
Kubernetes Boston — Custom High Availability of Kubernetes
 
Consuming Cinder from Docker
Consuming Cinder from DockerConsuming Cinder from Docker
Consuming Cinder from Docker
 
A Hands-on Introduction on Terraform Best Concepts and Best Practices
A Hands-on Introduction on Terraform Best Concepts and Best Practices A Hands-on Introduction on Terraform Best Concepts and Best Practices
A Hands-on Introduction on Terraform Best Concepts and Best Practices
 
Introduction openstack-meetup-nov-28
Introduction openstack-meetup-nov-28Introduction openstack-meetup-nov-28
Introduction openstack-meetup-nov-28
 
Supercharging Content Delivery with Varnish
Supercharging Content Delivery with VarnishSupercharging Content Delivery with Varnish
Supercharging Content Delivery with Varnish
 
Lesson Learned from Using Docker Swarm at Pronto
Lesson Learned from Using Docker Swarm at ProntoLesson Learned from Using Docker Swarm at Pronto
Lesson Learned from Using Docker Swarm at Pronto
 
Ansible docker
Ansible dockerAnsible docker
Ansible docker
 
Scaling Docker Containers using Kubernetes and Azure Container Service
Scaling Docker Containers using Kubernetes and Azure Container ServiceScaling Docker Containers using Kubernetes and Azure Container Service
Scaling Docker Containers using Kubernetes and Azure Container Service
 
Docker 101 @KACST Saudi HPC 2016
Docker 101  @KACST Saudi HPC 2016Docker 101  @KACST Saudi HPC 2016
Docker 101 @KACST Saudi HPC 2016
 
Docker in production service discovery with consul - road to opscon 2015
Docker in production  service discovery with consul - road to opscon 2015Docker in production  service discovery with consul - road to opscon 2015
Docker in production service discovery with consul - road to opscon 2015
 
An intro to Docker, Terraform, and Amazon ECS
An intro to Docker, Terraform, and Amazon ECSAn intro to Docker, Terraform, and Amazon ECS
An intro to Docker, Terraform, and Amazon ECS
 
Monitoring Containers at New Relic by Sean Kane
Monitoring Containers at New Relic by Sean Kane Monitoring Containers at New Relic by Sean Kane
Monitoring Containers at New Relic by Sean Kane
 
Terraform 101: What's infrastructure as code?
Terraform 101: What's infrastructure as code?Terraform 101: What's infrastructure as code?
Terraform 101: What's infrastructure as code?
 
Microservices blue-green-deployment-with-docker
Microservices blue-green-deployment-with-dockerMicroservices blue-green-deployment-with-docker
Microservices blue-green-deployment-with-docker
 
Docker in production: reality, not hype (OSCON 2015)
Docker in production: reality, not hype (OSCON 2015)Docker in production: reality, not hype (OSCON 2015)
Docker in production: reality, not hype (OSCON 2015)
 
Docker meetup - PaaS interoperability
Docker meetup - PaaS interoperabilityDocker meetup - PaaS interoperability
Docker meetup - PaaS interoperability
 
From Docker to Production - ZendCon 2016
From Docker to Production - ZendCon 2016From Docker to Production - ZendCon 2016
From Docker to Production - ZendCon 2016
 
A Survey of Container Security in 2016: A Security Update on Container Platforms
A Survey of Container Security in 2016: A Security Update on Container PlatformsA Survey of Container Security in 2016: A Security Update on Container Platforms
A Survey of Container Security in 2016: A Security Update on Container Platforms
 

Viewers also liked

Viewers also liked (20)

Go.cd - the tool that Jenkins ain't
Go.cd - the tool that Jenkins ain'tGo.cd - the tool that Jenkins ain't
Go.cd - the tool that Jenkins ain't
 
Agile Testers Conference 2016 - GoCD + Docker + Docker Compose: uma história ...
Agile Testers Conference 2016 - GoCD + Docker + Docker Compose: uma história ...Agile Testers Conference 2016 - GoCD + Docker + Docker Compose: uma história ...
Agile Testers Conference 2016 - GoCD + Docker + Docker Compose: uma história ...
 
Meetup DevOps Carioca - GoCD + Docker + Docker Compose: uma história de amor
Meetup DevOps Carioca - GoCD + Docker + Docker Compose: uma história de amorMeetup DevOps Carioca - GoCD + Docker + Docker Compose: uma história de amor
Meetup DevOps Carioca - GoCD + Docker + Docker Compose: uma história de amor
 
Web Service Creation in HTML5
Web Service Creation in HTML5Web Service Creation in HTML5
Web Service Creation in HTML5
 
XebiCon'16 : Wescale - GoCD démystifié Aurélien Maury, Directeur Technique et...
XebiCon'16 : Wescale - GoCD démystifié Aurélien Maury, Directeur Technique et...XebiCon'16 : Wescale - GoCD démystifié Aurélien Maury, Directeur Technique et...
XebiCon'16 : Wescale - GoCD démystifié Aurélien Maury, Directeur Technique et...
 
Integrating Puppet with Cloud Infrastructures-Remco Overdijk
Integrating Puppet with Cloud Infrastructures-Remco OverdijkIntegrating Puppet with Cloud Infrastructures-Remco Overdijk
Integrating Puppet with Cloud Infrastructures-Remco Overdijk
 
Rapid Infrastructure Provisioning
Rapid Infrastructure ProvisioningRapid Infrastructure Provisioning
Rapid Infrastructure Provisioning
 
Terraform
TerraformTerraform
Terraform
 
Terraform and cloud.ca
Terraform and cloud.caTerraform and cloud.ca
Terraform and cloud.ca
 
Infrastructure as Code: Introduction to Terraform
Infrastructure as Code: Introduction to TerraformInfrastructure as Code: Introduction to Terraform
Infrastructure as Code: Introduction to Terraform
 
Terraform
TerraformTerraform
Terraform
 
Terraform
TerraformTerraform
Terraform
 
DevOps - Infrastructure as Code by Andre Marcelo-Tanner
DevOps - Infrastructure as Code by Andre Marcelo-TannerDevOps - Infrastructure as Code by Andre Marcelo-Tanner
DevOps - Infrastructure as Code by Andre Marcelo-Tanner
 
Terraform at Scale
Terraform at ScaleTerraform at Scale
Terraform at Scale
 
Terraform Introduction
Terraform IntroductionTerraform Introduction
Terraform Introduction
 
Etcd terraform by Alex Somesan
Etcd terraform by Alex SomesanEtcd terraform by Alex Somesan
Etcd terraform by Alex Somesan
 
Terraform: Cloud Configuration Management (WTC/IPC'16)
Terraform: Cloud Configuration Management (WTC/IPC'16)Terraform: Cloud Configuration Management (WTC/IPC'16)
Terraform: Cloud Configuration Management (WTC/IPC'16)
 
2016 - IGNITE - Terraform to go from Zero to Prod in less than 1 month and TH...
2016 - IGNITE - Terraform to go from Zero to Prod in less than 1 month and TH...2016 - IGNITE - Terraform to go from Zero to Prod in less than 1 month and TH...
2016 - IGNITE - Terraform to go from Zero to Prod in less than 1 month and TH...
 
Refactoring terraform
Refactoring terraformRefactoring terraform
Refactoring terraform
 
Rediscovering Developer Opportunities in the Philippines by Fred Tshidimba
Rediscovering Developer Opportunities in the Philippines by Fred TshidimbaRediscovering Developer Opportunities in the Philippines by Fred Tshidimba
Rediscovering Developer Opportunities in the Philippines by Fred Tshidimba
 

Similar to Delivering Go.CD with Terraform and Docker

Going live with BommandBox and docker Into The Box 2018
Going live with BommandBox and docker Into The Box 2018Going live with BommandBox and docker Into The Box 2018
Going live with BommandBox and docker Into The Box 2018
Ortus Solutions, Corp
 

Similar to Delivering Go.CD with Terraform and Docker (20)

[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
 
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
 
Challenges of container configuration
Challenges of container configurationChallenges of container configuration
Challenges of container configuration
 
Golang Project Layout and Practice
Golang Project Layout and PracticeGolang Project Layout and Practice
Golang Project Layout and Practice
 
Improving WordPress performance (xdebug and profiling)
Improving WordPress performance (xdebug and profiling)Improving WordPress performance (xdebug and profiling)
Improving WordPress performance (xdebug and profiling)
 
Improving WordPress Performance with Xdebug and PHP Profiling
Improving WordPress Performance with Xdebug and PHP ProfilingImproving WordPress Performance with Xdebug and PHP Profiling
Improving WordPress Performance with Xdebug and PHP Profiling
 
Docker, the Future of DevOps
Docker, the Future of DevOpsDocker, the Future of DevOps
Docker, the Future of DevOps
 
Docker linuxday 2015
Docker linuxday 2015Docker linuxday 2015
Docker linuxday 2015
 
Drone CI/CD 自動化測試及部署
Drone CI/CD 自動化測試及部署Drone CI/CD 自動化測試及部署
Drone CI/CD 自動化測試及部署
 
Deis, a PaaS built with Docker, Docker Meetup Sao Paulo #3 @Wayra
Deis, a PaaS built with Docker,  Docker Meetup Sao Paulo #3 @WayraDeis, a PaaS built with Docker,  Docker Meetup Sao Paulo #3 @Wayra
Deis, a PaaS built with Docker, Docker Meetup Sao Paulo #3 @Wayra
 
Into The Box 2018 Going live with commandbox and docker
Into The Box 2018 Going live with commandbox and dockerInto The Box 2018 Going live with commandbox and docker
Into The Box 2018 Going live with commandbox and docker
 
Going live with BommandBox and docker Into The Box 2018
Going live with BommandBox and docker Into The Box 2018Going live with BommandBox and docker Into The Box 2018
Going live with BommandBox and docker Into The Box 2018
 
Docker as development environment
Docker as development environmentDocker as development environment
Docker as development environment
 
Docker, c'est bonheur !
Docker, c'est bonheur !Docker, c'est bonheur !
Docker, c'est bonheur !
 
Docker slides
Docker slidesDocker slides
Docker slides
 
New Docker Features for Orchestration and Containers
New Docker Features for Orchestration and ContainersNew Docker Features for Orchestration and Containers
New Docker Features for Orchestration and Containers
 
Write php deploy everywhere
Write php deploy everywhereWrite php deploy everywhere
Write php deploy everywhere
 
The Fairy Tale of the One Command Build Script
The Fairy Tale of the One Command Build ScriptThe Fairy Tale of the One Command Build Script
The Fairy Tale of the One Command Build Script
 
Real World Experience of Running Docker in Development and Production
Real World Experience of Running Docker in Development and ProductionReal World Experience of Running Docker in Development and Production
Real World Experience of Running Docker in Development and Production
 
Geode on Docker
Geode on DockerGeode on Docker
Geode on Docker
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Delivering Go.CD with Terraform and Docker

  • 1. Delivering Go.CD with Terraform and Docker http://www.google.com/about/datacenters/gallery/#/all/2
  • 2. About me Jorrit Salverda Principle something at Travix I automate... ● builds ● deployments ● infrastructure
  • 3.
  • 5. resource "google_compute_instance" "gocd_demo_agent" { name = "gocd-demo-agent" machine_type = "n1-standard-2" zone = "${var.google_region}" disk { image = "container-vm" auto_delete = "true" } And Terraform?
  • 6. Containers... ● bundle dependencies ● allow content-agnostic manipulation ● deploy very fast ● run anywhere Why Docker?
  • 8. What’s next? ● Monitoring ● Ship logs ● Volume plugins ● Shrink container image ● Run on Kubernetes ● Windows agents for .net builds
  • 9.
  • 10.
  • 13. Terraform - variables variable "google_project" { default = "google-project-name" } variable "google_region" { default = "europe-west1-b" }
  • 14. Terraform - providers provider "google" { account_file = "${file("google-service-account-key.json")}" project = "${var.google_project}" region = "${var.google_region}" } provider "aws" { access_key = "${var.aws_access_key}" secret_key = "${var.aws_secret_key}" region = "${var.aws_region}" }
  • 15. Terraform - persistent disks resource "google_compute_disk" "gocd_demo_server_persistent_data" { name = "gocd-demo-server-persistent-data" zone = "${var.google_region}" type = "pd-ssd" size = "200" }
  • 16. Terraform - compute instances resource "google_compute_instance" "gocd_demo_server" { name = "gocd-demo-server" machine_type = "n1-standard-2" zone = "${var.google_region}" disk { image = "container-vm" } ...
  • 17. Terraform - compute instances ... network_interface { network = "private-dev" access_config { // Ephemeral IP } } metadata { startup-script = "${file("bootstrap/gocd-demo-server-startup.sh")}" google-container-manifest = "${file("bootstrap/gocd-demo-server-containers.yml")}" } }
  • 18. Terraform - outputs output "output_google_compute_instance_gocd_demo_server_internal_ip_address" { value = "${google_compute_instance.gocd_demo_server.network_interface.0.address}" } output "output_google_compute_instance_gocd_demo_server_external_ip_address" { value = "${google_compute_instance.gocd_demo_server.network_interface.0.access_config. 0.nat_ip}" }
  • 19. Dockerfile travix/gocd-server FROM travix/base-debian-git-jre7:latest MAINTAINER Travix # build time environment variables ENV GO_VERSION=15.2.0-2248 USER_NAME=go USER_ID=999 GROUP_NAME=go GROUP_ID=999
  • 20. Dockerfile travix/gocd-server # install go server RUN groupadd -r -g $GROUP_ID $GROUP_NAME && useradd -r -g $GROUP_NAME -u $USER_ID -d /var/go $USER_NAME && curl -fSL "http://download.go.cd/gocd-deb/go-server-$GO_VERSION.deb" -o go-server.deb && dpkg -i go-server.deb && rm -rf go-server.db && sed -i -e "s/DAEMON=Y/DAEMON=N/" /etc/default/go-server
  • 21. Dockerfile travix/gocd-server # runtime environment variables ENV SERVER_MEM=512m SERVER_MAX_MEM=1024m SERVER_MIN_PERM_GEN=128m SERVER_MAX_PERM_GEN=256m AGENT_KEY="" # expose ports EXPOSE 8153 8154
  • 22. Dockerfile travix/gocd-server # define default command CMD groupmod -g ${GROUP_ID} ${GROUP_NAME}; usermod -g ${GROUP_ID} -u ${USER_ID} ${USER_NAME}; chown -R ${USER_NAME}:${GROUP_NAME} /var/lib/go-server /var/log/go-server /etc/go; (/bin/su - ${USER_NAME} -c "/usr/share/go-server/server.sh &"); until curl -s -o /dev/null 'http://localhost:8153'; do sleep 1; done; /bin/su - ${USER_NAME} -c "exec tail -F /var/log/go-server/*"
  • 23. Startup script #! /bin/bash # create users for mounting local directories as container volumes sudo groupadd -r -g 999 go sudo useradd -r -g go -u 999 go sudo groupadd -r -g 998 haproxy sudo useradd -r -g haproxy -u 998 haproxy # mount local ssd sudo mkdir -p /mnt/gocd-server-local-ssd sudo /usr/share/google/safe_format_and_mount -m "mkfs.ext4 -F" /dev/disk/by-id/google- local-ssd-0 /mnt/gocd-server-local-ssd sudo resize2fs /dev/disk/by-id/google-local-ssd-0
  • 24. Kubelet manifest - container version: v1 kind: Pod metadata: name: gocd-server spec: containers: - name: gocd-server image: travix/gocd-server:latest imagePullPolicy: Always
  • 25. Kubelet manifest - volumes volumeMounts: - mountPath: /var/lib/go-server/db/h2db name: gocd-server-db - mountPath: /etc/go name: gocd-server-config volumes: - name: gocd-server-db hostPath: Path: /mnt/gocd-server-persistent-disk/db - name: gocd-server-config hostPath: Path: /mnt/gocd-server-persistent-disk/config
  • 26. Kubelet manifest - ports ports: - name: server-http containerPort: 8153 hostPort: 8153 protocol: TCP - name: server-https containerPort: 8154 hostPort: 8154 protocol: TCP
  • 27. Kubelet manifest - environment vars env: - name: "AGENT_KEY" value: "secret-key-for-autoregistration" - name: "SERVER_MEM" value: "4096m" - name: "SERVER_MAX_MEM" value: "4096m" - name: "SERVER_MIN_PERM_GEN" value: "1024m" - name: "SERVER_MAX_PERM_GEN" value: "1024m"