From 1a3c3996779529863b30e0daa2c10455a3022df4 Mon Sep 17 00:00:00 2001 From: Cyril Dubuisson Date: Wed, 24 Jul 2019 18:31:41 +0200 Subject: [PATCH] :sparkles: : add terraform version management for modules --- src/main/java/io/codeka/gaia/bo/Job.java | 10 ++++++++ .../io/codeka/gaia/bo/TerraformModule.java | 11 ++++++++ .../io/codeka/gaia/runner/StackRunner.java | 6 ++++- .../gaia/runner/config/DockerConfig.java | 1 - src/main/resources/static/css/style.css | 7 +++++- src/main/resources/templates/job.html | 3 ++- src/main/resources/templates/module.html | 25 +++++++++++-------- src/main/resources/templates/modules.html | 1 + 8 files changed, 49 insertions(+), 15 deletions(-) diff --git a/src/main/java/io/codeka/gaia/bo/Job.java b/src/main/java/io/codeka/gaia/bo/Job.java index 1dd58dd42..b9f904010 100644 --- a/src/main/java/io/codeka/gaia/bo/Job.java +++ b/src/main/java/io/codeka/gaia/bo/Job.java @@ -36,6 +36,8 @@ public void setDateTime(LocalDateTime dateTime) { private JobType jobType; + private String cliVersion; + public String getId() { return id; } @@ -89,4 +91,12 @@ public JobType getType() { return this.jobType; } + public String getCliVersion() { + return cliVersion; + } + + public void setCliVersion(String cliVersion) { + this.cliVersion = cliVersion; + } + } diff --git a/src/main/java/io/codeka/gaia/bo/TerraformModule.java b/src/main/java/io/codeka/gaia/bo/TerraformModule.java index 8811a4368..ce96beb64 100644 --- a/src/main/java/io/codeka/gaia/bo/TerraformModule.java +++ b/src/main/java/io/codeka/gaia/bo/TerraformModule.java @@ -16,6 +16,8 @@ public class TerraformModule { private String name; private String description; + private String cliVersion; + public String getId() { return id; } @@ -71,4 +73,13 @@ public List getVariables() { public void setVariables(List variables) { this.variables = variables; } + + public String getCliVersion() { + return cliVersion; + } + + public void setCliVersion(String cliVersion) { + this.cliVersion = cliVersion; + } + } diff --git a/src/main/java/io/codeka/gaia/runner/StackRunner.java b/src/main/java/io/codeka/gaia/runner/StackRunner.java index 288152b09..e3bc11e8b 100644 --- a/src/main/java/io/codeka/gaia/runner/StackRunner.java +++ b/src/main/java/io/codeka/gaia/runner/StackRunner.java @@ -58,10 +58,11 @@ private int runContainerForJob(Job job, String script) { // FIXME This is certainly no thread safe ! var containerConfig = containerConfigBuilder .env(settings.env()) + .image("hashicorp/terraform:" + job.getCliVersion()) .build(); // pull the image - dockerClient.pull("hashicorp/terraform:0.12.3"); + dockerClient.pull("hashicorp/terraform:" + job.getCliVersion()); var containerCreation = dockerClient.createContainer(containerConfig); var containerId = containerCreation.id(); @@ -102,6 +103,7 @@ private int runContainerForJob(Job job, String script) { @Async public void apply(Job job, TerraformModule module, Stack stack) { this.jobs.put(job.getId(), job); + job.setCliVersion(module.getCliVersion()); job.start(JobType.RUN); var applyScript = stackCommandBuilder.buildApplyScript(stack, module); @@ -134,6 +136,7 @@ public void apply(Job job, TerraformModule module, Stack stack) { @Async public void plan(Job job, TerraformModule module, Stack stack) { this.jobs.put(job.getId(), job); + job.setCliVersion(module.getCliVersion()); job.start(JobType.PREVIEW); var planScript = stackCommandBuilder.buildPlanScript(stack, module); @@ -181,6 +184,7 @@ public Job getJob(String jobId) { @Async public void stop(Job job, TerraformModule module, Stack stack) { this.jobs.put(job.getId(), job); + job.setCliVersion(module.getCliVersion()); job.start(JobType.STOP); var destroyScript = stackCommandBuilder.buildDestroyScript(stack, module); diff --git a/src/main/java/io/codeka/gaia/runner/config/DockerConfig.java b/src/main/java/io/codeka/gaia/runner/config/DockerConfig.java index d0079eed1..65bcf31d3 100644 --- a/src/main/java/io/codeka/gaia/runner/config/DockerConfig.java +++ b/src/main/java/io/codeka/gaia/runner/config/DockerConfig.java @@ -30,7 +30,6 @@ DockerClient client(Settings settings) { @Bean ContainerConfig.Builder containerConfig(){ return ContainerConfig.builder() - .image("hashicorp/terraform:0.12.3") // bind mounting the docker sock (to be able to use docker provider in terraform) .hostConfig(HostConfig.builder().binds(HostConfig.Bind.builder().from("/var/run/docker.sock").to("/var/run/docker.sock").build()).build()) // resetting entrypoint to empty diff --git a/src/main/resources/static/css/style.css b/src/main/resources/static/css/style.css index 0e8df14a0..9bd5209ba 100755 --- a/src/main/resources/static/css/style.css +++ b/src/main/resources/static/css/style.css @@ -551,12 +551,17 @@ a:focus { margin-top: 0; } -.block_head{ +.block_head, .block_head_flex { padding: 18px 25px 15px; width: 100%; border-bottom: solid #f3f3f3 2px; } +.block_head_flex { + display: flex; + justify-content: space-between; +} + .block h2 { line-height: normal; font-size: 21px; diff --git a/src/main/resources/templates/job.html b/src/main/resources/templates/job.html index a9a5e725c..a9bf65252 100644 --- a/src/main/resources/templates/job.html +++ b/src/main/resources/templates/job.html @@ -39,8 +39,9 @@
-
+

Stack {{stack.name}}

+
diff --git a/src/main/resources/templates/module.html b/src/main/resources/templates/module.html index 2e8c46129..adea223ae 100644 --- a/src/main/resources/templates/module.html +++ b/src/main/resources/templates/module.html @@ -44,31 +44,35 @@

Module