Skip to content

Instantly share code, notes, and snippets.

@ankon
Last active April 17, 2018 09:58
Show Gist options
  • Save ankon/247a6181e600086bc5f9665a8ff567c3 to your computer and use it in GitHub Desktop.
Save ankon/247a6181e600086bc5f9665a8ff567c3 to your computer and use it in GitHub Desktop.
docker-maven-plugin and ECR
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>build</artifactId>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>ecr-login</id>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<macrodef name="ecr-login" xmlns:if="ant:if" xmlns:unless="ant:unless">
<attribute name="registryid" default="NOT SET"/>
<attribute name="region" default="NOT SET"/>
<sequential>
<echo>Logging into ECR registry @{registryid} in region @{region}</echo>
<local name="ecr.out"/>
<local name="ecr.err"/>
<exec outputproperty="ecr.out" errorproperty="ecr.err" executable="aws">
<arg value="--region"/>
<arg value="@{region}"/>
<arg value="ecr"/>
<arg value="get-login"/>
<arg value="--registry-ids"/>
<arg value="@{registryid}"/>
</exec>
<fail message="${ecr.err}">
<condition>
<matches string="${ecr.err}" pattern=".+"/>
</condition>
</fail>
<exec failonerror="true" command="${ecr.out}"/>
</sequential>
</macrodef>
<!-- For our own stuff -->
<ecr-login registryid="238947823742" region="eu-west-1" unless:true="${skipDocker}"/>
<!-- For amazonlinux -->
<ecr-login registryid="137112412989" region="eu-west-1" unless:true="${skipDocker}"/>
<echo if:true="${skipDocker}">Skipping ECR login</echo>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment