Skip to content

Commit 6b9b76d

Browse files
author
Matthew Fisher
committed
Merge pull request #3374 from bacongobbler/1532-add-config-push
feat(client): add deis config:push
2 parents 90e3f2e + ad8c62b commit 6b9b76d

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

client/deis.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,7 @@ def config(self, args):
984984
config:set set environment variables for an app
985985
config:unset unset environment variables for an app
986986
config:pull extract environment variables to .env
987+
config:push set environment variables from .env
987988
988989
Use `deis help [command]` to learn more.
989990
"""
@@ -1184,6 +1185,30 @@ def config_pull(self, args):
11841185
else:
11851186
raise ResponseError(response)
11861187

1188+
def config_push(self, args):
1189+
"""
1190+
Sets environment variables for an application.
1191+
1192+
Your environment is read from a file named .env. This file can be
1193+
read by foreman to load the local environment for your app.
1194+
1195+
Usage: deis config:push [options]
1196+
1197+
Options:
1198+
-a --app=<app>
1199+
the uniquely identifiable name for the application.
1200+
"""
1201+
app = args.get('--app')
1202+
if not app:
1203+
app = self._session.app
1204+
# read from .env
1205+
try:
1206+
with open('.env', 'r') as f:
1207+
self._config_set(app, dictify([line.strip() for line in f]))
1208+
except IOError:
1209+
self._logger.error('could not read from local env')
1210+
sys.exit(1)
1211+
11871212
def domains(self, args):
11881213
"""
11891214
Valid commands for domains:

tests/config_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package tests
44

55
import (
6+
"io/ioutil"
67
"testing"
78

89
"github.com/deis/deis/tests/utils"
@@ -20,6 +21,7 @@ var (
2021
func TestConfig(t *testing.T) {
2122
params := configSetup(t)
2223
configSetTest(t, params)
24+
configPushTest(t, params)
2325
configListTest(t, params, false)
2426
appsOpenTest(t, params)
2527
configUnsetTest(t, params)
@@ -69,8 +71,23 @@ func configSetTest(t *testing.T, params *utils.DeisTestConfig) {
6971
utils.CheckList(t, appsInfoCmd, params, "(v6)", false)
7072
}
7173

74+
func configPushTest(t *testing.T, params *utils.DeisTestConfig) {
75+
if err := utils.Chdir(params.ExampleApp); err != nil {
76+
t.Fatal(err)
77+
}
78+
// create a .env in the project root
79+
if err := ioutil.WriteFile(".env", []byte("POWERED_BY=Deis"), 0664); err != nil {
80+
t.Fatal(err)
81+
}
82+
utils.Execute(t, "config:push --app {{.AppName}}", params, false, "Deis")
83+
utils.CheckList(t, appsInfoCmd, params, "(v7)", false)
84+
if err := utils.Chdir(".."); err != nil {
85+
t.Fatal(err)
86+
}
87+
}
88+
7289
func configUnsetTest(t *testing.T, params *utils.DeisTestConfig) {
7390
utils.Execute(t, configUnsetCmd, params, false, "")
74-
utils.CheckList(t, appsInfoCmd, params, "(v7)", false)
91+
utils.CheckList(t, appsInfoCmd, params, "(v8)", false)
7592
utils.CheckList(t, "run env --app={{.AppName}}", params, "FOO", true)
7693
}

0 commit comments

Comments
 (0)