Skip to content
This repository has been archived by the owner on Apr 26, 2019. It is now read-only.

Commit

Permalink
Add GoCD DinD agent.
Browse files Browse the repository at this point in the history
  • Loading branch information
varshavaradarajan committed Feb 16, 2018
1 parent ffbd24e commit 76b9abb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
39 changes: 34 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ create_user_and_group_cmd = [
'useradd -u ${UID} -g go -d /home/go -m go'
]

maybe_credentials = "#{ENV['GIT_USER']}:#{ENV['GIT_PASSWORD']}@" if ENV['GIT_USER'] && ENV['GIT_PASSWORD']

[
{
distro: 'alpine',
Expand Down Expand Up @@ -97,6 +99,24 @@ create_user_and_group_cmd = [
'apk add --no-cache openjdk8-jre-base git mercurial subversion openssh-client bash curl'
]
},
{
distro: 'docker',
version: 'dind',
add_files: tini_and_gosu_add_file_meta,
repo_url: "https://#{maybe_credentials}github.com/#{ENV['REPO_OWNER'] || 'gocd'}/gocd-agent-docker-dind",
create_user_and_group: [
'addgroup -g ${GID} go',
'adduser -D -u ${UID} -s /bin/bash -G go go',
'addgroup go root'
],
before_install: [
'apk --no-cache upgrade',
'apk add --no-cache openjdk8-jre-base git mercurial subversion openssh-client bash curl'
],
setup_commands: [
'sh -c "$(which dind) dockerd --host=unix:///var/run/docker.sock --host=tcp://0.0.0.0:2375 --storage-driver=vfs" > /usr/local/bin/nohup.out 2>&1 &'
]
},
{
distro: 'debian',
version: '7',
Expand Down Expand Up @@ -199,12 +219,12 @@ create_user_and_group_cmd = [
before_install = image[:before_install]
add_files = image[:add_files] || {}
create_user_and_group = image[:create_user_and_group] || []
setup_commands = image[:setup_commands] || []

image_name = "gocd-agent-#{distro}-#{version}"
repo_name = "docker-#{image_name}"
dir_name = "build/#{repo_name}"
maybe_credentials = "#{ENV['GIT_USER']}:#{ENV['GIT_PASSWORD']}@" if ENV['GIT_USER'] && ENV['GIT_PASSWORD']
repo_url = "https://#{maybe_credentials}github.com/#{ENV['REPO_OWNER'] || 'gocd'}/#{repo_name}"
repo_url = image[:repo_url] || "https://#{maybe_credentials}github.com/#{ENV['REPO_OWNER'] || 'gocd'}/#{repo_name}"

namespace image_name do
task :clean do
Expand Down Expand Up @@ -235,13 +255,22 @@ create_user_and_group_cmd = [
end
end

task :create_entrypoint_script do
docker_template = File.read('docker-entrypoint.sh.erb')
docker_renderer = ERB.new(docker_template, nil, '-')
File.open("#{dir_name}/docker-entrypoint.sh", 'w') do |f|
f.puts(docker_renderer.result(binding))
end
sh("chmod +x docker-entrypoint.sh")
end

task :build_docker_image do
cd dir_name do
sh("docker build . -t #{image_name}:#{ENV['TAG'] || image_tag}")
end
end

task :commit_dockerfile do
task :commit_files do
cd dir_name do
sh('git add .')
sh("git commit -m 'Update with GoCD Version #{gocd_version}' --author 'GoCD CI User <godev+gocd-ci-user@thoughtworks.com>'")
Expand Down Expand Up @@ -277,10 +306,10 @@ create_user_and_group_cmd = [
end

desc "Publish #{image_name} to dockerhub"
task publish: [:clean, :init, :create_dockerfile, :commit_dockerfile, :create_tag, :git_push]
task publish: [:clean, :init, :create_dockerfile, :create_entrypoint_script, :commit_files, :create_tag, :git_push]

desc "Build #{image_name} image locally"
task build_image: [:clean, :init, :create_dockerfile, :build_docker_image]
task build_image: [:clean, :init, :create_dockerfile, :create_entrypoint_script, :build_docker_image]
end

desc 'Publish all images to dockerhub'
Expand Down
1 change: 1 addition & 0 deletions docker-entrypoint.sh → docker-entrypoint.sh.erb
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ VOLUME_DIR="/godata"

AGENT_WORK_DIR="/go"

<%= setup_commands.join(" \n ") -%>
# no arguments are passed so assume user wants to run the gocd server
# we prepend "/go-agent/agent.sh" to the argument list
if [[ $# -eq 0 ]] ; then
Expand Down

0 comments on commit 76b9abb

Please sign in to comment.