Skip to content

Instantly share code, notes, and snippets.

@KenVanHoeylandt
Created March 29, 2017 21:52
Show Gist options
  • Save KenVanHoeylandt/5ec0075e8177141035702956f561e445 to your computer and use it in GitHub Desktop.
Save KenVanHoeylandt/5ec0075e8177141035702956f561e445 to your computer and use it in GitHub Desktop.
Terraform and Docker with GitLab and Jenkins instances
# Bind Docker socket to port
socat -d TCP-LISTEN:2376,range=127.0.0.1/32,reuseaddr,fork UNIX:/var/run/docker.sock
provider "docker" {
host = "tcp://127.0.0.1:2376/"
}
resource "docker_network" "ci_network" {
name = "CI Network"
}
resource "docker_container" "gitlab" {
image = "${docker_image.gitlab.latest}"
name = "Gitlab"
network_mode = "bridge"
networks = [ "${docker_network.ci_network.name}" ]
hostname = "gitlab"
ports = {
internal = 80
external = 8080
}
}
resource "docker_container" "jenkins_master" {
image = "${docker_image.jenkins_master.latest}"
name = "JenkinsMaster"
network_mode = "bridge"
networks = [ "${docker_network.ci_network.name}" ]
hostname = "jenkins-master"
ports = {
internal = 80
external = 9000
}
}
resource "docker_container" "jenkins_slave" {
count = 2
image = "${docker_image.jenkins_slave.latest}"
name = "JenkinsSlave${count.index + 1}"
network_mode = "bridge"
networks = [ "${docker_network.ci_network.name}" ]
hostname = "jenkins-slave"
ports = {
internal = 80
external = "${9001 + count.index}"
}
}
resource "docker_image" "gitlab" {
name = "gitlab/gitlab-ce:latest"
}
resource "docker_image" "jenkins_master" {
name = "jenkins:latest"
}
resource "docker_image" "jenkins_slave" {
name = "publicisworldwide/jenkins-slave:latest"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment