Can't build go project
Using a Dockerfile I can't seem to get the GOROOT working, and package imports seem to break.
254 Replies
Project ID:
dd3f96f7-3ab3-4453-86a3-32328b2f81d6
dd3f96f7-3ab3-4453-86a3-32328b2f81d6
i'm probably being dumb
hold on, whats with the atoi for on the redis env?
total go nooby
that's the database I think
/0 i think usually
Atoi turns a string into an int
Can you use Nixpacks?
yup, those ENV vars always strings right
i would but... it's on an ancient Go version
Ah, fair
pretty sure you shouldn't use atoi for the redis db though
yeah why are you trying to convert the database url into an int?
You have all of your dependencies listed in your go.mod, right?
sorry those ENV vars are mostly fine for my local dev, I'll have to change them around when I get it compiling for Railway
kinda looks like that locally
I'd just use the REDIS_URL
bruh, my bad i was reading
REDIS_DB
as REDIS_URL
couldnt figure out what the hell you where doingahah, I'll fix that, tbh it looks bad
like so
ooo
what happened to my newlines
that looks nice
there we go
hollup
how did you manage this terminal prompt?
thats not any better lol
Ray.so - Create beautiful images of your code
Turn your code into beautiful images. Choose from a range of syntax colors, hide or show the background, and toggle between a dark and light window.
fancy
THE NEWLINES EXIST IN MY BROWSER
I SWEAR
I TOOK A SCREENSHOT OF IT
oh wait hold on
i'm dumb
😄
there we go
Well i feel in great company with learning Go now 😄
thanks!
okay back to the main problem, whats this exotic auth thing
ok this service is what will power the initial screen....
it's basically gonna be a central server
that will create a community, and then register it in a database, it'll then spin up a server on railway
nitpick: I feel like the I agree checkbox should be a checkbox
instead of a radiobutton
oo
yes, should be 😄
so i have this auth thingy working locally, but just wanted to test it running on a real server
Ah!
so locally where is
exotic/exotic-auth/handlers
?then I'm gonna start playing with the GraphQL api to create a server
You need to have a URL-based package name
like github.com/macwilko/exotic/exotic-auth
not always
Otherwise it treats it as part of the stdlib, right?
What's the name specified in your go.mod?
should I change that?
Try changing that, yeah
Generally change it to the URL of the git repository
try to just
exotic
don't do what brody says
that's advice for a normal go file, not
go.mod
i have never needed a url in my go.mod file
🤷♂️
yes
try that
ok
Do you have the
db/chat_users_db/model
directory in your project?
Or is that a separate module?yes it's a directory
huh
weird right >.< I always seem to mess up build tools
so to be clear, yes use a url in the go.mod file if you are developing a module that will be imported by other go apps, but you arent doing that, this is the app itself, it does not need to have a url in the go.mod file
guys... omg im dumb
it was a got dang issues with the files copy
the COPY command wasn't copying those files that were flagged as erroring
lol
my bad >.<
thankyou for the help both of you
now do a multistage image
O.O
@Brody sorry one last thing...
DB_SERVER_URL="root:Password123@tcp(127.0.0.1:3306)/chat_users_db?parseTime=true"
this was a oddity ...
for MySQL i had to specify tcp()
this works locally on my server on the machine at home
but on railway it's giving an error
2023/10/25 17:31:45 ERROR Unable to connect to db
2023/10/25 17:31:45 ERROR dial tcp: lookup mysql.railway.internal on 8.8.8.8:53: no such host
panic: dial tcp: lookup mysql.railway.internal on 8.8.8.8:53: no such host
I modified the URL to be ...
wow
after I removed the TCP proxy it worked O.O
(in the database settings on Railway)
yeah the drivers want a dsn, railway only provides a url
gotcha
ok app says its running
and the failed lookup, the private networks dns resolver is not available until about 2 seconds
exotic-auth-production.up.railway.app
but not getting through, probably the PORT is wrong
I hard coded the app to be on 3000
right 😄
perfect
its weird Railway doesn't add that to the variables
you'd think PORT is added here
its generated behind the scenes and changes every deployment
0.1% cpu usage?
does railway agree with that?
apparently lol
no
railway says 0.0 right?
yeah
okay cool
what does your response time say?
you're in canada right?
cool metrics
also, huge available ram
it's from gogiber 😄
dayum
yup
its around 100ms
ok
would be cool if Railway could use the private url if the database isn't exposed
i wouldnt worry about it, the data tab is flakey at best
😦
fair
why mysql tho
i'll probably need to expose it though right, otherwise I'm not really able to expose it
doesnt mysql use 500mb of mem on idle?
i like boring tech for data things. Less surprises 😄
fair, ill change my question, why mysql over postgres
honestly it's just I'm a little more familiar with it
i didn't see an especially good reason to learn postgres
mariadb 🙂
right
doesnt use as much mem as mysql, but not as little as postgres
how much is postgres out of curiousity?
and i have a nice template for mariadb 🙂
i guess the biggest cost running free chat servers will be the database, good point
so how are you handling the dsn database variable?
hold on a sec, I'll see if I can answer that
AI is processing your answer
why dont you just answer the question lol
I think i'll keep it public
the database?
yeah
why
I won't be able to connect to it otherwise (outside of the app)
gotcha
but how are you giving your code the dsn string?
make it private just in prod
thats what i do
how are you gonna fix problems to users if you can't modify the databse?
build tooling to do that
don't let users have problems in prod
is that neccisary though? I mean my PlanetScale database is public, how can someone hack your database? The passwords are so long it's impossible to brute force
better be safe than sorry
but my question mac 😦
i'm doing a string replace atm, so manually adding the tcp() bit lol
my smooth 🧠
just make a referenceable dsn variable, set this in the database's service variables and then referance this in your service
that works
I'll try that one sec
was that a question or a statement
statement
that'll make it much easier to build the template thingy
ok everything seems to be working good now... next task is to use the Railway GraphQL API from the Auth server, to create a new project with some services and such
use this https://github.com/Khan/genqlient
alright 😄 thx!
oh, right, back to the original problem though...
connecting via tcp() with the internal address seems to fail?
should I use udp or something?
fail with that 8.8.8.8 dns error?
yes
if you remove the tcp proxy it works, but I don't wanna do that, otherwise I can't access the database from home (outside of railway)
you are using
github.com/go-sql-driver/mysql
right?yep
add a
time.Sleep(5 * time.Second)
before the sql.Open
right ok
adding a sleep, one sec
are you using an alpine image to run your app in?
strange
different error now
side question, you are missing the schema there??
at least from what I've seen in sqlx, this is the right way
Gist
Go mysql sqlx example
Go mysql sqlx example. GitHub Gist: instantly share code, notes, and snippets.
okay ill see what i can do, since i have had no issues with just
database/sql
right >.<
thankyou
yeah that's weird... I'de prefer to use sqlx because plain sql makes things much harder
(no sql injection protection for bindvars)
wouldnt it be funny if i upload this test code and see no issues
(im testing with sqlx.Connect)
going to try socket() instead of tcp()
okay its not just you
yeah 😦
i'm not barking mad promise
😄
okay but why would sqlx require a different format, thats just frustrating
https://dev.mysql.com/doc/refman/8.0/en/transport-protocols.html
i know... it's weird
i was wondering if anyone of those would help
hmm i might try omit the tcp bit entirely maybe
nope 😦
is your database sleeping?
nope
i only got that error since the databases where sleeping, once they are awake i cant reproduce
oh
is your url like this:
though i am using
github.com/xo/dburl
to turn the regular database url environment variable into a dsncan you share that code please ^.^
never even heard of a DSN until today lol
actually my URL is
Although I doubt that makes much difference
this code prints the same dsn that reference variable would render to
sorry brody do you mind sharing:
the ENV var you're using
the lines that involve sqlx.Connect?
using 100% default database url env vars for both the public and private version of that env
right
code, one sec
DATABASE_URL=${{MySQL.MYSQL_PRIVATE_URL}}
yep thats what im doing, i havent modified any variables on the database services
sounds good, will make it easier too...
i guess I just assumed the tcp was needed
didn't know about the DSN bit
it is
dsn.DSN will wrap the host:port in tcp()
i see
for the mysql driver that is needed
woo connected
works
wtf does it do differently
that's so weird
sqlx.Connect just calls sql.Open with the same driver name and data source name passed into it, so sqlx wasnt the problem
hmm, one thing is it seems to omit the parseTime=true
I need to check if the databsae works without that
then add it back
this is the code i have been using
https://github.com/brody192/database-connection-tester/blob/main/internal/dbtest/databases/sql.go#L16-L30
oo
brody
you are intense
🙂
idk how many support engineers go into this level of detail lol
they all do
guess so,
i used this setup to find out that the mongodb template railway offered didnt listen on ipv6 and ipv4 by default, only ipv4
🙂
yeah you're essentially automating all the testing I guess
cute little print out
well good job deploys are about ~1 minute now and not 10 minutes
ooo
10 minutes??
nice to see MySQL connects the fastest 😄
Yeah... the ruby build process is slow af
i think mysql was sleeping at that time
heres a test where all dbs are awake
12 tests all done at the same time in under 30ms
3s 😦
3s from sleep
right 😉
gotcha
so basically every query to the database is minimum 12ms?
those are connection times, queries would be far faster
at least the connection rtt would be, not accounting for actual the time it takes to do the query on the database itself
sec just seeing if I can fix this
bugs are fun
i live for the bugs
we're in business, everything working
so I figure to keep it more affordable, makes sense to have seperate databases probably a Pro feature.
I'll make it so free servers spin up their own little go api
but connect to the same database
and then the Pro or Self hosted options can have dedicated resources
use sqlite in a volume 🙂
oo
maybe lol, that would be neat
and really affordable to run
i mean what's the trade offs there? won't sqlite be very slow to access?
disk accessed databases would be faster than network accessed databases
it's closer and all that
true
and railways volumes are very fast
i guess its the locking of the database that's the issue for sqlite
interesting
sqlite handles that stuff doesn't it?
well, tbf that's a good thing to look into, and does change the game in terms of performance / cost
the only cost for sqlite would be the cost of the volume
right yeah that's basically nothing
ok so a typical server might have, what, 500 people in max?
so could an sqlite database handle 500 or so active partipants in a given server, writing occasionally to update their last_seen_at time and maybe post a message in a channel every often
remember because chat servers are inherently write heavy
single writer
a single writer for any data anywhere on the database, or just a single writer per table?
it doesnt mention that
https://www.sqlite.org/whentouse.html
you did just say writing occasionally
SQLite only supports one writer at a time per database file.
i mean, it could easily be there's many writers
think about when a couple of people are typing in a channel
and there's 20 odd channels
one one person will be able to write at a time 😦
conclusion, use postgres 🙂
heh
shame honestly, I'd wish sqlite would work
well just thinking about this.
there's very little benefit deploying dedicated databases per server. So I can stick with one database, but many replica's of the Go api (for websockets / api calls etc).
The only people needing a dedicated DB are enterprise users and they'll use a self hosted option anyway.
okay then use a different document database
lol why do you dislike mysql so much lol
it's fine
postgres is still sql
Do yourself a favor, don't use a document database
oh yeah, for sure won't be 😄
sqlite is a document database? no?
no
alrighty, time to get myself all dirty and get familiar with Railway GraphQL
sqlite is like, sql but liter
😄
I'm just calling on disk databases a document database
my bad
no worries
okay so use a different on disk database?
i'm guessing its a blob of data with lots of smart ways to efficiently index and lookup data
hmm, are there any other good options?
i think sqlite is the only on-disk database that offers sql like features I've heard of
but anyway, I think I've concluded, there's not much cost/benefit to seperate the db for free servers.
i can run a single mysql db for those users no issue, and then pro/self hosted options can use their own db
if I get issues with the railway database I can switch over to planetscale later
woohoo pog
is that what your concern is I guess
the resiliancy of the databases
brain empty no concerns found
phew
your brain is becoming a beautiful almond
almonds are too bumpy
lmao
ok dumb question, but what if I have another Dockerfile in my project
like Dockerfile.scheduler
can I have railway build that instead?
sure can (not a dumb question by any means)
https://docs.railway.app/develop/variables#user-provided-configuration-variables
amazing
argh i think it's a bug with Shared variables
I added this as a shared variable
but then in the service the RAILWAY_PRIVATE_DOMAIN is missing
I also don't see it here
i don't have the patience to fix this right now, gonna leave it as it is
gotta get other stuff working lol
not a bug, just simply not how that works
remove it from the shared variables, and add it to the redis service
i mean i appear to be missing the private url in redis
yes, add it back
oh
it never had one to begin with I can promise you that
i see