R
Railwayโ€ข14mo ago
macwilko

How to create templates from projects?

No description
123 Replies
Percy
Percyโ€ข14mo ago
Project ID: N/A
macwilko
macwilkoOPโ€ข14mo ago
It seems this requires me to use a public repo? 573f673d-17f9-4c3b-b05f-91f672f1d889
Brody
Brodyโ€ข14mo ago
would you really want to deploy a whole new project per chat?
macwilko
macwilkoOPโ€ข14mo ago
just a github repo at the moment
Brody
Brodyโ€ข14mo ago
right but wouldnt it make more sense to deploy a new service instead?
macwilko
macwilkoOPโ€ข14mo ago
yes ideally, but I don't want to do it manually. I'de like a way to create it by the API? And I think that requires a template right?
macwilko
macwilkoOPโ€ข14mo ago
No description
macwilko
macwilkoOPโ€ข14mo ago
there's this maybe this works? will that add a new service?
Brody
Brodyโ€ข14mo ago
what im thinking is building your own little terraformer, have a single base project, with a service that will orchestrate deploying additional services within that same project
macwilko
macwilkoOPโ€ข14mo ago
yes that's it looking at the API, looks like serviceCreate() is the right mutation and I can pass it a github repo
Brody
Brodyโ€ข14mo ago
would each service need different variables?
macwilko
macwilkoOPโ€ข14mo ago
yes
Brody
Brodyโ€ข14mo ago
then you will have to make a few api calls one after the other let me figure out what calls you need to make and in what order
macwilko
macwilkoOPโ€ข14mo ago
^.^ I'll get to grips with calling the api with that graphql library
Brody
Brodyโ€ข14mo ago
would each service need its own domain?
macwilko
macwilkoOPโ€ข14mo ago
yes i can use DNSimple to update dnsrecords
Brody
Brodyโ€ข14mo ago
so custom domain?
macwilko
macwilkoOPโ€ข14mo ago
community_id.custom_domain.xyz
Brody
Brodyโ€ข14mo ago
- mutation serviceCreate - to create the empty service - mutation customDomainCreate - to add a custom domain, returns the cname - mutation variableCollectionUpsert - to add the needed custom variables - mutation serviceInstanceUpdate - likely needed to modify service settings like the health check endpoint - mutation serviceConnect - to add your repo and kick off a deployment you might be able to do customDomainCreate, variableCollectionUpsert, and serviceInstanceUpdate concurrently
macwilko
macwilkoOPโ€ข14mo ago
alright ^.^ thankyou brody
Brody
Brodyโ€ข14mo ago
no problem ๐Ÿ™‚
macwilko
macwilkoOPโ€ข14mo ago
No description
macwilko
macwilkoOPโ€ข14mo ago
just getting started here
Brody
Brodyโ€ข14mo ago
let me know if you run into any issues, while i havent used the api to do this, i have used the api with go
macwilko
macwilkoOPโ€ข14mo ago
there was a unknown scalar type : ServiceVariables, but otherwise generated fine!
schema: railway_schema.graphql
operations:
- railway_operations.graphql
generated: generated_railway_graphql.go
package: railway
context_type: "-"
use_struct_references: true

bindings:
ServiceVariables:
type: map[string]string
DateTime:
type: time.Time
schema: railway_schema.graphql
operations:
- railway_operations.graphql
generated: generated_railway_graphql.go
package: railway
context_type: "-"
use_struct_references: true

bindings:
ServiceVariables:
type: map[string]string
DateTime:
type: time.Time
Brody
Brodyโ€ข14mo ago
looks good to me
macwilko
macwilkoOPโ€ข14mo ago
any idea what the Environment_ID might be? I'm guessing it's "Production" Project ID i got
macwilko
macwilkoOPโ€ข14mo ago
No description
Brody
Brodyโ€ข14mo ago
it would be uuid for the environment within the project you want to create a service in
macwilko
macwilkoOPโ€ข14mo ago
ahh
macwilko
macwilkoOPโ€ข14mo ago
No description
macwilko
macwilkoOPโ€ข14mo ago
found it
Brody
Brodyโ€ข14mo ago
so since you are deploying into the same environment using that environment variable is perfect
macwilko
macwilkoOPโ€ข14mo ago
now that golang runs at less than 20x of the memory, I might even be able to have a staging environment lol
Brody
Brodyโ€ข14mo ago
you can have a staging environment with ruby apps too, just sleep them
macwilko
macwilkoOPโ€ข14mo ago
true I'm doing something wrong but not sure what the issue is
macwilko
macwilkoOPโ€ข14mo ago
No description
macwilko
macwilkoOPโ€ข14mo ago
setup the railway client i'm sending the auth token I generated in the Railway app but when I call serviceCreate it gives me Not Authorized
Brody
Brodyโ€ข14mo ago
what type of token did you create?
macwilko
macwilkoOPโ€ข14mo ago
No description
Brody
Brodyโ€ข14mo ago
all that looks fine, can you show me how you are using the client?
macwilko
macwilkoOPโ€ข14mo ago
ok
macwilko
macwilkoOPโ€ข14mo ago
No description
macwilko
macwilkoOPโ€ข14mo ago
No description
Brody
Brodyโ€ข14mo ago
well you dont want to add a repo at that stage as for the unauthed, i have no clue
macwilko
macwilkoOPโ€ข14mo ago
ok lets try without a service? i mean without a repo but... that's weird, how can you create a service without a repo
Brody
Brodyโ€ข14mo ago
empty service
macwilko
macwilkoOPโ€ข14mo ago
i see
Brody
Brodyโ€ข14mo ago
you have never created one of those in the UI?
macwilko
macwilkoOPโ€ข14mo ago
Source: &railway.ServiceSourceInput{},
Source: &railway.ServiceSourceInput{},
same error ๐Ÿ˜ฆ
Brody
Brodyโ€ข14mo ago
i better start coding
macwilko
macwilkoOPโ€ข14mo ago
no don't leave me
Brody
Brodyโ€ข14mo ago
code to solve this
macwilko
macwilkoOPโ€ข14mo ago
oh
mutation ServiceCreate($input: ServiceCreateInput!) {
serviceCreate(input: $input) {
id
createdAt
deletedAt
name
deployments(last: 1) {
edges {
node {
id
status
}
}
}
}
}

