Skip to content

Commit a5f6822

Browse files
author
Matthew Fisher
committed
Merge pull request #2720 from bacongobbler/create-with-buildpack
feat(client): add --buildpack option to `deis create`
2 parents 0ad398f + b34e1c2 commit a5f6822

2 files changed

Lines changed: 53 additions & 35 deletions

File tree

client/deis.py

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,9 @@ def apps_create(self, args):
444444
Options:
445445
--no-remote
446446
do not create a `deis` git remote.
447+
448+
-b --buildpack BUILDPACK
449+
a buildpack url to use for this app
447450
"""
448451
body = {}
449452
app_name = None
@@ -464,31 +467,36 @@ def apps_create(self, args):
464467
finally:
465468
progress.cancel()
466469
progress.join()
467-
if response.status_code == requests.codes.created:
468-
data = response.json()
469-
app_id = data['id']
470-
self._logger.info("done, created {}".format(app_id))
471-
# set a git remote if necessary
472-
try:
473-
self._session.git_root()
474-
except EnvironmentError:
475-
return
476-
hostname = urlparse.urlparse(self._settings['controller']).netloc.split(':')[0]
477-
git_remote = "ssh://git@{hostname}:2222/{app_id}.git".format(**locals())
478-
if args.get('--no-remote'):
479-
self._logger.info('remote available at {}'.format(git_remote))
480-
else:
481-
try:
482-
subprocess.check_call(
483-
['git', 'remote', 'add', '-f', 'deis', git_remote],
484-
stdout=subprocess.PIPE)
485-
self._logger.info('Git remote deis added')
486-
except subprocess.CalledProcessError:
487-
self._logger.error('Could not create Deis remote')
488-
sys.exit(1)
489-
else:
470+
if response.status_code != requests.codes.created:
490471
raise ResponseError(response)
491472

473+
data = response.json()
474+
app_id = data['id']
475+
self._logger.info("done, created {}".format(app_id))
476+
477+
buildpack = args.get('--buildpack')
478+
if buildpack:
479+
self._config_set(app_id, {'BUILDPACK_URL': buildpack})
480+
481+
# set a git remote if necessary
482+
try:
483+
self._session.git_root()
484+
except EnvironmentError:
485+
return
486+
hostname = urlparse.urlparse(self._settings['controller']).netloc.split(':')[0]
487+
git_remote = "ssh://git@{hostname}:2222/{app_id}.git".format(**locals())
488+
if args.get('--no-remote'):
489+
self._logger.info('remote available at {}'.format(git_remote))
490+
else:
491+
try:
492+
subprocess.check_call(
493+
['git', 'remote', 'add', '-f', 'deis', git_remote],
494+
stdout=subprocess.PIPE)
495+
self._logger.info('Git remote deis added')
496+
except subprocess.CalledProcessError:
497+
self._logger.error('Could not create Deis remote')
498+
sys.exit(1)
499+
492500
def apps_destroy(self, args):
493501
"""
494502
Destroys an application.
@@ -1031,7 +1039,14 @@ def config_set(self, args):
10311039
app = args.get('--app')
10321040
if not app:
10331041
app = self._session.app
1034-
body = {'values': json.dumps(dictify(args['<var>=<value>']))}
1042+
values = dictify(args['<var>=<value>'])
1043+
self._config_set(app, values)
1044+
1045+
def _config_set(self, app, values):
1046+
"""
1047+
Internal logic to set environment variables for an application.
1048+
"""
1049+
body = {'values': json.dumps(values)}
10351050
sys.stdout.write('Creating config... ')
10361051
sys.stdout.flush()
10371052
try:

tests/apps_test.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ import (
1111
)
1212

1313
var (
14-
appsCreateCmd = "apps:create {{.AppName}}"
15-
appsCreateCmdNoRemote = "apps:create {{.AppName}} --no-remote"
16-
appsListCmd = "apps:list"
17-
appsRunCmd = "apps:run echo hello"
18-
appsOpenCmd = "apps:open --app={{.AppName}}"
19-
appsLogsCmd = "apps:logs --app={{.AppName}}"
20-
appsInfoCmd = "apps:info --app={{.AppName}}"
21-
appsDestroyCmd = "apps:destroy --app={{.AppName}} --confirm={{.AppName}}"
14+
appsCreateCmd = "apps:create {{.AppName}}"
15+
appsCreateCmdNoRemote = "apps:create {{.AppName}} --no-remote"
16+
appsCreateCmdBuildpack = "apps:create {{.AppName}} --buildpack https://example.com"
17+
appsListCmd = "apps:list"
18+
appsRunCmd = "apps:run echo hello"
19+
appsOpenCmd = "apps:open --app={{.AppName}}"
20+
appsLogsCmd = "apps:logs --app={{.AppName}}"
21+
appsInfoCmd = "apps:info --app={{.AppName}}"
22+
appsDestroyCmd = "apps:destroy --app={{.AppName}} --confirm={{.AppName}}"
2223
)
2324

2425
func randomString(n int) string {
@@ -56,9 +57,11 @@ func appsCreateTest(t *testing.T, params *utils.DeisTestConfig) {
5657
if err := utils.Chdir(params.ExampleApp); err != nil {
5758
t.Fatal(err)
5859
}
59-
cmd := appsCreateCmd
60-
utils.Execute(t, cmd, params, false, "")
61-
utils.Execute(t, cmd, params, true, "App with this Id already exists")
60+
// TODO: move --buildpack to client unit tests
61+
utils.Execute(t, appsCreateCmdBuildpack, params, false, "BUILDPACK_URL")
62+
utils.Execute(t, appsDestroyCmd, params, false, "")
63+
utils.Execute(t, appsCreateCmd, params, false, "")
64+
utils.Execute(t, appsCreateCmd, params, true, "App with this Id already exists")
6265
}
6366

6467
func appsDestroyTest(t *testing.T, params *utils.DeisTestConfig) {

0 commit comments

Comments
 (0)