about summary refs log tree commit diff stats
path: root/tools/gitolite.html
diff options
context:
space:
mode:
authorSilvino Silva <silvino@bk.ru>2018-04-11 17:29:59 +0100
committerSilvino Silva <silvino@bk.ru>2018-04-11 17:29:59 +0100
commit32e98307cbf720bf08b3b90850cb6c8c86c82faf (patch)
tree57571be2c5276bcf651f8c7f95e870c6d6c5312b /tools/gitolite.html
parent4f0a749494c7d31b8d203490ec008918c8bacc87 (diff)
downloaddoc-32e98307cbf720bf08b3b90850cb6c8c86c82faf.tar.gz
tools gitolite fix deploy script
Diffstat (limited to 'tools/gitolite.html')
-rw-r--r--tools/gitolite.html306
1 files changed, 241 insertions, 65 deletions
diff --git a/tools/gitolite.html b/tools/gitolite.html
index 1fa8e5a..141f323 100644
--- a/tools/gitolite.html
+++ b/tools/gitolite.html
@@ -163,28 +163,26 @@
         repo gitolite-admin
             RW+     =   gitolite
 
-        repo c9-doc c9-ports c9-pmwiki
-            config gitweb.owner         =   "c9 team"
-            config gitweb.category      =   "c9"
+        repo doc ports pmwiki assistant
+            config gitweb.owner         =   "Team"
+            config gitweb.category      =   "Projects"
 
-        repo c9-doc
-            config gitweb.description   =   "c9 documentation"
+        repo doc
+            config gitweb.description   =   "Documentation"
             option hook.post-receive     =  deploy-web-doc
 
-        repo c9-ports
-            config gitweb.description   =   "c9 ports"
+        repo ports
+            config gitweb.description   =   "System Ports"
 
-        repo c9-pmwiki
-            config gitweb.description   =   "c9 wiki"
+        repo pmwiki
+            config gitweb.description   =   "Wiki"
             option hook.post-receive     =  deploy-web-doc
 
-        repo c9-assistant
-            config gitweb.owner         =   "c9 team"
-            config gitweb.category      =   "c9"
-            config gitweb.description   =   "c9 open assistant"
+        repo assistant
+            config gitweb.description   =   "Open Assistant"
 
         @secret    =   gitolite-admin
-        @project   =   c9-doc c9-ports c9-pmwiki c9-assistant
+        @project   =   doc ports pmwiki assistant
         </pre>
 
         <p>Commit and push;</p>
@@ -200,13 +198,13 @@
 
         <pre>
         # cd /srv/gitolite/repositories/
-        # mv void.git c9-doc.git
+        # mv void.git doc.git
         </pre>
 
         <p>On workstation edit conf/gitolite.conf;</p>
 
         <pre>
-        repo c9-doc
+        repo doc
                 RW+     =       bob
         </pre>
 
@@ -221,7 +219,7 @@
 
         <pre>
         # cd /srv/gitolite/repositories/
-        # rm -rf c9-doc.git
+        # rm -rf doc.git
         </pre>
 
         <p>On workstation edit conf/gitolite.conf and remove c9-doc.</p>
@@ -371,33 +369,6 @@
         fi
         </pre>
 
-        <p>Activate this hook, the idea is to start with this one as a template working
-        and then implement the final one. Edit gitolite admin configuration file and
-        activate:</p>
-
-        <pre>
-        repo c9-doc
-            config gitweb.description   =   "c9 documentation"
-            option hook.post-receive     =  deploy-web-doc
-        </pre>
-
-        <p>Add, commit, and push the admin repo;</p>
-
-        <pre>
-        $ git add local/hooks/repo-specific/hook-deployweb
-        $ git add -u && git commit -m "added deploy c9 hook"
-        </pre>
-
-        <p>Now we can test if our script is functioning by creating a branch on c9-doc
-        making a random change and push;<p>
-
-        <pre>
-        $ cd c9-doc
-        $ git checkout -b deploy_branch
-        </pre>
-
-        <h4>4.3.2. Deploy Script</h4>
-
         <p>Create
         <a href="conf/srv/gitolite/deploy-web.sh">/srv/gitolite/deploy/scripts/deploy-web.sh</a>;</p>
 
@@ -479,29 +450,213 @@
         rm -r ${pkg_path}
         </pre>
 
-        <h4>4.3.3. Debuging hooks</h4>
+        <p>Activate this hook, the idea is to start with this one as a template working
+        and then implement the final one. Edit gitolite admin configuration file and
+        activate:</p>
 
-        <p>Comment gitolite admin repo script "if" and uncomment debug sections, this allow to
-        source the file with environment of hook.</p>
+        <pre>
+        repo doc
+            config gitweb.description   =   "Documentation"
+            option hook.post-receive     =  deploy-web-doc
+        </pre>
 
