Merge "Simplify entrypoint Gerrit script"
diff --git a/README.md b/README.md
index 14ee52c..48e96ea 100644
--- a/README.md
+++ b/README.md
@@ -30,4 +30,4 @@
## Templates
-* [Standalone Gerrit master sandbox without authentication](/single-master/README.md)
+* [Standalone Gerrit master sandbox with LDAP authentication](/single-master/README.md)
diff --git a/single-master/cf-cluster.yml b/single-master/cf-cluster.yml
index ada2e62..61035ef 100644
--- a/single-master/cf-cluster.yml
+++ b/single-master/cf-cluster.yml
@@ -29,6 +29,10 @@
Type: String
Default: gerrit-cluster-keys
Description: EC2 key pair name the cluter's instances
+ EnvironmentName:
+ Description: An environment name that will be prefixed to resource names
+ Type: String
+ Default: test
Mappings:
# Hard values for the subnet masks. These masks define
# the range of internal IP addresses that can be assigned.
@@ -102,6 +106,12 @@
- CidrIp: 0.0.0.0/0
IpProtocol: -1
+ CloudWatchLogsGroup:
+ Type: AWS::Logs::LogGroup
+ Properties:
+ LogGroupName: !Ref AWS::StackName
+ RetentionInDays: 14
+
# Autoscaling group. This launches the actual EC2 instances that will register
# themselves as members of the cluster, and run the docker containers.
ECSAutoScalingGroup:
@@ -134,6 +144,43 @@
# Make sure latest version of the helper scripts are installed as per recommendation:
# https://github.com/awsdocs/aws-cloudformation-user-guide/blob/master/doc_source/cfn-helper-scripts-reference.md#using-the-latest-version
yum install -y aws-cfn-bootstrap
+ # Get the CloudWatch Logs agent
+ echo -e "
+ {\"logs\":
+ {\"logs_collected\":
+ {\"files\":
+ {\"collect_list\":
+ [
+ {\"file_path\": \"/var/lib/docker/volumes/gerrit-logs/_data/httpd_log\",
+ \"log_group_name\": \"${AWS::StackName}\",
+ \"log_stream_name\": \"${EnvironmentName}/{instance_id}/httpd_log\",
+ \"timezone\": \"UTC\"
+ },
+ {\"file_path\": \"/var/lib/docker/volumes/gerrit-logs/_data/sshd_log\",
+ \"log_group_name\": \"${AWS::StackName}\",
+ \"log_stream_name\": \"${EnvironmentName}/{instance_id}/sshd_log\",
+ \"timezone\": \"UTC\"
+ },
+ {\"file_path\": \"/var/lib/docker/volumes/gerrit-logs/_data/gc_log\",
+ \"log_group_name\": \"${AWS::StackName}\",
+ \"log_stream_name\": \"${EnvironmentName}/{instance_id}/gc_log\",
+ \"timezone\": \"UTC\"
+ },
+ {\"file_path\": \"/var/lib/docker/volumes/gerrit-logs/_data/audit_log\",
+ \"log_group_name\": \"${AWS::StackName}\",
+ \"log_stream_name\": \"${EnvironmentName}/{instance_id}/audit_log\",
+ \"timezone\": \"UTC\"
+ }
+ ]
+ }
+ }
+ }
+ }" >> /home/ec2-user/gerritlogsaccess.json
+ # Install the CloudWatch Logs agent
+ yum install -y wget
+ wget https://s3.amazonaws.com/amazoncloudwatch-agent/centos/amd64/latest/amazon-cloudwatch-agent.rpm
+ rpm -U ./amazon-cloudwatch-agent.rpm
+ /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/home/ec2-user/gerritlogsaccess.json -s
# Signal to CloudFormation aws-cfn-bootstrap has been correctly updated
/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource ECSAutoScalingGroup --region ${AWS::Region}
AutoscalingRole:
diff --git a/single-master/cf-service.yml b/single-master/cf-service.yml
index 75d652f..00bbd83 100644
--- a/single-master/cf-service.yml
+++ b/single-master/cf-service.yml
@@ -57,6 +57,10 @@
Description: Gerrit index volume name
Type: String
Default: gerrit-index
+ GerritLogsVolume:
+ Description: Gerrit logs volume name
+ Type: String
+ Default: gerrit-logs
GerritCacheVolume:
Description: Gerrit cache volume name
Type: String
@@ -115,6 +119,8 @@
ContainerPath: /var/gerrit/cache
- SourceVolume: !Ref GerritDbVolume
ContainerPath: /var/gerrit/db
+ - SourceVolume: !Ref GerritLogsVolume
+ ContainerPath: /var/gerrit/logs
Cpu: 1024
Memory: 2048
PortMappings:
@@ -127,7 +133,7 @@
LogConfiguration:
LogDriver: awslogs
Options:
- awslogs-group: !Ref AWS::StackName
+ awslogs-group: !Ref ClusterStackName
awslogs-region: !Ref AWS::Region
awslogs-stream-prefix: !Ref EnvironmentName
Volumes:
@@ -166,11 +172,13 @@
Driver: local
Labels:
gerrit-index: !Join ['-', [!Ref EnvironmentName, !Ref GerritIndexVolume]]
- CloudWatchLogsGroup:
- Type: AWS::Logs::LogGroup
- Properties:
- LogGroupName: !Ref AWS::StackName
- RetentionInDays: 14
+ - Name: !Ref 'GerritLogsVolume'
+ DockerVolumeConfiguration:
+ Scope: shared
+ Autoprovision: true
+ Driver: local
+ Labels:
+ gerrit-logs: !Join ['-', [!Ref EnvironmentName, !Ref GerritLogsVolume]]
LoadBalancer:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer