Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

CI/CD: Define Snapshot Schedule / Retention Strategy (#1928)

Dennis Kuijs6f04a0871998
diff --git a/.ci_cd/aws/cloudformation-create-ec2.yml b/.ci_cd/aws/cloudformation-create-ec2.yml
index 07909c6c7..b10d34ddd 100644
--- a/.ci_cd/aws/cloudformation-create-ec2.yml
+++ b/.ci_cd/aws/cloudformation-create-ec2.yml
@@ -29,7 +29,7 @@ Parameters:
Host:
Description: FQDN for host
Type: String
- #AllowedPattern: "^((?!-))(xn--)?[a-z0-9][a-z0-9-_]{0,61}[a-z0-9]{0,1}\.(xn--)?([a-z0-9\-]{1,61}|[a-z0-9-]{1,30}\.[a-z]{2,})$"
+ # AllowedPattern: "^((?!-))(xn--)?[a-z0-9][a-z0-9-_]{0,61}[a-z0-9]{0,1}\.(xn--)?([a-z0-9\-]{1,61}|[a-z0-9-]{1,30}\.[a-z]{2,})$"
Default: ""
VpcId:
Description: VPC ID in which to create instance
@@ -70,7 +70,7 @@ Parameters:
DNSHostedZoneName:
Description: Name of hosted domain zone to insert host A record into
Type: String
- #AllowedPattern: "^((?!-))(xn--)?[a-z0-9][a-z0-9-_]{0,61}[a-z0-9]{0,1}\.(xn--)?([a-z0-9\-]{1,61}|[a-z0-9-]{1,30}\.[a-z]{2,})$"
+ # AllowedPattern: "^((?!-))(xn--)?[a-z0-9][a-z0-9-_]{0,61}[a-z0-9]{0,1}\.(xn--)?([a-z0-9\-]{1,61}|[a-z0-9-]{1,30}\.[a-z]{2,})$"
ConstraintDescription: Must be a valid FQDN
Default: ""
DNSHostedZoneRoleArn:
@@ -78,10 +78,10 @@ Parameters:
Type: String
Default: ""
DLMExecutionRoleArn:
- Description: Role ARN for executing the DLM operations
+ Description: Role ARN that can be assumed for executing DLM operations
Type: String
SnapshotId:
- Description: Snapshot ID to create the EBS data volume based of an existing snapshot
+ Description: Snapshot ID to create EBS data volume based on an existing snapshot
Type: String
Default: ""
ElasticIP:
@@ -99,11 +99,11 @@ Parameters:
- false
Default: false
RootDiskSize:
- Description: Root EBS volume size GB
+ Description: Size of the EBS root volume (in GB)
Type: Number
Default: 16
DataDiskSize:
- Description: Amount of storage you want to provision for this EBS data volume
+ Description: Size of the EBS data volume (in GB)
Type: Number
Default: 16
HealthChecks:
@@ -836,8 +836,8 @@ Resources:
ImageId: !If [UseAMIID, !Ref ImageAMI, !Ref ImageId]
SubnetId: !Ref SubnetId
SecurityGroupIds:
- - Ref: SSHSecurityGroupId
- - Ref: StandardSecurityGroup
+ - !Ref SSHSecurityGroupId
+ - !Ref StandardSecurityGroup
BlockDeviceMappings:
- DeviceName: /dev/xvda
Ebs:
@@ -881,6 +881,7 @@ Resources:
EBSDataVolume:
Type: AWS::EC2::Volume
+ DeletionPolicy: Snapshot
Properties:
AvailabilityZone: !GetAtt EC2Instance.AvailabilityZone
Size: !Ref DataDiskSize
@@ -891,7 +892,6 @@ Resources:
Value: !Sub ${Host}-data
- Key: Type
Value: !Sub ${Host}-or-data-not-in-use
- DeletionPolicy: Snapshot
# DLM Policy for automatic snapshot creation
@@ -900,7 +900,10 @@ Resources:
DependsOn: EBSDataVolume
Properties:
ExecutionRoleArn: !Ref DLMExecutionRoleArn
- Description: 'or-data'
+ Description: !Join
+ - ''
+ - - 'Docker Volumes from instance '
+ - !Ref EC2Instance
State: ENABLED
PolicyDetails:
PolicyLanguage: STANDARD
@@ -912,18 +915,22 @@ Resources:
- VOLUME
Schedules:
- Name: Daily Backup
+ CopyTags: true
+ CreateRule:
+ CronExpression: 'cron(0 3 * * ? * )'
+ RetainRule:
+ Count: 7
+ - Name: Weekly Backup
+ CopyTags: true
CreateRule:
- Interval: 24
- IntervalUnit: HOURS
- Times:
- - '05:00'
+ CronExpression: 'cron(0 3 ? * MON * )'
RetainRule:
- Count: 5
+ Count: 4
Tags:
- Key: Name
Value: !Ref Host
- # Telemetry and Alarms.
+ # Telemetry and Alarms
EmailSubscription:
Condition: CreateHealthChecks
diff --git a/.ci_cd/aws/cloudformation-create-smtp-user.yml b/.ci_cd/aws/cloudformation-create-smtp-user.yml
index 601aa5733..cec5e9f6e 100644
--- a/.ci_cd/aws/cloudformation-create-smtp-user.yml
+++ b/.ci_cd/aws/cloudformation-create-smtp-user.yml
@@ -9,7 +9,7 @@ Parameters:
UserName:
Description: User name for smtp user
Type: String
- #AllowedPattern: "^\S{4,}$"
+ # AllowedPattern: "^\S{4,}$"
Resources:
SMTPUser:
diff --git a/.ci_cd/aws/cloudformation-create-vpc.yml b/.ci_cd/aws/cloudformation-create-vpc.yml
index e6615cce3..664d318a5 100644
--- a/.ci_cd/aws/cloudformation-create-vpc.yml
+++ b/.ci_cd/aws/cloudformation-create-vpc.yml
@@ -42,7 +42,7 @@ Conditions:
CreateSSHSecurityGroup: !Equals [!Ref SSHSecurityGroup, "true"]
Resources:
- ## VPC
+ # VPC
Vpc:
Type: AWS::EC2::VPC
Properties:
@@ -60,7 +60,7 @@ Resources:
VpcId: !Ref Vpc
AmazonProvidedIpv6CidrBlock: true
- ## VPC Peering accept role
+ # VPC Peering accept role
VPCPeerRole:
Type: AWS::IAM::Role
Condition: CreateVPCAcceptRole
@@ -97,7 +97,7 @@ Resources:
'Fn::Sub': >-
arn:aws:ec2:${AWS::Region}:${AWS::AccountId}:vpc-peering-connection/*
- ## VPC Peering Request
+ # VPC Peering Request
VpcPeeringConnection:
Type: 'AWS::EC2::VPCPeeringConnection'
Condition: CreateVPCPeerRequest
@@ -107,7 +107,7 @@ Resources:
PeerOwnerId: !Ref PeerVPCAccountId
PeerRoleArn: !Ref PeerRoleArn
- ## SUBNETS
+ # Subnets
PublicSubnet1:
Type: AWS::EC2::Subnet
DependsOn: VpcCidrBlockIpv6
@@ -192,7 +192,7 @@ Resources:
- Key: Name
Value: or-subnet-private-3
- ## INTERNET GATEWAY
+ # Internet Gateway
InternetGateway:
Type: AWS::EC2::InternetGateway
@@ -202,7 +202,7 @@ Resources:
VpcId: !Ref Vpc
InternetGatewayId: !Ref InternetGateway
- ## PUBLIC ROUTING
+ # Public Routing
PublicRouteTable:
Type: AWS::EC2::RouteTable
Properties:
@@ -254,7 +254,7 @@ Resources:
SubnetId: !Ref PublicSubnet3
RouteTableId: !Ref PublicRouteTable
- ## SSH Security Group
+ # SSH Security Group
SecurityGroup:
Type: AWS::EC2::SecurityGroup
Condition: CreateSSHSecurityGroup
diff --git a/.ci_cd/aws/cloudformation-healthcheck-alarm.yml b/.ci_cd/aws/cloudformation-healthcheck-alarm.yml
index c2e91ede4..c1b72e232 100644
--- a/.ci_cd/aws/cloudformation-healthcheck-alarm.yml
+++ b/.ci_cd/aws/cloudformation-healthcheck-alarm.yml
@@ -1,8 +1,8 @@
# ---------------------------------------------------------------------------------------------------------------------
-# Creates an alarm for Route53 health check - must be run in the us-east-1 region
+# Creates an alarm for Route53 Health Check - must be run in the us-east-1 region
# ---------------------------------------------------------------------------------------------------------------------
AWSTemplateFormatVersion: '2010-09-09'
-Description: 'Route 53 Healthcheck alarm'
+Description: 'Route53 Health Check alarm'
Parameters:
Host:
Description: FQDN for host
diff --git a/.ci_cd/aws/provision_host.sh b/.ci_cd/aws/provision_host.sh
index a8fd02af4..716dcce4f 100644
--- a/.ci_cd/aws/provision_host.sh
+++ b/.ci_cd/aws/provision_host.sh
@@ -20,7 +20,7 @@
# 3 - INSTANCE_TYPE EC2 instance type see cloud formation template parameter
# 4 - ROOT_DISK_SIZE to use for created EBS root volume (GB)
# 5 - DATA_DISK_SIZE to use for created EBS data volume (GB)
-# 6 - SNAPSHOT_ID to use for creating the EBS data volume based off an existing snapshot
+# 6 - SNAPSHOT_ID to use for creating the EBS data volume based on an existing snapshot
# 7 - ELASTIC_IP if 'true' then create an elastic public IP for this host
# 8 - PROVISION_S3_BUCKET set to 'false' to not provision an S3 bucket for this host
# 9 - ENABLE_METRICS set to 'false' to not enable cloudwatch metrics for this instance
@@ -72,7 +72,6 @@ fi
STACK_NAME=$(tr '.' '-' <<< "$HOST")
SMTP_STACK_NAME="$STACK_NAME-smtp"
HEALTH_STACK_NAME="$STACK_NAME-healthcheck"
-SSM_STACK_NAME="$STACK_NAME-ssm-attach-detach-documents"
# Provision SMTP user using CloudFormation (if stack doesn't already exist)
echo "Provisioning SMTP user"
@@ -286,7 +285,7 @@ if [ -n "$STATUS" ] && [ "$STATUS" != 'available' ]; then
echo "EBS data volume is already attached or not available for this host '$HOST' current status is '$STATUS'"
else
- EBS_DEVICE_NAME="/dev/sdf" # Only change if you know what you are doing
+ EBS_DEVICE_NAME="/dev/sdf" # Don't change it unless you know what you are doing
INSTANCE_ID=$(aws ec2 describe-instances --filters "Name=tag:Name,Values='$HOST'" --query "Reservations[].Instances[?Tags[?Value=='$STACK_ID']].InstanceId" --output text $ACCOUNT_PROFILE 2>/dev/null)
VOLUME_ID=$(aws ec2 describe-volumes --filters "Name=tag:Name,Values='$HOST-data'" --query "Volumes[?Tags[?Value=='$STACK_ID']].VolumeId" --output text $ACCOUNT_PROFILE 2>/dev/null)
@@ -335,7 +334,7 @@ if [ "$PROVISION_S3_BUCKET" != 'false' ]; then
fi
fi
-# Provision Route 53 healthcheck alarm CloudFormation (if stack doesn't already exist) - must be in the us-east-1 region
+# Provision Route53 Health Check Alarm CloudFormation (if stack doesn't already exist) - must be in the us-east-1 region
echo "Provisioning Healthcheck Alarm"
STATUS=$(aws cloudformation describe-stacks --stack-name $HEALTH_STACK_NAME --query "Stacks[0].StackStatus" --output text $ACCOUNT_PROFILE --region us-east-1 2>/dev/null)