Created
March 29, 2017 21:52
-
-
Save KenVanHoeylandt/5ec0075e8177141035702956f561e445 to your computer and use it in GitHub Desktop.
Terraform and Docker with GitLab and Jenkins instances
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bind Docker socket to port | |
socat -d TCP-LISTEN:2376,range=127.0.0.1/32,reuseaddr,fork UNIX:/var/run/docker.sock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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