git + gitlab git version control management to achieve localization + Automated Deployment

scene

If you deploy virtual machines in a local company network or the server gitlab, network control and management hope localized versions or inside, how to achieve that control or manage the localized version of the network at the same time, be able to deploy project-based version control management on-line server, this is the problem to be discussed below.

The above program exists checkpoint

  • How to clone a remote server or synchronize the local code gitlab

  • gitlab how to deploy the project to automate synchronization remote server

Implementation process

Build warehouses

  • Establish the project in gitlab (ie, the process of establishing a warehouse in gitlab)

  • The establishment of a bare warehouse in a remote server

    

  • Cloning gitlab local warehouse

      

Deployment ssh-keys

  • Form

ssh-keygen -t rsa -C "[email protected]"
  • Deploying Local ssh-key in gitlab

    first step:

    

Step two:

  • Gitlab deployment of ssh-key remote server

Deployment hook

  • Configuration information in the config file .ssh file gitlab

host test
    hostname 0.0.0.0 #你的主机地址
    user root
    port 22
    identityfile ~/.keys/test  #你的私钥地址
  • Create a folder under gitlab custom_hooks warehouse and create post-receive in custom_hook, edit

#!/bin/sh
# example hook script for the "post-receive" event.
#
# The "post-receive" script is run after receive-pack has accepted a pack
# and the repository has been updated.  It is passed arguments in through
# stdin in the form
#  <oldrev> <newrev> <refname>
# For example:
#  aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master
#
# see contrib/hooks/ for a sample, or uncomment the next line and
# rename the file to "post-receive".

#. /usr/share/git-core/contrib/hooks/post-receive-email
while read oldrev newrev ref
do
    branch=$(git rev-parse --symbolic --abbrev-ref $ref)
    if [ "$branch" = "1.0" ]
    then
        git push -f test:/var/www/html/test.git $branch
    fi
done
  • Hooks deployed in remote bare repository

#!/bin/sh
#
# An example hook script for the "post-receive" event.
#
# The "post-receive" script is run after receive-pack has accepted a pack
# and the repository has been updated.  It is passed arguments in through
# stdin in the form
#  <oldrev> <newrev> <refname>
# For example:
#  aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master
#
# see contrib/hooks/ for a sample, or uncomment the next line and
# rename the file to "post-receive".

#. /usr/share/git-core/contrib/hooks/post-receive-email
while read oldrev newrev ref
do
    if [[ $ref =~ .*/1.0$ ]];
    then
        echo "1.0 ref received.  Deploying 1.0 branch to test server..."
        git --work-tree=/var/www/html/test--git-dir=$GIT_DIR checkout -f $ref
    fi
done

test

  • New local file, submitted, how to test the service can automatically update that a successful deployment

Guess you like

Origin www.cnblogs.com/spydxk/p/11325950.html