使用Spotify Maven Docker插件,如何更改我添加到Docker容器的资源的文件权限?

时间:2016-05-10 22:57:12

标签: maven plugins docker

使用Spotify Maven Docker plugin,如何更改添加到Docker容器的资源的文件权限?例如,在下面的Maven Docker插件定义中,如何指示Maven使脚本wait-for-file.sh可执行?

    <plugin>
        <groupId>com.spotify</groupId>
        <artifactId>docker-maven-plugin</artifactId>
        <version>0.4.9</version>
        <configuration>
            <imageName>opes/${project.artifactId}</imageName>
            <imageTags>
                <imageTag>${project.version}</imageTag>
                <imageTag>latest</imageTag>
            </imageTags>                    
            <baseImage>opes/tomcat</baseImage>
            <maintainer>Derek Mahar &lt;dmahar@opessoftware.com&gt;</maintainer>
            <resources>
                <resource>
                    <targetPath>/usr/local/tomcat/webapps</targetPath>
                    <directory>${project.build.directory}</directory>
                    <include>${project.build.finalName}.war</include>
                </resource>
                <resource>
                    <targetPath>/</targetPath>
                    <directory>src/main/docker</directory>
                    <include>wait-for-file.sh</include>
                </resource>
            </resources>
        </configuration>
    </plugin>

2 个答案:

答案 0 :(得分:1)

据我所知,Spotify Maven Docker插件不提供显式更改其复制到Docker容器的文件权限的命令。

但是,Fabric8 Maven Docker plugin确实提供了这样的命令,而且它具有比Spotify插件更多的功能。

这是我的解决方案:

来自pom.xml

    <plugin>
        <groupId>io.fabric8</groupId>
        <artifactId>docker-maven-plugin</artifactId>
        <version>0.15.1</version>
        <configuration>
            <images>
                <image>
                    <name>opes/${project.artifactId}</name>
                    <build>
                        <tags>
                            <tag>latest</tag>
                            <tag>${project.version}</tag>
                        </tags>
                        <from>opes/tomcat</from>
                        <maintainer>Derek Mahar &lt;dmahar@opessoftware.com&gt;</maintainer>
                        <assembly>
                            <mode>tgz</mode>
                            <basedir>/</basedir>
                            <descriptor>assembly.xml</descriptor>
                        </assembly>
                    </build>                        
                </image>
            </images>
        </configuration>
    </plugin>

src/main/docker/assembly.xml的内容:

<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
    <id>platinum-oms</id>
    <files>
        <file>
            <source>${project.build.directory}/${project.build.finalName}.war</source>
            <outputDirectory>usr/local/tomcat/webapps</outputDirectory>
        </file>
        <file>
            <source>src/main/docker/wait-for-file.sh</source>
            <outputDirectory>/</outputDirectory>
            <fileMode>544</fileMode>
        </file>
    </files>
</assembly>

如果你很好奇,Fabric8会比较Docker Maven Plugin Shootout中的几个Maven Docker插件。

答案 1 :(得分:0)

我认为maven应该使用用户的权限复制资源。

尝试maven-antrun-plugin。 例如:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
    <execution>
        <id>permission</id>
        <phase> <!-- a lifecycle phase --></phase>
        <goals>
           <goal>run</goal>
        </goals>
        <configuration>
            <target>
                <chmod file="/wait-for-file.sh" perm="755"/>
            </target>
        </configuration>
      </execution>
</executions>
</plugin>

希望这会有所帮助