How can I run a Google API inside a Docker Container?
I'm making a worker service that interacts with the Gmail API. Currently, I use OAuth 2.0 Client for the credentials:
It works fine until I run it on a Docker Container:
I've search through this on the internet and it wants me to use a Service Account. But I couldn't get it to work. I also tried using a normal API key but it says that it has limited access. I hope someone can help me with this. 😇
330 Replies
isnt the google api just a bunch of endpoints?
that just looks like it can't find you secret in the path you provided
Error makes it sound like you're failing to read your credentials from whatever file you're saving them in. Are you mounting the file into your container (or copying it into the container)?
Yes I am mounting it
Usually, it looks for that credentials.json, and it looks for an access token on the FileDataStore, if no access token found, it opens a browser to authenticate and once authenticated, it creates it. I must provide the credentials.json.
I think the browser authentication was the problem here since theres no UI for Docker
It's actually my first time using Docker in a project
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
That's why I searched it and it wants me to use a Service Account which I couldn't make it work.
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Sorry I'm not following
You mean constructor?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
TLDR on
async
/await
:
* every .net API that is suffixed with Async
(eg: .Read()
and .ReadAsync()
) => use the Async
version
* if the API name ends with Async
=> await
it
* if the API returns a Task
=> await
it
* if you have to await
in a method:
* that method must have the async
keyword (you could even suffix your function name with Async
, up to you)
* if it was returning T
(eg:string
) => it should now return Task<T>
(eg: Task<string>
)
* APIs to ban and associated fix:
Oh yeah I didn't notice it
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
But why it works fine on a real computer?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Yeah I'm putting await now
Wait wut?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Oh my god my brain isn't working right now hold up I just woke up
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Yeah it's a school project
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Wanna see the repo?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
I hope I didn't commit something sensitive tho
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
GitHub
GitHub - dkroderos/mail at dockerize
Merr Mail. Contribute to dkroderos/mail development by creating an account on GitHub.
But I don't think you can run it since I use .env files
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Go ahead please
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
I always commit them 😄
And sometimes it's sensitive
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Like path to something
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Ohhhh
GitHub
GitHub - tonerdo/dotnet-env: A .NET library to load environment var...
A .NET library to load environment variables from .env files - tonerdo/dotnet-env
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Lmao
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Thanks I'll try it out
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Nah I only know C#
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Bro I'm still a student I have a lot to learn
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Thanks for it tho I learned something new
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
You working already?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Real work
On a company or smth?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Sheesh
I still have a lot to learn
Did you saw the code?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
I've just commited another one since I forgot to update the one that calls that func
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Only one
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Just started it 2 weeks ago
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Wanna call?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Yeah I do think thats better
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Hihi
You can send a PR on the main repo I'll merge it
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
DotNetEnv();
It does traverse search
Until it finds the .env
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
LMAO
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
ar?
Nope, I just think I might use another configuration format 😄
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Just paths to the sensitive files actually
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
I'm always seeing it actually
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Yes
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
We can call right now and review my shitty code 😄
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
I'm still knowing how to use the client secrets
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
On appsettings.json
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
So how do i not commit this?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Just .gitignore it?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
So this is appsettings.json?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Wait so many stuff to do I need guidance
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Lemme clone it again I got so many files already
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Yep
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
It's in the home folder right?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Windows
Currently
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Where?
Btw I just use student license I'm not rich
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Oh ok
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
There we go
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Are you starting to understand the project structure now?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Wait
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
I tried to use clean architecture but I don't know if I properly implemented the separation of concerns
Seeing that "hahahaha" once again still got me laughing
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Then I use jsonserializer right?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Just ok here?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
This is on domain right?
Domain/Models?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
I gotta try it first before I roast it 😄
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Could you send a pr?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
:blushowo:
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
I'll do the thing you suggested later
builder.services.blabla
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Done
TeBeCo
Quoted by
<@689473681302224947> from #How can I run a Google API inside a Docker Container? (click here)
React with ❌ to remove this embed.
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Ye
You removed the HttpClient?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
OHHH OK
Wait when did you do .AddHttpClient?
Ok I saw it now
So what now?
I think I haven't read the secrets
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Oh wait haven't i done this already?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
In all who needs it?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Is ApplicationOptions the common name for it?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Ohh
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Do you know a fast way to change every IConfigurationSettings configurationSettings to ApplicationOptions applicationOptions?
As well as the one who calls the properties?
Alright noted
So why empty string?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Ohh nice separation
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
If theres no another {} then its everything in here?
The ""
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Alright I'm starting to get it
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Alright
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
I'll comment this for now
Save it for later
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Why double required?
I actually haven't used [Required] before I'm just seeing it
Bro im still copying 😭
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Thanks I'll check it out
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Bro you're helping me so much thank you
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Bookmarked it
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
appsettings.json:
src/Foo/FooOptions.cs:
src/Foo/FooServiceCollectionExtensions.cs:
Program.cs / Startup.cs:
Bar.cs:
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
I didn't know there features like that on this server
Where do you live?
Its 11 pm right now here but I don't think I'll be able to sleep this night since I've just woken up
Btw are you a senior dev?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Talking about perfect timing
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
I also just got back, i'm currently renaming stuff
On the 'dockerize branch'?
I got back to the main branch and did the refactorings you suggested, i havent commit yet
Wait
GitHub
GitHub - dkroderos/mail at test
Merr Mail. Contribute to dkroderos/mail development by creating an account on GitHub.
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Noted
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Btw i didnt used that
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Before implementing the gmail api i did that and i just realized its not needed
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Yeah i forgot that class
Wait
Lemme commit wat
Look at this
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Thats trash too
Oh wait you refactored it?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Isn't record an init?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Look
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Yeah but i added the secrets
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
My bad i covered the first value
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
HAHAHAHAHAHAHAHAHAHAHA
Oh my god typical dev stuff
IT WORKED
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Thank you so much
Thanks a lot again! I learned a lot tonight
So
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
I'll clean it up tomorrow
Also
On the startAsync
I'm always checking if there is an internet
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
emails is [] ? balbal?
Like that?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Where is the
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
I don't want my main logic on the worker itself
Is that fine?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Go ahead please
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Alright i get it
Make sense
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Should I also refactor the architecture?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
private async Task<bool> CheckInternetConnectionAsync()
{
try
{
using var response = await httpClient.GetAsync("https://www.google.com");
return response.IsSuccessStatusCode;
}
catch
{
return false;
}
}
Is this redundant?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Pinging
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Since .AddHttpClient() is added its logging the ping now
If i delete this it will loop the ping log.
What do you think?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Actually when i started this project i wanted to test out clean architecture and see if it's better
But then i realize that you can only test the architecture once other people try to understand your code
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Right now my benefit in this architecture is that I can convince someone that I know how to use it 😄
For resume mabye
Its not done yet tho
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
I will still have to implement nlp to check on the database if there are matched emails and reply to it
So how do you structure your project?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Natural language processing
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Thanks ill check it out
If you take a look at the repo i think my groupmate placed a pdf file in the docs folder, you can see the project proposals
I hate school tho never learned something new there
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
I guess im gonna create another help post
Thanks again
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Dockerizing google api
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
HAHAHAHAHAH
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Im thinking of dockerizing as a way of publishing it
Idk
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Does a container able to open browsers?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
I think thats my current problem
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
I dont mean ports tho
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
When using this api key it needs to authenticate on the browser and accept the terms and stuff
I guess ill try it again
My current task is to move this secrets.json to the container
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Hmmm
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Yeah i bookmarked it
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
But i still can do right?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Mounting it?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Actually its my first using docker 😄
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
School sucks that I learned all of these things by myself
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Noted
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
DOTNET_ is required?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Thanks
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Oh thats nice
So it seems like I dont need to add more ignored files and folders to the .gitignore
This is the authentication im talking about
So if my environent variables are paths, i still need to mount it
Right?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
This doesnt 😄
So i cannot have a default docker-compose template?
Or i just suggest to put the paths to the secrets folder inside the repo?
If what im saying make sense 😄
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
My current docker compose file
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Havent touched it since the refactoring
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Yeah ill read it
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Yeah
I just showed it to you
My current dockerfile
I'll read the docs tomorrow
Or ill guess later since its 2 am here
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Oh wow
Since 2012
Thank you so much again
I guess I'll rest now :blushowo:
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
This one is already impressive
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
I'm just cleaning up my desk and ill sleep now