-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 39c206d
Showing
5 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# git | ||
Ansible role to create bare git repositories with hooks. | ||
|
||
## variables | ||
- eher_git_path - Path to where the git repository will be created | ||
- eher_git_hook_post_receive - Command to be executed at post-receive hook | ||
- eher_git_hook_pre_receive - Command to be executed at pre-receive hook | ||
|
||
## how it works? | ||
You cand use the role as you want. The basic use is add to your site.yml and set some required variables. | ||
```yml | ||
--- | ||
roles: | ||
- role: git | ||
eher_git_path: /home/git/queroservoluntario.git | ||
eher_git_hook_post_receive: "make deploy" | ||
``` | ||
Before run the role, make sure that you have your keys into files/authorized_keys. That keys are used to allow git connection. | ||
```bash | ||
cat ~/.ssh/id_rsa.pub >> files/authorized_keys | ||
``` | ||
|
||
After run the role, you should have your own git repository with hook. Then you can add as a remote server. | ||
```bash | ||
git remote add production git@myserver:querservoluntario.git | ||
``` | ||
|
||
Push the code and watch the hook output. | ||
```bash | ||
git push production master | ||
``` | ||
|
||
That will push your master branch to server and then trigger the post-receive hook. The command "make deploy" will run. Your "make deploy" can do wharever you want, as install dependencies, run tests, update database, copy the project to web directory, etc. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
- name: ensure git is installed | ||
action: apt pkg=git | ||
|
||
- name: ensure git user exists | ||
action: user name=git shell=/usr/bin/git-shell home=/home/git generate_ssh_key=yes | ||
|
||
- name: ensure authorized_keys exists | ||
action: copy src=files/authorized_keys dest=/home/git/.ssh/authorized_keys owner=git mode=0600 | ||
|
||
- name: ensure repository directories exists | ||
action: file path={{ eher_git_path }} owner=git group=git mode=0775 state=directory | ||
|
||
- name: create repositories | ||
action: command chdir={{ eher_git_path }} creates={{ eher_git_path }}/HEAD git init --bare | ||
|
||
- name: ensure repositories permisions | ||
action: command chdir={{ eher_git_path }} chown git.git -R . | ||
|
||
- name: ensure post-receive hooks exists | ||
action: template src=hooks/post-receive.j2 dest={{ eher_git_path }}/hooks/post-receive owner=git mode=0755 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
# post-receive hook | ||
{{ eher_git_hook_post_receive|default("") }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
# pre-receive hook | ||
{{ eher_git_hook_pre_receive|default("") }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/sh | ||
# update hook | ||
{% if item.hook_update %} | ||
{{ item.hook_update }} | ||
{% endif %} |