Get code from firebase console which I deployed earlier - node.js

I had created firebase functions in nodejs and deployed the code on firebase.
The function was to send an email when the new user is created.
I have lost the code now. Can we pull that code from firebase ?

Note: the process below may work or not for your case. Don't rely on it as a replacement for keeping your code in a proper version control system.
You can retrieve the code for your Cloud Functions from the Cloud Console.
Go to this URL
Select the project that the function is in
Select a function from the list
You will get to this page:
Select the Source at the top
Click the "Source location" link
A zip file with the latest source of your function will start to download.
Note that these files may periodically get deleted. In that case, the above process will not work to recover your source code.

In the firebase console in the left hand menu select Functions. Hover over the function you want to view and click the three vertical dots. Select Detailed Usage Stats. This will bring you to the Google Cloud console. Select 'Source' to get the source code.

When you click to select your project, make sure you have the right organization selected.

The google cloud console link didn't work for me (might have been outdated)
Updated
Go to https://console.cloud.google.com/
Select your project [1]
Go to https://console.cloud.google.com/functions/list
Under Actions (with the 3 dots), click Test Function [2]
Go to Source, and you will be able to see your entire deployed project functions [3]

After downloading the source using the method of the selected answer, you need to perform the following tasks to be able to create/edit functions.
Create a new folder. eg, myFunctions.
cd into myFunctions.
run firebase init.
Follow the onscreen instructions. Be sure to select "Cloud Functions" in the list of firebase features to initialise. Also be sure to choose existing project & choose your project.
After npm finishes, a functions folder will be created in myFunctions.
Delete the functions folder.
Copy the functions folder that you downloaded initially.
That should be the trick!

It looks like that the answers given above are outdated and do not work anymore. This is the latest and most robust thalaiva way of accomplishing the task assigned to you in this tight deadline.
Goto https://console.cloud.google.com/storage/
Choose the bucket staging.<project-name>.appspot.com
Click on firebase-functions-source file.
The zipped folder of your firebase functions will get downloaded
Cheers!

Related

Why is my code not updating on App Engine?

I have an App Engine Service, running on Google Cloud Platform.
I run an old version of my NodeJS application on it.
After having updated my code, I have run the following command: gcloud app deploy, in my GCP console, directly. It shows no error.
It says 'X files updated' and after that, I go on my application and the code is actually not updated.
I expect my code to be deployed and therefore, updated, after I run this command.
Why is this expectation not met?
Are you sure you are deploying to the same version? If you're deploying a different version, did you migrate traffic to this new version? To check this, login to console.cloud.google.com > App Engine > Versions
This will show you all the versions you currently have deployed and you can confirm which one(s) are serving traffic
You should also confirm that you actually have the 'updated' source code deployed. Following the link in bullet 1 above, you should see a column that says 'Diagnose' with 'TOOLS' under it. Click on the drop down and select 'source'. This will show you your source code. Confirm you have your updated code
If your files are static, they could be cached. You can try using cache bursting techniques (search Stackoverflow for this), or wait for some time and try again.

Deploying an Azure Function from VS Code - Succesfull but not visible in the Portal

I created a function and I am trying to deploy it from VS Code by clicking the Deploy to Function App.... The Deployment runs successfully based on the output log - Deployment successful but then when I go to the portal, the function is not listed under Functions.
What shall I do and what is the problem here?
When I debug in VS Code, I get this: No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
Unfortunatly I would not know if those steps don't work for uploading. The deployment finishes, and every single time it becomes visible in my portal. Uh, maybe there is a slight difference. The app service itself is pre-created via terraform. Just the uploading of the code I do via VSC.
As far as deletion goes:
Open the resource group, in the list lookup the App Service. Select the checkbox in front of it. Delete in the top nav bar of that pane.
Trying to delete it any other way will indeed give you the "Not found" error.
I've had the same 'issue', in my case it turns out that the issue was a bad entry in the requirements.txt
I had an incorrect line with 'io' and when it was present despite the deployment appearing to complete successfully in VS code, the function was not updated if it was previously deployed or not deployed if it wasn't resulting in the same 'no results' in the functions list.
Having other requirements such as 'numpy' or 'scipy' worked just fine.
It's an old thread but maybe it'll be helpful to whoever gets here in the future.
Even as of now, some changes I make in VS Code seem to take time to be immediately visible on the portal. I had a similar issue with resources, i.e. creating a resource from VS Code wouldn't make it immediately visible on Azure Portal. You can always go to Functions on the portal and click Refresh. Also try going to Advanced Tools, then Kudu and checking if your function can be found there.
One word of advice: if you publish your functions from VS Code, then work on that resource only from VS Code. You will find it reiterated all over Azure Functions docs that:
Publishing to an existing function app overwrites the content of that
app in Azure.