-        <p>Later you can delete this branch locally and remote and start fresh. To test
-        if hook is called each time you push run;</p>
+        <p>Add, commit, and push the admin repo;</p>
 
+        <pre>
+        $ git add local/hooks/repo-specific/hook-deployweb
+        $ git add -u && git commit -m "added deploy c9 hook"
+        </pre>
+
+        <p>Now we can test if our script is functioning by creating a branch on c9-doc
+        making a random change and push;<p>
 
         <pre>
-        $ echo $(( ( RANDOM % 10 ) +1 )) >> index.html && git add -u && git commit -m "test deploy" && git push git
+        $ cd c9-doc
+        $ git checkout -b deploy_branch
         </pre>
 
-        <p>See if a file was created in /srv/gitolite/deploy with name of project and
-        with environmental variables of gitolite script.</p>
+        <h4>4.3.2. Deploy Script</h4>
 
-        <p>From now on you can test changes directly on
-        /srv/gitolite/.gitolite/local/hooks/repo-specific/hook-deployweb
-        and repeat above command to see the results or create a separate script with
-        all variables generated by above script set so you don't have to push at all.</p>
+        <p>Create <a href="conf/srv/gitolite/deploy.sh">/srv/gitolite/deploy/scripts/deploy.sh</a>;</p>
+
+        <pre>
+        #!/bin/bash
 
