Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/com/wolox/ProjectConfiguration.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ class ProjectConfiguration {
DockerConfiguration dockerConfiguration;
def env;
def timeout;
def baseImage;
}
17 changes: 13 additions & 4 deletions vars/base.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@ import com.wolox.*;

def call(ProjectConfiguration projectConfig, def _, def nextClosure) {
return { variables ->
timeout(time: projectConfig.timeout, unit: 'SECONDS') {
withEnv(projectConfig.environment) {
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'XTerm']) {
nextClosure(variables)
podTemplate(label: 'base', containers: [
containerTemplate(
name: 'base',
image: projectConfig.baseImage)
],
volumes: [
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock')
]) {
timeout(time: projectConfig.timeout, unit: 'SECONDS') {
withEnv(projectConfig.environment) {
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'XTerm']) {
nextClosure(variables)
}
}
}
}
Expand Down
18 changes: 15 additions & 3 deletions vars/postgres.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,21 @@ import com.wolox.*;
def call(ProjectConfiguration projectConfig, def version, def nextClosure) {
return { variables ->
/* Build postgres image */
docker.image("postgres:${version}").withRun() { db ->
withEnv(['DB_USERNAME=postgres', 'DB_PASSWORD=', "DB_HOST=db", "DB_PORT=5432"]) {
variables.db = db;
podTemplate(label: 'somelabel', containers: [
containerTemplate(
name: 'postgres',
image: "postgres:${version}",
envVars: [
envVar(key: 'DB_USERNAME', value: 'postgres'),
envVar(key: 'DB_PASSWORD', value: ''),
envVar(key: 'DB_HOST', value: 'localhost'),
envVar(key: 'DB_PORT', value: '5432')
])
],
volumes: [
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock')
]) {
withEnv(['DB_USERNAME=postgres', 'DB_PASSWORD=', "DB_HOST=localhost", "DB_PORT=5432"]) {
nextClosure(variables)
}
}
Expand Down
17 changes: 13 additions & 4 deletions vars/redis.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@ import com.wolox.*;
def call(ProjectConfiguration projectConfig, def version, def nextClosure) {
return { variables ->
/* Build redis image */
docker.image("redis:${version}").withRun() { redis ->
withEnv(["REDIS_URL=redis://redis"]) {
variables.redis = redis;
nextClosure(variables)
podTemplate(label: 'redis', containers: [
containerTemplate(
name: 'postgres',
image: "redis:${version}")
],
volumes: [
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock')
]) {
container("redis").withRun() { redis ->
withEnv(["REDIS_URL=redis://redis"]) {
variables.redis = redis;
nextClosure(variables)
}
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions vars/woloxCi.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ def call(String yamlName) {

def imageName = projectConfig.dockerConfiguration.imageName().toLowerCase();

def file = readFile(projectConfig.dockerfile)
def from = file.split('\n')[0]

projectConfig.baseImage = from

// build the image specified in the configuration
def customImage = docker.build(imageName, "--file ${projectConfig.dockerfile} .");
// def customImage = doscker.build(imageName, "--file ${projectConfig.dockerfile} .");

// adds the last step of the build.
def closure = buildSteps(projectConfig, customImage);
def closure = buildSteps(projectConfig, null);

// each service is a closure that when called it executes its logic and then calls a closure, the next step.
projectConfig.services.each {
Expand All @@ -28,6 +33,5 @@ def call(String yamlName) {
try {
closure([:]);
} finally{
deleteDockerImages(projectConfig);
}
}