Skip to content

Commit

Permalink
Fix #67 Any type of project can now use a Dockerfile.template
Browse files Browse the repository at this point in the history
  • Loading branch information
Krijger committed Sep 15, 2016
1 parent ba67451 commit d5139c7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
Expand Up @@ -16,7 +16,7 @@ class PrepareDockerFileTask extends AbstractTask {

dependsOn project.task("parseDockerFileTemplate", type: Copy) {
// disable task caching
onlyIf { dependsOnBaseImage() }
onlyIf { usingDockerfileTemplate() }
outputs.upToDateWhen { false }
description = 'Parsing the Dockerfile.template'

Expand All @@ -28,15 +28,14 @@ class PrepareDockerFileTask extends AbstractTask {
}

doLast {
project.stackwork.dockerFile = dependsOnBaseImage() ?
project.stackwork.dockerFile = usingDockerfileTemplate() ?
project.file("${project.stackwork.buildDir}/Dockerfile").absolutePath :
project.file('Dockerfile').absolutePath
}
}

boolean dependsOnBaseImage() {
def baseImageProject = getBaseImageProject()
baseImageProject != null && baseImageProject != project
boolean usingDockerfileTemplate() {
project.file('Dockerfile.template').exists()
}

Project getBaseImageProject() {
Expand Down
@@ -0,0 +1,2 @@
FROM scratch
LABEL image.version="${project.version}"
30 changes: 30 additions & 0 deletions src/test/gradle-projects/build-templated-dockerfile/build.gradle
@@ -0,0 +1,30 @@
import static org.stackwork.gradle.docker.ModuleType.*

buildscript {
repositories {
maven { url = "file://${project.projectDir}/../../../../build/repoForTests" }
mavenCentral()
}
dependencies {
classpath group: 'org.stackwork.gradle', name: 'stackwork', version: '0.1-TEST'
}
}
apply from: '../../gradle-plugins/stackwork-extended-for-tests.gradle'

version='1'

stackwork {
moduleType = IMAGE
}

task('inspectImage',
description: 'Inspect the image. If this works, we know it has been built.',
group: 'Stackwork',
type: Exec) {
commandLine 'docker', 'inspect', '--format=\'{{.Id}}\'', "${-> project.stackwork.imageId}"
}

tasks.inspectImage.dependsOn tasks.buildImage
afterEvaluate {
tasks.stackworkCheck.dependsOn tasks.inspectImage
}
@@ -1,5 +1,6 @@
package org.stackwork.gradle.docker

import spock.lang.IgnoreRest
import spock.lang.Specification

class DockerPluginSpecification extends Specification {
Expand All @@ -24,6 +25,14 @@ class DockerPluginSpecification extends Specification {
output.standardOut.contains 'Step 2 : COPY Dockerfile /'
}

def "The Dockerfile may be templated using project properties"() {
when:
GradleOutput output = runGradleTask('build-templated-dockerfile')

then: 'the build is successful'
output.process.exitValue() == 0
}

def "A test module that applies the JavaPlugin is allowed to connect to an image in unit tests trough appropriately set system properties"() {
when:
GradleOutput output = runGradleTask('unit-test')
Expand Down

0 comments on commit d5139c7

Please sign in to comment.