Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make default image and size match the blog post #359

Merged
merged 1 commit into from
Mar 8, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions src/cloud/digitalocean/provisioner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ declare var forge: any;

const POLL_TIMEOUT: number = 5000; //milliseconds

// To see available regions:
// https://developers.digitalocean.com/documentation/v2/#list-all-regions
const DEFAULT_REGION: string = 'nyc3';
// This is the image and size recommended by the blog post.
// The only way to see the complete current list of options for each
// is by querying the API, e.g.:
// this.doRequest_('GET', 'images?per_page=100').then((resp: any) => {
// console.log('available images: ' + JSON.stringify(resp, undefined, 2));
// });
const DEFAULT_REGION: string = 'nyc1';
const DEFAULT_IMAGE: string = 'ubuntu-14-04-x64';
const DEFAULT_SIZE: string = '1gb';

const STATUS_CODES: { [k: string]: string; } = {
'START': 'Starting provisioner',
Expand Down Expand Up @@ -54,8 +60,7 @@ class Provisioner {
* @param {String} region to create VM in
* @return {Promise.<Object>}
*/
public start = (name: string, region: string = DEFAULT_REGION) :
Promise<Object> => {
public start = (name: string, region = DEFAULT_REGION, image = DEFAULT_IMAGE, size = DEFAULT_SIZE): Promise<Object> => {
this.sendStatus_('START');
// Do oAuth
return this.doOAuth_().then((oauthObj: any) => {
Expand All @@ -64,7 +69,7 @@ class Provisioner {
// Get SSH keys
}).then((keys: KeyPair) => {
this.state_.ssh = keys;
return this.setupDigitalOcean_(name, region);
return this.setupDigitalOcean_(name, region, image, size);
// Setup Digital Ocean (SSH key + droplet)
}).then(() => {
return this.doRequest_('GET', 'droplets/' + this.state_.cloud.vm.id);
Expand Down Expand Up @@ -309,8 +314,7 @@ class Provisioner {
* @param {String} region to create VM in
* @return {Promise.<void>} resolves on success, rejects on failure
*/
private setupDigitalOcean_ = (name: string, region: string) :
Promise<void> => {
private setupDigitalOcean_ = (name: string, region: string, image: string, size: string): Promise<void> => {
return new Promise<void>((F, R) => {
this.state_.cloud = {};
this.sendStatus_('CLOUD_INIT_ADDKEY');
Expand Down Expand Up @@ -347,13 +351,8 @@ class Provisioner {
return this.doRequest_('POST', 'droplets', JSON.stringify({
name: name,
region: region,
size: '512mb',
// 'docker' is a slug name, a.k.a. application image, a.k.a. one-click app.
// The full list of available slugs is available only through the API, e.g.:
// this.doRequest_('GET', 'images?type=application&per_page=50').then((resp: any) => {
// console.log('available application images: ' + JSON.stringify(resp, undefined, 2));
// });
image: 'docker',
size: size,
image: image,
ssh_keys: [ this.state_.cloud.ssh.id ]
}));
// If missing, create the droplet
Expand Down