Last active
November 17, 2019 16:12
-
-
Save kellymears/5899db4ff619bf28fd99225afb1c82ac to your computer and use it in GitHub Desktop.
Trellis/Bedrock/Sentry versioned deployments
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
<?php | |
/** | |
* composer require sentry/sentry-sdk | |
*/ | |
use Sentry; | |
Env::init(); | |
// Bedrock application config... | |
if (env('SENTRY_DSN')) { | |
Sentry\init([ | |
'dsn' => env('SENTRY_DSN'), | |
'release' => env('SENTRY_RELEASE'), | |
'environment' => env('SENTRY_ENVIRONMENT'), | |
'error_types' => E_ALL & ~E_NOTICE & ~E_DEPRECATED, | |
]); | |
Sentry\configureScope(function (Sentry\State\Scope $scope): void { | |
$scope->setTag('trellis_version', env('SENTRY_TRELLIS_VERSION')); | |
}); | |
} | |
// ... |
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
# typed: true | |
class Deploy | |
def initialize trellis, org, site, project, env | |
@trellis = trellis | |
@org = org | |
@site = site | |
@project = project | |
@env = env | |
end | |
def setup | |
ENV["SENTRY_ORG"]=@org | |
ENV["SENTRY_PROJECT"]=@project | |
self | |
end | |
def release | |
`sentry-cli releases propose-version` | |
end | |
def trellisDeploy | |
system "ansible-playbook deploy.yml -e \"\ | |
env=#{@env} \ | |
site=#{@site}\ | |
\" \ | |
--extra-vars=\"\ | |
sentry_project=#{@project} \ | |
sentry_release=#{self.release()} \ | |
sentry_organization=#{@org} \ | |
sentry_environment=#{@env}\ | |
\"" | |
end | |
def createRelease | |
puts "Versioning #{@project}\@#{self.release()}..." | |
system "sentry-cli releases new #{self.release()}" | |
system "sentry-cli releases set-commits --auto #{self.release()}" | |
self | |
end | |
def deploy | |
puts "Deploying #{@project}\@#{self.release()} to #{@env} ๐" | |
if (Dir.chdir(@trellis)) | |
if (self.trellisDeploy()) | |
system "sentry-cli releases finalize #{self.release()}" | |
system "sentry-cli releases deploys new -e=#{@env}" | |
else | |
puts "deployment failed ๐" | |
end | |
end | |
end | |
end |
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
# Modify your sentry organization name | |
# and your Trellis system path. My sentry project | |
# names are all the site hostname with '-' in place of '.' | |
# but you may need or want to modify that convention as well. | |
# Trellis path | |
trellis = '/Users/kellymears/code/sites/sites.tinypixel.dev/trellis' | |
# Sentry organization | |
org = 'tiny-pixel-collective' | |
site = ARGV[0] | |
env = ARGV[1] | |
# Sentry project name | |
project = site.sub('.', '-') | |
require_relative 'deploy' | |
deployment = Deploy.new trellis, org, site, project, env | |
deployment | |
.setup() | |
.createRelease() | |
.deploy() | |
exit true |
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
# Sentry deployment tasks | |
# | |
# I'm calling this from `finalize-after.yml` deploy-hook like: | |
# - import_tasks: "{{ playbook_dir }}/deploy-hooks/plugins/sentry.yml" | |
# | |
# You could also just include directly. | |
# | |
- name: "Set Sentry environment {{ sentry_environment }}" | |
shell: | |
cmd: echo SENTRY_ENVIRONMENT={{ sentry_environment }} >> .env | |
chdir: "{{ deploy_helper.new_release_path }}" | |
- name: "Set Sentry organization {{ sentry_organization }}" | |
shell: | |
cmd: echo SENTRY_ORGANIZATION={{ sentry_organization }} >> .env | |
chdir: "{{ deploy_helper.new_release_path }}" | |
- name: "Set Sentry project {{ sentry_project }}" | |
shell: | |
cmd: echo SENTRY_PROJECT={{ sentry_project }} >> .env | |
chdir: "{{ deploy_helper.new_release_path }}" | |
- name: "Set Sentry release {{ sentry_project }}@{{ sentry_release }}" | |
shell: | |
cmd: echo SENTRY_RELEASE={{ sentry_project }}@{{ sentry_release }} >> .env | |
chdir: "{{ deploy_helper.new_release_path }}" | |
- name: "Tag Sentry release with Trellis deployment ID" | |
shell: | |
cmd: echo SENTRY_TRELLIS_VERSION={{ project_version }} >> .env | |
chdir: "{{ deploy_helper.new_release_path }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment