Skip to content

Commit 0a5d2ff

Browse files
authored
Merge pull request #3 from tmshkr/update-listener-rules
v4
2 parents 9077a9a + 93b4ed3 commit 0a5d2ff

25 files changed

+1282
-1196
lines changed

.env.example

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
AWS_ACCESS_KEY_ID=
2+
AWS_REGION=
3+
AWS_SECRET_ACCESS_KEY=
4+
5+
INPUT_APP_NAME="my-app"
6+
INPUT_BLUE_ENV="my-blue-env"
7+
INPUT_CREATE_ENVIRONMENT="true"
8+
INPUT_DEPLOY="true"
9+
INPUT_DISABLE_TERMINATION_PROTECTION="false"
10+
INPUT_ENABLE_TERMINATION_PROTECTION="false"
11+
INPUT_GREEN_ENV="my-green-env"
12+
INPUT_OPTION_SETTINGS=
13+
INPUT_PLATFORM_BRANCH_NAME="Docker running on 64bit Amazon Linux 2023"
14+
INPUT_PRODUCTION_CNAME="my-production-cname"
15+
INPUT_PROMOTE="true"
16+
INPUT_SOURCE_BUNDLE=
17+
INPUT_STAGING_CNAME="my-staging-cname"
18+
INPUT_TEMPLATE_NAME=
19+
INPUT_TERMINATE_UNHEALTHY_ENVIRONMENT="true"
20+
INPUT_UPDATE_ENVIRONMENT="true"
21+
INPUT_UPDATE_LISTENER_RULES="false"
22+
INPUT_VERSION_DESCRIPTION=
23+
INPUT_VERSION_LABEL=
24+
INPUT_WAIT_FOR_DEPLOYMENT="true"
25+
INPUT_WAIT_FOR_ENVIRONMENT="true"
26+
INPUT_WAIT_FOR_TERMINATION="true"
27+
INPUT_USE_DEFAULT_OPTION_SETTINGS="true"

README.md

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,24 @@ The action will create the following resources:
77
- An Elastic Beanstalk application, if it doesn't already exist.
88
- An Elastic Beanstalk application version, if it doesn't already exist.
99
- An Elastic Beanstalk environment, if it doesn't already exist.
10-
- An Application Load Balancer, if it doesn't already exist, when using the `shared_alb` strategy.
1110

12-
Based on the provided inputs, the action will determine which environment is the target environment, i.e., the environment to which a new application version should be deployed.
11+
Based on the provided inputs, the action will determine which environment is the target environment, to which a new application version should be deployed.
1312

14-
## Inputs/Outputs
15-
16-
See [action.yml](action.yml)
17-
18-
## Deployment Strategies
19-
20-
This action supports two blue/green deployment strategies: `swap_cnames` and `shared_alb`.
21-
22-
The default strategy is `swap_cnames`.
23-
24-
### `swap_cnames`
25-
26-
The `swap_cnames` strategy uses the value of the `production_cname` input to determine which environment is the production environment.
27-
28-
If neither the blue or green environments exist, it will create a new environment with the `production_cname` input. If the production environment already exists, the action will target the staging environment, creating it if it doesn't exist.
13+
The action uses the values of the `production_cname` and `staging_cname` inputs to determine which environment is the production or staging environment. Accordingly, the `production_cname` and `staging_cname` inputs should be set to the CNAME prefix of the production and staging environments, respectively.
2914

30-
The action will then swap the CNAMEs of the staging and production environments if `promote` is set to true.
15+
If neither environment exists, it will create a new environment with the `production_cname` input. If the production environment already exists, the action will target the staging environment, creating it if it doesn't exist.
3116

32-
### `shared_alb`
17+
After deploying, the action will swap the CNAMEs of the staging and production environments, if `swap_cnames` is set to true.
3318

34-
The `shared_alb` strategy determines which environment is the production environment by finding the `elasticbeanstalk:environment-id` tag on the associated ALB target groups, which is automatically created by Elastic Beanstalk. If the target groups are not properly tagged, the action will fail.
35-
36-
If neither the blue or green environments exist, it will provision an Application Load Balancer to share between the environments, and then create the production environment. If the production environment already exists, the action will target the staging environment, creating it if it doesn't exist.
37-
38-
When `promote` is set to true, the action will update the default action for each listener on the ALB with a port provided in the `ports` input, so that it forwards to the target group associated with the target environment.
19+
## Inputs/Outputs
3920

40-
When specifying multiple ports, the action will forward to the target group associated with that port, or else the target group associated with the first port provided, if no target group is associated with the port. For example, if `80,443,3000` is provided as the input, and only ports 80 and 3000 have target groups, the action will forward ports 80 and 443 to the target group for port 80, and port 3000 to the target group for port 3000.
21+
See [action.yml](action.yml)
4122

4223
## Terminating Environments
4324

44-
If the action finds that the staging environment is in an unhealthy state, it will be terminated and recreated, unless `terminate_unhealthy_environment` is set to false. The environment should be configured to recreate any associated resources that are deleted during environment termination, so that they are available when it is recreated.
25+
If the action finds that the target environment is in an unhealthy state, it will be terminated and recreated, unless `terminate_unhealthy_environment` is set to false. The environment should be configured to recreate any associated resources that are deleted during environment termination, so that they are available when it is recreated.
26+
27+
The action will also enable or disable termination protection on the target environment's underlying CloudFormation stack, if `enable_termination_protection` or `disable_termination_protection` are set to true, respectively.
4528

4629
## Usage
4730

