简体   繁体   中英

How to create Revision URL using gcloud run?

I recently noticed a beta feature in the Google Cloud Run web UI that allows you to create a Revision URL (tag). Super handy feature!

My question: how can I create a tag for a revision so I can do this using gcloud ? I'm not seeing anything in the docs for it yet (probably because it's such a fresh feature).

The revision URL is also named "TAG". Use the update command to tag the latest revision.

gcloud beta run services update --tag=test --platform=managed --region=us-central1  go111

Apr, 2022 Update:

You can add one or more tags for one or more revisions with "gcloud" . There are 2 ways to do it. One is when creating a revision and one is for existed revisions .

<When creating a revision>

Now, there is only one revision "editor-v1-0-0" with the tag "blue" as shown below:

在此处输入图像描述

Then, to add a tag to a revision when creating it, this flag below is used:

--tag <tag>

Now, I'll add the tag "green" to a revision:

--tag green

Then, including the flag above, I run the full command referring to Shipping the public editor service in Securing Cloud Run services tutorial as shown below to create a revision with "editor:2.0.0" image :

* When creating a revision, you can add only one tag to it.

gcloud run deploy editor --image gcr.io/myproject-318173/editor:2.0.0 \
    --service-account editor-identity \
    --set-env-vars EDITOR_UPSTREAM_RENDER_URL=https://renderer-4bdlubpdxq-an.a.run.app \
    --allow-unauthenticated \
    --revision-suffix v2-0-0 \
    --no-traffic \
    --tag green // Here 

Now, the revision "editor-v2-0-0" with the tag "green" is created as shown below:

在此处输入图像描述

<For existed revisions>

There are two commands "gcloud run services update" and "gcloud run services update-traffic" to add one or more tags. Actually, "gcloud run services update-traffic" can do more things about Tag :

<"gcloud run services update">

First of all, I'll show you how to add one or more tags with "gcloud run services update" and with "gcloud run services update" , you can add only one tag at one command to only the latest revision .

Now, there is the latest revision "editor-v2-0-0" with no tags :

在此处输入图像描述

Then, run the command with the tag "green" as shown below:

gcloud run services update editor --tag green

Now, the tag "green" is added to the latest revision "editor-v2-0-0" as shown below:

在此处输入图像描述

Then, if you run the command with the tag "orange" below:

gcloud run services update editor --tag orange

Now, the tag "orange" is added to the latest revision "editor-v2-0-0" without updating "green" to "orange" as shown below:

在此处输入图像描述

In addtion, if the tag which is already used for other revision is added to a revision, the tag is removed from other revision then added to a revision.

So, if running the command with the tag "blue" as shown below, the tag "blue" is removed from the revision "editor-v1-0-0" then added to the revision "editor-v2-0-0" :

gcloud run services update editor --tag blue

在此处输入图像描述

<"gcloud run services update-traffic">

Next, I'll show you how to add one or more tags with "gcloud run services update-traffic" .

Now, there are two revisions "editor-v2-0-0" with no tags and "editor-v1-0-0" with the tag "blue" :

在此处输入图像描述

Then, this flag below can add one or more tags to one or more revisions but this flag below cannot update one or more tags of one or more revisions even though the flag name is "--update-tags" so this flag below can just add one or more tags to one or more revisions :

--update-tags <tag>=<revision>,…

Now, I'll add the tag "green" to the revision "editor-v2-0-0" :

--update-tags green=editor-v2-0-0

Then, including the flag above, I run the full command as shown below:

gcloud run services update-traffic editor --update-tags green=editor-v2-0-0

Now, the tag "green" is added to the revision "editor-v2-0-0" as shown below:

在此处输入图像描述

And, this command below can add two tags "orange" and "yellow" to the revision "editor-v2-0-0" and one tag "black" to the revision "editor-v1-0-0" :

gcloud run services update-traffic editor --update-tags \
orange=editor-v2-0-0,yellow=editor-v2-0-0,black=editor-v1-0-0

Now, two tags "orange" and "yellow" are added to the revision "editor-v2-0-0" and one tag "black" is added to the revision "editor-v1-0-0" as shown below:

在此处输入图像描述

*Be careful, if there are one or more empty strings before or after a comma in a list of values , there is an error.

So, if an empty string is before a comma:

gcloud run services update-traffic editor --update-tags \
orange=editor-v2-0-0 ,yellow=editor-v2-0-0,black=editor-v1-0-0
                 // An empty string before a comma

Then, there is an error:

ERROR: (gcloud.run.services.update-traffic) unrecognized arguments: ,yellow=editor-v2-0-0,black=editor-v1-0-0

And if an empty string is after a comma:

gcloud run services update-traffic editor --update-tags \
orange=editor-v2-0-0, yellow=editor-v2-0-0,black=editor-v1-0-0
           // An empty string after a comma

Then, there is an error:

ERROR: (gcloud.run.services.update-traffic) unrecognized arguments: yellow=editor-v2-0-0,black=editor-v1-0-0

So, don't put one or more empty strings before or after a comma in a list of values :

gcloud run services update-traffic editor --update-tags \
orange=editor-v2-0-0,yellow=editor-v2-0-0,black=editor-v1-0-0
                 // No empty strings 
                 // before or after a comma

Next, this flag below can update one or more tags of one or more revisions :

--set-tags <tag>=<revision>,…

Now, there are two revisions "editor-v2-0-0" with three tags "green", "orange" and "yellow" and "editor-v1-0-0" with two tags "blue" and "black" :

在此处输入图像描述

Then, I'll update three tags "green", "orange" and "yellow" of the revision "editor-v2-0-0" to two tags "gold" and "silver" and two tags "blue" and "black" of the revision "editor-v1-0-0" to one tag "white" :

--set-tags gold=editor-v2-0-0,silver=editor-v2-0-0,white=editor-v1-0-0

Then, including the flag above, I run the full command as shown below:

gcloud run services update-traffic editor --set-tags \
gold=editor-v2-0-0,silver=editor-v2-0-0,white=editor-v1-0-0

Now, three tags "green", "orange" and "yellow" of the revision "editor-v2-0-0" are updated to two tags "gold" and "silver" and two tags "blue" and "black" of the revision "editor-v1-0-0" are updated to one tag "white" as shown below:

在此处输入图像描述

Then, this flag below can remove one or more tags from one or more revisions :

--remove-tags <tag>,…

Now, there are two revisions "editor-v2-0-0" with three tags "green", "orange" and "yellow" and "editor-v1-0-0" with two tags "blue" and "black" :

在此处输入图像描述

Then, I'll remove two tags "green" and "yellow" from the revision "editor-v2-0-0" and one tag "blue" from the revision "editor-v1-0-0" :

--remove-tags green,yellow,blue

Then, including the flag above, I run the full command as shown below:

gcloud run services update-traffic editor --remove-tags green,yellow,blue

Now, two tags "green" and "yellow" are removed from the revision "editor-v2-0-0" and one tag "blue" is removed from the revision "editor-v1-0-0" as shown below:

在此处输入图像描述

Then, this flag below can remove all tags from all revisions :

--clear-tags

Now, there are two revisions "editor-v2-0-0" with three tags "green", "orange" and "yellow" and "editor-v1-0-0" with two tags "blue" and "black" :

在此处输入图像描述

Then, including the flag above, I run the full command as shown below to remove all the tags from all the revisions :

gcloud run services update-traffic editor --clear-tags

Now, all the tags are removed from all the revisions as shown below:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM