Skip to content

Commit

Permalink
πŸ”€ : merge pull request #476 from gaia-app/extract-runner
Browse files Browse the repository at this point in the history
β™» : extract runner code from gaia
  • Loading branch information
cdubuisson authored Nov 15, 2020
2 parents 103efbf + 8ffbeaa commit d2f40fb
Show file tree
Hide file tree
Showing 54 changed files with 1,211 additions and 1,296 deletions.
7 changes: 0 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ jobs:
- echo "checking is percy is enabled on PR $TRAVIS_PULL_REQUEST"
- NO_PERCY=$(curl -s https://api.github.com/repos/gaia-app/gaia/pulls/$TRAVIS_PULL_REQUEST | jq '.labels[].name | select(.=="no-percy")' | tr -d \")
- if [[ $NO_PERCY != "no-percy" ]]; then npm install @percy/agent; npx percy exec -- mvn test -Dgroups=e2e; fi
- stage: deploy
name: "Deploy to hub.docker.com"
script:
- export DOCKER_TAG=`echo $TRAVIS_TAG | cut -d 'v' -f 2`
- echo "$DOCKER_PASSWORD" | docker login -u codekaio --password-stdin
- docker build -t codekaio/gaia:$DOCKER_TAG .
- docker push codekaio/gaia:$DOCKER_TAG

after_success:
- wget https://raw.githubusercontent.com/CodeKaio/travis-ci-discord-webhook/master/send.sh
Expand Down
2 changes: 0 additions & 2 deletions docker-compose-with-vault.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ services:
- "GAIA_EXTERNAL_URL=http://172.17.0.1:8080"
- "SPRING_PROFILES_ACTIVE=vault"
- "GAIA_VAULT_URI=http://vault:8200"
volumes:
- /var/run/docker.sock:/var/run/docker.sock

mongo:
build:
Expand Down
5 changes: 2 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ services:
environment:
- "GAIA_MONGODB_URI=mongodb://mongo/gaia"
- "GAIA_EXTERNAL_URL=http://172.17.0.1:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- "GAIA_RUNNER_API_PASSWORD=123456"

mongo:
build:
context: .
dockerfile: ./Dockerfile-db
image: gaia-db
image: gaia-db
12 changes: 0 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
<properties>
<antlr4.version>4.8-1</antlr4.version>
<cucumber-jvm.version>6.7.0</cucumber-jvm.version>
<docker-java.version>3.2.5</docker-java.version>
<java.version>11</java.version>
<jersey.version>2.27</jersey.version>
<junit-jupiter.version>5.5.2</junit-jupiter.version>
Expand Down Expand Up @@ -117,17 +116,6 @@
<artifactId>spring-boot-devtools</artifactId>
</dependency>

<dependency>
<groupId>com.github.docker-java</groupId>
<artifactId>docker-java-core</artifactId>
<version>${docker-java.version}</version>
</dependency>
<dependency>
<groupId>com.github.docker-java</groupId>
<artifactId>docker-java-transport-okhttp</artifactId>
<version>${docker-java.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
Expand Down
9 changes: 9 additions & 0 deletions src/main/client/app/pages/stacks/job/job-metadata.vue
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@
margin-bottom: 1rem;
}
.job-metadata-container[class*=PENDING] {
background: linear-gradient(to right, #91B0B1 0, #91B0B1 1rem, #fff 1rem, #fff 100%) no-repeat;
color: #91B0B1;
}
.job-metadata-container[class*=PENDING] .job-detail-title {
color: #91B0B1;
}
.job-metadata-container[class*=STARTED] {
background: linear-gradient(to right, #2196f3 0, #2196f3 1rem, #fff 1rem, #fff 100%) no-repeat;
}
Expand Down
9 changes: 7 additions & 2 deletions src/main/client/app/pages/stacks/job/job-step.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<div class="job-step-header-title">
<span>{{ headerTitle }}</span>
<font-awesome-icon
v-if="step.status === 'STARTED'"
v-if="step.status === 'STARTED' || step.status === 'PENDING'"
icon="circle-notch"
spin
class="icon"
Expand Down Expand Up @@ -78,7 +78,7 @@
<app-console
:id="'logs-' + id"
:css-style="'max-height: 300px'"
:logs="step.logs"
:logs="step.logs.join('')"
/>
</b-collapse>
</div>
Expand Down Expand Up @@ -175,6 +175,11 @@
cursor: default;
}
.job-step-container[class*=PENDING] .job-step-header {
background: linear-gradient(to right, #91B0B1 0, #91B0B1 1rem, #fff 1rem, #fff 100%) no-repeat;
color: #91B0B1;
}
.job-step-container[class*=STARTED] .job-step-header {
background: linear-gradient(to right, #2196f3 0, #2196f3 1rem, #fff 1rem, #fff 100%) no-repeat;
color: #2196f3;
Expand Down
30 changes: 4 additions & 26 deletions src/main/client/app/pages/stacks/job/job.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
applyJob,
deleteJob,
getJob,
planJob,
retryJob,
} from '@/shared/api/jobs-api';
import { getStack } from '@/shared/api/stacks-api';
Expand Down Expand Up @@ -83,6 +82,7 @@
},
isSecondStepDoable() {
return this.job.status
&& !this.job.status.includes('PENDING')
&& !this.job.status.includes('STARTED')
&& !this.job.status.includes('FAILED')
&& !this.job.status.includes('APPLY');
Expand All @@ -91,29 +91,20 @@
async created() {
[this.stack, this.job] = await Promise.all([getStack(this.stackId), this.refreshJobUntilCompletion()]);
this.loaded = true;
if (!this.job.status) {
await this.planJob();
}
this.refreshIntervalId = setInterval(this.refreshJobUntilCompletion, INTERVAL_TIMEOUT);
},
destroyed() {
clearInterval(this.refreshIntervalId);
},
methods: {
async planJob() {
await planJob(this.jobId);
await this.waitUntilJobStarted();
this.refreshIntervalId = setInterval(this.refreshJobUntilCompletion, INTERVAL_TIMEOUT);
},
async applyJob() {
await applyJob(this.jobId);
await this.waitUntilJobStarted();
this.refreshIntervalId = setInterval(this.refreshJobUntilCompletion, INTERVAL_TIMEOUT);
},
async retryJob() {
await retryJob(this.jobId);
await this.waitUntilJobStarted();
this.refreshIntervalId = setInterval(this.refreshJobUntilCompletion, INTERVAL_TIMEOUT);
},
Expand All @@ -132,24 +123,11 @@
},
async refreshJobUntilCompletion() {
this.job = await getJob(this.jobId);
if (this.job.status && !this.job.status.includes('STARTED')) {
if (this.job.status.includes('FINISHED') || this.job.status.includes('FAILED')) {
clearInterval(this.refreshIntervalId);
}
return this.job;
},
// wait until the job is in "started" state
async waitUntilJobStarted() {
const poll = async (resolve) => {
this.job = await getJob(this.jobId);
if (this.job.status && this.job.status.includes('STARTED')) {
resolve();
} else {
setTimeout(() => poll(resolve), 500);
}
};
return new Promise(poll);
},
},
};
</script>
4 changes: 3 additions & 1 deletion src/main/client/app/pages/stacks/stack-edition.vue
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
displayConfirmDialog,
displayNotification,
} from '@/shared/services/modal-service';
import { getJobs } from '@/shared/api/jobs-api';
import { getJobs, planJob } from '@/shared/api/jobs-api';
import { getCredentialsList } from '@/shared/api/credentials-api';
export default {
Expand Down Expand Up @@ -275,6 +275,7 @@
if (await displayConfirmDialog(this, { title: 'Run request', message })) {
await this.saveStack();
const { jobId } = await runStack(this.stack.id);
await planJob(jobId);
this.$router.push({ name: 'job', params: { jobId } });
}
},
Expand All @@ -283,6 +284,7 @@
const message = 'This will completely stop the stack, and destroy all created resources. Continue?';
if (await displayConfirmDialog(this, { title: 'Stop request', message })) {
const { jobId } = await destroyStack(this.stack.id);
await planJob(jobId);
this.$router.push({ name: 'job', params: { jobId } });
}
},
Expand Down
136 changes: 0 additions & 136 deletions src/main/java/io/gaia_app/runner/DockerRunner.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import io.gaia_app.stacks.bo.Job;
import io.gaia_app.stacks.bo.Stack;
import io.gaia_app.stacks.bo.mustache.TerraformScript;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand All @@ -20,15 +21,17 @@
* A builder class to create stack commands
*/
@Component
public class StackCommandBuilder {
public class RunnerCommandBuilder {

private static final Logger logger = LoggerFactory.getLogger(RunnerCommandBuilder.class);

private Settings settings;
private RunnerApiSecurityConfig.RunnerApiSecurityProperties runnerApiSecurityProperties;
private Mustache terraformMustache;
private List<RegistryOAuth2Provider> registryOAuth2Providers;

@Autowired
StackCommandBuilder(Settings settings, Mustache terraformMustache, List<RegistryOAuth2Provider> registryOAuth2Providers, RunnerApiSecurityConfig.RunnerApiSecurityProperties runnerApiSecurityProperties) {
RunnerCommandBuilder(Settings settings, Mustache terraformMustache, List<RegistryOAuth2Provider> registryOAuth2Providers, RunnerApiSecurityConfig.RunnerApiSecurityProperties runnerApiSecurityProperties) {
this.settings = settings;
this.terraformMustache = terraformMustache;
this.registryOAuth2Providers = registryOAuth2Providers;
Expand Down Expand Up @@ -60,7 +63,7 @@ private String buildScript(Job job, Stack stack, TerraformModule module, String
.setGitRepositoryUrl(evalGitRepositoryUrl(module))
.setTerraformImage(job.getTerraformImage().image());

if (StringUtils.isNotBlank(module.getDirectory())) {
if (module.getDirectory() != null && !module.getDirectory().isBlank()) {
script.setGitDirectory(module.getDirectory());
}

Expand All @@ -71,9 +74,9 @@ private String buildScript(Job job, Stack stack, TerraformModule module, String
terraformMustache.execute(writer, script).flush();
return writer.toString();
} catch (IOException e) {
e.printStackTrace();
logger.error("Unable to generate script : {}", e.getMessage());
}
return StringUtils.EMPTY;
return "";
}

/**
Expand Down
Loading

0 comments on commit d2f40fb

Please sign in to comment.