Chef cookbook to set up a basic git repository container to be accessed via SSH.
This cookbook has been tested on the following platforms:
- Amazon Linux
- Arch
- CentOS
- Debian
- Fedora
- FreeBSD
- OpenSUSE
- Oracle Linux
- RedHat
- Scientific Linux
- SUSE
- Ubuntu
- Windows
Please, let us know if you use it successfully on any other platform.
- Ruby
1.9.3
or higher.
Attribute | Default | Description |
---|---|---|
node['git-ssh-server']['base_path'] |
calculated | Git repository base path. |
node['git-ssh-server']['user'] |
'git' |
System user used to manage the repositories. |
node['git-ssh-server']['group'] |
'git' |
System group used to manage the repositories. |
node['git-ssh-server']['shell'] |
'/usr/bin/git-shell' |
Git user shell. |
node['git-ssh-server']['hostname'] |
calculated | Machine hostname, used only in the README template. |
Configures a git repository container
Creates a new bare repository.
create
: Creates a bare repository (default).
Parameters | Default | Description |
---|---|---|
name | resource name | Repository name. |
base_path | calculated | Git repository base path. |
add_update_server_hook | false |
Create the post-update-hook with exec git update-server-info (true or false ). |
git_ssh_server_bare 'library1'
git_ssh_server_bare 'webapp1' do
add_update_server_hook true
end
Grant access to a SSH key to all the repositories.
Parameters | Default | Description |
---|---|---|
keyname | resource name | SSH key name. |
key | required | SSH RSA public key value. |
keytype | 'ssh-rsa' |
SSH RSA key type. |
base_path | calculated | Git repository base path. |
# the SSH public key from your ~/.ssh/*.pub file
git_ssh_server_ssh_key 'battle-laptop' do
key 'AAAAB3NzaC1yc2EAAAABIwAAAQEA[...]'
end
include_recipe 'git-ssh-server::default' # or put it in your run_list
git_ssh_server_bare 'my-library-one'
git_ssh_server_bare 'my-library-two'
git_ssh_server_bare 'my-webapp'
git_ssh_server_ssh_key 'my-laptop-key' do
key(
'AAAAB3NzaC1yc2EAAAADAQABAAABAQDjvOJeZHLa15iajIat6YxtDM2BtVwxZ/WMIcGh6NeQB'\
'I1Nhs4nIpHRCC5bOG4Pg5d6QYaFLDXHx7rHWzprBMi7XuBANGUKESFemByF2DU7hO60/DhA+K'\
'mzeEkCVIqGTh+G7GFucjNGvJgles7MjkOenIc7Xb+OXKcPdTRpQslwJErsIqb1EfRT+8kZvVn'\
'9d9RBS9grWkiOz+d+SVU/D6S40st2f4VDE5NHxcA9/U0vT7tLvC+G6lNJ4+w8M1jpvTDosKeq'\
'yfqQnucf61VWc6ClGh8p88WTSZ081jGB0OkM+nFBsOtzJ+Gmy/N2I+eJGjTykAC7MvLPUsQjA'\
'0KYsZRL'
)
end
git_ssh_server_ssh_key 'another-developer' do
key(
'AAAAB3NzaC1yc2EAAAADAQABAAABAQC75j5iuOWD2Xqw/hKVoJ32n0r6jRjlBofjtEkFDknZp'\
'CMG3whdy64FGNvYYgoajLOc/TyhF+ntt/Go3CrasxNhEusnj6HQu57d0nAnnTleDBHLgcCxFW'\
'QrGTXpop+JziHYXpZHT5bvMV0zfw0C6ezheUnlXlA5+2JNZx3JwhfZqu0L18iwOdWzWbL3zta'\
'D84l0e030JTyg6SP/feXvM5bnQpySCWnqk6L2yzhXQh3tpg95l/8srSE1tuRwgWx4gW2k0E9x'\
'gWtDwcx4lsskMdti6vZ/aM4Ll/jTFAO0hmXZEDnsSr0NEuwm/n8jvN9qwHPLBsk2YWf57VPKq'\
'VQ2rYLx'
)
end
Don't forget to include the git-ssh-server
cookbook as a dependency in the metadata.
# metadata.rb
# [...]
depends 'git-ssh-server'
Another alternative is to include the default recipe in your Run List.
{
"name": "git.example.com",
"[...]": "[...]",
"run_list": [
"[...]",
"recipe[git-ssh-server]"
]
}
See TESTING.md.
Helper method for locating a git_ssh_server_bare
resource in the collection.
resource = chef_run.git_ssh_server_bare(name)
expect(resource).to notify('service[apache2]').to(:reload)
Assert that the Chef Run creates a bare repository in the Git SSH Server.
expect(chef_run).to create_git_ssh_server_bare(name)
To create ChefSpec tests for the git_ssh_server_ssh_key
definition, you can use the render_file
matcher to check the authorized_keys file content:
it 'allows bob to access git repositories' do
expect(chef_run).to render_file('/srv/git/.ssh/authorized_keys')
.with_content(/^ssh-rsa [A-Za-z0-9+\/=]+ bob@acme\.com$/)
end
You can also test against the internal template:
it 'creates /srv/git/.ssh/authorized_keys file' do
expect(chef_run).to create_template('/srv/git/.ssh/authorized_keys')
end
Please do not hesitate to open an issue with any questions or problems.
See CONTRIBUTING.md.
Author: | Raúl Rodríguez (raul@onddo.com) |
Author: | Xabier de Zuazo (xabier@zuazo.org) |
Contributor: | Arnold Krille |
Copyright: | Copyright (c) 2015, Xabier de Zuazo |
Copyright: | Copyright (c) 2013 Onddo Labs, SL. |
License: | Apache License, Version 2.0 |
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.