Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@ i.e. a mix of configurations that allow easy deployment with capistrano.

The basic command to deploy `<application>` in the `<environment>` to a `<server>` is

$ bundle exec cap <server>_<environment>_<application> deploy
$ bundle exec cap <server>_<application> deploy

where the three place holders can be:
* `<server>` is one of
* `live` (ontohub.org)
* `staging` (staging.ontohub.org)
* `<environment>` is one of
* `production`
* `<application>` is one of
* `ontohub-frontend`
* `ontohub-backend`
* `hets-rabbitmq-wrapper`

so to deploy the backend to staging.ontohub.org, you need to execute

$ bundle exec cap staging_production_ontohub-backend deploy
$ bundle exec cap staging_ontohub-backend deploy

## First deployment

Expand Down
5 changes: 5 additions & 0 deletions config/deploy/live_hets-rabbitmq-wrapper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

mixin 'servers/ontohub.org'
mixin 'environments/production'
mixin 'applications/hets-rabbitmq-wrapper'
5 changes: 5 additions & 0 deletions config/deploy/live_ontohub-backend.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

mixin 'servers/ontohub.org'
mixin 'environments/production'
mixin 'applications/ontohub-backend'
5 changes: 5 additions & 0 deletions config/deploy/live_ontohub-frontend.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

mixin 'servers/ontohub.org'
mixin 'environments/production'
mixin 'applications/ontohub-frontend'
12 changes: 12 additions & 0 deletions config/mixins/applications/ontohub-frontend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@
end
end

# Find the latest tag in the local repository
# (overwrite the task for the live stage)
Rake::Task['set_latest_tag'].clear_actions
after :'git:update', :set_latest_tag do
run_locally do
Dir.chdir(fetch(:local_repo_path)) do
set :latest_tag, `git tag --list`.lines.last.strip
end
end
end
after :set_latest_tag, :set_deploy_tag

after :'git:update', :'git:checkout' do
run_locally do
Dir.chdir(fetch(:local_repo_path)) do
Expand Down
47 changes: 47 additions & 0 deletions config/mixins/servers/ontohub.org.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# frozen_string_literal: true

set :deploy_user, 'webadm'
server 'staging.ontohub.org', user: fetch(:deploy_user), roles: %w(app db web)
set :tmp_dir, '/var/tmp'
set :rbenv_custom_path, '/local/usr/ruby'

# The branch will be set in the :set_deploy_tag task
set :branch, nil
set :backend_url, 'https://tb.iks.cs.ovgu.de'
set :grecaptcha_site_key, '6LdKSR8UAAAAANuiYuJcuJRQm4Go-dQh0he82vpU'

# Find the latest tag in the repository
after :'git:update', :set_latest_tag do
on roles(:all) do
within repo_path do
with fetch(:git_environmental_variables) do
set :latest_tag, capture(:git, 'tag', '--list').lines.last.strip
end
end
end
end

# Set the tag to deploy (sets the branch)
after :set_latest_tag, :set_deploy_tag do
# Exit if a branch is given (e.g. by command line)
unless fetch(:branch).nil?
$stderr.puts 'Cannot deploy: Deploying a branch is disabled for this stage.'
exit
end
# Get the latest tags and set the default
default_tag = fetch(:latest_tag)

# Allow the developer to choose a tag to deploy
# rubocop:disable Layout/SpaceInsideStringInterpolation
set(:tag,
ask("a tag to deploy: [Default: #{ default_tag }] ", default_tag))
# rubocop:enable Layout/SpaceInsideStringInterpolation

# Be extra cautious and exit if a tag cannot be found
if fetch(:tag).nil? || fetch(:tag).empty?
$stderr.puts 'Cannot deploy: The tag was not found.'
exit
end

set(:branch, fetch(:tag))
end
3 changes: 3 additions & 0 deletions config/mixins/servers/staging.ontohub.org.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@
set :branch, 'master'
set :backend_url, 'https://tb.iks.cs.ovgu.de'
set :grecaptcha_site_key, '6LdKSR8UAAAAANuiYuJcuJRQm4Go-dQh0he82vpU'

after :'git:update', :set_latest_tag {}
after :set_latest_tag, :set_deploy_tag {}