Skip to content
Snippets Groups Projects
Commit 6c6a6157 authored by nimrod's avatar nimrod
Browse files

- Added tests, found issues, added corrections and imporvements.

parent a1c77500
No related branches found
No related tags found
No related merge requests found
...@@ -3,12 +3,13 @@ ...@@ -3,12 +3,13 @@
- name: Assertions - name: Assertions
assert: assert:
that: that:
- ansible_os_family in ['OpenBSD', 'Debian'] - ansible_os_family in pelican_gitreceive_www_root
- ansible_distribution_release in ['6.0', 'xenial', 'trusty', 'jessie'] - ansible_distribution_release in ['6.0', 'xenial', 'trusty', 'jessie']
- pelican_gitreceive_public_keys is iterable - pelican_gitreceive_public_keys is iterable
- pelican_gitreceive_output is defined - pelican_gitreceive_output is defined
- name: APT install prerequisites - name: APT install prerequisites
when: ansible_pkg_mgr == 'apt'
apt: apt:
name: python-dev name: python-dev
state: present state: present
...@@ -25,7 +26,7 @@ ...@@ -25,7 +26,7 @@
- name: Create directory structure - name: Create directory structure
file: file:
path: /var/www/htdocs/www.shore.co.il/blog/ path: '{{ pelican_gitreceive_www_root[ansible_os_family] }}/blog/'
owner: git owner: git
group: git group: git
state: directory state: directory
......
#!/bin/sh #!/bin/sh
set -eu set -eu
echo Recieving blog...
tempdir="$(mktemp -d)" # This part was copied verbatim from
cd $tempdir # https://github.com/progrium/gitreceive/wiki/TipsAndTricks
fetch_submodules () {
# We reinitialize .git to avoid conflicts
rm -fr .git
# GIT_DIR is previously set by gitreceive to ".", we want it back to default
# for this
unset GIT_DIR
git init .
# We read the submodules from .gitmodules
git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
while read path_key path
do
rm -fr $path
url_key=`echo $path_key | sed 's/\.path/.url/'`
url=`git config -f .gitmodules --get "$url_key"`
git submodule add $url $path
done
}
mkdir -p /var/tmp/gitreceive
cd /var/tmp/gitreceive
echo '----> Unpacking ...'
tar -xf - tar -xf -
echo Fetching Git submodules if [ -f .gitmodules ]
git submodule update --init --recursive then
echo Building blog... echo '----> Fetching submodules ...'
fetch_submodules
fi
echo '----> Building blog ...'
fab build fab build
echo Syncing blog... echo '----> Copying blog ...'
rsync -Prv --delete --cvs-exclude output/ {{ pelican_gitreceive_output }} rsync -Prv --delete --cvs-exclude output/ {{ pelican_gitreceive_output }}
echo Cleanup... echo '----> Cleanup ...'
cd - cd -
rm -r "$tempdir" rm -rf /var/tmp/gitreceive
echo Successfully finished... echo '----> OK.'
...@@ -22,3 +22,55 @@ ...@@ -22,3 +22,55 @@
- role: adarnimrod.nginx - role: adarnimrod.nginx
- role: pelican-gitreceive - role: pelican-gitreceive
pelican_gitreceive_public_keys: ['{{ lookup("file", "id_rsa.pub") }}'] pelican_gitreceive_public_keys: ['{{ lookup("file", "id_rsa.pub") }}']
post_tasks:
- name: Install curl
package:
name: curl
state: present
- name: Create .ssh directory
file:
path: /root/.ssh
owner: root
group: 0
mode: 0o0700
state: directory
- name: Copy private SSH key
copy:
src: id_rsa
dest: /root/.ssh/blog_rsa
owner: root
group: 0
mode: 0o0400
- name: Add SSH config
blockinfile:
dest: /root/.ssh/config
state: present
create: yes
block: |
Host localhost
HostName localhost
User git
IdentityFile /root/.ssh/blog_rsa
- name: Clone test blog
git:
dest: /root/blog
repo: https://www.shore.co.il/git/blog
version: master
recursive: yes
- name: Add localhost host keys to known hosts
shell: ssh-keyscan localhost > /root/.ssh/known_hosts
args:
creates: /root/.ssh/known_hosts
- name: Add localhost as a git remote
blockinfile:
dest: /root/blog/.git/config
block: |
[remote "test"]
url = git@localhost:test
fetch = +refs/heads/*:refs/remotes/test/*
server {
listen 80;
listen [::]:80;
root {{ pelican_gitreceive_www_root[ansible_os_family] }}/blog;
server_name localhost;
}
from testinfra.utils.ansible_runner import AnsibleRunner
testinfra_hosts = AnsibleRunner('.molecule/ansible_inventory').get_hosts('all')
def test_git_push(Command, Sudo):
with Sudo():
Command('rm -rf /home/git/test /var/tmp/gitreceive')
push = Command('git -C /root/blog push test')
assert push.rc == 0
for message in ['----> Unpacking ...', '----> Fetching submodules ...',
'----> Building blog ...', 'Copying blog ...',
'----> Cleanup ...', '----> OK.']:
assert message in push.stderr
with Sudo():
second_push = Command('git -C /root/blog push test')
assert second_push.rc == 0
assert 'Everything up-to-date' in second_push.stderr
def test_blog_website(Command):
curl = Command('curl http://localhost/')
assert curl.rc == 0
assert '<title>My notes and rumblings</title>' in curl.stdout
assert 'Mockingbird theme' in curl.stdout
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment