Skip to content
This repository was archived by the owner on Apr 24, 2021. It is now read-only.

Commit 5ced8ab

Browse files
authored
Merge pull request #16 from dgraph-io/arpan/dedicated-deployment
feat: Dedicated deployments
2 parents a26ac03 + f935225 commit 5ced8ab

5 files changed

Lines changed: 58 additions & 24 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,4 +563,4 @@ EXAMPLE
563563
```
564564

565565
_See code: [src/commands/update-schema.ts](https://github.com/dgraph-io/slash-graphql-cli/blob/v1.16.7/src/commands/update-schema.ts)_
566-
<!-- commandsstop -->
566+
<!-- commandsstop -->

src/commands/deploy-backend.ts

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,26 @@ import sleep = require('sleep-promise')
66

77
const defaultRegion: Record<string, string> = {dev: 'us-test-1', stg: 'us-east-1', prod: 'us-west-2'}
88

9+
const CREATE_DEPLOYMENT = `
10+
mutation CreateDeployment($dep: NewDeployment!) {
11+
createDeployment(input: $dep) {
12+
uid
13+
name
14+
url
15+
owner
16+
jwtToken
17+
deploymentMode
18+
lambdaScript
19+
}
20+
}
21+
`;
22+
923
export default class DeployBackend extends BaseCommand {
1024
static description = 'Launch a new Backend'
1125

1226
static examples = [
1327
'$ slash-graphql deploy-backend "My New Backend"',
28+
'$ slash-graphql deploy-backend "My New Backend"',
1429
]
1530

1631
static aliases = ['create-backend', 'launch-backend']
@@ -21,47 +36,63 @@ export default class DeployBackend extends BaseCommand {
2136
organizationId: flags.string({char: 'o', description: 'Organization ID', default: ''}),
2237
subdomain: flags.string({char: 's', description: 'Subdomain'}),
2338
mode: flags.string({char: 'm', description: 'Backend Mode', default: 'graphql', options: ['readonly', 'graphql', 'flexible']}),
39+
type: flags.string({char: 'T', description: 'Backend Type', default: 'slash-graphql', options: ['slash-graphql', 'dedicated']}),
40+
jaeger: flags.string({description: 'Enable Jaeger (Only works for dedicated backends)', default: 'false', options: ['true', 'false']}),
41+
acl: flags.string({description: 'Enable ACL (Only works for dedicated backends)', default: 'false', options: ['true', 'false']}),
42+
dgraphHA: flags.string({description: 'Enable High Availability (Only works for dedicated backends)', default: 'false', options: ['true', 'false']}),
43+
size: flags.string({description: 'Backend Size (Only Works for dedicated backends)', default: 'small', options: ['small', 'medium', 'large', 'xlarge']}),
44+
storage: flags.integer({description: 'Alpha Storage in GBs - Accepts Only Integers (Only Works for dedicated backends)', default: 10}),
45+
dataFile: flags.string({description: 'Data File Path for Bulk Loader (Only works for dedicated backends)', default: ''}),
46+
schemaFile: flags.string({description: 'Dgraph Schema File Path for Bulk Loader (Only works for dedicated backends)', default: ''}),
47+
gqlSchemaFile: flags.string({description: 'GQL Schema File Path for Bulk Loader (Only works for dedicated backends)', default: ''}),
2448
}
2549

2650
static args = [{name: 'name', description: 'Backend Name', required: true}]
2751

2852
async run() {
2953
const opts = this.parse(DeployBackend)
30-
const {apiServer, authFile} = getEnvironment(opts.flags.environment)
54+
const {apiServer, authFile, deploymentProtocol} = getEnvironment(opts.flags.environment)
3155

3256
const token = await this.getAccessToken(apiServer, authFile)
3357

3458
if (!token) {
3559
this.error('Please login with `slash-graphql login` before creating a backend')
3660
}
3761

38-
const response = await fetch(`${apiServer}/deployments/create`, {
39-
method: 'POST',
40-
headers: {
41-
'Content-Type': 'application/json',
42-
Authorization: `Bearer ${token}`,
43-
},
44-
body: JSON.stringify({
62+
const {errors, data} = await this.sendGraphQLRequest(apiServer, token, CREATE_DEPLOYMENT, {
63+
dep: {
4564
name: opts.args.name,
4665
zone: opts.flags.region || defaultRegion[opts.flags.environment],
4766
subdomain: opts.flags.subdomain,
4867
deploymentMode: opts.flags.mode,
49-
organizationId: opts.flags.organizationId,
50-
}),
68+
organizationUID: opts.flags.organizationId === "" ? null : opts.flags.organizationId,
69+
enterprise: opts.flags.type === "dedicated" ? "true" : "false",
70+
size: opts.flags.size,
71+
storage: opts.flags.storage,
72+
aclEnabled: opts.flags.acl,
73+
jaegerEnabled: opts.flags.jaeger,
74+
dgraphHA: opts.flags.dgraphHA,
75+
bulkLoadSchemaFilePath: opts.flags.schemaFile,
76+
bulkLoadGQLSchemaFilePath: opts.flags.gqlSchemaFile,
77+
bulkLoadDataFilePath: opts.flags.dataFile,
78+
},
5179
})
52-
if (response.status !== 200) {
53-
this.error(`Unable to create backend. ${response.status} ${await response.text()}`)
80+
if (errors) {
81+
for (const {message} of errors) {
82+
this.error("Unable to create backend. " + message)
83+
}
84+
return
5485
}
55-
const deployment = await response.json() as APIBackend
56-
const endpoint = `https://${deployment.url}/graphql`
86+
87+
const deployment = data.createDeployment as APIBackend
88+
const endpoint = `${deploymentProtocol}://${deployment.url}/graphql`
5789

