R
Railwayโ€ข8mo ago
macwilko

How to create templates from projects?

No description
123 Replies
Percy
Percyโ€ข8mo ago
Project ID: N/A
macwilko
macwilkoโ€ข8mo ago
It seems this requires me to use a public repo? 573f673d-17f9-4c3b-b05f-91f672f1d889
Brody
Brodyโ€ข8mo ago
would you really want to deploy a whole new project per chat?
macwilko
macwilkoโ€ข8mo ago
just a github repo at the moment
Brody
Brodyโ€ข8mo ago
right but wouldnt it make more sense to deploy a new service instead?
macwilko
macwilkoโ€ข8mo 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
macwilkoโ€ข8mo ago
No description
macwilko
macwilkoโ€ข8mo ago
there's this maybe this works? will that add a new service?
Brody
Brodyโ€ข8mo 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
macwilkoโ€ข8mo 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โ€ข8mo ago
would each service need different variables?
macwilko
macwilkoโ€ข8mo ago
yes
Brody
Brodyโ€ข8mo 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
macwilkoโ€ข8mo ago
^.^ I'll get to grips with calling the api with that graphql library
Brody
Brodyโ€ข8mo ago
would each service need its own domain?
macwilko
macwilkoโ€ข8mo ago
yes i can use DNSimple to update dnsrecords
Brody
Brodyโ€ข8mo ago
so custom domain?
macwilko
macwilkoโ€ข8mo ago
community_id.custom_domain.xyz
Brody
Brodyโ€ข8mo 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
macwilkoโ€ข8mo ago
alright ^.^ thankyou brody
Brody
Brodyโ€ข8mo ago
no problem ๐Ÿ™‚
macwilko
macwilkoโ€ข8mo ago
No description
macwilko
macwilkoโ€ข8mo ago
just getting started here
Brody
Brodyโ€ข8mo 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
macwilkoโ€ข8mo 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โ€ข8mo ago
looks good to me
macwilko
macwilkoโ€ข8mo ago
any idea what the Environment_ID might be? I'm guessing it's "Production" Project ID i got
macwilko
macwilkoโ€ข8mo ago
No description
Brody
Brodyโ€ข8mo ago
it would be uuid for the environment within the project you want to create a service in
macwilko
macwilkoโ€ข8mo ago
ahh
macwilko
macwilkoโ€ข8mo ago
No description
macwilko
macwilkoโ€ข8mo ago
found it
Brody
Brodyโ€ข8mo ago
so since you are deploying into the same environment using that environment variable is perfect
macwilko
macwilkoโ€ข8mo 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โ€ข8mo ago
you can have a staging environment with ruby apps too, just sleep them
macwilko
macwilkoโ€ข8mo ago
true I'm doing something wrong but not sure what the issue is
macwilko
macwilkoโ€ข8mo ago
No description
macwilko
macwilkoโ€ข8mo 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โ€ข8mo ago
what type of token did you create?
macwilko
macwilkoโ€ข8mo ago
No description
Brody
Brodyโ€ข8mo ago
all that looks fine, can you show me how you are using the client?
macwilko
macwilkoโ€ข8mo ago
ok
macwilko
macwilkoโ€ข8mo ago
No description
macwilko
macwilkoโ€ข8mo ago
No description
Brody
Brodyโ€ข8mo ago
well you dont want to add a repo at that stage as for the unauthed, i have no clue
macwilko
macwilkoโ€ข8mo 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โ€ข8mo ago
empty service
macwilko
macwilkoโ€ข8mo ago
i see
Brody
Brodyโ€ข8mo ago
you have never created one of those in the UI?
macwilko
macwilkoโ€ข8mo ago
Source: &railway.ServiceSourceInput{},
Source: &railway.ServiceSourceInput{},
same error ๐Ÿ˜ฆ
Brody
Brodyโ€ข8mo ago
i better start coding
macwilko
macwilkoโ€ข8mo ago
no don't leave me
Brody
Brodyโ€ข8mo ago
code to solve this
macwilko
macwilkoโ€ข8mo 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โ€ข8mo ago
it will, ill see what i can whip up what are you using the service query for though?
macwilko
macwilkoโ€ข8mo 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โ€ข8mo ago
use a webhook
macwilko
macwilkoโ€ข8mo ago
oo yeah i'll use a webhook
Brody
Brodyโ€ข8mo ago
the webhook you set in the project will send you a request for each stage
macwilko
macwilkoโ€ข8mo ago
ok alright its nearly 2am here and i better sleep >.<
Brody
Brodyโ€ข8mo ago
ill have some example code for you
macwilko
macwilkoโ€ข8mo ago
will be hyped to wake up to that then! thankyou for the help today brody!!
Brody
Brodyโ€ข8mo ago
macwilko
macwilkoโ€ข8mo 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โ€ข8mo 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
macwilkoโ€ข8mo ago
gotcha thankyou Sang
Brody
Brodyโ€ข8mo ago
use a team token when manipulating stuff on a team, use a personal token when manipulating stuff on the personal account
macwilko
macwilkoโ€ข8mo ago
@Brody thats the weird. thing its resources within the team thats why I was so surprised
Brody
Brodyโ€ข8mo ago
interesting
macwilko
macwilkoโ€ข8mo ago
let me show you
Brody
Brodyโ€ข8mo ago
I believe you
macwilko
macwilkoโ€ข8mo ago
No description
macwilko
macwilkoโ€ข8mo ago
thats the team project
macwilko
macwilkoโ€ข8mo ago
these tokens (from project settings in the team) don't work
No description
Brody
Brodyโ€ข8mo ago
that's a project token that I know for sure wouldn't work for what you are doing
macwilko
macwilkoโ€ข8mo ago
honestly no idea but Railway doesn't make that clear at all
Brody
Brodyโ€ข8mo ago
that's fair you don't know what token can do what
macwilko
macwilkoโ€ข8mo ago
pretty much it's all working great though now but figured i'de let you know
Brody
Brodyโ€ข8mo ago
was the code I wrote useful?
macwilko
macwilkoโ€ข8mo ago
super useful
Brody
Brodyโ€ข8mo ago
awesome
macwilko
macwilkoโ€ข8mo ago
i'm gonna use App sleeping also to keep the costs down, I think this will be an excellent improvement
Brody
Brodyโ€ข8mo ago
I had to fork the graphql generator library lol
macwilko
macwilkoโ€ข8mo 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โ€ข8mo ago
yeah, the original library would send empty fields to the backboard instead of omitting them
macwilko
macwilkoโ€ข8mo 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โ€ข8mo 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
macwilkoโ€ข8mo ago
if the field has a ! in it, it will be required to send something
Brody
Brodyโ€ข8mo ago
there was tags that didn't have a ! that weren't being marked as non required for some reason
macwilko
macwilkoโ€ข8mo ago
damn >.< well props for fixing that, I might have to use your fork
Brody
Brodyโ€ข8mo 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
macwilkoโ€ข8mo ago
No description
macwilko
macwilkoโ€ข8mo ago
this part is working ok but I havent done service instance yet
Brody
Brodyโ€ข8mo 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
macwilkoโ€ข8mo 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โ€ข8mo ago
I have no clue how fields don't have omitempty by default, every api request railways dashboard makes omits empty fields
macwilko
macwilkoโ€ข8mo ago
it had decorators for generating the types
Brody
Brodyโ€ข8mo ago
does this work? it threw errors when I tried to use this to set fields omitempty value
macwilko
macwilkoโ€ข8mo 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
macwilkoโ€ข8mo 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โ€ข8mo ago
yep and that's why I needed to fork, we can't wait for a fix
macwilko
macwilkoโ€ข8mo ago
use_struct_references: true
use_extensions: true
optional: pointer
use_struct_references: true
use_extensions: true
optional: pointer
Brody
Brodyโ€ข8mo ago
but then it will just send null, that would likely just break other things
macwilko
macwilkoโ€ข8mo ago
No description
macwilko
macwilkoโ€ข8mo ago
nil would be fine i will try it one sec
Brody
Brodyโ€ข8mo ago
null* this is json but this means you have to have pointers to strings, not ideal from a development standpoint
macwilko
macwilkoโ€ข8mo ago
No description
macwilko
macwilkoโ€ข8mo ago
this should be fine, i've not seen a graphql server not handle null before
Brody
Brodyโ€ข8mo 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
macwilkoโ€ข8mo 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โ€ข8mo ago
why did you turn on use_extensions though? this is fun for me too!
macwilko
macwilkoโ€ข8mo 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โ€ข8mo ago
I think it's like 1000 api calls per hour? yes it is
macwilko
macwilkoโ€ข8mo 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โ€ข8mo ago
yeah that's plenty for now business class when?
macwilko
macwilkoโ€ข8mo ago
hehe can't wait to show you the MVP ^.^
Brody
Brodyโ€ข8mo ago
MVP?
macwilko
macwilkoโ€ข8mo 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โ€ข8mo ago
more apps are more better
macwilko
macwilkoโ€ข8mo ago
yeah