mirror of https://github.com/ceph/ceph-ansible.git
contrib: add a new script to update remote repos
This script allows us to split ceph-ansible role directory into repositories that can be pushed. This script is an enhanced version of splitup.yml that was using git subtree. I haven't found any straighforward way to push tag using git subtree where git filter-branch seems easier and more practical. Now we can not only push commits from master but also all the relative tags. It is nice for projects that want to consume our roles from the Ansible Galaxy, pointing to a specific tags looking for a particular release. For backward compatobility, I pushed a branch called "master-history-bkp" on all the github.com/ceph/ansbible-ceph-* repositories. So current projects using a SHA to retrieve the roles won't be impacted by this change. At the time of the commit, running this script took 104.60s to complete. Signed-off-by: Sébastien Han <seb@redhat.com> Co-Authored-By: Erwan Velu <erwan@redhat.com> Co-Authored-By: Logan Vig <logan2211@gmail.com>pull/1117/head
parent
9cfd0f4118
commit
90a28b8b41
|
@ -0,0 +1,70 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -xe
|
||||||
|
|
||||||
|
# VARIABLES
|
||||||
|
BASEDIR=$(dirname "$0")
|
||||||
|
LOCAL_BRANCH=$(cd $BASEDIR && git rev-parse --abbrev-ref HEAD)
|
||||||
|
BRANCHES="master ansible-1.9"
|
||||||
|
ROLES="ceph-common ceph-mon ceph-osd ceph-mds ceph-rgw ceph-restapi ceph-agent ceph-fetch-keys ceph-rbd-mirror ceph-client"
|
||||||
|
|
||||||
|
|
||||||
|
# FUNCTIONS
|
||||||
|
function check_existing_remote {
|
||||||
|
if ! git remote show $1 &> /dev/null; then
|
||||||
|
git remote add $1 git@github.com:/ceph/ansible-$1.git
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function pull_origin {
|
||||||
|
git pull origin --tags
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset_hard_origin {
|
||||||
|
# let's bring everything back to normal
|
||||||
|
git checkout $LOCAL_BRANCH
|
||||||
|
git fetch origin
|
||||||
|
git fetch --tags
|
||||||
|
git reset --hard origin/master
|
||||||
|
}
|
||||||
|
|
||||||
|
function check_git_status {
|
||||||
|
if [[ $(git status --porcelain | wc -l) -gt 0 ]]; then
|
||||||
|
echo "It looks like the following changes haven't been committed yet"
|
||||||
|
echo ""
|
||||||
|
git status --short
|
||||||
|
echo ""
|
||||||
|
echo ""
|
||||||
|
echo "Do you really want to continue?"
|
||||||
|
echo "Press ENTER to continue or CTRL C to break"
|
||||||
|
read
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# MAIN
|
||||||
|
check_git_status
|
||||||
|
trap reset_hard_origin EXIT
|
||||||
|
trap reset_hard_origin ERR
|
||||||
|
pull_origin
|
||||||
|
|
||||||
|
for ROLE in $ROLES; do
|
||||||
|
# For readability we use 2 variables with the same content
|
||||||
|
# so we always make sure we 'push' to a remote and 'filter' a role
|
||||||
|
REMOTE=$ROLE
|
||||||
|
check_existing_remote $REMOTE
|
||||||
|
reset_hard_origin
|
||||||
|
# First we filter branches by rewriting master with the content of roles/$ROLE
|
||||||
|
# this gives us a new commit history
|
||||||
|
for BRANCH in $BRANCHES; do
|
||||||
|
git checkout -B $BRANCH origin/$BRANCH
|
||||||
|
git filter-branch -f --prune-empty --subdirectory-filter roles/$ROLE
|
||||||
|
git push $REMOTE $BRANCH
|
||||||
|
done
|
||||||
|
reset_hard_origin
|
||||||
|
# then we filter tags starting from version 2.0 and push them
|
||||||
|
for TAG in $(git tag | egrep '^v[2-9].[0-9]*.[0-9]*$'); do
|
||||||
|
git filter-branch -f --prune-empty --subdirectory-filter roles/$ROLE $TAG
|
||||||
|
git push $REMOTE $TAG
|
||||||
|
reset_hard_origin
|
||||||
|
done
|
||||||
|
done
|
|
@ -1,71 +0,0 @@
|
||||||
---
|
|
||||||
|
|
||||||
# This repice can be used to split this repo and keep the part updated!
|
|
||||||
# Use it like this:
|
|
||||||
#
|
|
||||||
# ansible-playbook -i dummy-ansible-hosts contrib/splitup.yml \
|
|
||||||
# --tags split --extra-vars github=mhubig/ansible
|
|
||||||
#
|
|
||||||
# ansible-playbook -i dummy-ansible-hosts contrib/splitup.yml \
|
|
||||||
# --tags update --extra-vars github=mhubig/ansible
|
|
||||||
#
|
|
||||||
# To point to a specific role, ie: ceph-mon just run with "-e roles=ceph-mon"
|
|
||||||
#
|
|
||||||
|
|
||||||
- name: This recipe split the roles into repos and keeps them updated.
|
|
||||||
hosts: localhost
|
|
||||||
connection: local
|
|
||||||
gather_facts: False
|
|
||||||
|
|
||||||
vars:
|
|
||||||
github: ceph/ansible
|
|
||||||
roles:
|
|
||||||
- ceph-common
|
|
||||||
- ceph-mon
|
|
||||||
- ceph-osd
|
|
||||||
- ceph-mds
|
|
||||||
- ceph-rgw
|
|
||||||
- ceph-restapi
|
|
||||||
- ceph-agent
|
|
||||||
- ceph-fetch-keys
|
|
||||||
- ceph-rbd-mirror
|
|
||||||
- ceph-client
|
|
||||||
basedir: "{{ lookup('pipe', 'git rev-parse --show-toplevel') }}"
|
|
||||||
|
|
||||||
tasks:
|
|
||||||
|
|
||||||
- name: check for github prefix option on commandline
|
|
||||||
tags: split
|
|
||||||
fail:
|
|
||||||
msg: 'github prefix missing! e.g: (--extra-vars github=ceph/ansible).'
|
|
||||||
when: github == False
|
|
||||||
|
|
||||||
- name: split the repo in separate branches
|
|
||||||
tags: split
|
|
||||||
command: git subtree split --prefix=roles/{{ item }} -b {{ item }} --squash
|
|
||||||
args:
|
|
||||||
chdir: "{{ basedir }}"
|
|
||||||
with_items: "{{ roles }}"
|
|
||||||
|
|
||||||
- name: adds remote github repos for the splits
|
|
||||||
tags: split
|
|
||||||
command: git remote add {{ item }} git@github.com:{{ github }}-{{ item }}.git
|
|
||||||
args:
|
|
||||||
chdir: "{{ basedir }}"
|
|
||||||
with_items: "{{ roles }}"
|
|
||||||
|
|
||||||
- name: adds upstream remote
|
|
||||||
tags: update
|
|
||||||
command: git remote add upstream git@github.com:ceph/ceph-ansible.git
|
|
||||||
failed_when: false
|
|
||||||
|
|
||||||
- name: pulles the newest changes from upstream
|
|
||||||
tags: update
|
|
||||||
command: git pull upstream master:master
|
|
||||||
|
|
||||||
- name: update the split repos from master
|
|
||||||
tags: update
|
|
||||||
shell: git push {{ item }} $(git subtree split --prefix roles/{{ item }} master):master --force
|
|
||||||
args:
|
|
||||||
chdir: "{{ basedir }}"
|
|
||||||
with_items: "{{ roles }}"
|
|
Loading…
Reference in New Issue