@@ -65,7 +48,7 @@ jobs:
6548
- name: Generate source bundle
6649
run: zip -r bundle.zip . -x '*.git*'
6750
- name: Deploy
68-
uses: tmshkr/blue-green-beanstalk@v3
51+
uses: tmshkr/blue-green-beanstalk@v4
6952
with:
7053
app_name: "test-app"
7154
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
@@ -76,9 +59,15 @@ jobs:
7659
green_env: "my-green-env"
7760
platform_branch_name: "Docker running on 64bit Amazon Linux 2023"
7861
production_cname: "blue-green-beanstalk-prod"
79-
promote: ${{ github.ref_name == 'main' }}
8062
source_bundle: "bundle.zip"
63+
swap_cnames: ${{ github.ref_name == 'main' }}
8164
staging_cname: "blue-green-beanstalk-staging"
8265
version_description: ${{ github.event.head_commit.message }}
8366
version_label: ${{ github.ref_name }}-${{ github.sha }}
8467
```
68+
69+
### Using a Shared Load Balancer
70+
71+
When using a [shared load balancer](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/environments-cfg-alb-shared.html), the `update_listener_rules` input can be set to true, so that the action will update any listener rules that are tagged with a `bluegreenbeanstalk:target_cname` key, whose value is equal to the `production_cname` or `staging_cname` inputs, so that the listener rule points to the same target group as the CNAME.
72+
73+
To forward to a process on a port besides the default port 80, set another tag on the listener rule with a `bluegreenbeanstalk:target_port` key and a value equal to the port number.

action.yml

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ inputs:
1515
blue_env:
1616
description: "Name of the blue environment."
1717
required: true
18+
create_environment:
19+
description: "Whether to create a new environment during deployment if the target environment doesn't exist."
20+
default: "true"
1821
deploy:
19-
description: "Whether to deploy the new application version to the target environment."
22+
description: "Whether to deploy to the target environment."
2023
default: "false"
2124
disable_termination_protection:
2225
description: "Whether to disable termination protection for the target environment's CloudFormation stack before attempting to terminate it."
@@ -28,31 +31,33 @@ inputs:
2831
description: "Name of the green environment."
2932
required: true
3033
option_settings:
31-
description: "Path to a JSON file of option settings to use when creating a new environment. When using custom option settings, the default option settings will be ignored, but the SharedLoadBalancer will still be provided when using the `shared_alb` strategy."
34+
description: "Path to a JSON file consisting of an array of option settings to use when creating a new environment."
3235
platform_branch_name:
3336
description: "Name of the platform branch to use. When creating a new environment, it will be launched with the latest version of the specified platform branch. To see the list of available platform branches, run the `aws elasticbeanstalk list-platform-branches` command."
34-
prep:
35-
description: "When prep is set to true, the action will exit if the target environment is healthy, or create a new environment if it is not healthy. This is useful for preparing the target environment, e.g. with the sample application, before deploying a new application version in a later step."
36-
default: "false"
37-
ports:
38-
description: "Comma-separated list of ALB listener ports for use with the `shared_alb` strategy. When using the action to create an ALB, HTTP listeners will be created for each port. To enable HTTPS, port 443 must be configured on the ALB with ACM. When using an existing ALB, the action will update each specified port's default listener rule to point to the target environment if `promote` is set to true."
39-
default: "80"
4037
production_cname:
41-
description: "CNAME prefix for the domain that serves production traffic. Only required for the `swap_cnames` strategy."
42-
promote:
43-
description: "Whether to promote the target environment to production. When using the `swap_cnames` strategy, the action will swap the CNAMEs of the blue and green environments to redirect production traffic to the target environment. When using the `shared_alb` strategy, the action will update the shared Application Load Balancer's default listener rule to point to the target environment, replacing the other environment."
44-
default: "false"
45-
staging_cname:
46-
description: "CNAME prefix for the staging environment when using the `swap_cnames` strategy."
38+
description: "CNAME prefix for the domain that serves production traffic."
39+
required: true
4740
source_bundle:
4841
description: "Path to the source bundle to deploy. If not specified, the sample application will be used."
49-
strategy:
50-
description: "Deployment strategy to use: `swap_cnames` or `shared_alb`. See the `promote` input description for more details."
51-
default: "swap_cnames"
42+
staging_cname:
43+
description: "CNAME prefix for the staging environment."
44+
required: true
45+
swap_cnames:
46+
description: "Whether to swap the CNAMEs of the blue and green environments."
47+
default: "false"
5248
template_name:
5349
description: "Name of an Elastic Beanstalk configuration template to use when creating a new environment."
5450
terminate_unhealthy_environment:
55-
description: "Whether to terminate an unhealthy target environment. If set to false, the action will exit with an error when the target environment is unhealthy."
51+
description: "Whether to terminate an unhealthy target environment."
52+
default: "true"
53+
update_environment:
54+
description: "Whether to update an existing environment during deployment."
55+
default: "true"
56+
update_listener_rules:
57+
description: "When set to true, the action will update any elbv2 listener rules on the environments' SharedLoadBalancer tagged with a `bluegreenbeanstalk:target_cname` key, whose value is equal to the staging or production CNAME prefix, so that it forwards to the corresponding target group. The action will also remove any target group from the listener before terminating the environment. The port of the process may be specified by another tag with the key `bluegreenbeanstalk:target_port` whose value is the port number. If no such tag is found, the default port of 80 will be used."
58+
default: "false"
59+
use_default_option_settings:
60+
description: "Whether to use default option settings when creating a new environment."
5661
default: "true"
5762
version_description:
5863
description: "Description to use for the new application version."
@@ -67,9 +72,6 @@ inputs:
6772
wait_for_termination:
6873
description: "Whether to wait for an environment to be terminated."
6974
default: "true"
70-
use_default_option_settings:
71-
description: "Whether to use default option settings when creating a new environment."
72-
default: "true"
7375
outputs:
7476
target_env_cname:
7577
description: "CNAME of the target environment."

0 commit comments

Comments
 (0)