|
| 1 | +INSERT INTO "plugin_parent_metadata" ("id", "name","identifier", "description","type","icon","deleted", "created_on", "created_by", "updated_on", "updated_by") |
| 2 | +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); |
| 3 | + |
| 4 | + |
| 5 | +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") |
| 6 | +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); |
| 7 | + |
| 8 | +INSERT INTO "plugin_stage_mapping" ("plugin_id","stage_type","created_on", "created_by", "updated_on", "updated_by") |
| 9 | +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); |
| 10 | + |
| 11 | +INSERT INTO "plugin_pipeline_script" ("id", "script","type","deleted","created_on", "created_by", "updated_on", "updated_by")VALUES ( |
| 12 | + nextval('id_seq_plugin_pipeline_script'), |
| 13 | + E' |
| 14 | + #!/bin/sh |
| 15 | + set -eo pipefail |
| 16 | + #set -v ## uncomment this to debug the script |
| 17 | + if [[ "$AwsEcrFixedTag" && "$AwsEcrTagPrefix" ]];then |
| 18 | + echo "Please provide only one input" |
| 19 | + exit 1; |
| 20 | + elif [[ $AwsEcrFixedTag ]]; then |
| 21 | + Tag=$AwsEcrFixedTag |
| 22 | + elif [[ $AwsEcrTagPrefix ]]; then |
| 23 | + Tag=$AwsEcrTagPrefix-$DOCKER_IMAGE_TAG |
| 24 | + else |
| 25 | + echo "No Tags Provided for retagging" |
| 26 | + fi |
| 27 | + echo $Tag |
| 28 | + AwsAccessKey="${AwsAccessEcrKey:-$(echo "$CI_CD_EVENT" | jq -r \'.commonWorkflowRequest.accessKey\')}" |
| 29 | + AwsSecretKey="${AwsSecretEcrKey:-$(echo "$CI_CD_EVENT" | jq -r \'.commonWorkflowRequest.secretKey\')}" |
| 30 | + mkdir -p ~/.aws |
| 31 | + echo -e "\n[tag-profile]\naws_access_key_id = $AwsAccessKey\naws_secret_access_key =$AwsSecretKey" >> ~/.aws/credentials |
| 32 | + if [[ $AwsAccessKey ]]; then |
| 33 | + export AWS_PROFILE=tag-profile |
| 34 | + fi |
| 35 | + pipeline_type=$(echo $CI_CD_EVENT | jq -r \'.type\') |
| 36 | + Region=$(echo $CI_CD_EVENT | jq -r .commonWorkflowRequest.dockerRegistryURL | sed \'s|https://||\'| awk -F. \'{print $4}\') |
| 37 | +
|
| 38 | + echo "************* Starting the AWS ECR Retag plugin *******************" |
| 39 | + if [[ "$pipeline_type" == "CI" ]]; then |
| 40 | + image_repo=$(echo $CI_CD_EVENT | jq -r .commonWorkflowRequest.dockerRepository) |
| 41 | + image_tag=$(echo $CI_CD_EVENT | jq -r .commonWorkflowRequest.dockerImageTag) |
| 42 | + MANIFEST=$(aws ecr batch-get-image --repository-name $image_repo --image-ids imageTag=$image_tag --region $Region --output text --query \'images[].imageManifest\') |
| 43 | + aws ecr put-image --repository-name $image_repo --image-tag=$Tag --image-manifest "$MANIFEST" --region $Region |
| 44 | + elif [[ "$pipeline_type" == "CD" ]]; then |
| 45 | + image_repo=$(echo $CI_CD_EVENT | jq -r .commonWorkflowRequest.ciArtifactDTO.image | cut -d\'/\' -f2 | cut -d\':\' -f1) |
| 46 | + image_tag=$(echo $CI_CD_EVENT | jq -r .commonWorkflowRequest.ciArtifactDTO.image | cut -d \':\' -f2) |
| 47 | + MANIFEST=$(aws ecr batch-get-image --repository-name $image_repo --image-ids imageTag=$image_tag --region $Region --output text --query \'images[].imageManifest\') |
| 48 | + aws ecr put-image --repository-name $image_repo --image-tag=$Tag --image-manifest "$MANIFEST" --region $Region |
| 49 | + fi |
| 50 | + if [ $? -ne 0 ]; then |
| 51 | + echo "*************Failed to Retag the image****************" |
| 52 | + else |
| 53 | + echo "*************Image Retag is done sucessfully*********************" |
| 54 | + fi |
| 55 | + ' ,'SHELL','f','now()',1,'now()',1); |
| 56 | + |
| 57 | + |
| 58 | +INSERT INTO "plugin_step" ("id", "plugin_id","name","description","index","step_type","script_id","deleted", "created_on", "created_by", "updated_on", "updated_by") |
| 59 | +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); |
| 60 | + |
| 61 | +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) |
| 62 | +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), |
| 63 | +(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), |
| 64 | +(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), |
| 65 | +(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); |
0 commit comments