3
votes

I accidentally lost my up to date source file of a cloud function and then deployed again the cloud function with an old version of it.

Each time I deploy a cloud function I see on the console the version id of the deploy.

Is there something I can do to roll back to the previous version of the source file?

3
You might be able to retrieve it with the approach shown here: stackoverflow.com/questions/43916490/…Frank van Puffelen
I know the code exists on the web console, but because i accidently deployed an old version of the function i first must roll back to the previous version of the deploy i have done, is such thing possible to do? if not then why do they keep the version count?Ariel

3 Answers

8
votes

I finally figured this out:

Each time you make a deploy to a cloud function you get an output line like this:

sourceArchiveUrl: gs://my-store-bucket/us-central1-function_name-xxoxtdxvxaxx.zip

I entered my Google Cloud Platform Developer Console -> Cloud Functions -> function_name -> Source tab

and there almost at the bottom it says: Source location

my-store-bucket/us-central1-function_name-xxoxtdxvxaxx.zip

the same as it was shown in the CLI, but without gs:// that link lead me to the following: https://storage.cloud.google.com/my-store-bucket/us-central1-function_name-........

I removed from the link everything that came after

https://storage.cloud.google.com/my-store-bucket

and that lead me to a huge list of files that each one of them represented a an image of all my cloud functions at the time point of each time i have made a deploy, exactly what i needed!

The only thing left to do was to locate the file with the last date before my mistaken deploy

1
votes

The following shows where to locate and restore a previous deployment version of your Google Cloud Function.

You can select each of your previous versions on the scrolldown menu at the top left of your GCF screen once you enter a function.

On this overview page, while NOT entering EDIT mode, you can select some previous versions (although not all) from the menu - the selected version is then deployed (here: Version 5).

enter image description here

0
votes

When you deploy a new version of a CF the code is store in a GCS bucket.This bucket only stores the last 2 deployed versions. You can set a retention policy to keep older versions of the CF.

The name of the bucket it's similar to something like this:

gcf-source-[ID]-[region of the function]

A workaround to restore old version of a CF would be to download the code from the bucket and redeploy the function with it.