diff --git a/Readme.md b/Readme.md index d84dd65..c3f3802 100644 --- a/Readme.md +++ b/Readme.md @@ -8,13 +8,12 @@ i.e. a mix of configurations that allow easy deployment with capistrano. The basic command to deploy `` in the `` to a `` is - $ bundle exec cap __ deploy + $ bundle exec cap _ deploy where the three place holders can be: * `` is one of + * `live` (ontohub.org) * `staging` (staging.ontohub.org) -* `` is one of - * `production` * `` is one of * `ontohub-frontend` * `ontohub-backend` @@ -22,7 +21,7 @@ where the three place holders can be: 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 diff --git a/config/deploy/live_hets-rabbitmq-wrapper.rb b/config/deploy/live_hets-rabbitmq-wrapper.rb new file mode 100644 index 0000000..5dd21cc --- /dev/null +++ b/config/deploy/live_hets-rabbitmq-wrapper.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +mixin 'servers/ontohub.org' +mixin 'environments/production' +mixin 'applications/hets-rabbitmq-wrapper' diff --git a/config/deploy/live_ontohub-backend.rb b/config/deploy/live_ontohub-backend.rb new file mode 100644 index 0000000..64ff450 --- /dev/null +++ b/config/deploy/live_ontohub-backend.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +mixin 'servers/ontohub.org' +mixin 'environments/production' +mixin 'applications/ontohub-backend' diff --git a/config/deploy/live_ontohub-frontend.rb b/config/deploy/live_ontohub-frontend.rb new file mode 100644 index 0000000..1edfa4f --- /dev/null +++ b/config/deploy/live_ontohub-frontend.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +mixin 'servers/ontohub.org' +mixin 'environments/production' +mixin 'applications/ontohub-frontend' diff --git a/config/deploy/staging_production_hets-rabbitmq-wrapper.rb b/config/deploy/staging_hets-rabbitmq-wrapper.rb similarity index 100% rename from config/deploy/staging_production_hets-rabbitmq-wrapper.rb rename to config/deploy/staging_hets-rabbitmq-wrapper.rb diff --git a/config/deploy/staging_production_ontohub-backend.rb b/config/deploy/staging_ontohub-backend.rb similarity index 100% rename from config/deploy/staging_production_ontohub-backend.rb rename to config/deploy/staging_ontohub-backend.rb diff --git a/config/deploy/staging_production_ontohub-frontend.rb b/config/deploy/staging_ontohub-frontend.rb similarity index 100% rename from config/deploy/staging_production_ontohub-frontend.rb rename to config/deploy/staging_ontohub-frontend.rb diff --git a/config/mixins/applications/ontohub-frontend.rb b/config/mixins/applications/ontohub-frontend.rb index 732baa6..397b813 100644 --- a/config/mixins/applications/ontohub-frontend.rb +++ b/config/mixins/applications/ontohub-frontend.rb @@ -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 diff --git a/config/mixins/servers/ontohub.org.rb b/config/mixins/servers/ontohub.org.rb new file mode 100644 index 0000000..1ae5d4a --- /dev/null +++ b/config/mixins/servers/ontohub.org.rb @@ -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 diff --git a/config/mixins/servers/staging.ontohub.org.rb b/config/mixins/servers/staging.ontohub.org.rb index 0c82a67..6cd8be5 100644 --- a/config/mixins/servers/staging.ontohub.org.rb +++ b/config/mixins/servers/staging.ontohub.org.rb @@ -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 {}