query Service($id: String!) {
service(id: $id) {
id
createdAt
deletedAt
name
deployments(last: 1) {
edges {
node {
id
status
}
}
}
}
}
mutation ServiceCreate($input: ServiceCreateInput!) {
serviceCreate(input: $input) {
id
createdAt
deletedAt
name
deployments(last: 1) {
edges {
node {
id
status
}
}
}
}
}

query Service($id: String!) {
service(id: $id) {
id
createdAt
deletedAt
name
deployments(last: 1) {
edges {
node {
id
status
}
}
}
}
}
maybe that'll help
Brody
Brodyโ€ข14mo ago
it will, ill see what i can whip up what are you using the service query for though?
macwilko
macwilkoOPโ€ข14mo ago
to create a service and then query it later (for its deployment) i will poll the service until its status is deployed
Brody
Brodyโ€ข14mo ago
use a webhook
macwilko
macwilkoOPโ€ข14mo ago
oo yeah i'll use a webhook
Brody
Brodyโ€ข14mo ago
the webhook you set in the project will send you a request for each stage
macwilko
macwilkoOPโ€ข14mo ago
ok alright its nearly 2am here and i better sleep >.<
Brody
Brodyโ€ข14mo ago
ill have some example code for you
macwilko
macwilkoOPโ€ข14mo ago
will be hyped to wake up to that then! thankyou for the help today brody!!
Brody
Brodyโ€ข14mo ago
macwilko
macwilkoOPโ€ข14mo ago
this helps so much I'm still stuck on this though, weirdly getting the unauthorized error I've got Proxy logs to show i'm sending the request correctly I'm wondering if it's an issue with team plan / tokens? can DM you anything when you're ๐ŸŒž alright we figured it out @Sang Dang ty! it was because I needed to use a personal token ๐Ÿ˜’ confusingly the tokens issuesd from the team page don't seem to work with this API but creating from account then selecting team drop down does
Sang Dang
Sang Dangโ€ข14mo ago
yeah I still don't know exactly what is the differents, just notice they have 2 places to create token and it's also confused me until now HAHAHA
macwilko
macwilkoOPโ€ข14mo ago
gotcha thankyou Sang
Brody
Brodyโ€ข14mo ago
use a team token when manipulating stuff on a team, use a personal token when manipulating stuff on the personal account
macwilko
macwilkoOPโ€ข14mo ago
@Brody thats the weird. thing its resources within the team thats why I was so surprised
Brody
Brodyโ€ข14mo ago
interesting
macwilko
macwilkoOPโ€ข14mo ago
let me show you
Brody
Brodyโ€ข14mo ago
I believe you
macwilko
macwilkoOPโ€ข14mo ago
No description
macwilko
macwilkoOPโ€ข14mo ago
thats the team project
macwilko
macwilkoOPโ€ข14mo ago
these tokens (from project settings in the team) don't work
No description
Brody
Brodyโ€ข14mo ago
that's a project token that I know for sure wouldn't work for what you are doing
macwilko
macwilkoOPโ€ข14mo ago
honestly no idea but Railway doesn't make that clear at all
Brody
Brodyโ€ข14mo ago
that's fair you don't know what token can do what
macwilko
macwilkoOPโ€ข14mo ago
pretty much it's all working great though now but figured i'de let you know
Brody
Brodyโ€ข14mo ago
was the code I wrote useful?
macwilko
macwilkoOPโ€ข14mo ago
super useful
Brody
Brodyโ€ข14mo ago
awesome
macwilko
macwilkoOPโ€ข14mo ago
i'm gonna use App sleeping also to keep the costs down, I think this will be an excellent improvement
Brody
Brodyโ€ข14mo ago
I had to fork the graphql generator library lol
macwilko
macwilkoOPโ€ข14mo ago
so someone creates a free chat server, and then if it's not used it will sleep oh man really wtf? I didn't encounter that requirement yet?
Brody
Brodyโ€ข14mo ago
yeah, the original library would send empty fields to the backboard instead of omitting them
macwilko
macwilkoOPโ€ข14mo ago
oh yes i noticed that although I expect its because the GraphQL schema is saying SomethingInput has a field of type String!
Brody
Brodyโ€ข14mo ago
the backboard didn't like that, so I modified the generator's code to always add an omitempty tag on the json structs so that the api calls always omit any empty fields
macwilko
macwilkoOPโ€ข14mo ago
if the field has a ! in it, it will be required to send something
Brody
Brodyโ€ข14mo ago
there was tags that didn't have a ! that weren't being marked as non required for some reason
macwilko
macwilkoOPโ€ข14mo ago
damn >.< well props for fixing that, I might have to use your fork
Brody
Brodyโ€ข14mo ago
I'd be lying if I said I wasn't confused as to how it's not been an issue for you, aren't you calling service instance update? unless you are just using my generated.go file?
macwilko
macwilkoOPโ€ข14mo ago
No description
macwilko
macwilkoOPโ€ข14mo ago
this part is working ok but I havent done service instance yet
Brody
Brodyโ€ข14mo ago
okay well that explains why you haven't gotten any errors haha well when you do, use my library fork and use it to generate new code and that should be all you need to do
macwilko
macwilkoOPโ€ข14mo ago
i'm lookin at the generated code though and you're right this is the behaviour how on earth is this a thing lol; man this is dumb
# @genqlient(omitempty: true)
# @genqlient(for: "Input.requiredField", omitempty: false)
# @genqlient(omitempty: true)
# @genqlient(for: "Input.requiredField", omitempty: false)
Brody
Brodyโ€ข14mo ago
I have no clue how fields don't have omitempty by default, every api request railways dashboard makes omits empty fields
macwilko
macwilkoOPโ€ข14mo ago
it had decorators for generating the types
Brody
Brodyโ€ข14mo ago
does this work? it threw errors when I tried to use this to set fields omitempty value
macwilko
macwilkoOPโ€ข14mo ago
GitHub
Global omitempty option ยท Issue #260 ยท Khan/genqlient
Let's say a graphql query accepts an input object, which has an optional string in it, if I use the input object, and not give a value to that string, it should be committed, that's just ho...
macwilko
macwilkoOPโ€ข14mo ago
just reading the issue here, maybe there's a solution, but it seems like people have run into this (obvious) defect i expect the maintainers are thinking about it it is not normal graphql behaviour
Brody
Brodyโ€ข14mo ago
yep and that's why I needed to fork, we can't wait for a fix
macwilko
macwilkoOPโ€ข14mo ago
use_struct_references: true
use_extensions: true
optional: pointer
use_struct_references: true
use_extensions: true
optional: pointer
Brody
Brodyโ€ข14mo ago
but then it will just send null, that would likely just break other things
macwilko
macwilkoOPโ€ข14mo ago
No description
macwilko
macwilkoOPโ€ข14mo ago
nil would be fine i will try it one sec
Brody
Brodyโ€ข14mo ago
null* this is json but this means you have to have pointers to strings, not ideal from a development standpoint
macwilko
macwilkoOPโ€ข14mo ago
No description
macwilko
macwilkoOPโ€ข14mo ago
this should be fine, i've not seen a graphql server not handle null before
Brody
Brodyโ€ข14mo ago
well there wasn't a problem with that api call, try making the same service instance update call I do in my code where you only update the healthcheck
macwilko
macwilkoOPโ€ข14mo ago
ok, I will try i'm gonna make some bacon and eggs, I'll update later ๐Ÿ™‚ seriously thanks again, I'm really enjoyingthis project and your help has made it even more enjoyable
Brody
Brodyโ€ข14mo ago
why did you turn on use_extensions though? this is fun for me too!
macwilko
macwilkoOPโ€ข14mo ago
just to see what extensions are generated ๐Ÿ˜„ I beleive there's some rate limiting sometimes those are exposed though extensions, wasn't sure if I get alot of people making chat servers I could get rate limited
Brody
Brodyโ€ข14mo ago
I think it's like 1000 api calls per hour? yes it is
macwilko
macwilkoOPโ€ข14mo ago
yeah it's about that I mean, its unlikely but I think setup of a server costs maybe 5 api calls per server so 200 servers per hour, that's alot
Brody
Brodyโ€ข14mo ago
yeah that's plenty for now business class when?
macwilko
macwilkoOPโ€ข14mo ago
hehe can't wait to show you the MVP ^.^
Brody
Brodyโ€ข14mo ago
MVP?
macwilko
macwilkoOPโ€ข14mo ago
ohh right, yeah this is a new product zenshop is on pause for the moment, and I'm gonna work on this app until mid January i think
Brody
Brodyโ€ข14mo ago
more apps are more better
macwilko
macwilkoOPโ€ข14mo ago
yeah
Want results from more Discord servers?
Add your server