You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: LICENSE.md
+5-8Lines changed: 5 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,13 @@
1
1
Copyright (c) 2019, Narrative Science
2
+
2
3
All rights reserved.
3
4
4
5
Redistribution and use in source and binary forms, with or without
5
6
modification, are permitted provided that the following conditions are met:
6
-
* Redistributions of source code must retain the above copyright
7
-
notice, this list of conditions and the following disclaimer.
8
-
* Redistributions in binary form must reproduce the above copyright
9
-
notice, this list of conditions and the following disclaimer in the
10
-
documentation and/or other materials provided with the distribution.
11
-
* Neither the name of the <organization> nor the
12
-
names of its contributors may be used to endorse or promote products
13
-
derived from this software without specific prior written permission.
7
+
8
+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9
+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
10
+
* Neither the name of the <organization> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
14
11
15
12
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
13
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Manage workflow concurrency and job state using an external store.
3
+
[View in CircleCI Orb Registry](https://circleci.com/orbs/registry/orb/narrativescience/workflow-manager)
4
+
5
+
Manage workflow concurrency and job state using an external store.
6
+
7
+
This orb allows you to:
8
+
9
+
- Limit the number of concurrently running workflows. This is useful when you want to only deploy one batch of changes at a time or use AWS CloudFormation and need to wait for the previous deploy to finish.
10
+
- Squash commits that are deployed in a workflow when the workflow is allowed to proceed
11
+
- Store and retreive data from a key-value store in jobs, even if they're run in parallel
12
+
- Track the status of a workflow from the command line
13
+
- Send a Slack message when a workflow succeeds after failing
4
14
5
15
## Rationale
6
16
7
17
Even though we tested it in different jobs, the [queue orb](https://circleci.com/orbs/registry/orb/eddiewebb/queue) did not consistently block the deploy workflow from executing more than one commit at a time. We don't think the issue is necessarily with the queue orb, it's most likely with the CircleCI API.
8
18
9
19
Instead of using the CircleCI API to determine if the workflow can continue, we can use a remote key-value store (DynamoDB) that acts as a first-in-first-out (FIFO) queue. This will allow us to process deploys one at a time, in the order the commits were merged.
10
20
11
-
## Supporting Infrastructure
21
+
## Installation
12
22
13
23
### Requirements
14
24
15
25
- Install the [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html)
- Set your AWS user profile or `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, and `AWS_DEFAULT_REGION` in your shell
17
28
18
-
### How to deploy
29
+
### Deploying the Stack
19
30
20
-
Deploy the [CloudFormation stack](./cloudformation_template.yml) with infrastructure to support this orb using the AWS CLI:
31
+
This orb uses a DynamoDB table to store state. Deploy the [CloudFormation stack](./cloudformation_template.yml) with infrastructure to support this orb using the AWS CLI:
21
32
22
33
```bash
23
34
aws cloudformation deploy \
@@ -27,9 +38,9 @@ aws cloudformation deploy \
27
38
28
39
This will create a DynamoDB table. You can tweak that template to align with your organization's standards or use the AWS console instead.
29
40
30
-
### Permissions
41
+
### IAM Permissions
31
42
32
-
You need to allow your CircleCI AWS user to interact with the DynamoDB table. Create a managed or inline policy and attach it to the IAM user:
43
+
You need to allow your CircleCI AWS IAM user to interact with the DynamoDB table. Create a managed or inline policy and attach it to the IAM user:
33
44
34
45
```json
35
46
{
@@ -52,11 +63,28 @@ You need to allow your CircleCI AWS user to interact with the DynamoDB table. Cr
52
63
}
53
64
```
54
65
55
-
### Deploy Queue
66
+
### CircleCI Context
67
+
68
+
For each workflow that uses this `workflow-manager` orb, create a [CircleCI Context](https://circleci.com/docs/2.0/contexts/) with an environment variable named `WORKFLOW_LOCK_KEY` set to the name of a workflow. Then, set `context: my-new-context` for every job in the workflow.
56
69
57
-
#### Entering the Queue
70
+
## Usage
71
+
72
+
### Entering the Queue: `wait-in-queue`
73
+
74
+
We run the [`wait-in-queue` job](src/jobs/wait-in-queue.yml) first in the deploy workflow. For example:
We run the [`wait-in-queue` job](src/jobs/wait-in-queue.yml) first in the deploy workflow. It starts by adding an item to the table with some attributes pertaining to the workflow instance:
87
+
It starts by adding an item to the table with some attributes pertaining to the workflow instance:
60
88
61
89
Field | Type | Description
62
90
--- | --- | ---
@@ -72,9 +100,22 @@ status | string | Localized secondary index. One of `QUEUED`, `RUNNING`, `SUCCES
72
100
73
101
The job then starts polling the table for the oldest item that doesn't have a status attribute of `SUCCESS` or `FAILED`. If that item has the same `workflow_id` as the job, that means the job is at the "front" of the queue and can continue; we set the item's status to `RUNNING` and the workflow transitions to the next job. It will wait in the queue for up to 4 hours before failing. When the workflow is allowed to continue, it can be said to have a "lock" on the deploy.
74
102
75
-
####Exiting the Queue
103
+
### Exiting the Queue: `exit-queue`
76
104
77
-
The [`exit-queue` job](src/jobs/exit-queue.yml) updates the table item's status attribute to be `SUCCESS` or `FAILED` depending on the value of the `exit_condition` parameter. By updating the job status, it allows other workflows to continue. This job should be called as the last job of every "branch" in a given workflow. For our deploy workflow this means putting it in 3 or 4 places.
105
+
The [`exit-queue` job](src/jobs/exit-queue.yml) updates the table item's status attribute to be `SUCCESS` or `FAILED` depending on the value of the `exit_condition` parameter. By updating the job status, it allows other workflows to continue. This job should be called as the last job of every "branch" in a given workflow. For example:
106
+
107
+
```yaml
108
+
jobs:
109
+
# ...
110
+
- workflow-manager/exit-queue:
111
+
context: my-deploy
112
+
requires:
113
+
- deploy-stack
114
+
filters:
115
+
branches:
116
+
only: master
117
+
send_slack_on_recovery: true
118
+
```
78
119
79
120
Even if we add the `exit-queue` job in all the right places in the workflow, we can still get into a state in which the lock is not released when a job fails. CircleCI does not have support for "run a job if some other job failed" so we have to add boilerplate to do so. This takes the form of adding the following step at the bottom of every job that the deploy workflow uses:
80
121
@@ -87,7 +128,7 @@ The `exit-queue` command will then release the lock only if a previous step in t
87
128
88
129
Instead of passing a lock key parameter down through the job/command parameter stack, we can instead leverage a [CircleCI Context](https://circleci.com/docs/2.0/contexts/) that sets an environment variable called `WORKFLOW_LOCK_KEY`. If all jobs in the workflow include the `context: <context name>` parameter, all commands will have access to that environment variable. The lock-related commands can source that variable to set the lock key.
89
130
90
-
#### Squashing Commits
131
+
### Squashing Commits
91
132
92
133
The deploy worklow has the capability to "squash commits", which replicates a feature of Jenkins that didn't come for free in CircleCI.
93
134
@@ -99,19 +140,10 @@ __What if I don't want my commit squashed?__ If you don't want this behavior for
99
140
100
141
__Note:__ As of now, if there's a failure in the deploy workflow, the Slack message sent to the channel will only include the author of that commit, i.e. it won't contain the list of authors of commits that were squashed. We can see how it plays out before deciding if this behavior should be added.
101
142
102
-
## Workflows CLI
143
+
### Workflows CLI
103
144
104
145
The `./workflows-cli.sh` script is a CLI for working with CircleCI workflows. It's mostly a wrapper on top of the `aws` CLI and primarily queries the workflows table in DynamoDB (see: [Deploy Queue](#deploy-queue)).
105
146
106
-
### Installation
107
-
108
-
Requirements:
109
-
110
-
- Install the [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html)
0 commit comments