atlassian/firebase-deploy is failing with odd error
Asked by Larry Johnson:

Deployments using Atlassian Firebase pipe are failing with this odd error...
> Traceback (most recent call last):  
> File "/main.py", line 170, in \<module\>  
> pipe.run()  
> File "/main.py", line 69, in run  
> functions_dir_path = data\["functions"\]\["source"\]  
> TypeError: list indices must be integers or slices, not str

This failed the same way with versions 1.3.0 and 3.0.0 of the pipe "atlassian/firebase-deploy"

IIUC, here's the code block from the [Atlassian code](https://bitbucket.org/atlassian/firebase-deploy/src/09823ecdad9cf0a498b24a00c1807e8dc24a2ca8/pipe/main.py?at=master)...

```
# check for alternative path to functions directory
try:
  with open('firebase.json', 'r') as f:
    data = json.load(f)
    functions_dir_path = data["functions"]["source"]
  except FileNotFoundError:
    pass
  except KeyError:
    pass

It seems to be looking at our firebase.json for nodes source that is under a node functions. This doesn't seem to jive with my understanding of a firebase.json file. I don't think it even has a plural 'functions' node.
```

Any help is appreciated.


Answers:
author: Igor Stoyanov
body: [@Larry Johnson](/t5/user/viewprofilepage/user-id/545022) [@tomcatbuzz](/t5/user/viewprofilepage/user-id/3630742) [@Danilo Lombardi](/t5/user/viewprofilepage/user-id/5110393) hi.  
We released a [new version 3.1.1](https://bitbucket.org/atlassian/firebase-deploy/src/3.1.1/) of the firebase-deploy pipe, where the bug should be fixed.  
Waiting for your feedback.  
Regards, Igor  

comments: author: Igor Stoyanov
body: By default the pipe will use nodeJS version **16** . You could change this with i.e to use nodeJS version **18** for hosting with **\`** **NODE_JS_VERSION\`** variable:

```
script:  - pipe: atlassian/firebase-deploy:3.1.1    variables:      KEY_FILE: $KEY_FILE      NODE_JS_VERSION: '18'
```

Supported values are: **14** , **16** (default), **18** .  

With **\`firebase deploy --only functions\`** command **\`** **NODE_JS_VERSION\`** variable has no power (you could omit it); you have the ability to use nodeJS version provided in the **`engines`** field of the **package.json** file in your **`functions/`** directory started from nodeJS version **\`10\`**.


author: tomcatbuzz
body: The pipeline is now failing saying Error: Failed to authenticate, have you run firebase login? I have the KEY_FILE: $KEY_FILE set in the settings like the docs said.


author: Igor Stoyanov
body: [@tomcatbuzz](/t5/user/viewprofilepage/user-id/3630742) hi. Create a new question and provide more details with your pipeline config and log output.

Have you created your KEY_FILE variable according to this article?  
[bitbucket-cloud/docs/use-multiple-ssh-keys-in-your-pipeline](https://support.atlassian.com/bitbucket-cloud/docs/use-multiple-ssh-keys-in-your-pipeline/)

Linux

```
base64 -w 0 < your_key_file
```

Mac

```
base64 < your_key_file
```

and then pass the result as value to Repository variables KEY_FILE


author: tomcatbuzz
body: I have now generated 2 base64 encoded variables and both times they are failing. This is based on the google credential json. I think Bitbucket has over complicated the Auth method, since before we could simply use a token before \<- easy. It should not take hours of trial and error to Simply have a simple deploy on push solution. This has completely ruined the past experience of pipelines. Thanks for your reply. I am moving to another platform for Deploying.


author: Igor Stoyanov
body: [@tomcatbuzz](/t5/user/viewprofilepage/user-id/3630742) : "since before we could simply use a token before \<- easy." this method is still available.  


author: Igor Stoyanov
body: [@Larry Johnson](/t5/user/viewprofilepage/user-id/545022) hi.   
Is it possible in monorepo in different function packages.json have different node versions?  

I think about fetching node version from the first element of the list of functions. Is this correct?  

Or do you think it is better to just provide node version as a pipe variable NODE_VERSION?   

This solutions will not support multiple node version in different function packages.  
Still confusing with multiple node version support, i think this will be hard to implement, is this a real case?

comments: author: Larry Johnson
body: It probably is unreasonable to require the pipeline to support multiple node versions. But I am no expert in any of the technologies used.

Adding a NODE_VERSION pipe variable would work for us. If it is present the pipe could skip the code trying to find node version.

I've only been looking at main.py in the MAIN branch. Unless I'm missing something, it seems line 75 always reverses whatever may be done in line 69. I'm guessing I'm not looking at the latest code.

Also, we use the pipe for firebase 'hosting' sites as well, which has worked well for us. But as I look at the main.py in the MAIN branch, I do not see how that version ever handled hosting sites.


author: Igor Stoyanov
body: [@Larry Johnson](/t5/user/viewprofilepage/user-id/545022)

\`\`\`It probably is unreasonable to require the pipeline to support multiple node versions. \`\`\` we already support multiple node versions:  
n@6.7.0 \&\& n 8 \&\& n 10 \&\& n 12 \&\& n 14 \&\& n 16

<br />

\`\`\` line 75 always reverses whatever may be done in line 69.\`\`\` -- thats true, this will be fixed.

<br />

I will add a little clarification about what i asking. My question was about monorepo:

    $  tree .
    ??? firebase.json
    ??? teamA
    ?   ??? index.js
    ?   ??? package.json
    ??? teamB
        ??? index.js
        ??? package.json

as you can see here is the list (your case) with two package.json present.

Content of firebase.json:

    "functions": [
      {
        "source": "teamA",
        "codebase": "team-a"
      },
      {
        "source": "teamB",
        "codebase": "team-b"
      },
    ]

When you will run this all is ok when node version is the same (node 16 here):

    $ firebase deploy --only functions
    i  deploying functions
    i  functions: preparing codebase team-a for deployment
    i  functions: preparing codebase team-b for deployment
    i  functions: creating Node.js 16 function team-a:helloATeam(us-central1)...
    i  functions: creating Node.js 16 function team-b:helloBTeam(us-central1)...
    ...

My question: is it possible to be different node version in package.json teamA and package.json teamB. And if yes, then what firebase cli will do.

Previously we don't have such cases (with monorepo), so i'm a little confused.

Anyway i will thinking about feature to provide node as a pipe variable.


author: Larry Johnson
body: I'm not an expert on Firebase or Node. But to answer as best I can...

I would think the Firebase CLI would allow multiple node versions.

But I can see where you can make it a requirement for the pipeline that all versions be the same. We're a greenfield project so this should not be a problem for us. Not so sure about other clients.

Sorry if this is no help, but don't want to pretend to be an expert.


author: Danilo Lombardi
body: The same error here. [@Larry Johnson](/t5/user/viewprofilepage/user-id/545022) could you help me.


author: Danilo Lombardi
body: Where is the place to add a NODE_VERSION? I tried at bitbucket-pipelines.yml

NODE_VERSION: '16'  
but i found the same error.

![Screen Shot 2022-12-29 at 16.42.49.png](https://community.atlassian.com/t5/image/serverpage/image-id/232370i956D44A62FBABBA6/image-size/large?v=v2&px=999 "Screen Shot 2022-12-29 at 16.42.49.png")


author: Larry Johnson
body: [@Danilo Lombardi](/t5/user/viewprofilepage/user-id/5110393) , That feature has not been added. The conversation started by [@Igor Stoyanov](/t5/user/viewprofilepage/user-id/4550492) on December 27 is regarding the various possible changes that Atlassian might be making to the pipe to address this problem. In another conversatio on this same topic, Igor thinks the fix may be available in a few days or a few weeks.

I know that is no help, sorry. Hope you have a wonderful New Year.


author: tomcatbuzz
body: [@Danilo Lombardi](/t5/user/viewprofilepage/user-id/4279395) if it is for Functions, the node version is defined in the package.json for your functions folder. Using  
"engines": {  
"node": "16"  
},  
but that should be auto generated when you install dependencies. As Larry mentioned, we think the pipeline version 3.0.0 is currently bugged since it is failing and won't deploy to hosting. It would be nice if an earlier version could be used, but I have tried other pipeline versions, but when executed it will search for and use Version 3.0.0 pipeline image and fail.


author: Larry Johnson
body: It appears that the Bitbucket Pipeline for firebase-deploy has a bug. It expects the firebase.json to have an object at the path 'functions/source', where as a monorepo will have an array in this location.

comments: author: Igor Stoyanov
body: Hi [@Larry Johnson](/t5/user/viewprofilepage/user-id/5077137) . Thanks for your feedback. Yes, seems like this i bug according to your investigation. We will dive deep into this this and notify you about results.

Regards, Igor


author: tomcatbuzz
body: I am having the same error and keep changing deploy templates. It is failing every deploy. Well I used to love the simplicity of the deploy pipelines but obviously the new 3.0.0 is not working. And how many weeks does it take to fix this? If it gets fixed I will try again. Going to just script my own deploy for now on push.


author: Larry Johnson
body: [@Igor Stoyanov](/t5/user/viewprofilepage/user-id/4550492) , Do you know when this will be resolved?

[@tomcatbuzz](/t5/user/viewprofilepage/user-id/3630742) Would you be willing to share your solution? I was thinking I'd have to resort to a Container


author: tomcatbuzz
body: @\[deleted\] I just have to run firebase deploy manually from the cli. If the new pipeline image 3.0.0 is failing for its Primary purpose of deploying to firebase it is useless in my opinion. I have older deploys still working with image 1.2.4 and $FIREBASE_TOKEN. The newer updates tell us to use the KEYS as of recent changes. I have not resorted to making an older template to work with TOKEN. I am not even sure it will work. If it is not FIXED soon I will USE Github Actions for Firebase Deploy. I have a project in Github using Github Actions and works like it is supposed to.

NOTE: A work around (depends on your setup) is creating a script in your package.json.

Similar to \`\`\`build: your build script\`\`\`

I created this to build, commit, and deploy \`\`\`  
"deploy": "npm run build \&\& git add . \&\& git commit -m 'wip' \&\& git push -u origin master \&\& firebase deploy --only hosting"\`\`\`  
I am having a cli issue though keeping this from completing the deploy portion on my machine. Maybe a node issue, but it opens my firebase.config file instead.


author: Igor Stoyanov
body: [@Larry Johnson](/t5/user/viewprofilepage/user-id/545022) hi. We will try to release a new version from few days to 3 weeks.

Regards, Igor


author: Larry Johnson
body: [@tomcatbuzz](/t5/user/viewprofilepage/user-id/3630742) thanks for the detail.

[@Igor Stoyanov](/t5/user/viewprofilepage/user-id/4550492) Thanks for your attention to this. We're trying to stick with Atlassian Pipelines and look forward to the new release. In the meantime, do you know of a Container Image we can use that has the Firestore CLI installed? If not, I guess we can create one.


author: Igor Stoyanov
body: > In the meantime, do you know of a Container Image we can use that has the Firestore CLI installed

I don't know any official docker images for Firestore CLI.


author: tomcatbuzz
body: [@Larry Johnson](/t5/user/viewprofilepage/user-id/5077137) I did a search and found this repo. I don't really use docker, but this seems to be a repo that is being maintained and also listed on docker.hub. <https://github.com/AndreySenov/firebase-tools-docker>


author: Larry Johnson
body: Looking at main.py in the atlassian/firebase-deploy, what good is this code at L:63

```
# check for alternative path to functions directory
try:
    with open('firebase.json', 'r') as f:
        data = json.load(f)
        functions_dir_path = data["functions"]["source"]
except FileNotFoundError:
    pass
except KeyError:
    pass
```

<br />

When it's immediately followed by this line that overwrites it at L:75

```
functions_dir_path = DEFAULT_FUNCTIONS_DIR_PATH
```


Tags: bitbucket-cloud

cloud