Skip to content

Commit

Permalink
✨ : add information about image used for jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
cdubuisson committed Feb 2, 2020
1 parent 555ff00 commit 053d839
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/io/codeka/gaia/runner/StackCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ private String buildScript(Stack stack, TerraformModule module,
var script = new TerraformScript()
.setExternalUrl(settings.getExternalUrl())
.setStackId(stack.getId())
.setGitRepositoryUrl(evalGitRepositoryUrl(module));
.setGitRepositoryUrl(evalGitRepositoryUrl(module))
.setTerraformImage(module.getTerraformImage().image());

if (StringUtils.isNotBlank(module.getDirectory())) {
script.setGitDirectory(module.getDirectory());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@
*/
public class TerraformScript {

private String terraformImage;
private String gitRepositoryUrl;
private String gitDirectory;
private String externalUrl;
private String stackId;
private String command;

public String getTerraformImage() {
return terraformImage;
}

public TerraformScript setTerraformImage(String terraformImage) {
this.terraformImage = terraformImage;
return this;
}

public String getGitRepositoryUrl() {
return gitRepositoryUrl;
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/mustache/terraform.mustache
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
set -e

echo 'using image {{terraformImage}}'

echo 'cloning {{gitRepositoryUrl}}' | awk '{ sub(/oauth2:(.*)@/, "oauth2:[MASKED]@");}1'
git clone {{gitRepositoryUrl}} module

Expand Down
12 changes: 12 additions & 0 deletions src/test/java/io/codeka/gaia/runner/StackCommandBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ void buildPlanScript_shouldGenerateAFullScript() {
var stack = new Stack();
var script = stackCommandBuilder.buildPlanScript(stack, module);

assertTrue(script.contains("echo 'using image hashicorp/terraform:latest'"));
assertTrue(script.contains("echo 'cloning git://test' | awk '{ sub(/oauth2:(.*)@/, \"oauth2:[MASKED]@\");}1'"));
assertTrue(script.contains("git clone git://test module"));
assertTrue(script.contains("cd module"));
Expand All @@ -117,6 +118,7 @@ void buildPlanScript_shouldGenerateAFullScript_forAModuleWithoutDirectory() {
var stack = new Stack();
var script = stackCommandBuilder.buildPlanScript(stack, module);

assertTrue(script.contains("echo 'using image hashicorp/terraform:latest'"));
assertTrue(script.contains("echo 'cloning git://test' | awk '{ sub(/oauth2:(.*)@/, \"oauth2:[MASKED]@\");}1'"));
assertTrue(script.contains("git clone git://test module"));
assertTrue(script.contains("cd module"));
Expand All @@ -136,6 +138,7 @@ void buildPlanScript_shouldGenerateAFullScript_forAModuleWithAccessToken() {
when(registryOAuth2Provider.getOAuth2Url(anyString(), anyString())).thenReturn("url_with_token");
var script = stackCommandBuilder.buildPlanScript(stack, module);

assertTrue(script.contains("echo 'using image hashicorp/terraform:latest'"));
assertTrue(script.contains("echo 'cloning url_with_token' | awk '{ sub(/oauth2:(.*)@/, \"oauth2:[MASKED]@\");}1'"));
assertTrue(script.contains("git clone url_with_token"));
assertTrue(script.contains("cd module"));
Expand Down Expand Up @@ -209,6 +212,7 @@ void buildApplyScript_shouldGenerateAFullScript() {
var stack = new Stack();
var script = stackCommandBuilder.buildApplyScript(stack, module);

assertTrue(script.contains("echo 'using image hashicorp/terraform:latest'"));
assertTrue(script.contains("echo 'cloning git://test' | awk '{ sub(/oauth2:(.*)@/, \"oauth2:[MASKED]@\");}1'"));
assertTrue(script.contains("git clone git://test module"));
assertTrue(script.contains("cd module"));
Expand All @@ -226,6 +230,7 @@ void buildApplyScript_shouldGenerateAFullScript_forAModuleWithoutDirectory() {
var stack = new Stack();
var script = stackCommandBuilder.buildApplyScript(stack, module);

assertTrue(script.contains("echo 'using image hashicorp/terraform:latest'"));
assertTrue(script.contains("echo 'cloning git://test' | awk '{ sub(/oauth2:(.*)@/, \"oauth2:[MASKED]@\");}1'"));
assertTrue(script.contains("git clone git://test module"));
assertTrue(script.contains("cd module"));
Expand All @@ -245,6 +250,7 @@ void buildApplyScript_shouldGenerateAFullScript_forAModuleWithAccessToken() {
when(registryOAuth2Provider.getOAuth2Url(anyString(), anyString())).thenReturn("url_with_token");
var script = stackCommandBuilder.buildApplyScript(stack, module);

assertTrue(script.contains("echo 'using image hashicorp/terraform:latest'"));
assertTrue(script.contains("echo 'cloning url_with_token' | awk '{ sub(/oauth2:(.*)@/, \"oauth2:[MASKED]@\");}1'"));
assertTrue(script.contains("git clone url_with_token"));
assertTrue(script.contains("cd module"));
Expand Down Expand Up @@ -318,6 +324,7 @@ void buildPlanDestroyScript_shouldGenerateAFullScript() {
var stack = new Stack();
var script = stackCommandBuilder.buildPlanDestroyScript(stack, module);

assertTrue(script.contains("echo 'using image hashicorp/terraform:latest'"));
assertTrue(script.contains("echo 'cloning git://test' | awk '{ sub(/oauth2:(.*)@/, \"oauth2:[MASKED]@\");}1'"));
assertTrue(script.contains("git clone git://test module"));
assertTrue(script.contains("cd module"));
Expand All @@ -335,6 +342,7 @@ void buildPlanDestroyScript_shouldGenerateAFullScript_forAModuleWithoutDirectory
var stack = new Stack();
var script = stackCommandBuilder.buildPlanDestroyScript(stack, module);

assertTrue(script.contains("echo 'using image hashicorp/terraform:latest'"));
assertTrue(script.contains("echo 'cloning git://test' | awk '{ sub(/oauth2:(.*)@/, \"oauth2:[MASKED]@\");}1'"));
assertTrue(script.contains("git clone git://test module"));
assertTrue(script.contains("cd module"));
Expand All @@ -354,6 +362,7 @@ void buildPlanDestroyScript_shouldGenerateAFullScript_forAModuleWithAccessToken(
when(registryOAuth2Provider.getOAuth2Url(anyString(), anyString())).thenReturn("url_with_token");
var script = stackCommandBuilder.buildPlanDestroyScript(stack, module);

assertTrue(script.contains("echo 'using image hashicorp/terraform:latest'"));
assertTrue(script.contains("echo 'cloning url_with_token' | awk '{ sub(/oauth2:(.*)@/, \"oauth2:[MASKED]@\");}1'"));
assertTrue(script.contains("git clone url_with_token"));
assertTrue(script.contains("cd module"));
Expand Down Expand Up @@ -427,6 +436,7 @@ void buildDestroyScript_shouldGenerateAFullScript() {
var stack = new Stack();
var script = stackCommandBuilder.buildDestroyScript(stack, module);

assertTrue(script.contains("echo 'using image hashicorp/terraform:latest'"));
assertTrue(script.contains("echo 'cloning git://test' | awk '{ sub(/oauth2:(.*)@/, \"oauth2:[MASKED]@\");}1'"));
assertTrue(script.contains("git clone git://test module"));
assertTrue(script.contains("cd module"));
Expand All @@ -444,6 +454,7 @@ void buildDestroyScript_shouldGenerateAFullScript_forAModuleWithoutDirectory() {
var stack = new Stack();
var script = stackCommandBuilder.buildDestroyScript(stack, module);

assertTrue(script.contains("echo 'using image hashicorp/terraform:latest'"));
assertTrue(script.contains("echo 'cloning git://test' | awk '{ sub(/oauth2:(.*)@/, \"oauth2:[MASKED]@\");}1'"));
assertTrue(script.contains("git clone git://test module"));
assertTrue(script.contains("cd module"));
Expand All @@ -463,6 +474,7 @@ void buildDestroyScript_shouldGenerateAFullScript_forAModuleWithAccessToken() {
when(registryOAuth2Provider.getOAuth2Url(anyString(), anyString())).thenReturn("url_with_token");
var script = stackCommandBuilder.buildDestroyScript(stack, module);

assertTrue(script.contains("echo 'using image hashicorp/terraform:latest'"));
assertTrue(script.contains("echo 'cloning url_with_token' | awk '{ sub(/oauth2:(.*)@/, \"oauth2:[MASKED]@\");}1'"));
assertTrue(script.contains("git clone url_with_token"));
assertTrue(script.contains("cd module"));
Expand Down

0 comments on commit 053d839

Please sign in to comment.