What is the best way to move an online Azure Function to a local git repository?

I have written an Azure Function App by using the User Interface of Azure Portal. The code is written in C#.
Now, I want to:
download all of the relevant code and configuration files of this
function app
Create an IDE project (e.g. IntelliJ, Visual Studio Code, ...)
store it in a git repository
Deploy the code from IDE or command line to Azure and thereby replacing the previously written Azure function.
So far, I have found only documentation on how to initiate Azure function projects with no previous code. Does somebody know how to do above?
Yes, you could go to your function Overview page, click on Download app content as shown below.
And in your situation, you want configuration files, so select the Content and Visual Studio Project and Include app settings in the download. What is app settings? This will include a local.settings.json file which contains your application settings.
Also the third party .dlls are included.
In the VS, select the folder and it will be working.
Update:
Open the function with vs, then just right click the function and choose Publish, it will show you the publish page. Click start, then you will be able to publish it to a existing Function.
Follow this Setting up a CI/CD pipeline for Azure Functions doc which explain each step in detail.

Where can i find the code of an Azure Function?

I'm new to Azure Functions and been thrown into a project without a proper introduction and anybody I could ask is out of office. My simple most likely stupid question is; where can I find the actual code?
In the azure portal, the functions are listed as "read-only" and only contains a function.json. The resource is an App Service and it has a couple of functions. There is no link to any git repository in properties.
Read-only Functions would be compiled and published (e.g. through Visual Studio or a CI/CD pipeline.) The Azure Functions Portal engineers are working on a new, improved experience for this but for now, if your Function app has a deployment source configured, you can view it from the Portal in two ways from your Function app:
Platform Features > Deployment Options.
Platform Features > Resource Explorer. In the file tree on the lefthand side, find your Function app's name, and under that, sourcecontrols. Click to expand in the righthand window.
If your Function app doesn't have a deployment source configured (e.g. your team has been publishing code manually) then things get harder. Depending on how your company has set up their source control and what you already have access to, the function.json you see might help: the entryPoint property in a build-generated function.json will give you the full assembly name of that function (e.g. VSSample.HelloSequence.Run). That or the assembly name of the uploaded DLL in the scriptfile property might help you locate the project.
Good luck! Keep posting if you have further questions; we're here to help.
AFAIK, if we create the azure function in the Visual Studio and publish it to Azure(there may be other ways), it will appear in the situation you described like the screenshot.
Actually, the code is existing in the portal, but the code has been compiled, you could access it in the Platform features -> Advanced tools (Kudu) -> Debug console.
If you want to get the .cs file, I think you should ask it for your coworkers, there will not be in azure.
You said that the Azure function is listed as "read-only". Did you check from the Application Settings menu if you can change the Azure function app edit mode to Read/Write?

Output link when "deploying functions" for Firebase looks nothing like the github example

quick question.
I've been going through the google actions tutorials and sdk and quickly went through their github located at:
https://github.com/actions-on-google/dialogflow-webhook-template-nodejs
I followed the steps to initialize my firebase client and put in the addMessage and makeUppercase functions. Per the next step I did a firebase deploy --only functions, but this is where it gets weird.
In the sdk read.me it says it should output a link that looks similar to:
https://${REGION}-${PROJECT}.cloudfunctions.net/yourAction
However the link that terminal spit out for me was a link to my function "console" and the link looked like:
https://console.firebase.google.com/project/"my project name"/overview
I'm curious where I went wrong here as I simply copy and pasted the functions step by step and then deployed as they said.
Is this just how firebase returns the functions now? Maybe there was an update since the node.js sdk was published the other month? I'm worried that this outputted link is not the correct one for my webhooke in dialogflow. When I go to my console link, I can't find anywhere that gives me a link for a webhook within that dashboard so I'm a bit confused here
EDIT: So I dug deeper in their resource page, it's telling me it should output both my Project Console link as it did above as well as the function link. The function link is not being shown, which is leading to my confusion. Any idea as to why the function link is not being created?
The Firebase command line tool has changed something recently, so it only reports that URL the first time a function gets deployed. Or something like that.
The canonical way to get the URL for your function is to
Go to the Firebase Console (https://console.firebase.google.com/)
Login and select your project, if necessary.
Click on the "Functions" menu item on the left, which may be grouped under the "Develop" section.
In the center area, you'll see the function you have deployed for that project, along with the URL for it.
I went and deleted everything and tried again, now the function url is showing when I deployed my functions. I think what had happened before is I had ran an npm init on my folder out of habit before doing my firebase stuff, and when using firebase functions it will build the node dependencies for you as part of the process. I think running this early npm init screwed something up and was causing my firebase commands to act weird.

Resources