diff --git a/assets/plugin-icons/ic-plugin-aws-ecr-retag.png b/assets/plugin-icons/ic-plugin-aws-ecr-retag.png new file mode 100644 index 0000000000..00588c1ac4 Binary files /dev/null and b/assets/plugin-icons/ic-plugin-aws-ecr-retag.png differ diff --git a/scripts/sql/34003900_aws_retagging.down.sql b/scripts/sql/34003900_aws_retagging.down.sql new file mode 100644 index 0000000000..5f3e3e9ea3 --- /dev/null +++ b/scripts/sql/34003900_aws_retagging.down.sql @@ -0,0 +1,6 @@ +DELETE FROM plugin_step_variable WHERE plugin_step_id=(SELECT id FROM plugin_metadata WHERE name='AWS ECR Retag' and plugin_version='1.0.0'); +DELETE FROM plugin_step where plugin_id=(SELECT id FROM plugin_metadata WHERE name='AWS ECR Retag' and plugin_version='1.0.0'); +DELETE FROM plugin_pipeline_script where id=(SELECT id FROM plugin_metadata WHERE name='AWS ECR Retag'); +DELETE FROM plugin_stage_mapping where plugin_id=(SELECT id from plugin_metadata where name='AWS ECR Retag'); +DELETE FROM plugin_metadata where name='AWS ECR Retag'; +DELETE FROM plugin_parent_metadata where name='AWS ECR Retag'; \ No newline at end of file diff --git a/scripts/sql/34003900_aws_retagging.up.sql b/scripts/sql/34003900_aws_retagging.up.sql new file mode 100644 index 0000000000..f4adbbc5c7 --- /dev/null +++ b/scripts/sql/34003900_aws_retagging.up.sql @@ -0,0 +1,65 @@ +INSERT INTO "plugin_parent_metadata" ("id", "name","identifier", "description","type","icon","deleted", "created_on", "created_by", "updated_on", "updated_by") +VALUES (nextval('id_seq_plugin_parent_metadata'), 'AWS ECR Retag','aws-retag','AWS ECR Retag plugin that enables retagging of container images within ECR','PRESET','https://raw.githubusercontent.com/devtron-labs/devtron/main/assets/plugin-icons/ic-plugin-aws-ecr-retag.png','f', 'now()', 1, 'now()', 1); + + +INSERT INTO "plugin_metadata" ("id", "name", "description","deleted", "created_on", "created_by", "updated_on", "updated_by","plugin_parent_metadata_id","plugin_version","is_deprecated","is_latest") +VALUES (nextval('id_seq_plugin_metadata'), 'AWS ECR Retag','Retag your ECR image with AWS ECR Retag','f', 'now()', 1, 'now()', 1, (SELECT id FROM plugin_parent_metadata WHERE identifier='aws-retag'),'1.0.0', false, true); + +INSERT INTO "plugin_stage_mapping" ("plugin_id","stage_type","created_on", "created_by", "updated_on", "updated_by") +VALUES ((SELECT id FROM plugin_metadata WHERE plugin_version='1.0.0' and name='AWS ECR Retag' and deleted= false),0,'now()', 1, 'now()', 1); + +INSERT INTO "plugin_pipeline_script" ("id", "script","type","deleted","created_on", "created_by", "updated_on", "updated_by")VALUES ( + nextval('id_seq_plugin_pipeline_script'), + E' + #!/bin/sh + set -eo pipefail + #set -v ## uncomment this to debug the script + if [[ "$AwsEcrFixedTag" && "$AwsEcrTagPrefix" ]];then + echo "Please provide only one input" + exit 1; + elif [[ $AwsEcrFixedTag ]]; then + Tag=$AwsEcrFixedTag + elif [[ $AwsEcrTagPrefix ]]; then + Tag=$AwsEcrTagPrefix-$DOCKER_IMAGE_TAG + else + echo "No Tags Provided for retagging" + fi + echo $Tag + AwsAccessKey="${AwsAccessEcrKey:-$(echo "$CI_CD_EVENT" | jq -r \'.commonWorkflowRequest.accessKey\')}" + AwsSecretKey="${AwsSecretEcrKey:-$(echo "$CI_CD_EVENT" | jq -r \'.commonWorkflowRequest.secretKey\')}" + mkdir -p ~/.aws + echo -e "\n[tag-profile]\naws_access_key_id = $AwsAccessKey\naws_secret_access_key =$AwsSecretKey" >> ~/.aws/credentials + if [[ $AwsAccessKey ]]; then + export AWS_PROFILE=tag-profile + fi + pipeline_type=$(echo $CI_CD_EVENT | jq -r \'.type\') + Region=$(echo $CI_CD_EVENT | jq -r .commonWorkflowRequest.dockerRegistryURL | sed \'s|https://||\'| awk -F. \'{print $4}\') + + echo "************* Starting the AWS ECR Retag plugin *******************" + if [[ "$pipeline_type" == "CI" ]]; then + image_repo=$(echo $CI_CD_EVENT | jq -r .commonWorkflowRequest.dockerRepository) + image_tag=$(echo $CI_CD_EVENT | jq -r .commonWorkflowRequest.dockerImageTag) + MANIFEST=$(aws ecr batch-get-image --repository-name $image_repo --image-ids imageTag=$image_tag --region $Region --output text --query \'images[].imageManifest\') + aws ecr put-image --repository-name $image_repo --image-tag=$Tag --image-manifest "$MANIFEST" --region $Region + elif [[ "$pipeline_type" == "CD" ]]; then + image_repo=$(echo $CI_CD_EVENT | jq -r .commonWorkflowRequest.ciArtifactDTO.image | cut -d\'/\' -f2 | cut -d\':\' -f1) + image_tag=$(echo $CI_CD_EVENT | jq -r .commonWorkflowRequest.ciArtifactDTO.image | cut -d \':\' -f2) + MANIFEST=$(aws ecr batch-get-image --repository-name $image_repo --image-ids imageTag=$image_tag --region $Region --output text --query \'images[].imageManifest\') + aws ecr put-image --repository-name $image_repo --image-tag=$Tag --image-manifest "$MANIFEST" --region $Region + fi + if [ $? -ne 0 ]; then + echo "*************Failed to Retag the image****************" + else + echo "*************Image Retag is done sucessfully*********************" + fi + ' ,'SHELL','f','now()',1,'now()',1); + + +INSERT INTO "plugin_step" ("id", "plugin_id","name","description","index","step_type","script_id","deleted", "created_on", "created_by", "updated_on", "updated_by") +VALUES (nextval('id_seq_plugin_step'), (SELECT id FROM plugin_metadata WHERE name='AWS ECR Retag' AND plugin_version='1.0.0' AND deleted= false),'Step 1','Runnig the plugin','1','INLINE',(SELECT last_value FROM id_seq_plugin_pipeline_script),'f','now()', 1, 'now()', 1); + +INSERT INTO plugin_step_variable (id,plugin_step_id,name,format,description,is_exposed,allow_empty_value,default_value,value,variable_type,value_type,previous_step_index,variable_step_index,variable_step_index_in_plugin,reference_variable_name,deleted,created_on,created_by,updated_on,updated_by) +VALUES (nextval('id_seq_plugin_step_variable'),(SELECT ps.id FROM plugin_metadata p inner JOIN plugin_step ps on ps.plugin_id=p.id WHERE p.name='AWS ECR Retag' and p.plugin_version='1.0.0' and ps."index"=1 and ps.deleted=false),'AwsEcrFixedTag','STRING','Provide the fixed tag for retagging','t','t',null,null,'INPUT','NEW',null,1,null,null,'f','now()',1,'now()',1), +(nextval('id_seq_plugin_step_variable'),(SELECT ps.id FROM plugin_metadata p inner JOIN plugin_step ps on ps.plugin_id=p.id WHERE p.name='AWS ECR Retag' and p.plugin_version='1.0.0' and ps."index"=1 and ps.deleted=false),'AwsEcrTagPrefix','STRING','Provide the tag prefix','t','t',null,null,'INPUT','NEW',null,1,null,null,'f','now()',1,'now()',1), +(nextval('id_seq_plugin_step_variable'),(SELECT ps.id FROM plugin_metadata p inner JOIN plugin_step ps on ps.plugin_id=p.id WHERE p.name='AWS ECR Retag' and p.plugin_version='1.0.0' and ps."index"=1 and ps.deleted=false),'AwsAccessEcrKey','STRING','Provide the access key with ECR permission','t','t',null,null,'INPUT','NEW',null,1,null,null,'f','now()',1,'now()',1), +(nextval('id_seq_plugin_step_variable'),(SELECT ps.id FROM plugin_metadata p inner JOIN plugin_step ps on ps.plugin_id=p.id WHERE p.name='AWS ECR Retag' and p.plugin_version='1.0.0' and ps."index"=1 and ps.deleted=false),'AwsSecretEcrKey','STRING','Provide the secret key with ECR permission','t','t',null,null,'INPUT','NEW',null,1,null,null,'f','now()',1,'now()',1);