Skip to content

Commit

Permalink
Stack: update build_deploy to pass allow_concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
kartiki975 committed Mar 20, 2024
1 parent 0834c0b commit 5e3767d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Migrate from legacy Rails secrets to credentials (#1326)
* Rails secrets were [deprecated in Rails 7.1](https://github.com/rails/rails/pull/48472)
* [Guide on credentials](https://guides.rubyonrails.org/security.html#custom-credentials)
* For deployments, `allow_concurrency` defaults to the same value as `force`. If wanted, it can be set separately by passing the intended value for `allow_concurrency` to `build_deploy` method


# 0.39.0

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,11 @@ For example:
fetch:
curl --silent https://app.example.com/services/ping/version
```

**Note:** Currently, deployments in emergency mode are configured to occur concurrently via [the `build_deploy` method](https://github.com/Shopify/shipit-engine/blob/main/app/models/shipit/stack.rb),
whose `allow_concurrency` keyword argument defaults to `force`, where `force` is true when emergency mode is enabled.
If you'd like to separate these two from one another, override this method as desired in your service.

<h3 id="kubernetes">Kubernetes</h3>

**<code>kubernetes</code>** allows to specify a Kubernetes namespace and context to deploy to.
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/shipit/api/deploys_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ def index
params do
requires :sha, String, length: { in: 6..40 }
accepts :force, Boolean, default: false
accepts :allow_concurrency, Boolean
accepts :require_ci, Boolean, default: false
accepts :env, Hash, default: {}
end
def create
commit = stack.commits.by_sha(params.sha) || param_error!(:sha, 'Unknown revision')
param_error!(:force, "Can't deploy a locked stack") if !params.force && stack.locked?
param_error!(:require_ci, "Commit is not deployable") if params.require_ci && !commit.deployable?
deploy = stack.trigger_deploy(commit, current_user, env: params.env, force: params.force)
deploy = stack.trigger_deploy(commit, current_user, env: params.env, force: params.force,
allow_concurrency: params.allow_concurrency || params.force)
render_resource(deploy, status: :accepted)
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/shipit/stack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ def trigger_task(definition_id, user, env: nil, force: false)
task
end

def build_deploy(until_commit, user, env: nil, force: false)
def build_deploy(until_commit, user, env: nil, force: false, allow_concurrency: force)
since_commit = last_deployed_commit.presence || commits.first
deploys.build(
user_id: user.id,
until_commit: until_commit,
since_commit: since_commit,
env: filter_deploy_envs(env&.to_h || {}),
allow_concurrency: force,
allow_concurrency: allow_concurrency,
ignored_safeties: force || !until_commit.deployable?,
max_retries: retries_on_deploy,
)
Expand Down

0 comments on commit 5e3767d

Please sign in to comment.