-
-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support deployments and releases as separate concepts (#426)
Also allow multiple versions of an application to be deployed to the same environment, differentiated by a "target".
- Loading branch information
Showing
31 changed files
with
766 additions
and
79 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
db/migrations/20210414_create_currently_deployed_version_ids_table.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Sequel.migration do | ||
change do | ||
create_table(:currently_deployed_version_ids, charset: 'utf8') do | ||
primary_key :id | ||
String :target_for_index, null: false | ||
foreign_key :pacticipant_id, :pacticipants, null: false, on_delete: :cascade | ||
foreign_key :environment_id, :environments, null: false, on_delete: :cascade | ||
foreign_key :version_id, :versions, null: false, on_delete: :cascade | ||
foreign_key :deployed_version_id, null: false, on_delete: :cascade | ||
index [:pacticipant_id, :environment_id, :target_for_index], unique: true, name: "currently_deployed_version_pacticipant_environment_target_index" | ||
end | ||
end | ||
end |
21 changes: 21 additions & 0 deletions
21
db/migrations/20210415_add_target_column_to_deployed_version.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Sequel.migration do | ||
up do | ||
alter_table(:deployed_versions) do | ||
add_column(:target, String) | ||
add_column(:target_for_index, String, default: "", null: false) | ||
set_column_allow_null(:replaced_previous_deployed_version) | ||
set_column_allow_null(:currently_deployed) | ||
drop_index [:pacticipant_id, :currently_deployed], name: "deployed_versions_pacticipant_id_currently_deployed_index" | ||
end | ||
end | ||
|
||
down do | ||
alter_table(:deployed_versions) do | ||
drop_column(:target) | ||
drop_column(:target_for_index) | ||
set_column_not_null(:replaced_previous_deployed_version) | ||
set_column_not_null(:currently_deployed) | ||
add_index [:pacticipant_id, :currently_deployed], name: "deployed_versions_pacticipant_id_currently_deployed_index" | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Sequel.migration do | ||
change do | ||
create_table(:released_versions, charset: 'utf8') do | ||
primary_key :id | ||
String :uuid, null: false | ||
foreign_key :version_id, :versions, null: false | ||
Integer :pacticipant_id, null: false | ||
foreign_key :environment_id, :environments, null: false | ||
DateTime :created_at | ||
DateTime :updated_at | ||
DateTime :support_ended_at | ||
index [:uuid], unique: true, name: "released_versions_uuid_index" | ||
index [:version_id, :environment_id], unique: true, name: "released_versions_version_id_environment_id_index" | ||
index [:support_ended_at], name: "released_version_support_ended_at_index" | ||
end | ||
end | ||
end |
This file contains 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
This file contains 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
14 changes: 14 additions & 0 deletions
14
lib/pact_broker/api/decorators/released_version_decorator.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'pact_broker/api/decorators/base_decorator' | ||
|
||
module PactBroker | ||
module Api | ||
module Decorators | ||
class ReleasedVersionDecorator < BaseDecorator | ||
property :uuid | ||
property :currently_supported, camelize: true | ||
|
||
include Timestamps | ||
end | ||
end | ||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
require 'pact_broker/api/resources/base_resource' | ||
require 'pact_broker/api/decorators/released_version_decorator' | ||
|
||
module PactBroker | ||
module Api | ||
module Resources | ||
class ReleasedVersion < BaseResource | ||
def content_types_provided | ||
[["application/hal+json", :to_json]] | ||
end | ||
|
||
def allowed_methods | ||
["GET", "OPTIONS"] | ||
end | ||
|
||
def resource_exists? | ||
!!released_version | ||
end | ||
|
||
def to_json | ||
decorator_class(:released_version_decorator).new(released_version).to_json(decorator_options) | ||
end | ||
|
||
def policy_name | ||
:'versions::versions' | ||
end | ||
|
||
# For PF | ||
def policy_record_context | ||
# Not sure whether the context should be empty or the pacticipant should be nil | ||
if released_version | ||
{ pacticipant: released_version.pacticipant } | ||
else | ||
{} | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :released_version | ||
|
||
def released_version | ||
@released_version ||= released_version_service.find_by_uuid(uuid) | ||
end | ||
|
||
def uuid | ||
identifier_from_path[:uuid] | ||
end | ||
end | ||
end | ||
end | ||
end |
94 changes: 94 additions & 0 deletions
94
lib/pact_broker/api/resources/released_versions_for_version_and_environment.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
require 'pact_broker/api/resources/base_resource' | ||
require 'pact_broker/api/decorators/versions_decorator' | ||
|
||
module PactBroker | ||
module Api | ||
module Resources | ||
class ReleasedVersionsForVersionAndEnvironment < BaseResource | ||
def initialize | ||
super | ||
@existing_released_version = version && environment && released_version_service.find_released_version_for_version_and_environment(version, environment) | ||
end | ||
|
||
def content_types_accepted | ||
[["application/json", :from_json]] | ||
end | ||
|
||
def content_types_provided | ||
[["application/hal+json", :to_json]] | ||
end | ||
|
||
def allowed_methods | ||
["GET", "POST", "OPTIONS"] | ||
end | ||
|
||
def resource_exists? | ||
!!version && !!environment | ||
end | ||
|
||
def post_is_create? | ||
true | ||
end | ||
|
||
def create_path | ||
released_version_url(existing_released_version || OpenStruct.new(uuid: next_released_version_uuid), base_url) | ||
end | ||
|
||
def from_json | ||
@released_version = existing_released_version || released_version_service.create(next_released_version_uuid, version, environment) | ||
response.body = decorator_class(:released_version_decorator).new(released_version).to_json(decorator_options) | ||
true | ||
end | ||
|
||
def to_json | ||
decorator_class(:released_versions_decorator).new(released_versions).to_json(decorator_options(title: title)) | ||
end | ||
|
||
def policy_name | ||
:'versions::versions' | ||
end | ||
|
||
def finish_request | ||
if request.post? && existing_released_version | ||
response.code = 200 | ||
end | ||
super | ||
end | ||
|
||
private | ||
|
||
attr_reader :released_version, :existing_released_version | ||
|
||
def version | ||
@version ||= version_service.find_by_pacticipant_name_and_number(identifier_from_path) | ||
end | ||
|
||
def environment | ||
@environment ||= environment_service.find(environment_uuid) | ||
end | ||
|
||
def released_versions | ||
@released_versions ||= begin | ||
if existing_released_version | ||
[existing_released_version] | ||
else | ||
[] | ||
end | ||
end | ||
end | ||
|
||
def environment_uuid | ||
identifier_from_path[:environment_uuid] | ||
end | ||
|
||
def next_released_version_uuid | ||
@released_version_uuid ||= released_version_service.next_uuid | ||
end | ||
|
||
def title | ||
"Released versions for #{pacticipant.display_name} version #{pacticipant_version_number} in #{environment.display_name}" | ||
end | ||
end | ||
end | ||
end | ||
end |
14 changes: 14 additions & 0 deletions
14
lib/pact_broker/deployments/currently_deployed_version_id.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'sequel' | ||
require 'pact_broker/repositories/helpers' | ||
|
||
module PactBroker | ||
module Deployments | ||
class CurrentlyDeployedVersionId < Sequel::Model | ||
plugin :upsert, identifying_columns: [:pacticipant_id, :environment_id, :target_for_index] | ||
|
||
dataset_module do | ||
include PactBroker::Repositories::Helpers | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.