Installing an R package in a Docker image that has a dependency on another Bitbucket package
Asked by Charith Wijewardena:

I'm trying to install a Bitbucket R package in a Docker image. The command to do this in my Dockerfile is:

    RUN --mount=type=secret,id=bitbucket_password . /run/secrets/bitbucket_password && R -e "remotes::install_bitbucket(repo='myorg/afp.model',ref='v0.1.1',auth_user='$BITBUCKET_USER',password='$BITBUCKET_PASSWORD')"

The problem is this package has a dependency on another of our R packages `afp.data` which I've specified in the `Remotes` section of the package DESCRIPTION file as:

    Remotes:     bitbucket::myorg/afp.data@v0.2.2

When I try to build the package I get the following error at the terminal:

    Error: Failed to install 'afp.model' from Bitbucket:  cannot open URL 'https://api.bitbucket.org/2.0/repositories/myorg/afp.data/src/v0.2.2/DESCRIPTION'

I've already passed in my username and password, and I am able to install our other packages that don't have such dependencies, so I'm not sure why it can't open that URL (if it's a permissions issue)?

Installing this package on my local desktop works fine, it's just in the Docker image that's the problem.

Would appreciate any help in troubleshooting this!


Answers:
author: Patrik S
body: Hello [@Charith Wijewardena](/t5/user/viewprofilepage/user-id/5215522) ,

Welcome to the Community!

From the description you have shared, I suspect the issue is related to authentication.

When trying to install the **afp.model** package, your application is using the Bitbucket Cloud API (the URL that appears on the logs), and you mentioned to have configured the authentication as your username and password. However, when using basic authentication for API calls you will need to provide the bitbucket **username** and an **app password**.

The app password is different from the password you use to login in the UI, and is used to authenticate git commands and also API calls.

With that in mind, could you try to [create an app password](https://support.atlassian.com/bitbucket-cloud/docs/app-passwords/) under your bitbucket account and use it along with your bitbucket username as the credentials for authentication in your Dockerfile?

Let me know in case you have any questions.

Thank you, [@Charith Wijewardena](/t5/user/viewprofilepage/user-id/5215522) !

Patrik S

comments: author: Charith Wijewardena
body: Hi Patrik, thanks for your reply! I just created an app password and gave it the following permissions. Now it says:

\`\`\`

cannot open URL '<https://api.bitbucket.org/2.0/repositories/myorg/afp.data/commit/v0.2.2>'

\`\`\`.

The error message seems a bit different but I'm not sure if it's relevant...

![Screenshot 2023-05-15 110516.png](https://community.atlassian.com/t5/image/serverpage/image-id/257149iB7E520D85F7E0E42/image-size/large?v=v2&px=999 "Screenshot 2023-05-15 110516.png")


author: Patrik S
body: Hello [@Charith Wijewardena](/t5/user/viewprofilepage/user-id/5215522) ,

Thank you for sharing the results of the testing.

I suspect that R is not propagating the credentials for authenticating the request to download the dependency of your dependency (**afp.data**), which is causing the error you reported.

I would suggest trying to provide the credentials as environment variables as per what is described in [R's install Bitbucket documentation](https://rdrr.io/cran/remotes/man/install_bitbucket.html). You would need to create an env variable **BITBUCKET_USER** with the value of your bitbucket user, and **BITBUCKET_PASSWORD**with the app password you have created. Maybe with the credentials set on the environment level, they will be propagated when trying to download the nested dependency.

If that still does not work, I would suggest reporting this issue on [r-libs issue tracker](https://github.com/r-lib/remotes/issues).

Thank you, [@Charith Wijewardena](/t5/user/viewprofilepage/user-id/5215522) !

Patrik S


author: Charith Wijewardena
body: Thanks Patrik, it didn't work either so I'll raise an issue or try to work around our dependencies so we don't get that problem.


Tags: bitbucket-cloud

cloud