-        <h4 id="gtl-deploy">4.4. Deploy with Cron</h4>
+        # origin package directory
+        packages_dir="/srv/gitolite/deploy/packages"
+        # temporary work directory
+        deploy_dir="/srv/gitolite/deploy/deploy_dir"
+        # scripts to deploy packages
+        deploy_scripts="/srv/gitolite/deploy/scripts"
+
+        function get_script(){
+            # receives package path return script to call
+            local pkg_path=$1
+            echo $(head -2 ${pkg_path}/project | tail -1)
+        }
+
+        function get_new(){
+            # receives package path return commit hash (new)
+            local pkg_path=$1
+            echo $(head -3 ${pkg_path}/project | tail -1)
+        }
+
+        function get_dep(){
+            # receives package path return previews commit hash (old)
+            local pkg_path=$1
+
+            new=$(head -3 ${pkg_path}/project | tail -1)
+            old=$(head -4 ${pkg_path}/project | tail -1)
+
+            if [[ ! ${new} = ${old} ]]; then
+                echo ${old} | cut -c1-7
+            fi
+        }
+
+        function project_extract(){
+
+            # project directory containing extracted packages
+            local prj_dir=$1
+
+            # final extracted package
+            local prj_pkg="${prj_dir}/package"
+
+            # temporary vars for swapping/iterating pkg_news
+            local pkg_new=""
+            local pkg_old=""
+            local pkg_dir=""
+            local pkg_temp=""
+            local pkg_next=1
+            local pkg_del=""
+            local x=0
+            local y=0
+
+            # array with all the news hashes
+            local pkg_news=($(ls ${prj_dir}))
+
+            # total new packages
+            local total=${#pkg_news[@]}
+
+            echo "Deploy: $(basename ${prj_dir}) extracting packages ${pkg_news[*]}"
+
+            # find first package
+            for pkg_new in ${pkg_news[@]}
+            do
+                # get package dependency
+                pkg_dir="${prj_dir}/${pkg_new}"
+                pkg_old=$(get_dep ${pkg_dir})
+                if [[ ! " ${pkg_news[@]} " =~ " ${pkg_old} " ]]; then
+                    # pkg_news don't contain package
+                    # we found initial package
+                    pkg_temp=${pkg_news[0]}
+                    pkg_news[0]=${pkg_new}
+                    pkg_news[${x}]=${pkg_temp}
+                    break
+                fi
+                x=$((${x}+1))
+            done
+
+            # Order packages by dependency start with first package
+            for (( y=0; y&lt;${total}; y++ ))
+            do
+                pkg_next=$(($y+1))
+                if [[ ${pkg_next} = ${total} ]]; then
+                    ## we are in the last one
+                    break
+                fi
+
+                pkg_new=${pkg_news[$y]}
+                for (( x=pkg_next; x&lt;${total}; x++ ))
+                do
+                    pkg_dir="${prj_dir}/${pkg_news[${x}]}"
+                    pkg_old=$(get_dep ${pkg_dir})
+                    # is dependent on current
+                    if [[ ${pkg_old} = ${pkg_new} ]]; then
+                        pkg_temp=${pkg_news[${pkg_next}]}
+                        pkg_news[${pkg_next}]=${pkg_news[${x}]}
+                        pkg_news[${x}]=${pkg_temp}
+                        # we can break and pass next one
+                        break
+                    fi
+                done
+            done
+
+            # create project final package directory
+            mkdir -p ${prj_pkg}/files
+
+            # copy project information of last commit
+            cp ${prj_dir}/${pkg_news[$((${total}-1))]}/project ${prj_pkg}
+
+            # now that packages are ordered we can start creating files
+            for pkg_new in ${pkg_news[@]}
+            do
+                pkg_dir=${prj_dir}/${pkg_new}
+                tar xf ${pkg_dir}/files.tar.xz \
+                    --directory ${prj_pkg}/files
+
+                # if deleted files exists
+                if [ -f "${pkg_dir}/deleted" ]; then
+                    # first collect all files/directories don't exist
+                    while read pkg_del; do
+                        # if file don't exist add entry to project deleted file
+                        pkg_temp="${prj_pkg}/files/${pkg_del}"
+                        if [ ! -f ${pkg_temp} ]; then
+                            if [ ! -d ${pkg_temp} ]; then
+                                # is not a file or directory from previous packages
+                                echo ${pkg_del} &gt;&gt; ${prj_pkg}/deleted
+                            fi
+                        fi
+                    done &lt;${prj_dir}/${pkg_new}/deleted
+
+                    # delete directories and files
+                    while read pkg_del; do
+                        pkg_temp="${prj_pkg}/files/${pkg_del}"
+                        if [ -d ${pkg_temp} ]; then
+                            rm -r ${pkg_temp}
+                        elif [ -f ${pkg_temp} ]; then
+                            rm ${pkg_temp}
+                        fi
+                    done &lt;${prj_dir}/${pkg_new}/deleted
+                fi
+
+                #remove temporary directory
+                rm -r ${prj_dir}/${pkg_new}
+            done
+
+            # call project deploy script
+            call_script=${deploy_scripts}/$(get_script $prj_pkg)
+            echo "Deploy: calling deploy script: ${call_script}"
+            /bin/bash ${call_script} ${prj_pkg}
+
+        }
+
+        if [[ ! $(ls ${deploy_dir}) = "" ]]; then
+            rm -r ${deploy_dir}/*
+        fi
+
+        # first extract all packages from origin directory
+        for pkg_path in `find ${packages_dir} -type f -name "*.tar.gz"`
+        do
+            if [ -f ${pkg_path} ]; then
+                pkg_name=$(basename ${pkg_path})
+                pkg_proj=$(echo ${pkg_name} | cut -d "_" -f 1)
+                pkg_new7=$(echo ${pkg_name} | tail -c -15 | cut -c -7)
+                pkg_temp=${deploy_dir}/${pkg_proj}/${pkg_new7}
+                mkdir -p ${pkg_temp}
+                tar xf ${pkg_path} --directory ${pkg_temp}
+                rm ${pkg_path}
+            fi
+        done
 
+        # loop for all projects and deploy them
+        for prj_dir in `find ${deploy_dir} -maxdepth 1 -mindepth 1 -type d`
+        do
+            # order index of hashes based on old commit
+            echo "prj_dir $prj_dir"
+            project_extract ${prj_dir}
+        done
+        </pre>
+        
         <p>Add cron job to call deploy script every minute;</p>
 
         <pre>
@@ -526,6 +681,27 @@
         # End of file
         </pre>
 
+        <h4>4.3.3. Debuging hooks</h4>
+
+        <p>Comment gitolite admin repo script "if" and uncomment debug sections, this allow to
+        source the file with environment of hook.</p>
+
+        <p>Later you can delete this branch locally and remote and start fresh. To test
+        if hook is called each time you push run;</p>
+
+
+        <pre>
+        $ echo $(( ( RANDOM % 10 ) +1 )) >> index.html && git add -u && git commit -m "test deploy" && git push git
+        </pre>
+
+        <p>See if a file was created in /srv/gitolite/deploy with name of project and
+        with environmental variables of gitolite script.</p>
+
+        <p>From now on you can test changes directly on
+        /srv/gitolite/.gitolite/local/hooks/repo-specific/hook-deployweb
+        and repeat above command to see the results or create a separate script with
+        all variables generated by above script set so you don't have to push at all.</p>
+
         <h2 id="gitweb">5. Gitweb</h2>
 
         <pre>
@@ -626,15 +802,15 @@
         <p>Edit gitolite-admin/conf/gitolite.conf;</p>
 
         <pre>
-        repo c9-doc
-            config gitweb.owner         =   c9 team
-            config gitweb.description   =   c9 documentation
-            config gitweb.category      =   c9
+        repo doc
+            config gitweb.owner         =   team
+            config gitweb.description   =   Documentation
+            config gitweb.category      =   Projects
 
-        repo c9-ports
-            config gitweb.owner         =   c9 team
-            config gitweb.description   =   c9 ports
-            config gitweb.category      =   c9
+        repo ports
+            config gitweb.owner         =   team
+            config gitweb.description   =   System ports
+            config gitweb.category      =   Projects
         </pre>
 
         <a href="index.html">Tools Index</a>