使用 Spotify docker-maven-plugin 将 docker 镜像推送到 AWS ECR

时间:2021-03-05 04:14:08

标签: java docker maven spotify amazon-ecr

我目前正在将工件存储库从 Nexus 迁移到 AWS ECR。这是我在 pom 中的插件详细信息,

              <plugin>
                    <groupId>com.spotify</groupId>
                    <artifactId>docker-maven-plugin</artifactId>
                    <version>0.4.13</version>
                    <executions>
                        <execution>
                            <id>clean-local</id>
                            <phase>clean</phase>
                            <goals>
                                <goal>removeImage</goal>
                            </goals>
                            <configuration>
                                <imageName>${project.build.finalName}:latest</imageName>
                                <skipDocker>${skip.docker}</skipDocker>
                            </configuration>
                        </execution>
                        <execution>
                            <id>clean-nexus</id>
                            <phase>clean</phase>
                            <goals>
                                <goal>removeImage</goal>
                            </goals>
                            <configuration>
                                <imageName>${docker.image.prefix}/${project.build.finalName}:${project.version}</imageName>
                                <skipDocker>${skip.docker}</skipDocker>
                            </configuration>
                        </execution>
                        <execution>
                            <id>build-image</id>
                            <phase>package</phase>
                            <goals>
                                <goal>build</goal>
                            </goals>
                            <configuration>
                                <skipDocker>${skip.docker}</skipDocker>
                            </configuration>
                        </execution>
                        <execution>
                            <id>tag-image</id>
                            <phase>package</phase>
                            <goals>
                                <goal>tag</goal>
                            </goals>
                            <configuration>
                                <image>${project.build.finalName}</image>
                                <newName>${docker.image.prefix}/${project.build.finalName}:${project.version}</newName>
                                <skipDocker>${skip.docker}</skipDocker>
                            </configuration>
                        </execution>
                        <execution>
                            <id>push-image</id>
                            <phase>deploy</phase>
                            <goals>
                                <goal>push</goal>
                            </goals>
                            <configuration>
                                <serverId>${docker.image.prefix}</serverId>
                                <imageName>${project.build.finalName}:${project.version}</imageName>
                                <skipDockerPush>${skip.docker}</skipDockerPush>
                                <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
                            </configuration>
                        </execution>
                    </executions>
                    <configuration>
                        <imageName>${project.build.finalName}</imageName>
                        <baseImage>java:8</baseImage>
                        <entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
                        <resources>
                            <resource>
                                <targetPath>/</targetPath>
                                <directory>${project.build.directory}</directory>
                                <include>${project.build.finalName}.jar</include>
                            </resource>
                        </resources>
                        <imageTags>
                            <imageTag>${project.version}</imageTag>
                            <imageTag>latest</imageTag>
                        </imageTags>
                    </configuration>
                </plugin>

我还使用 aws cli 登录到 ECR 并添加了服务器详细信息作为分发管理,如下所示,

<distributionManagement>
        <repository>
            <id>aws.ecr</id>
            <name>Internal Releases</name>
            <url>https://${docker.image.prefix}/${project.build.finalName}</url>
        </repository>
    </distributionManagement>

由于这是失败的,我也尝试在设置 xml 中添加服务器详细信息,

<server>
    <id>{id}.dkr.ecr.{region}.amazonaws.com</id>
    <username>AWS</username>
    <password>{key}</password>
</server>

两次尝试都失败了,我得到的错误是,

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project my-project: Failed to retrieve remote metadata com.sac.my:my-project:1.11.0-SNAPSHOT/maven-metadata.xml: Could not transfer metadata com.my.project:my-project:1.11.0-SNAPSHOT/maven-metadata.xml from/to aws.ecr (https://ID.dkr.ecr.REGION.amazonaws.com/my-project-1.11.0-SNAPSHOT): Authentication failed for https://ID.dkr.ecr.REGION.amazonaws.com/my-project-1.11.0-SNAPSHOT/com/my/project/my-project/1.11.0-SNAPSHOT/maven-metadata.xml 401 Unauthorized

0 个答案:

没有答案