diff --git a/README.md b/README.md index 93ec41e..5f8f1ee 100644 --- a/README.md +++ b/README.md @@ -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_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_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) - **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) diff --git a/scripts/start.sh b/scripts/start.sh index c33c42d..26bcf76 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -5,6 +5,10 @@ mkdir -p -m 0700 /root/.ssh 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 echo $SSH_KEY > /root/.ssh/id_rsa.base64 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 # Remove the test index file rm -Rf /var/www/html/* + + GIT_COMMAND='git clone ' + if [ ! -z "$GIT_BRANCH" ]; then - if [ -z "$GIT_USERNAME" ] && [ -z "$GIT_PERSONAL_TOKEN" ]; then - 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 + GIT_COMMAND=${GIT_COMMAND}" -b ${GIT_BRANCH}" 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 fi fi