Skip to content

Commit

Permalink
♻️ : replace cliVersion concept by a terraform image in module
Browse files Browse the repository at this point in the history
 - delete the controller and repository loading terraform cli versions
 - delete cliVersion attribute in Module
 - add new bo TerraformImage
 - add terraformImage attribute in Module
  • Loading branch information
cdubuisson committed Feb 2, 2020
1 parent a141732 commit 070d66e
Show file tree
Hide file tree
Showing 30 changed files with 127 additions and 383 deletions.
15 changes: 15 additions & 0 deletions src/main/java/io/codeka/gaia/modules/bo/TerraformImage.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.codeka.gaia.modules.bo

import javax.validation.constraints.NotBlank

data class TerraformImage @JvmOverloads constructor(
@field:NotBlank val repository: String,
@field:NotBlank val tag: String) {

fun image() = "$repository:$tag"

companion object {
fun defaultInstance() = TerraformImage("hashicorp/terraform", "latest")
}

}
12 changes: 6 additions & 6 deletions src/main/java/io/codeka/gaia/modules/bo/TerraformModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public class TerraformModule {

private String description;

@NotBlank
private String cliVersion;
@Valid
private TerraformImage terraformImage = TerraformImage.Companion.defaultInstance();

@DBRef
private List<Team> authorizedTeams = new ArrayList<>();
Expand Down Expand Up @@ -102,12 +102,12 @@ public void setVariables(List<Variable> variables) {
this.variables = variables;
}

public String getCliVersion() {
return cliVersion;
public TerraformImage getTerraformImage() {
return terraformImage;
}

public void setCliVersion(String cliVersion) {
this.cliVersion = cliVersion;
public void setTerraformImage(TerraformImage terraformImage) {
this.terraformImage = terraformImage;
}

public List<Team> getAuthorizedTeams() {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
package io.codeka.gaia.registries.controller

import io.codeka.gaia.hcl.HclParser
import io.codeka.gaia.modules.bo.ModuleMetadata
import io.codeka.gaia.modules.bo.TerraformModule
import io.codeka.gaia.modules.repository.TerraformCLIRepository
import io.codeka.gaia.modules.repository.TerraformModuleRepository
import io.codeka.gaia.registries.RegistryApi
import io.codeka.gaia.registries.RegistryDetails
import io.codeka.gaia.registries.RegistryType
import io.codeka.gaia.registries.github.GithubRegistryApi
import io.codeka.gaia.registries.github.GithubRepository
import io.codeka.gaia.registries.service.RegistryService
import io.codeka.gaia.teams.User
import org.springframework.http.HttpStatus
import org.springframework.security.access.annotation.Secured
import org.springframework.web.bind.annotation.*
import java.util.*

@RestController
@RequestMapping("/api/registries/github")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
package io.codeka.gaia.registries.controller

import io.codeka.gaia.hcl.HclParser
import io.codeka.gaia.modules.bo.TerraformModule
import io.codeka.gaia.modules.repository.TerraformCLIRepository
import io.codeka.gaia.modules.repository.TerraformModuleRepository
import io.codeka.gaia.registries.RegistryApi
import io.codeka.gaia.registries.RegistryDetails
import io.codeka.gaia.registries.RegistryType
import io.codeka.gaia.registries.gitlab.GitlabRepository
import io.codeka.gaia.registries.service.RegistryService
import io.codeka.gaia.teams.User
import org.springframework.http.HttpStatus
import org.springframework.security.access.annotation.Secured
import org.springframework.web.bind.annotation.*
import java.util.*

@RestController
@RequestMapping("/api/registries/gitlab")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package io.codeka.gaia.registries.service

import io.codeka.gaia.hcl.HclParser
import io.codeka.gaia.modules.bo.ModuleMetadata
import io.codeka.gaia.modules.bo.TerraformImage
import io.codeka.gaia.modules.bo.TerraformModule
import io.codeka.gaia.modules.repository.TerraformCLIRepository
import io.codeka.gaia.modules.repository.TerraformModuleRepository
import io.codeka.gaia.registries.RegistryApi
import io.codeka.gaia.registries.RegistryDetails
Expand All @@ -19,13 +19,12 @@ interface RegistryService {

@Service
class RegistryServiceImpl(
private val cliRepository: TerraformCLIRepository,
private val hclParser: HclParser,
private val moduleRepository: TerraformModuleRepository,
private val registryApis: Map<RegistryType, RegistryApi<out SourceRepository>>
) : RegistryService {

override fun importRepository(projectId: String, registryType: RegistryType, user: User) : TerraformModule {
override fun importRepository(projectId: String, registryType: RegistryType, user: User): TerraformModule {
val module = TerraformModule()
module.id = UUID.randomUUID().toString()

Expand All @@ -34,7 +33,7 @@ class RegistryServiceImpl(
module.gitRepositoryUrl = codeRepository.htmlUrl
module.gitBranch = "master"
module.name = codeRepository.fullName
module.cliVersion = cliRepository.listCLIVersion().first()
module.terraformImage = TerraformImage.defaultInstance()

module.registryDetails = RegistryDetails(registryType, codeRepository.id)
module.moduleMetadata = ModuleMetadata(createdBy = user)
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/codeka/gaia/runner/DockerRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ int runContainerForJob(JobWorkflow jobWorkflow, String script) {
// FIXME This is certainly no thread safe !
var containerConfig = containerConfigBuilder
.env(env)
.image("hashicorp/terraform:" + job.getCliVersion())
.image(job.getTerraformImage().image())
.build();

// pull the image
dockerClient.pull("hashicorp/terraform:" + job.getCliVersion());
dockerClient.pull(containerConfig.image());

var containerCreation = dockerClient.createContainer(containerConfig);
var containerId = containerCreation.id();
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/io/codeka/gaia/stacks/bo/Job.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.codeka.gaia.stacks.bo;

import io.codeka.gaia.modules.bo.TerraformImage;
import io.codeka.gaia.teams.User;
import org.springframework.data.mongodb.core.mapping.DBRef;

Expand All @@ -20,7 +21,7 @@ public class Job {
private LocalDateTime endDateTime;
private JobType type;
private JobStatus status;
private String cliVersion;
private TerraformImage terraformImage;
@DBRef
private List<Step> steps = new ArrayList<>(2);
@DBRef
Expand Down Expand Up @@ -106,12 +107,12 @@ public void setStatus(JobStatus status) {
this.status = status;
}

public String getCliVersion() {
return cliVersion;
public TerraformImage getTerraformImage() {
return terraformImage;
}

public void setCliVersion(String cliVersion) {
this.cliVersion = cliVersion;
public void setTerraformImage(TerraformImage terraformImage) {
this.terraformImage = terraformImage;
}

public List<Step> getSteps() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public String launchJob(@PathVariable String stackId, @PathVariable JobType jobT

// create a new job
var job = new Job(jobType, stackId, user);
job.setCliVersion(module.getCliVersion());
job.setTerraformImage(module.getTerraformImage());
jobRepository.save(job);
model.addAttribute("jobId", job.getId());

Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@ gaia.mongodb.uri=mongodb://localhost/gaia
gaia.externalUrl=http://localhost:${server.port:8080}
gaia.dockerDaemonUrl=unix:///var/run/docker.sock

terraform.releases.url=https://releases.hashicorp.com/terraform/
terraform.releases.version.min=0.11.13
docker.registry.api.url=https://registry.hub.docker.com/v2
2 changes: 1 addition & 1 deletion src/main/resources/templates/job.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<div class="block">
<div class="block_head_flex">
<h2>Stack {{stack.name}}</h2>
<cli-badge :cli-version="job.cliVersion" :badge-style="'for-the-badge'"></cli-badge>
<cli-badge :cli="job.terraformImage" badge-style="for-the-badge"></cli-badge>
</div>
<div class="block_content">

Expand Down
Loading

0 comments on commit 070d66e

Please sign in to comment.