Created
July 26, 2019 10:46
-
-
Save khoipro/cc9327c12eeb96e10236e6bb3f99c58f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| # Script Name: deploy-multidev-pantheon.sh | |
| # Author: khoiprodotcom | |
| # Author URI: https://github.com/khoipro | |
| # ======================================== | |
| # A, What is this script? | |
| # It makes an automation deployment from single Gitlab repository to multiple Pantheon repositories which have the same tag. | |
| # | |
| # B, Requirements fields in GitLab Repository | Settings | CI/CD | Variables | |
| # 1. TERMINUS_EMAIL: Your email account at Pantheon | |
| # 2. TERMINUS_KEY: Usually you can generate from User Dashboard | User Account | Machine Tokens | |
| # 3. PANTHEON_TAG, for example: "green", "Live Env" | |
| # 4. PANTHEON_ORG_ID: the strings which you can see from your Pantheon Dashboard URL, for example: https://dashboard.pantheon.io/organizations/1633yhss-37dd-66da-a649-3d043296aaa8. "1633yhss-37dd-66da-a649-3d043296aaa8" is your org id. | |
| # 5. SSH_PRIVATE_KEY: the private key (not public key). It helps to create a commit in case you wish to build an assets before pushing. | |
| # ======================================== | |
| terminus auth:login --email=$TERMINUS_EMAIL --machine-token=$TERMINUS_KEY | |
| echo -e "Get all sites by tags ${PANTHEON_TAG}" | |
| PANTHEON_SITES=`terminus org:site:list --format=list --field=Name --tag="${PANTHEON_TAG}" ${PANTHEON_ORG_ID}` | |
| while read -r PANTHEON_SITE_NAME; do | |
| IS_FROZEN="$(terminus site:info $PANTHEON_SITE_NAME --field=frozen)" | |
| if [[ "true" == "${IS_FROZEN}" ]] | |
| then | |
| ## Skip frozen sites | |
| echo -e "Skipping touch a frozen site $PANTHEON_SITE_NAME." | |
| else | |
| ## Read A Git Repository | |
| GIT_URL="$(terminus connection:info --format=list --field="git_url" $PANTHEON_SITE_NAME.dev)" | |
| if [ $? -eq 0 ]; then | |
| echo -e "[$PANTHEON_SITE_NAME] Git URL: ${GIT_URL}" | |
| # Check if git repo exists | |
| git ls-remote pantheon-${PANTHEON_SITE_NAME} HEAD --exit-code > /dev/null | |
| if [ $? -eq "0" ]; then | |
| echo -e "Change Git URL of existing repository" | |
| git remote set-url pantheon-${PANTHEON_SITE_NAME} ${GIT_URL} | |
| else | |
| echo -e "Add new pantheon-${PANTHEON_SITE_NAME} repository" | |
| git remote add pantheon-${PANTHEON_SITE_NAME} ${GIT_URL} | |
| fi | |
| # Fetching existing branches | |
| git fetch pantheon-${PANTHEON_SITE_NAME} | |
| git remote prune pantheon-${PANTHEON_SITE_NAME} | |
| # Force push | |
| echo -e "[$PANTHEON_SITE_NAME] Pushing to pantheon/develop" | |
| git push pantheon-${PANTHEON_SITE_NAME} HEAD:develop --force | |
| if [ $? -eq 0 ]; then | |
| echo -e "Deployed to URL https://develop-${PANTHEON_SITE_NAME}.pantheonsite.io" | |
| fi | |
| else | |
| echo -e "Error! Can't load a Git URL from $PANTHEON_SITE_NAME" | |
| fi | |
| fi | |
| done <<< "$PANTHEON_SITES" | |
| echo -e "Done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment