Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
98 lines (92 sloc) 3.24 KB
image: ubuntu:16.04
stages:
- deploy
deploy_review:
stage: deploy
script:
- echo "Deploy a review app"
- apt-get update
- apt-get install -y python-pip git
- pip install gigalixir
- echo "Logging into gigalixir"
- gigalixir login -e "$GIGALIXIR_EMAIL" -y -p "$GIGALIXIR_PASSWORD"
- APP_NAME="$GIGALIXIR_APP_NAME-$CI_ENVIRONMENT_SLUG"
- echo "Creating gigalixir app $APP_NAME"
- gigalixir create --name $APP_NAME || gigalixir git:remote $APP_NAME
- echo "Creating database"
- if [ "$(gigalixir pg -a $APP_NAME)" = "[]" ]; then gigalixir pg:create -a $APP_NAME; fi
- while true; do if [[ `gigalixir pg -a $APP_NAME | grep AVAILABLE | wc -l` == 1 ]]; then break; fi; sleep 2; done
- echo "Pushing"
- git push -f gigalixir HEAD:refs/heads/master
- echo "Databases may take some time to create. You can check the status by running gigalixir pg -a $APP_NAME"
- echo "To run migrations automatically, see http://gigalixir.readthedocs.io/en/latest/main.html#how-to-set-up-continuous-integration-ci-cd"
- echo "Don't forget to set config variables here if needed by running gigalixir config:set -a $APP_NAME KEY=VALUE"
environment:
name: review/$CI_COMMIT_REF_NAME
url: https://$GIGALIXIR_APP_NAME-$CI_ENVIRONMENT_SLUG.gigalixirapp.com
on_stop: stop_review
only:
- branches
except:
- master
deploy_staging:
stage: deploy
script:
- echo "Deploy to staging server"
- apt-get update
- apt-get install -y python-pip git
- pip install gigalixir
- echo "Logging into gigalixir"
- gigalixir login -e "$GIGALIXIR_EMAIL" -y -p "$GIGALIXIR_PASSWORD"
- echo "Setting git remote"
- gigalixir git:remote $GIGALIXIR_APP_NAME-staging
- echo "Pushing"
- git push -f gigalixir HEAD:refs/heads/master
environment:
name: staging
url: https://$GIGALIXIR_APP_NAME-staging.gigalixirapp.com
only:
- master
deploy_prod:
stage: deploy
script:
- echo "Deploy to production server"
- apt-get update
- apt-get install -y python-pip git
- pip install gigalixir
- echo "Logging into gigalixir"
- gigalixir login -e "$GIGALIXIR_EMAIL" -y -p "$GIGALIXIR_PASSWORD"
- echo "Setting git remote"
- gigalixir git:remote $GIGALIXIR_APP_NAME
- echo "Pushing"
- git push -f gigalixir HEAD:refs/heads/master
environment:
name: production
url: https://$GIGALIXIR_APP_NAME.gigalixirapp.com
when: manual
only:
- master
stop_review:
stage: deploy
variables:
GIT_STRATEGY: none
script:
- apt-get update
- apt-get install -y python-pip jq
- pip install gigalixir
- echo "Logging into gigalixir"
- gigalixir login -e "$GIGALIXIR_EMAIL" -y -p "$GIGALIXIR_PASSWORD"
- APP_NAME="$GIGALIXIR_APP_NAME-$CI_ENVIRONMENT_SLUG"
- echo "Scaling app $APP_NAME to 0 replicas"
- gigalixir ps:scale --replicas=0 -a $APP_NAME
- echo "Looking for databases"
- DATABASE_IDS=$(gigalixir pg -a $APP_NAME | jq -r '.[] | select(.state == "AVAILABLE") | .id')
- for db in $DATABASE_IDS; do echo "Deleting database ${DATABASE_IDS}"; echo 'y' | gigalixir pg:destroy -a $APP_NAME -d $db; done
when: manual
environment:
name: review/$CI_COMMIT_REF_NAME
action: stop
only:
- branches
except:
- master
You can’t perform that action at this time.