Skip to content

Commit

Permalink
Add Amazon ECR plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
dai0304 committed Feb 16, 2017
1 parent 809b4fc commit 31d3383
Show file tree
Hide file tree
Showing 8 changed files with 264 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ dependencies {
compile "com.amazonaws:aws-java-sdk-iam:$awsJavaSdkVersion"
compile "com.amazonaws:aws-java-sdk-sqs:$awsJavaSdkVersion"
compile "com.amazonaws:aws-java-sdk-sns:$awsJavaSdkVersion"
compile "com.amazonaws:aws-java-sdk-ecr:$awsJavaSdkVersion"

// tests
testCompile "junit:junit:$junitVersion"
Expand Down
4 changes: 4 additions & 0 deletions deploy/jp.classmethod.aws.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ pluginBundle {
id = 'jp.classmethod.aws.cloudformation'
displayName = 'Gradle AWS CloudFormation plugin'
}
awsECRPlugin {
id = 'jp.classmethod.aws.ecr'
displayName = 'Gradle Amazon ECR plugin'
}
awsEC2Plugin {
id = 'jp.classmethod.aws.ec2'
displayName = 'Gradle Amazon EC2 plugin'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2015-2016 the original author or authors.
*
* 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.
*/
package jp.classmethod.aws.gradle.ecr;

import lombok.Getter;
import lombok.Setter;

import org.gradle.api.internal.ConventionTask;
import org.gradle.api.tasks.TaskAction;

import com.amazonaws.services.ecr.AmazonECR;
import com.amazonaws.services.ecr.model.CreateRepositoryRequest;
import com.amazonaws.services.ecr.model.CreateRepositoryResult;
import com.amazonaws.services.ecr.model.Repository;
import com.google.common.base.MoreObjects;

public class AmazonECRCreateRepositoryTask extends ConventionTask {

@Getter
@Setter
private String repositoryName;

@Getter
private Repository repository;


public AmazonECRCreateRepositoryTask() {
setDescription("Create ECR repository");
setGroup("AWS");
}

@TaskAction
public void createRepository() {
AmazonECRPluginExtension ext = getProject().getExtensions().getByType(AmazonECRPluginExtension.class);
AmazonECR ecr = ext.getClient();

String repositoryName = MoreObjects.firstNonNull(getRepositoryName(), ext.getRepositoryName());

CreateRepositoryResult result = ecr.createRepository(new CreateRepositoryRequest()
.withRepositoryName(repositoryName));
repository = result.getRepository();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2015-2016 the original author or authors.
*
* 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.
*/
package jp.classmethod.aws.gradle.ecr;

import lombok.Getter;
import lombok.Setter;

import org.gradle.api.internal.ConventionTask;
import org.gradle.api.tasks.TaskAction;

import com.amazonaws.services.ecr.AmazonECR;
import com.amazonaws.services.ecr.model.DeleteRepositoryRequest;
import com.amazonaws.services.ecr.model.DeleteRepositoryResult;
import com.amazonaws.services.ecr.model.Repository;
import com.google.common.base.MoreObjects;

public class AmazonECRDeleteRepositoryTask extends ConventionTask {

@Getter
@Setter
private String repositoryName;

@Getter
private Repository repository;


public AmazonECRDeleteRepositoryTask() {
setDescription("Delete ECR repository");
setGroup("AWS");
}

@TaskAction
public void createRepository() {
AmazonECRPluginExtension ext = getProject().getExtensions().getByType(AmazonECRPluginExtension.class);
AmazonECR ecr = ext.getClient();

String repositoryName = MoreObjects.firstNonNull(getRepositoryName(), ext.getRepositoryName());

DeleteRepositoryResult result = ecr.deleteRepository(new DeleteRepositoryRequest()
.withRepositoryName(repositoryName));
repository = result.getRepository();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2015-2016 the original author or authors.
*
* 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.
*/
package jp.classmethod.aws.gradle.ecr;

import java.util.List;

import lombok.Getter;
import lombok.Setter;

import org.gradle.api.GradleException;
import org.gradle.api.internal.ConventionTask;
import org.gradle.api.tasks.TaskAction;

import com.amazonaws.services.ecr.AmazonECR;
import com.amazonaws.services.ecr.model.AuthorizationData;
import com.amazonaws.services.ecr.model.GetAuthorizationTokenRequest;
import com.amazonaws.services.ecr.model.GetAuthorizationTokenResult;

public class AmazonECRGetAuthorizationTokenTask extends ConventionTask {

@Getter
@Setter
private List<String> repositoryIds;

@Getter
private List<AuthorizationData> authorizationData;


public AmazonECRGetAuthorizationTokenTask() {
setDescription("Get authorization token for ECR repository");
setGroup("AWS");
}

@TaskAction
public void createRepository() {
List<String> repositoryIds = getRepositoryIds();

if (repositoryIds == null || repositoryIds.isEmpty()) {
throw new GradleException("Must specify ECR repositoryIds");
}

AmazonECRPluginExtension ext = getProject().getExtensions().getByType(AmazonECRPluginExtension.class);
AmazonECR ecr = ext.getClient();

GetAuthorizationTokenResult result = ecr.getAuthorizationToken(new GetAuthorizationTokenRequest()
.withRegistryIds(repositoryIds));
authorizationData = result.getAuthorizationData();
}
}
29 changes: 29 additions & 0 deletions src/main/java/jp/classmethod/aws/gradle/ecr/AmazonECRPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2015-2016 the original author or authors.
*
* 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.
*/
package jp.classmethod.aws.gradle.ecr;

import org.gradle.api.Plugin;
import org.gradle.api.Project;

import jp.classmethod.aws.gradle.AwsPlugin;

public class AmazonECRPlugin implements Plugin<Project> {

public void apply(Project project) {
project.getPluginManager().apply(AwsPlugin.class);
project.getExtensions().create(AmazonECRPluginExtension.NAME, AmazonECRPluginExtension.class, project);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2015-2016 the original author or authors.
*
* 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.
*/
package jp.classmethod.aws.gradle.ecr;

import lombok.Getter;
import lombok.Setter;

import org.gradle.api.Project;

import com.amazonaws.services.ecr.AmazonECRClient;

import jp.classmethod.aws.gradle.common.BaseRegionAwarePluginExtension;

public class AmazonECRPluginExtension extends BaseRegionAwarePluginExtension<AmazonECRClient> {

public static final String NAME = "ecr";

@Getter
@Setter
private String repositoryName;


public AmazonECRPluginExtension(Project project) {
super(project, AmazonECRClient.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Copyright 2013-2016 Classmethod, Inc.
#
# 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.
#

implementation-class=jp.classmethod.aws.gradle.ecr.AmazonECRPlugin

0 comments on commit 31d3383

Please sign in to comment.