se.transmode.gradle.plugins.docker.image.Dockerfile.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-docker Show documentation
Show all versions of gradle-docker Show documentation
Gradle plugin to build und publish Docker images from the build script.
The newest version!
/*
* Copyright 2014 Transmode AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package se.transmode.gradle.plugins.docker.image
class Dockerfile {
List instructions
Dockerfile(List instructions=[]) {
this.instructions = instructions
}
Dockerfile append(def instruction) {
this.instructions.add(instruction.toString())
return this
}
Dockerfile appendAll(List instructions) {
this.instructions.addAll(instructions*.toString())
return this
}
void writeToFile(File destination) {
destination.withWriter { out ->
instructions.each() { line ->
out.writeLine(line)
}
}
}
static Dockerfile fromExternalFile(File source) {
def dockerfile = new Dockerfile()
source.eachLine {
dockerfile.append(it)
}
return dockerfile
}
static Dockerfile fromBaseImage(String base) {
return new Dockerfile(["FROM ${base}"])
}
}