use of io.fabric8.maven.docker.util.Logger in project docker-maven-plugin by fabric8io.
the class DockerAssemblyManager method createDockerTarArchive.
/**
* Create an docker tar archive from the given configuration which can be send to the Docker host for
* creating the image.
*
* @param imageName Name of the image to create (used for creating build directories)
* @param params Mojos parameters (used for finding the directories)
* @param buildConfig configuration for how to build the image
* @param log Logger used to display warning if permissions are to be normalized
* @param finalCustomizer finalCustomizer to be applied to the tar archive
* @return file holding the path to the created assembly tar file
* @throws MojoExecutionException
*/
public File createDockerTarArchive(String imageName, MojoParameters params, final BuildImageConfiguration buildConfig, Logger log, ArchiverCustomizer finalCustomizer) throws MojoExecutionException {
final BuildDirs buildDirs = createBuildDirs(imageName, params);
final AssemblyConfiguration assemblyConfig = buildConfig.getAssemblyConfiguration();
final List<ArchiverCustomizer> archiveCustomizers = new ArrayList<>();
// Build up assembly. In dockerfile mode this must be added explicitly in the Dockerfile with an ADD
if (hasAssemblyConfiguration(assemblyConfig)) {
createAssemblyArchive(assemblyConfig, params, buildDirs);
}
try {
if (buildConfig.isDockerFileMode()) {
// Use specified docker directory which must include a Dockerfile.
final File dockerFile = buildConfig.getAbsoluteDockerFilePath(params);
if (!dockerFile.exists()) {
throw new MojoExecutionException("Configured Dockerfile \"" + buildConfig.getDockerFile() + "\" (resolved to \"" + dockerFile + "\") doesn't exist");
}
FixedStringSearchInterpolator interpolator = DockerFileUtil.createInterpolator(params, buildConfig.getFilter());
verifyGivenDockerfile(dockerFile, buildConfig, interpolator, log);
interpolateDockerfile(dockerFile, buildDirs, interpolator);
// User dedicated Dockerfile from extra directory
archiveCustomizers.add(new ArchiverCustomizer() {
@Override
public TarArchiver customize(TarArchiver archiver) throws IOException {
DefaultFileSet fileSet = DefaultFileSet.fileSet(dockerFile.getParentFile());
addDockerIgnoreIfPresent(fileSet);
// Exclude non-interpolated dockerfile from source tree
// Interpolated Dockerfile is already added as it was created into the output directory when
// using dir dir mode
excludeDockerfile(fileSet, dockerFile);
// directly to docker.tar (as the output builddir is not picked up in archive mode)
if (isArchive(assemblyConfig)) {
String name = dockerFile.getName();
archiver.addFile(new File(buildDirs.getOutputDirectory(), name), name);
}
archiver.addFileSet(fileSet);
return archiver;
}
});
} else {
// Create custom docker file in output dir
DockerFileBuilder builder = createDockerFileBuilder(buildConfig, assemblyConfig);
builder.write(buildDirs.getOutputDirectory());
// Add own Dockerfile
final File dockerFile = new File(buildDirs.getOutputDirectory(), DOCKERFILE_NAME);
archiveCustomizers.add(new ArchiverCustomizer() {
@Override
public TarArchiver customize(TarArchiver archiver) throws IOException {
archiver.addFile(dockerFile, DOCKERFILE_NAME);
return archiver;
}
});
}
// If required make all files in the assembly executable
if (assemblyConfig != null) {
AssemblyConfiguration.PermissionMode mode = assemblyConfig.getPermissions();
if (mode == AssemblyConfiguration.PermissionMode.exec || mode == AssemblyConfiguration.PermissionMode.auto && EnvUtil.isWindows()) {
archiveCustomizers.add(new AllFilesExecCustomizer(log));
}
}
if (finalCustomizer != null) {
archiveCustomizers.add(finalCustomizer);
}
return createBuildTarBall(buildDirs, archiveCustomizers, assemblyConfig, buildConfig.getCompression());
} catch (IOException e) {
throw new MojoExecutionException(String.format("Cannot create %s in %s", DOCKERFILE_NAME, buildDirs.getOutputDirectory()), e);
}
}
use of io.fabric8.maven.docker.util.Logger in project docker-maven-plugin by fabric8io.
the class DockerAssemblyManager method verifyGivenDockerfile.
// visible for testing
void verifyGivenDockerfile(File dockerFile, BuildImageConfiguration buildConfig, FixedStringSearchInterpolator interpolator, Logger log) throws IOException {
AssemblyConfiguration assemblyConfig = buildConfig.getAssemblyConfiguration();
if (assemblyConfig == null) {
return;
}
String name = assemblyConfig.getName();
for (String keyword : new String[] { "ADD", "COPY" }) {
List<String[]> lines = DockerFileUtil.extractLines(dockerFile, keyword, interpolator);
for (String[] line : lines) {
if (!line[0].startsWith("#")) {
// Skip command flags like --chown
int i;
for (i = 1; i < line.length; i++) {
String component = line[i];
if (!component.startsWith("--")) {
break;
}
}
// contains an ADD/COPY ... targetDir .... All good.
if (i < line.length && line[i].contains(name)) {
return;
}
}
}
}
log.warn("Dockerfile %s does not contain an ADD or COPY directive to include assembly created at %s. Ignoring assembly.", dockerFile.getPath(), name);
}
use of io.fabric8.maven.docker.util.Logger in project docker-maven-plugin by fabric8io.
the class DockerAccessFactory method getDefaultDockerHostProviders.
/**
* Return a list of providers which could delive connection parameters from
* calling external commands. For this plugin this is docker-machine, but can be overridden
* to add other config options, too.
*
* @return list of providers or <code>null</code> if none are applicable
*/
private List<DockerConnectionDetector.DockerHostProvider> getDefaultDockerHostProviders(DockerAccessContext dockerAccessContext, Logger log) {
DockerMachineConfiguration config = dockerAccessContext.getMachine();
if (dockerAccessContext.isSkipMachine()) {
config = null;
} else if (config == null) {
Properties projectProps = dockerAccessContext.getProjectProperties();
if (projectProps.containsKey(DockerMachineConfiguration.DOCKER_MACHINE_NAME_PROP)) {
config = new DockerMachineConfiguration(projectProps.getProperty(DockerMachineConfiguration.DOCKER_MACHINE_NAME_PROP), projectProps.getProperty(DockerMachineConfiguration.DOCKER_MACHINE_AUTO_CREATE_PROP));
}
}
List<DockerConnectionDetector.DockerHostProvider> ret = new ArrayList<>();
ret.add(new DockerMachine(log, config));
return ret;
}
use of io.fabric8.maven.docker.util.Logger in project docker-maven-plugin by fabric8io.
the class EcrExtendedAuthTest method testHeaders.
@Test
public void testHeaders() throws ParseException {
EcrExtendedAuth eea = new EcrExtendedAuth(logger, "123456789012.dkr.ecr.eu-west-1.amazonaws.com");
AuthConfig localCredentials = new AuthConfig("username", "password", null, null);
Date signingTime = AwsSigner4Request.TIME_FORMAT.parse("20161217T211058Z");
HttpPost request = eea.createSignedRequest(localCredentials, signingTime);
assertEquals("ecr.eu-west-1.amazonaws.com", request.getFirstHeader("host").getValue());
assertEquals("20161217T211058Z", request.getFirstHeader("X-Amz-Date").getValue());
assertEquals("AWS4-HMAC-SHA256 Credential=username/20161217/eu-west-1/ecr/aws4_request, SignedHeaders=content-type;host;x-amz-target, Signature=1bab0f5c269debe913e532011d5d192b190bb4c55d3de1bc1506eefb93e058e1", request.getFirstHeader("Authorization").getValue());
}
use of io.fabric8.maven.docker.util.Logger in project docker-maven-plugin by fabric8io.
the class DockerAssemblyManagerTest method testCopyChownValidVerifyGivenDockerfile.
@Test
public void testCopyChownValidVerifyGivenDockerfile(@Injectable final Logger logger) throws IOException {
BuildImageConfiguration buildConfig = createBuildConfig();
assemblyManager.verifyGivenDockerfile(new File(getClass().getResource("/docker/Dockerfile_assembly_verify_copy_chown_valid.test").getPath()), buildConfig, createInterpolator(buildConfig), logger);
new Verifications() {
{
logger.warn(anyString, (Object[]) any);
times = 0;
}
};
}
Aggregations