rhymbit
rhymbit3mo ago

Google Cloud Storage library error inside docker, but outside on my pc it's working fine.

The library in question is this :- "@google-cloud/storage": "npm:@google-cloud/storage@^7.11.2", Inside the code, the library simply download a json file from google storage. When I run code outside the docker container locally, it works fine and is able to download the file. The dockerfile I'm currently using is this :-
FROM node:slim
# Install Deno
COPY --from=denoland/deno:latest /deno /usr/local/bin/deno
EXPOSE 8000
WORKDIR /app
ADD . /app
# set DENO_DIR to avoid conflicts with google cloud
ENV DENO_DIR=./.deno_cache
RUN deno cache src/main.ts

CMD ["deno", "serve", "-A", "src/main.ts", "--env_type=production"]
FROM node:slim
# Install Deno
COPY --from=denoland/deno:latest /deno /usr/local/bin/deno
EXPOSE 8000
WORKDIR /app
ADD . /app
# set DENO_DIR to avoid conflicts with google cloud
ENV DENO_DIR=./.deno_cache
RUN deno cache src/main.ts

CMD ["deno", "serve", "-A", "src/main.ts", "--env_type=production"]
I've already tried using deno's official image FROM denoland/deno:latest and install nodejs inside it, but it throws the same error.
3 Replies
rhymbit
rhymbit3mo ago
And here's the error :- can't paste it all in one go without discord nitro 🙏
Error: request to https://www.googleapis.com/oauth2/v4/token failed, reason: client error (Connect)
at Gaxios._request (file:///app/.deno_cache/npm/registry.npmjs.org/gaxios/6.6.0/build/src/gaxios.js:149:19)
at eventLoopTick (ext:core/01_core.js:168:7)
at async GoogleToken._GoogleToken_requestToken (file:///app/.deno_cache/npm/registry.npmjs.org/gtoken/7.1.0/build/src/index.js:241:19)
at async GoogleToken._GoogleToken_getTokenAsync (file:///app/.deno_cache/npm/registry.npmjs.org/gtoken/7.1.0/build/src/index.js:160:16)
at async JWT.refreshTokenNoCache (file:///app/.deno_cache/npm/registry.npmjs.org/google-auth-library/9.11.0/build/src/auth/jwtclient.js:173:23)
at async JWT.getRequestMetadataAsync (file:///app/.deno_cache/npm/registry.npmjs.org/google-auth-library/9.11.0/build/src/auth/oauth2client.js:333:17)
at async JWT.getRequestHeaders (file:///app/.deno_cache/npm/registry.npmjs.org/google-auth-library/9.11.0/build/src/auth/oauth2client.js:296:26)
at async GoogleAuth.authorizeRequest (file:///app/.deno_cache/npm/registry.npmjs.org/google-auth-library/9.11.0/build/src/auth/googleauth.js:737:25)
at async Promise.all (index 1)
at async prepareRequest
Error: request to https://www.googleapis.com/oauth2/v4/token failed, reason: client error (Connect)
at Gaxios._request (file:///app/.deno_cache/npm/registry.npmjs.org/gaxios/6.6.0/build/src/gaxios.js:149:19)
at eventLoopTick (ext:core/01_core.js:168:7)
at async GoogleToken._GoogleToken_requestToken (file:///app/.deno_cache/npm/registry.npmjs.org/gtoken/7.1.0/build/src/index.js:241:19)
at async GoogleToken._GoogleToken_getTokenAsync (file:///app/.deno_cache/npm/registry.npmjs.org/gtoken/7.1.0/build/src/index.js:160:16)
at async JWT.refreshTokenNoCache (file:///app/.deno_cache/npm/registry.npmjs.org/google-auth-library/9.11.0/build/src/auth/jwtclient.js:173:23)
at async JWT.getRequestMetadataAsync (file:///app/.deno_cache/npm/registry.npmjs.org/google-auth-library/9.11.0/build/src/auth/oauth2client.js:333:17)
at async JWT.getRequestHeaders (file:///app/.deno_cache/npm/registry.npmjs.org/google-auth-library/9.11.0/build/src/auth/oauth2client.js:296:26)
at async GoogleAuth.authorizeRequest (file:///app/.deno_cache/npm/registry.npmjs.org/google-auth-library/9.11.0/build/src/auth/googleauth.js:737:25)
at async Promise.all (index 1)
at async prepareRequest
(file:///app/.deno_cache/npm/registry.npmjs.org/@google-cloud/storage/7.11.2/build/esm/src/nodejs-common/util.js:463:61) {
config: {
method: "POST",
url: "https://www.googleapis.com/oauth2/v4/token",
data: {
grant_type: "<<REDACTED> - See `errorRedactor` option in `gaxios` for configuration>.",
assertion: "<<REDACTED> - See `errorRedactor` option in `gaxios` for configuration>."
},
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": "google-api-nodejs-client/9.11.0",
"x-goog-api-client": "gl-node/20.11.1",
Accept: "application/json"
},
responseType: "json",
retryConfig: {
httpMethodsToRetry: [ "POST" ],
currentRetryAttempt: 2,
retry: 3,
noResponseRetries: 2,
statusCodesToRetry: [ [ 100, 199 ], [ 408, 408 ], [ 429, 429 ], [ 500, 599 ] ]
},
paramsSerializer: [Function: paramsSerializer],
body: "<<REDACTED> - See `errorRedactor` option in `gaxios` for configuration>.",
validateStatus: [Function: validateStatus],
errorRedactor: [Function: defaultErrorRedactor]
},
response: undefined,
error: FetchError: request to https://www.googleapis.com/oauth2/v4/token failed, reason: client error (Connect)
at HttpsClientRequest.<anonymous> (file:///app/.deno_cache/npm/registry.npmjs.org/node-fetch/2.7.0/lib/index.js:1501:11)
at HttpsClientRequest.emit (ext:deno_node/_stream.mjs:1851:9)
at node:http:495:16
at eventLoopTick (ext:core/01_core.js:168:7) {
message: "request to https://www.googleapis.com/oauth2/v4/token failed, reason: client error (Connect)",
type: "system",
errno: undefined,
code: undefined
},
[Symbol("gaxios-gaxios-error")]: "6.6.0"
}
(file:///app/.deno_cache/npm/registry.npmjs.org/@google-cloud/storage/7.11.2/build/esm/src/nodejs-common/util.js:463:61) {
config: {
method: "POST",
url: "https://www.googleapis.com/oauth2/v4/token",
data: {
grant_type: "<<REDACTED> - See `errorRedactor` option in `gaxios` for configuration>.",
assertion: "<<REDACTED> - See `errorRedactor` option in `gaxios` for configuration>."
},
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": "google-api-nodejs-client/9.11.0",
"x-goog-api-client": "gl-node/20.11.1",
Accept: "application/json"
},
responseType: "json",
retryConfig: {
httpMethodsToRetry: [ "POST" ],
currentRetryAttempt: 2,
retry: 3,
noResponseRetries: 2,
statusCodesToRetry: [ [ 100, 199 ], [ 408, 408 ], [ 429, 429 ], [ 500, 599 ] ]
},
paramsSerializer: [Function: paramsSerializer],
body: "<<REDACTED> - See `errorRedactor` option in `gaxios` for configuration>.",
validateStatus: [Function: validateStatus],
errorRedactor: [Function: defaultErrorRedactor]
},
response: undefined,
error: FetchError: request to https://www.googleapis.com/oauth2/v4/token failed, reason: client error (Connect)
at HttpsClientRequest.<anonymous> (file:///app/.deno_cache/npm/registry.npmjs.org/node-fetch/2.7.0/lib/index.js:1501:11)
at HttpsClientRequest.emit (ext:deno_node/_stream.mjs:1851:9)
at node:http:495:16
at eventLoopTick (ext:core/01_core.js:168:7) {
message: "request to https://www.googleapis.com/oauth2/v4/token failed, reason: client error (Connect)",
type: "system",
errno: undefined,
code: undefined
},
[Symbol("gaxios-gaxios-error")]: "6.6.0"
}
An Update :- - I was using podman instead of docker, and it wasn't working inside podman. - I installed docker again and tried with docker, and it works fine. I think there was some problem with podman's network configs or something that wasn't allowing that google library to connect to https://googleapis.com/v4 (something like this url) to verify token and stuff. For now, I don't have patience to figure out a way to make it work in podman 😓 , so I'll just take docker. PS: Also deployed this container image (using podman itself) to google cloud run and it works fine over there as well. ✌️
Deno AI Helper
Deno AI Helper3mo ago
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the information you've provided in your message, I can offer some general advice. Firstly, it's important to note that the @google-cloud/storage library you're using is an npm package, which is designed to be used with Node.js, not Deno. Deno does not use npm packages directly as it has a different module system. If you're trying to use an npm package within Deno, you would typically need to use a compatibility layer or find an equivalent Deno module. In your Dockerfile, you're using a Node.js base image and then copying Deno into it. This setup can work, but it's not typical for Deno applications. Deno applications usually don't require Node.js, and vice versa. Here are a few things you might want to check or try: 1. Ensure that the environment variables and credentials required by the @google-cloud/storage library are correctly set up in your Docker container. These might include GOOGLE_APPLICATION_CREDENTIALS or other related environment variables. 2. Verify that the network configuration in your Docker container allows for outbound connections to Google Cloud Storage. 3. If you're using Deno, consider looking for a Deno module that provides Google Cloud Storage functionality, or use the Deno FFI (Foreign Function Interface) to interact with the Google Cloud Storage C++ client libraries. 4. If you need to use the @google-cloud/storage npm package, you might want to stick with a Node.js environment rather than trying to integrate it with Deno. Please note that this advice is not based on the Deno documentation, and I would advise you to double-check the accuracy of the advice given. If you continue to experience issues, you may want to seek
Deno AI Helper
Deno AI Helper3mo ago
assistance from the community or the maintainers of the @google-cloud/storage library for more Docker-specific troubleshooting.