How to push docker image to Amazon ECR using io.fabric8 maven plugin with authorization

我是研究僧i 提交于 2020-01-24 18:02:11

问题


I have a plugin to create a image, once created it need to be pushed to amazon ECR Please look into my plugin in the below`

<?xml version="1.0" encoding="UTF-8"?>
<plugin>
   <groupId>io.fabric8</groupId>
   <artifactId>docker-maven-plugin</artifactId>
   <version>0.24.0</version>
   <configuration>
      <dockerHost>https://accountID.dkr.ecr.us-east-1.amazonaws.com</dockerHost>
      <authConfig>
         <authToken>authorization Token</authToken>
         <username>Access Key ID</username>
         <password>Secret Key Id</password>
      </authConfig>
      <images>
         <image>
            <alias>service</alias>
            <name>${project.artifactId}</name>
            <build>
               <from>openjdk:8-jdk-alpine</from>
               <entryPoint>
                  <exec>
                     <arg>java</arg>
                     <arg>-jar</arg>
                     <arg>maven/app.jar</arg>
                  </exec>
               </entryPoint>
               <assembly>
                  <descriptorRef>artifact-with-dependencies</descriptorRef>
               </assembly>
            </build>
         </image>
      </images>
   </configuration>
   <executions>
      <execution>
         <id>docker-build</id>
         <goals>
            <goal>build</goal>
         </goals>
      </execution>
   </executions>
</plugin>

`

I have tried with above plugin with authorization token as authtoken . when i am running maven build getting not authorized .

Help will be appreciated

Thanks, Damodar


回答1:


You can use the AWS ECR credential helper

Please read the documentation for further details, but here are the major steps to get it working:

  1. AWS credentials are set up (e.g. ~/.aws/credentials)
  2. install the ECR credential helper
  3. Adapt your ~/.docker/config.json (for us it has been the second mentioned option with specific aws account id)
{
  "credHelpers": {
    "accountID.dkr.ecr.us-east-1.amazonaws.com": "ecr-login"
  },
  ... (already existing stuff in my setup)
}
  1. Use correct environment variables in the shell where the fabric8 maven-docker-plugin is executed:
AWS_SDK_LOAD_CONFIG=true
AWS_PROFILE=your_aws_profile

Maybe you will need to define AWS_REGION as environment variable as well.

Now when running the maven build, the ECR credential helper should take care of the authentication process, so the "authConfig"-part of the config in the question can be removed.



来源:https://stackoverflow.com/questions/49378313/how-to-push-docker-image-to-amazon-ecr-using-io-fabric8-maven-plugin-with-author

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!