-
Notifications
You must be signed in to change notification settings - Fork 644
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit for a 'docker:source' goal.
Implements #311
- Loading branch information
Showing
12 changed files
with
205 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
### docker:source | ||
|
||
The `docker:source` target can be used to attach a docker build | ||
archive containing the Dockerfile and all added files to the Maven | ||
project with a certain classifier. It reuses the configuration from | ||
[docker:build](docker-build.md). | ||
|
||
`docker:source` uses the image's [alias](image-configuration.md) as | ||
part of the classifier, so it is mandatory that the alias is set for | ||
this goal to work. The classifier is calculated as `docker-<alias>` so | ||
when the alias is set to `service`, then the classifier is | ||
`docker-service`. | ||
|
||
`docker:source` can be attached to a Maven execution phase, which is | ||
`generate-sources` by default. | ||
|
||
For example, this configuration will attach the docker build archive | ||
to the artifacts to store in the repository: | ||
|
||
````xml | ||
<plugin> | ||
<artifactId>docker-maven-plugin</artifactId> | ||
<!-- ..... --> | ||
<executions> | ||
<execution> | ||
<id>sources</id> | ||
<goals> | ||
<goal>source</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
```` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package org.jolokia.docker.maven;/* | ||
* | ||
* Copyright 2015 Roland Huss | ||
* | ||
* 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. | ||
*/ | ||
|
||
import java.io.File; | ||
|
||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.project.MavenProjectHelper; | ||
import org.jolokia.docker.maven.access.DockerAccess; | ||
import org.jolokia.docker.maven.access.DockerAccessException; | ||
import org.jolokia.docker.maven.config.BuildImageConfiguration; | ||
import org.jolokia.docker.maven.config.ImageConfiguration; | ||
import org.jolokia.docker.maven.util.MojoParameters; | ||
|
||
/** | ||
* Mojo for attaching one more source docker tar file to an artifact. | ||
* | ||
* @goal source | ||
* @phase package | ||
* @execute phase="generate-sources" | ||
* @executionStrategy once-per-session | ||
* | ||
* @author roland | ||
* @since 25/10/15 | ||
*/ | ||
public class SourceMojo extends AbstractBuildSupportMojo { | ||
|
||
/** @component */ | ||
private MavenProjectHelper projectHelper; | ||
|
||
@Override | ||
protected void executeInternal(DockerAccess dockerAccess) throws DockerAccessException, MojoExecutionException { | ||
MojoParameters params = createMojoParameters(); | ||
for (ImageConfiguration imageConfig : getImages()) { | ||
BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration(); | ||
if (buildConfig != null) { | ||
if (buildConfig.skip()) { | ||
log.info(imageConfig.getDescription() + ": Skipped creating source"); | ||
} else { | ||
File dockerTar = serviceHub.getBuildService().createDockerBuildTar(imageConfig, params); | ||
String alias = imageConfig.getAlias(); | ||
if (alias == null) { | ||
throw new IllegalArgumentException( | ||
"Image " + imageConfig.getDescription() + " must have an 'alias' configured to be " + | ||
"used as a classifier for attaching a docker build tar as source to the maven build"); | ||
} | ||
projectHelper.attachArtifact(project, buildConfig.getCompression().getFileSuffix(),"docker-" + alias, dockerTar); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/org/jolokia/docker/maven/config/BuildTarArchiveCompression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.jolokia.docker.maven.config;/* | ||
* | ||
* Copyright 2015 Roland Huss | ||
* | ||
* 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. | ||
*/ | ||
|
||
import org.codehaus.plexus.archiver.tar.TarArchiver; | ||
|
||
/** | ||
* Enumeration for determine the compression mode when creating docker | ||
* build archives. | ||
* | ||
* @author roland | ||
* @since 26/10/15 | ||
*/ | ||
public enum BuildTarArchiveCompression { | ||
|
||
none(TarArchiver.TarCompressionMethod.none, "tar"), | ||
gzip(TarArchiver.TarCompressionMethod.gzip,"tar.gz"), | ||
bzip2(TarArchiver.TarCompressionMethod.bzip2,"tar.bz"); | ||
|
||
private final TarArchiver.TarCompressionMethod tarCompressionMethod; | ||
private final String fileSuffix; | ||
|
||
BuildTarArchiveCompression(TarArchiver.TarCompressionMethod tarCompressionMethod, String fileSuffix) { | ||
this.tarCompressionMethod = tarCompressionMethod; | ||
this.fileSuffix = fileSuffix; | ||
} | ||
|
||
public TarArchiver.TarCompressionMethod getTarCompressionMethod() { | ||
return tarCompressionMethod; | ||
} | ||
|
||
public String getFileSuffix() { | ||
return fileSuffix; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters