Skip to content

Commit

Permalink
Merge pull request teracyhq#329 from datphan/tasks/295
Browse files Browse the repository at this point in the history
Tasks/295
  • Loading branch information
phuonglm committed Jul 21, 2017
2 parents 45fdf06 + 32bd8c7 commit b10207c
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions main-cookbooks/teracy-dev/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
recipe 'teracy-dev::directories', 'Manage directories.'
recipe 'teracy-dev::env_vars', 'Configures environment variables.'
recipe 'teracy-dev::docker', 'Installs Docker, docker-compose'
recipe 'teracy-dev::docker_registry', "Docker registry's tasks: login, ..."
recipe 'teracy-dev::docker_machine', 'Installs docker-machine'
recipe 'teracy-dev::inotify', 'Modify inotify, useful for development watching a lot of files'
recipe 'teracy-dev::proxy', 'Create a reverse proxy with nginx'
1 change: 1 addition & 0 deletions main-cookbooks/teracy-dev/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
include_recipe 'teracy-dev::aliases'
include_recipe 'teracy-dev::env_vars'
include_recipe 'teracy-dev::docker'
include_recipe 'teracy-dev::docker_registry'
include_recipe 'teracy-dev::docker_machine'
include_recipe 'teracy-dev::inotify'
include_recipe 'teracy-dev::proxy'
52 changes: 52 additions & 0 deletions main-cookbooks/teracy-dev/recipes/docker_registry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Author:: Hoat Le <hoatle@teracy.com>
# Cookbook:: teracy-dev
# Recipe:: docker_registry
# Login into the Docker registries

docker_conf = node['docker']

docker_registry_conf = node['docker_registry']

if docker_conf['enabled'] == true
execute 'rm ~/.docker/config.json' do
command 'rm /home/vagrant/.docker/config.json || true'
only_if {
docker_registry_conf['force'] == true and
File.exist?('/home/vagrant/.docker/config.json')
}
end

docker_registry_conf['entries'].each.with_index do |entry, index|
# private registry login

username = entry['username'] ? entry['username'] : ''

password = entry['password'] ? entry['password'] : ''

if not username.empty? and not password.empty?
opt = [
"-u #{username}",
"-p #{password}"
].join(' ');

execute 'docker login' do
command "docker login #{entry['host']} #{opt}"
# because we need root to execute docker-compose, not 'vagrant'
only_if {
docker_registry_conf['force'] == true or
not File.exist?('/root/.docker/config.json')
}
end
end
end

execute 'copy /root/.docker/config.json to ~/.docker/config.json' do
command 'cp /root/.docker/config.json /home/vagrant/.docker/config.json'
only_if {
File.exist?('/root/.docker/config.json') and (
docker_registry_conf['force'] == true or
not File.exist?('/home/vagrant/.docker/config.json')
)
}
end
end
18 changes: 18 additions & 0 deletions vagrant_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,24 @@
"members": ["vagrant"], // to append this member to "docker" group
"action": "create" // one of create, delete. Default: create
},
"docker_registry": {
// set true to force re-login with all the defined entries, default: false (login once)
"force": false,
"entries": []
// example:
// "entries": [
// {
// "host": "https://index.docker.io/v1/",
// "username": "",
// "password": ""
// },
// {
// "host": "registry.gitlab.com",
// "username": "",
// "password": ""
// }
// ]
},
"docker_compose": {
"release": "", // more: https://github.com/docker/compose/releases/
"enabled": true // "docker" must be enabled to get this
Expand Down

0 comments on commit b10207c

Please sign in to comment.