From f86dce6001a2f3f9dc19de0ee6876787329bc37c Mon Sep 17 00:00:00 2001 From: Prakash Kumar Date: Fri, 13 Sep 2024 12:53:44 +0530 Subject: [PATCH 1/2] migration number fix --- .../sql/286_copy_container_image_v2.down.sql | 53 ++++++++++++++ .../sql/286_copy_container_image_v2.up.sql | 69 +++++++++++++++++++ ...lugin_policy_for_parent_plugin_id.down.sql | 1 + ..._plugin_policy_for_parent_plugin_id.up.sql | 1 + 4 files changed, 124 insertions(+) create mode 100644 scripts/sql/286_copy_container_image_v2.down.sql create mode 100644 scripts/sql/286_copy_container_image_v2.up.sql create mode 100644 scripts/sql/287_alter_mandatory_plugin_policy_for_parent_plugin_id.down.sql create mode 100644 scripts/sql/287_alter_mandatory_plugin_policy_for_parent_plugin_id.up.sql diff --git a/scripts/sql/286_copy_container_image_v2.down.sql b/scripts/sql/286_copy_container_image_v2.down.sql new file mode 100644 index 0000000000..bec7d2d5ad --- /dev/null +++ b/scripts/sql/286_copy_container_image_v2.down.sql @@ -0,0 +1,53 @@ +-- update the is_latest flag to true, for the plugin version 1.0.0 +UPDATE plugin_metadata +SET is_latest = true +WHERE id = ( + SELECT id + FROM plugin_metadata + WHERE name='Copy container image' + AND plugin_version='1.0.0' + AND is_latest = false + AND deleted = false +); + +DO +$$ +DECLARE +temprow record; +BEGIN + -- select the plugin_metadata_id, plugin_step_id, plugin_pipeline_script_id +SELECT plugin_metadata.id AS plugin_metadata_id, + plugin_step.id AS plugin_step_id, + plugin_step.script_id AS plugin_pipeline_script_id +INTO temprow +FROM plugin_metadata + LEFT JOIN plugin_step ON plugin_metadata.id = plugin_step.plugin_id +WHERE plugin_metadata.plugin_version='2.0.0' + AND plugin_metadata.name='Copy container image'; + +-- down script for the new plugin version 2.0.0 +DELETE FROM plugin_step_variable +WHERE plugin_step_id = temprow.plugin_step_id; +DELETE FROM script_path_arg_port_mapping +WHERE script_id = temprow.plugin_pipeline_script_id; +DELETE FROM plugin_step +WHERE plugin_id = temprow.plugin_metadata_id; +DELETE FROM plugin_stage_mapping +WHERE plugin_id = temprow.plugin_metadata_id; +DELETE FROM pipeline_stage_step_variable +WHERE pipeline_stage_step_id IN ( + SELECT id + FROM pipeline_stage_step + WHERE ref_plugin_id = temprow.plugin_metadata_id +); +DELETE FROM pipeline_stage_step +WHERE ref_plugin_id = temprow.plugin_metadata_id; +DELETE from plugin_pipeline_script +WHERE id = temprow.plugin_pipeline_script_id; +DELETE FROM plugin_tag_relation +WHERE plugin_id = temprow.plugin_metadata_id; +DELETE FROM plugin_metadata +WHERE id = temprow.plugin_metadata_id; + +END; +$$; \ No newline at end of file diff --git a/scripts/sql/286_copy_container_image_v2.up.sql b/scripts/sql/286_copy_container_image_v2.up.sql new file mode 100644 index 0000000000..dac241ea01 --- /dev/null +++ b/scripts/sql/286_copy_container_image_v2.up.sql @@ -0,0 +1,69 @@ +INSERT INTO "plugin_parent_metadata" ("id", "name", "identifier", "description", "type", "icon", "deleted", "created_on", "created_by", "updated_on", "updated_by") +SELECT nextval('id_seq_plugin_parent_metadata'), 'Copy container image','copy-container-image', 'Copy container images from the source repository to a desired repository','PRESET','https://raw.githubusercontent.com/devtron-labs/devtron/main/assets/ic-plugin-copy-container-image.png','f', 'now()', 1, 'now()', 1 + WHERE NOT EXISTS ( + SELECT 1 + FROM plugin_parent_metadata + WHERE identifier='copy-container-image' + AND deleted = false +); + +-- update the plugin_metadata with the plugin_parent_metadata_id +UPDATE plugin_metadata +SET plugin_parent_metadata_id = ( + SELECT id + FROM plugin_parent_metadata + WHERE identifier='copy-container-image' + AND deleted = false +),plugin_version='1.0.0' +WHERE name='Copy container image' + AND ( + plugin_parent_metadata_id IS NULL + OR plugin_parent_metadata_id = 0 + ) + AND deleted = false; + + +UPDATE plugin_metadata SET is_latest = false WHERE id = (SELECT id FROM plugin_metadata WHERE name= 'Copy container image' and is_latest= true); + + +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'), 'Copy container image','Copy container images from the source repository to a desired repository','f', 'now()', 1, 'now()', 1, (SELECT id FROM plugin_parent_metadata WHERE identifier='copy-container-image'),'2.0.0', false, true); + + +INSERT INTO "plugin_tag_relation" ("id", "tag_id", "plugin_id", "created_on", "created_by", "updated_on", "updated_by") +VALUES (nextval('id_seq_plugin_tag_relation'),(SELECT id FROM plugin_tag WHERE name='Image source') , (SELECT id FROM plugin_metadata WHERE name='Copy container image' and plugin_version='1.0.0'),'now()', 1, 'now()', 1); + + +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='2.0.0' and name='Copy container image' and deleted= false),0,'now()', 1, 'now()', 1); + + +INSERT INTO "plugin_pipeline_script" ("id","type","mount_directory_from_host","container_image_path","deleted","created_on", "created_by", "updated_on", "updated_by") +VALUES (nextval('id_seq_plugin_pipeline_script'),'CONTAINER_IMAGE','t','quay.io/devtron/devtron-plugins:skopeo-2.0.1','f','now()',1,'now()',1); + +INSERT INTO "script_path_arg_port_mapping" ("id", "type_of_mapping", "file_path_on_disk","file_path_on_container","script_id","deleted","created_on","created_by", "updated_on", "updated_by") +VALUES (nextval('id_seq_script_path_arg_port_mapping'),'FILE_PATH','/tmp/pluginArtifacts' ,'/tmp/output',(SELECT last_value FROM id_seq_plugin_pipeline_script),'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 plugin_version='2.0.0' and name='Copy container image' and deleted= false),'Step 1','Step 1 - Copy container images','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","variable_type", "value_type", "variable_step_index", "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='Copy container image' and p.plugin_version='2.0.0' and ps."index"=1 and ps.deleted=false), 'DESTINATION_INFO','STRING', + 'In case of CI, build image will be copied to registry and repository provided in DESTINATION_INFO. In case of PRE-CD/POST-CD, Image used to trigger stage will be copied in DESTINATION_INFO + Format: + | ,', true,false,'INPUT','NEW',1 ,'f','now()', 1, 'now()', 1); + +INSERT INTO "plugin_step_variable" ("id", "plugin_step_id", "name", "format", "description", "is_exposed", "allow_empty_value","variable_type", "value_type", "variable_step_index",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='Copy container image' and p.plugin_version='2.0.0' and ps."index"=1 and ps.deleted=false), 'DOCKER_IMAGE','STRING','',false,true,'INPUT','GLOBAL',1 ,'DOCKER_IMAGE','f','now()', 1, 'now()', 1); + +INSERT INTO "plugin_step_variable" ("id", "plugin_step_id", "name", "format", "description", "is_exposed", "allow_empty_value","variable_type", "value_type", "variable_step_index",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='Copy container image' and p.plugin_version='2.0.0' and ps."index"=1 and ps.deleted=false), 'REGISTRY_DESTINATION_IMAGE_MAP','STRING','map of registry name and images needed to be copied in that images',false,true,'INPUT','GLOBAL',1 ,'REGISTRY_DESTINATION_IMAGE_MAP','f','now()', 1, 'now()', 1); + +INSERT INTO "plugin_step_variable" ("id", "plugin_step_id", "name", "format", "description", "is_exposed", "allow_empty_value","variable_type", "value_type", "variable_step_index",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='Copy container image' and p.plugin_version='2.0.0' and ps."index"=1 and ps.deleted=false), 'REGISTRY_CREDENTIALS','STRING','',false,true,'INPUT','GLOBAL',1 ,'REGISTRY_CREDENTIALS','f','now()', 1, 'now()', 1); + +INSERT INTO "plugin_step_variable" ("id", "plugin_step_id", "name", "format", "description", "is_exposed", "allow_empty_value","variable_type", "value_type", "variable_step_index",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='Copy container image' and p.plugin_version='2.0.0' and ps."index"=1 and ps.deleted=false), 'DOCKER_IMAGE_TAG','STRING','',false,true,'INPUT','GLOBAL',1 ,'DOCKER_TAG','f','now()', 1, 'now()', 1); + +INSERT INTO "plugin_step_variable" ("id", "plugin_step_id", "name", "format", "description", "is_exposed", "allow_empty_value","variable_type", "value_type", "variable_step_index",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='Copy container image' and p.plugin_version='2.0.0' and ps."index"=1 and ps.deleted=false), 'DOCKER_IMAGE_TAG_OVERRIDE','STRING','',true,true,'INPUT','FROM_PREVIOUS_STEP',1 ,'DOCKER_IMAGE_TAG_OVERRIDE','f','now()', 1, 'now()', 1); diff --git a/scripts/sql/287_alter_mandatory_plugin_policy_for_parent_plugin_id.down.sql b/scripts/sql/287_alter_mandatory_plugin_policy_for_parent_plugin_id.down.sql new file mode 100644 index 0000000000..5876fd62eb --- /dev/null +++ b/scripts/sql/287_alter_mandatory_plugin_policy_for_parent_plugin_id.down.sql @@ -0,0 +1 @@ +--empty script for maintaining script number common across repo. \ No newline at end of file diff --git a/scripts/sql/287_alter_mandatory_plugin_policy_for_parent_plugin_id.up.sql b/scripts/sql/287_alter_mandatory_plugin_policy_for_parent_plugin_id.up.sql new file mode 100644 index 0000000000..5876fd62eb --- /dev/null +++ b/scripts/sql/287_alter_mandatory_plugin_policy_for_parent_plugin_id.up.sql @@ -0,0 +1 @@ +--empty script for maintaining script number common across repo. \ No newline at end of file From 946e3566523c04deacb4803bbb4c307f6d66992c Mon Sep 17 00:00:00 2001 From: Prakash Kumar Date: Fri, 13 Sep 2024 13:57:51 +0530 Subject: [PATCH 2/2] go mod --- go.mod | 1 - go.sum | 7 ------- 2 files changed, 8 deletions(-) diff --git a/go.mod b/go.mod index d5f09c6b3d..7eb2b5d156 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,6 @@ require ( github.com/argoproj/argo-workflows/v3 v3.5.10 github.com/argoproj/gitops-engine v0.7.1-0.20240715141028-c68bce0f979c github.com/aws/aws-sdk-go v1.44.317 - github.com/aws/aws-sdk-go-v2/service/ecr v1.20.0 github.com/caarlos0/env v3.5.0+incompatible github.com/caarlos0/env/v6 v6.7.2 github.com/casbin/casbin v1.9.1 diff --git a/go.sum b/go.sum index d4251e80e8..ba488c2627 100644 --- a/go.sum +++ b/go.sum @@ -95,13 +95,6 @@ github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:l github.com/aws/aws-sdk-go v1.44.290/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= github.com/aws/aws-sdk-go v1.44.317 h1:+8XWrLmGMwPPXSRSLPzhgcGnzJ2mYkgkrcB9C/GnSOU= github.com/aws/aws-sdk-go v1.44.317/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= -github.com/aws/aws-sdk-go-v2 v1.21.0/go.mod h1:/RfNgGmRxI+iFOB1OeJUyxiU+9s88k3pfHvDagGEp0M= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.41/go.mod h1:CrObHAuPneJBlfEJ5T3szXOUkLEThaGfvnhTf33buas= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.35/go.mod h1:SJC1nEVVva1g3pHAIdCp7QsRIkMmLAgoDquQ9Rr8kYw= -github.com/aws/aws-sdk-go-v2/service/ecr v1.20.0 h1:Qw8H7V55d2P1d/a9+cLgAcdez4GtP6l30KQAeYqx9vY= -github.com/aws/aws-sdk-go-v2/service/ecr v1.20.0/go.mod h1:pGwmNL8hN0jpBfKfTbmu+Rl0bJkDhaGl+9PQLrZ4KLo= -github.com/aws/smithy-go v1.14.2 h1:MJU9hqBGbvWZdApzpvoF2WAIJDbtjK2NDJSiJP7HblQ= -github.com/aws/smithy-go v1.14.2/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=