Skip to content

Instantly share code, notes, and snippets.

@wilcorrea
Created March 25, 2020 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilcorrea/bf4df19ee675d89425d73da5c2ec7575 to your computer and use it in GitHub Desktop.
Save wilcorrea/bf4df19ee675d89425d73da5c2ec7575 to your computer and use it in GitHub Desktop.
image: docker:git
before_script:
- git config --global user.email "ci@my-compnany.com"
- git config --global user.name "My Company"
stages:
# - test
- development
- stage
- production
#test:
# stage: test
# only:
# - merge_requests
# - dev
# - homolog
# - master
# script:
# - echo "run tests!"
development:
stage: development
only:
- dev
script:
- git checkout dev
- git branch -vv
- rm -rf .git
- git init
- git add .
- touch "$(pwd)/.env"
- cat "${DEPLOY_DEVELOP_ENV}" > "$(pwd)/.env"
- cp .docker/docker-compose.yml docker-compose.yml
- git add -f .env
- git add -f docker-compose.yml
- git commit --quiet -m "[deploy] $(date)"
- DEPLOY_REMOTE="https://${DEPLOY_DEVELOP_USER}:${DEPLOY_DEVELOP_PASSWORD}@${DEPLOY_DEVELOP_PATH}"
- echo "Deploy 'dev' (https://${DEPLOY_DEVELOP_PATH})"
- git remote add deploy ${DEPLOY_REMOTE}
- git push deploy master --force
stage:
stage: stage
only:
- homolog
script:
- git checkout homolog
- git branch -vv
- rm -rf .git
- git init
- git add .
- touch "$(pwd)/.env"
- cat "${DEPLOY_HOMOLOG_ENV}" > "$(pwd)/.env"
- cp .docker/docker-compose.yml docker-compose.yml
- git add -f .env
- git add -f docker-compose.yml
- git commit --quiet -m "[deploy] $(date)"
- DEPLOY_REMOTE="https://${DEPLOY_HOMOLOG_USER}:${DEPLOY_HOMOLOG_PASSWORD}@${DEPLOY_HOMOLOG_PATH}"
- echo "Deploy 'homolog' (https://${DEPLOY_HOMOLOG_PATH})"
- git remote add deploy ${DEPLOY_REMOTE}
- git push deploy master --force
production:
stage: production
only:
- master
script:
- git checkout master
- git branch -vv
- rm -rf .git
- git init
- git add .
- touch "$(pwd)/.env"
- cat "${DEPLOY_MASTER_ENV}" > "$(pwd)/.env"
- cp .docker/docker-compose.yml docker-compose.yml
- git add -f .env
- git add -f docker-compose.yml
- git commit --quiet -m "[deploy] $(date)"
- DEPLOY_REMOTE="https://${DEPLOY_MASTER_USER}:${DEPLOY_MASTER_PASSWORD}@${DEPLOY_MASTER_PATH}"
- echo "Deploy 'master' (https://${DEPLOY_MASTER_PATH})"
- git remote add deploy ${DEPLOY_REMOTE}
- git push deploy master --force
image: tevun/quasar:latest
cache: &global_cache
key: ${CI_COMMIT_REF_SLUG}
paths:
- quasar/node_modules/
policy: pull-push
before_script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval "$(ssh-agent -s)"
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "${DEPLOY_SERVER_PRIVATE_KEY}" | tr -d '\r' > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- ssh-add ~/.ssh/id_rsa
- git config --global user.email "ci@disk.ninja"
- git config --global user.name "CI"
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
development:
only:
- development
script:
- echo "Add host ${DEVELOPMENT_DEPLOY_HOST}"
- ssh-keyscan -H "${DEVELOPMENT_DEPLOY_HOST}" > ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- echo "Deploy to ${DEVELOPMENT_DEPLOY_REMOTE}"
- bash "${PWD}/dist/stage/deploy.sh" "stage" "${DEVELOPMENT_DEPLOY_REMOTE}"
master:
only:
- master
script:
- echo "Add host ${MASTER_DEPLOY_HOST}"
- ssh-keyscan -H "${MASTER_DEPLOY_HOST}" > ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- echo "Deploy to ${MASTER_DEPLOY_REMOTE}"
- bash "${PWD}/dist/production/deploy.sh" "production" "${MASTER_DEPLOY_REMOTE}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment