Implemented deploy stage, allow to manually specify the environment for the Sentry

This commit is contained in:
ErickSkrauch 2020-06-10 18:15:19 +03:00
parent 39d7cad8b5
commit 053e591c3b
2 changed files with 81 additions and 1 deletions

View File

@ -4,6 +4,7 @@ stages:
- prepare - prepare
- testing - testing
- build - build
- deploy
variables: variables:
APP_IMAGE_NAME: "$CI_REGISTRY_IMAGE/app" APP_IMAGE_NAME: "$CI_REGISTRY_IMAGE/app"
@ -31,6 +32,16 @@ variables:
.dockerLogin: &dockerLogin |- .dockerLogin: &dockerLogin |-
docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
.installSentry: &installSentry |-
apk add --update-cache --upgrade curl bash
curl -sL https://sentry.io/get-cli/ | bash
.setupSSH: &setupSSH |-
mkdir ~/.ssh
echo -e "Host *\n StrictHostKeyChecking no\n" > ~/.ssh/config
eval $(ssh-agent -s)
echo "$SSH_DEPLOY_KEY" | tr -d '\r' | ssh-add -
################### ###################
# Steps to extend # # Steps to extend #
################### ###################
@ -158,3 +169,66 @@ Docker:
only: only:
- master - master
- tags - tags
##########
# Deploy #
##########
.beforeSentryDeploy: &beforeSentryDeploy |-
sentry-cli releases new $VERSION
sentry-cli releases set-commits --commit "elyby/accounts@${CI_COMMIT_SHA}" $VERSION
.afterSentryDeploy: &afterSentryDeploy |-
sentry-cli releases deploys $VERSION new -e $CI_ENVIRONMENT_NAME
sentry-cli releases finalize $VERSION
.deployJob:
stage: deploy
image: docksal/ssh-agent:1.3
needs:
- Docker
variables:
GIT_STRATEGY: none
before_script:
- *defineVars
- *installSentry
- *setupSSH
script:
- *beforeSentryDeploy
# Escape $ with backslash to prevent value evaluation from CI container.
# We're not using $APP_IMAGE_LATEST_NAME because on remote server might be
# a different semantic of preferred image version tag
- |
ssh -J deploy@ely.by:4534 -p 722 "root@$VM_HOST_NAME" /bin/bash << EOF
set -e
cd "$VM_DEPLOY_PATH"
docker pull "$APP_VERSIONED_IMAGE_NAME"
docker pull "$WEB_VERSIONED_IMAGE_NAME"
docker tag "$APP_VERSIONED_IMAGE_NAME" "$APP_IMAGE_NAME:latest"
docker tag "$WEB_VERSIONED_IMAGE_NAME" "$WEB_IMAGE_NAME:latest"
docker-compose stop app worker cron
docker-compose rm -fv app worker cron
docker-compose up -d app worker cron
docker-compose stop web
docker-compose rm -fv web
docker-compose up -d web
EOF
- *afterSentryDeploy
Dev:
extends:
- .deployJob
environment:
name: Development
variables:
VM_HOST_NAME: playground.ely.local
VM_DEPLOY_PATH: /srv/dev.account.ely.by
rules:
- if: '$CI_COMMIT_TAG'
when: on_success
- if: '$CI_COMMIT_BRANCH == "master"'
when: on_success
- if: '$CI_COMMIT_MESSAGE =~ /\[deploy dev\]/'
when: on_success
# Default:
- when: never

View File

@ -65,7 +65,13 @@ return [
'class' => common\components\Sentry::class, 'class' => common\components\Sentry::class,
'enabled' => !empty(getenv('SENTRY_DSN')), 'enabled' => !empty(getenv('SENTRY_DSN')),
'dsn' => getenv('SENTRY_DSN'), 'dsn' => getenv('SENTRY_DSN'),
'environment' => YII_ENV_DEV ? 'development' : 'production', 'environment' => (function(): string {
if (!empty(getenv('SENTRY_ENV'))) {
return getenv('SENTRY_ENV');
}
return YII_ENV_DEV ? 'Development' : 'Production';
})(),
'client' => [ 'client' => [
'curl_method' => 'async', 'curl_method' => 'async',
], ],