-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
163d6c0
commit 4c2f449
Showing
7 changed files
with
64 additions
and
56 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
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
13 changes: 13 additions & 0 deletions
13
zip-deployboard-orca/src/main/java/io/ziphq/deployboard/DynamoStatusStage.java
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,13 @@ | ||
package io.ziphq.deployboard; | ||
|
||
import com.netflix.spinnaker.orca.api.pipeline.graph.StageDefinitionBuilder; | ||
import com.netflix.spinnaker.orca.api.pipeline.graph.TaskNode; | ||
import com.netflix.spinnaker.orca.api.pipeline.models.StageExecution; | ||
import org.pf4j.Extension; | ||
|
||
@Extension | ||
public class DynamoStatusStage implements StageDefinitionBuilder { | ||
public void taskGraph(StageExecution stage, TaskNode.Builder builder) { | ||
builder.withTask("dynamoStatus", DynamoStatusTask.class); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
zip-deployboard-orca/src/main/java/io/ziphq/deployboard/DynamoStatusTask.java
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,44 @@ | ||
package io.ziphq.deployboard; | ||
|
||
import com.amazonaws.auth.WebIdentityTokenCredentialsProvider; | ||
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; | ||
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder; | ||
import com.amazonaws.services.dynamodbv2.document.DynamoDB; | ||
import com.amazonaws.services.dynamodbv2.document.Item; | ||
import com.amazonaws.services.dynamodbv2.document.Table; | ||
import com.amazonaws.services.dynamodbv2.document.spec.DeleteItemSpec; | ||
import com.netflix.spinnaker.orca.api.pipeline.Task; | ||
import com.netflix.spinnaker.orca.api.pipeline.TaskResult; | ||
import com.netflix.spinnaker.orca.api.pipeline.models.StageExecution; | ||
import org.pf4j.Extension; | ||
|
||
@Extension | ||
public class DynamoStatusTask implements Task { | ||
private String dynamoTableName = "zip-spinnaker-ci-deploys"; | ||
|
||
public TaskResult execute(StageExecution stage) { | ||
DynamoStatusContext context = stage.mapTo(DynamoStatusContext.class); | ||
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().withRegion("us-east-2").withCredentials(WebIdentityTokenCredentialsProvider.create()).build(); | ||
DynamoDB dynamoDB = new DynamoDB(client); | ||
Table table = dynamoDB.getTable(dynamoTableName); | ||
|
||
// On successful build, update deployed field in dynamo. | ||
if (context.getSuccess()) { | ||
Item item = new Item() | ||
.withPrimaryKey("branch", context.getBranch(), "status", "DEPLOYED") | ||
.withString("image", context.getImage()); | ||
table.putItem(item); | ||
DeleteItemSpec deleteSpec = new DeleteItemSpec() | ||
.withPrimaryKey("branch", context.getBranch(), "status", "DEPLOYING"); | ||
table.deleteItem(deleteSpec); | ||
} else { | ||
// Otherwise, update deploying field and add 10 min TTL. | ||
Item item = new Item() | ||
.withPrimaryKey("branch", context.getBranch(), "status", "DEPLOYING") | ||
.withString("image", context.getImage()) | ||
.withLong("ttl", (System.currentTimeMillis() / 1000L + 10 * 60 * 60)); | ||
table.putItem(item); | ||
} | ||
return TaskResult.SUCCEEDED; | ||
} | ||
} |
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