-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gha): add github action for service update
- Loading branch information
1 parent
2ba4968
commit b0820a3
Showing
8 changed files
with
184 additions
and
35 deletions.
There are no files selected for viewing
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,60 @@ | ||
name: 'Action for updating ECS service' | ||
description: 'Action for updating ECS service' | ||
author: 'Brian Caffey' | ||
inputs: | ||
BASE_ENV: | ||
required: true | ||
description: 'Base env name (e.g. dev)' | ||
APP_ENV: | ||
required: true | ||
description: 'App env name (e.g. alpha)' | ||
VERSION: | ||
required: true | ||
description: 'Application version git tag (e.g. v1.2.3)' | ||
ECR_REPO: | ||
required: true | ||
description: 'ECR repo to use' | ||
CONTAINER_NAME: | ||
required: true | ||
description: 'Name of the container to update' | ||
AWS_REGION: | ||
required: false | ||
description: 'AWS Region' | ||
default: 'us-east-1' | ||
|
||
# Trigger / Inputs | ||
runs: | ||
using: "composite" | ||
steps: | ||
# Note: this assumes that your ECR repo lives in the same AWS account as your ECS cluster | ||
- name: Get current AWS Account | ||
id: get-aws-account | ||
shell: bash | ||
run: | | ||
AWS_ACCOUNT_ID=$(aws sts get-caller-identity | jq -r .Account) | ||
echo "AWS_ACCOUNT_ID=$AWS_ACCOUNT_ID" >> $GITHUB_ENV | ||
- name: Download existing task definition | ||
id: download-task-definition | ||
shell: bash | ||
run: | | ||
aws ecs describe-task-definition \ | ||
--task-definition ${{ env.FULL_TASK_NAME }} \ | ||
| jq '.taskDefinition' > task-definition.json | ||
- name: Render new task definition | ||
id: render-new-task-definition | ||
uses: aws-actions/amazon-ecs-render-task-definition@v1 | ||
with: | ||
task-definition: task-definition.json | ||
container-name: ${{ inputs.CONTAINER_NAME }} | ||
image: ${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ inputs.AWS_REGION}}.amazonaws.com/${{ inputs.ECR_REPO }}:${{ inputs.VERSION }} | ||
|
||
- name: Deploy new task definition | ||
id: deploy-new-task-definition | ||
uses: aws-actions/amazon-ecs-deploy-task-definition@v1 | ||
with: | ||
cluster: ${{ inputs.APP_ENV }}-cluster | ||
service: ${{ inputs.APP_ENV }}-${{ inputs.CONTAINER_NAME }} | ||
task-definition: ${{ steps.render-new-task-definition.outputs.task-definition }} | ||
|
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,68 @@ | ||
import { IVpc, Port, SecurityGroup, SubnetType } from 'aws-cdk-lib/aws-ec2'; | ||
import { CfnSubnetGroup, CfnCacheCluster, CfnParameterGroup } from 'aws-cdk-lib/aws-elasticache'; | ||
import { Construct } from 'constructs'; | ||
|
||
|
||
interface ElastiCacheClusterProps { | ||
readonly vpc: IVpc; | ||
readonly appSecurityGroup: SecurityGroup; | ||
readonly instanceClass?: string; | ||
readonly instanceSize?: string; | ||
} | ||
|
||
export class ElastiCacheCluster extends Construct { | ||
// public rdsInstance: DatabaseInstance; | ||
private instanceClass: string; | ||
private instanceSize: string; | ||
public elastiCacheHost: string; | ||
|
||
|
||
constructor(scope: Construct, id: string, props: ElastiCacheClusterProps) { | ||
super(scope, id); | ||
|
||
// const stackName = Stack.of(this).stackName; | ||
|
||
// instance type from props | ||
this.instanceClass = props.instanceClass ?? 't4g'; | ||
this.instanceSize = props.instanceSize ?? 'micro'; | ||
|
||
const cacheNodeType = `cache.${this.instanceClass}.${this.instanceSize}`; | ||
|
||
// security group | ||
const elastiCacheSecurityGroup = new SecurityGroup(this, 'SecurityGroup', { | ||
vpc: props.vpc, | ||
description: 'Allow all outbound traffic', | ||
allowAllOutbound: true, | ||
}); | ||
|
||
// elastiCacheSecurityGroup.addIngressRule(Peer.anyIpv4(), Port.tcp(6379), 'ElastiCacheRedis'); | ||
elastiCacheSecurityGroup.addIngressRule(props.appSecurityGroup, Port.tcp(6379), 'AppSecurityGroup'); | ||
|
||
// ElastiCache subnet group | ||
const subnetGroup = new CfnSubnetGroup(this, 'SubnetGroup', { | ||
description: 'Subnet group for ElastiCache', | ||
subnetIds: props.vpc.selectSubnets({ subnetType: SubnetType.PRIVATE_WITH_EGRESS }).subnetIds, | ||
}); | ||
|
||
// ElastiCache parameter group | ||
const elastiCacheParameterGroup = new CfnParameterGroup(this, 'ElastiCacheParameterGroup', { | ||
description: 'parameter group for elasticache cluster', | ||
cacheParameterGroupFamily: 'redis7', | ||
properties: {}, | ||
}); | ||
|
||
// ElastiCache cluster | ||
const cacheCluster = new CfnCacheCluster(this, 'CacheCluster', { | ||
cacheNodeType: cacheNodeType, // Node type for a single-node cluster | ||
engine: 'redis', | ||
engineVersion: '7.0', | ||
numCacheNodes: 1, // Single node | ||
cacheSubnetGroupName: subnetGroup.ref, | ||
cacheParameterGroupName: elastiCacheParameterGroup.ref, | ||
vpcSecurityGroupIds: [elastiCacheSecurityGroup.securityGroupId], | ||
}); | ||
|
||
this.elastiCacheHost = cacheCluster.attrRedisEndpointAddress; | ||
|
||
} | ||
} |
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