5890
if (!opts.flags.quiet) {
5991
this.log(`Waiting for backend to come up at ${endpoint}`)
6092
}
6193

6294
await this.pollForEndpoint(endpoint)
63-
64-
this.log(endpoint)
95+
this.log(`Deployment Launched at: ${endpoint}`)
6596
}
6697

6798
async pollForEndpoint(endpoint: string, endTime = new Date(new Date().getTime() + (120 * 1000))) {
@@ -79,6 +110,6 @@ export default class DeployBackend extends BaseCommand {
79110

80111
sleep(5000)
81112
}
82-
this.error('Gave up waiting for backend after 2 minutes')
113+
this.error("Looks like your backend is taking longer than usual to come up. If you are bulk loading, then it might take a little more time based on your data size.")
83114
}
84115
}

src/commands/list-backends.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default class ListBackends extends BaseCommand {
1717

1818
async run() {
1919
const opts = this.parse(ListBackends)
20-
const {apiServer, authFile} = getEnvironment(opts.flags.environment)
20+
const {apiServer, authFile, deploymentProtocol} = getEnvironment(opts.flags.environment)
2121

2222
const token = await this.getAccessToken(apiServer, authFile)
2323
if (!token) {
@@ -50,7 +50,7 @@ export default class ListBackends extends BaseCommand {
5050
extended: true,
5151
},
5252
endpoint: {
53-
get: ({url}) => `https://${url}/graphql`,
53+
get: ({url}) => `${deploymentProtocol}://${url}/graphql`,
5454
},
5555
}, {
5656
printLine: this.log,

src/lib/environments.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ const environments = {
22
stg: {
33
apiServer: 'https://api.thegaas.com',
44
authFile: 'auth-stg.yml',
5+
deploymentProtocol: 'https',
56
},
67
dev: {
78
apiServer: 'http://localhost:8070',
89
authFile: 'auth-stg.yml',
10+
deploymentProtocol: 'http',
911
},
1012
prod: {
1113
apiServer: 'https://api.cloud.dgraph.io',
1214
authFile: 'auth.yml',
15+
deploymentProtocol: 'https',
1316
},
1417
}
1518

src/lib/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ export abstract class BaseCommand extends Command {
6262
}
6363

6464
async backendFromOpts(opts: Output<{ endpoint: string | undefined; token: string | undefined; environment: string }, any>): Promise<Backend> {
65-
const {apiServer, authFile} = getEnvironment(opts.flags.environment)
66-
const endpoint = await this.convertToGraphQLEndpoint(apiServer, authFile, opts.flags.endpoint)
65+
const {apiServer, authFile, deploymentProtocol} = getEnvironment(opts.flags.environment)
66+
const endpoint = await this.convertToGraphQLEndpoint(apiServer, authFile, deploymentProtocol, opts.flags.endpoint)
6767
if (!endpoint) {
6868
this.error('Please pass an endpoint or cluster id with the -e flag')
6969
}
@@ -207,7 +207,7 @@ export abstract class BaseCommand extends Command {
207207
return backends.find(backend => backend.url === hotname) || null
208208
}
209209

210-
async convertToGraphQLEndpoint(apiServer: string, authFile: string, endpoint: string | undefined): Promise<string | null> {
210+
async convertToGraphQLEndpoint(apiServer: string, authFile: string, deploymentProtocol: string, endpoint: string | undefined): Promise<string | null> {
211211
if (!endpoint) {
212212
return null
213213
}
@@ -227,7 +227,7 @@ export abstract class BaseCommand extends Command {
227227
this.error(`Cannot find backend ${endpoint}`)
228228
}
229229

230-
return `https://${backend.url}/graphql`
230+
return `${deploymentProtocol}://${backend.url}/graphql`
231231
}
232232

233233
async convertToGraphQLUid(apiServer: string, authFile: string, endpoint: string | undefined): Promise<string | null> {

0 commit comments

Comments
 (0)