Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DB connectivity issues after a service rollback #101

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions src/main/java/com/libertymutualgroup/herman/aws/ecs/EcsPush.java
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,38 @@ private RegisterTaskDefinitionResult registerTask(EcsPushDefinition definition,
return taskResult;
}

private TaskDefinition registerPriorTaskDefinitionWithUpdatedContainerEnvConfig(EcsPushDefinition ecsPushDefinition, TaskDefinition priorTaskDef, AmazonECS ecsClient) {
RdsInstance currentRdsInstanceDefinition = ecsPushDefinition.getDatabase();
if (currentRdsInstanceDefinition != null) {
for (ContainerDefinition containerDef : priorTaskDef.getContainerDefinitions()) {
containerDef.getEnvironment().replaceAll(keyValuePair -> {
if (keyValuePair.getName().equals(currentRdsInstanceDefinition.getInjectNames().getEncryptedPassword()))
keyValuePair.setValue(currentRdsInstanceDefinition.getEncryptedPassword());
else if (keyValuePair.getName().equals(currentRdsInstanceDefinition.getInjectNames().getAppEncryptedPassword()))
keyValuePair.setValue(currentRdsInstanceDefinition.getAppEncryptedPassword());
else if (keyValuePair.getName().equals(currentRdsInstanceDefinition.getInjectNames().getAdminEncryptedPassword()))
keyValuePair.setValue(currentRdsInstanceDefinition.getAdminEncryptedPassword());
return keyValuePair;
});
}

RegisterTaskDefinitionResult taskResult = ecsClient.registerTaskDefinition(new RegisterTaskDefinitionRequest()
.withFamily(priorTaskDef.getFamily())
.withContainerDefinitions(priorTaskDef.getContainerDefinitions())
.withVolumes(priorTaskDef.getVolumes())
.withPlacementConstraints(priorTaskDef.getPlacementConstraints())
.withNetworkMode(priorTaskDef.getNetworkMode())
.withTaskRoleArn(priorTaskDef.getTaskRoleArn())
.withMemory(priorTaskDef.getMemory()));

logger.addLogEntry("Registered new task definition revision of prior working version: " + taskResult.getTaskDefinition().getTaskDefinitionArn());

return taskResult.getTaskDefinition();
}
return priorTaskDef;

}

private String deployService(AmazonECS ecsClient, EcsClusterMetadata clusterMetadata, EcsPushDefinition definition,
LoadBalancer balancer, TaskDefinition taskDefinition, TaskDefinition priorDef) {
String appName = definition.getAppName();
Expand Down Expand Up @@ -546,14 +578,15 @@ private String deployService(AmazonECS ecsClient, EcsClusterMetadata clusterMeta
if (!deploySuccessful) {
if (priorDef != null) {
logger.addLogEntry("Deployment never stabilized - rolling back!");
logger.addLogEntry("Rolling back to " + priorDef.getTaskRoleArn());
TaskDefinition rollBackTaskDefinition = registerPriorTaskDefinitionWithUpdatedContainerEnvConfig(definition, priorDef, ecsClient);
logger.addLogEntry("Rolling back to " + rollBackTaskDefinition.getTaskRoleArn());

UpdateServiceRequest updateRequest = new UpdateServiceRequest()
.withCluster(clusterMetadata.getClusterId())
.withDesiredCount(definition.getService().getInstanceCount())
.withDeploymentConfiguration(definition.getService().getDeploymentConfiguration())
.withTaskDefinition(
priorDef.getTaskDefinitionArn())// "aws-kms-encrypt-dev-us-east-1-task-LEP2I3IDX73G:1")
rollBackTaskDefinition.getTaskDefinitionArn())// "aws-kms-encrypt-dev-us-east-1-task-LEP2I3IDX73G:1")
.withService(appName);

if (balancer != null) {
Expand Down