updated script to work with bitbucket and use ssh vs https

updated scripts to support specifying a git branch

updated docs to reflect new environment variables

removed debugging comments
This commit is contained in:
Roy Rico
2016-10-22 14:06:03 -07:00
parent cab88604a6
commit 3d70ac9b3f
2 changed files with 22 additions and 11 deletions

View File

@@ -48,6 +48,7 @@ The following flags are a list of all the currently supported options that can b
- **GIT_BRANCH** : Select a specific branch (optional) - **GIT_BRANCH** : Select a specific branch (optional)
- **GIT_EMAIL** : Set your email for code pushing (required for git to work) - **GIT_EMAIL** : Set your email for code pushing (required for git to work)
- **GIT_NAME** : Set your name for code pushing (required for git to work) - **GIT_NAME** : Set your name for code pushing (required for git to work)
- **GIT_USE_SSH** : Set this to 1 if you want to use git over SSH (instead of HTTP), useful if you want to use Bitbucket instead of GitHub
- **SSH_KEY** : Private SSH deploy key for your repository base64 encoded (requires write permissions for pushing) - **SSH_KEY** : Private SSH deploy key for your repository base64 encoded (requires write permissions for pushing)
- **GIT_PERSONAL_TOKEN** : Personal access token for your git account (required for HTTPS git access) - **GIT_PERSONAL_TOKEN** : Personal access token for your git account (required for HTTPS git access)
- **GIT_USERNAME** : Git username for use with personal tokens. (required for HTTPS git access) - **GIT_USERNAME** : Git username for use with personal tokens. (required for HTTPS git access)

View File

@@ -5,6 +5,10 @@
mkdir -p -m 0700 /root/.ssh mkdir -p -m 0700 /root/.ssh
echo -e "Host *\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config echo -e "Host *\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config
if [[ "$GIT_USE_SSH" == "1" ]] ; then
echo -e "Host *\n\tUser ${GIT_USERNAME}\n\n" >> /root/.ssh/config
fi
if [ ! -z "$SSH_KEY" ]; then if [ ! -z "$SSH_KEY" ]; then
echo $SSH_KEY > /root/.ssh/id_rsa.base64 echo $SSH_KEY > /root/.ssh/id_rsa.base64
base64 -d /root/.ssh/id_rsa.base64 > /root/.ssh/id_rsa base64 -d /root/.ssh/id_rsa.base64 > /root/.ssh/id_rsa
@@ -34,19 +38,25 @@ if [ ! -d "/var/www/html/.git" ]; then
if [ ! -z "$GIT_REPO" ]; then if [ ! -z "$GIT_REPO" ]; then
# Remove the test index file # Remove the test index file
rm -Rf /var/www/html/* rm -Rf /var/www/html/*
GIT_COMMAND='git clone '
if [ ! -z "$GIT_BRANCH" ]; then if [ ! -z "$GIT_BRANCH" ]; then
if [ -z "$GIT_USERNAME" ] && [ -z "$GIT_PERSONAL_TOKEN" ]; then GIT_COMMAND=${GIT_COMMAND}" -b ${GIT_BRANCH}"
git clone -b $GIT_BRANCH $GIT_REPO /var/www/html/ || exit 1
else
git clone -b ${GIT_BRANCH} https://${GIT_USERNAME}:${GIT_PERSONAL_TOKEN}@${GIT_REPO} /var/www/html || exit 1
fi
else
if [ -z "$GIT_USERNAME" ] && [ -z "$GIT_PERSONAL_TOKEN" ]; then
git clone $GIT_REPO /var/www/html/ || exit 1
else
git clone https://${GIT_USERNAME}:${GIT_PERSONAL_TOKEN}@${GIT_REPO} /var/www/html || exit 1
fi
fi fi
if [ -z "$GIT_USERNAME" ] && [ -z "$GIT_PERSONAL_TOKEN" ]; then
GIT_COMMAND=${GIT_COMMAND}" ${GIT_REPO}"
else
if [[ "$GIT_USE_SSH" == "1" ]]; then
GIT_COMMAND=${GIT_COMMAND}" ${GIT_REPO}"
else
GIT_COMMAND=${GIT_COMMAND}" https://${GIT_USERNAME}:${GIT_PERSONAL_TOKEN}@${GIT_REPO}"
fi
fi
${GIT_COMMAND} /var/www/html || exit 1
chown -Rf nginx.nginx /var/www/html chown -Rf nginx.nginx /var/www/html
fi fi
fi fi