Open bromanko opened 2 years ago
Let's sort out the queries first.
I can write a single Graphql query to check if the app, volume, and machine are all setup.
query($appName: String!) {
app(name: $appName) {
appUrl,
createdAt,
deployed,
hostname,
id,
name,
organization { id, name }
regions { name, code },
status,
machines {
nodes {
name
id
ips {
nodes {
id
ip
kind
family
}
}
}
},
volumes {
nodes {
id
name
sizeGb
state
status
usedBytes
}
}
}
}
Keeping in mind "functional core, imperative shell" I'll use the single query as the source of truth for further logic. Create a data structure that represents the corresponding mutations to make, then aggregate the results in a response data structure.
let mkMutations qry =
let mutations = []
match qry.app with
| None -> mutations ++ [mkApp; mkVolume; mkMachine]
| Some { app.volumes.Length <= 0 } -> mutations ++ [mkVolume]
| Some { app.machines.Length <= 0 } -> mutations ++ [mkMachine]
mutations
let client = mkClient "token"
client.GetApp "app-name"
|> mkMutations
|> execMutations
|> updateDb
For the mkMachine
call, this should update the deployment to the latest version if the machine exists.
createApp
Create the appcreateVolume
Create the volumelaunchMachine
looks to be the correct call to create the machinedeployImage
looks like the way to update the current deployment. I can probably avoid this call if the image is the same as what is deployed.At this point I don't have a use for storing information about the deployment. I'm not going to.
Turns out I can't use the Graphql api to create the machine deployment. This must be done with the REST api:
An unexpected error occurred. The launchMachine endpoint has reached its EOL. Please visit https://fly.io/docs/reference/machines/ for more information on how to leverage our new Machines API!
I'll make a REST API client for these two calls.
I need to pass the deployment configuration to machines. I think I'd prefer this to be stored as a json file for ease of use.
I'll make a command that will be executed via a forthcoming task runner. The command needs to be idempotent. It's similar to the
deploy-admin-server.sh
script used to deploy the admin app; difference being the deployed image will be prebuilt and configured as part of the task-runner configuration.I'll name the command
DeployConsumerServer
since that's what I've called the consumer-facing server. I chose this overDeployTenant
since I anticipate tenants may have multiple components which will be deployed separately.App naming
Fly.io apps need a unique name. I'll use the tenant
fqdn
as the name.Pseudo code