Skip to content

Commit

Permalink
provision/dockercommon: default values for docker:user and docker:uid
Browse files Browse the repository at this point in the history
  • Loading branch information
cezarsa committed Jun 20, 2017
1 parent 9608145 commit 66d85c2
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
13 changes: 11 additions & 2 deletions docs/reference/config.rst
Expand Up @@ -883,8 +883,17 @@ default value expected by platforms defined in tsuru's basebuilder repository is
docker:user
+++++++++++

The user tsuru will use to start the container. The value expected for
basebuilder platforms is ``ubuntu``.
The user tsuru will use to start the container. The default value is
``ubuntu``, which is the expected value for default tsuru platforms. An empty
for this will make tsuru use the platform image user.

docker:uid
+++++++++++

The user ID tsuru will use to start the container in provisioners that do not
support ``docker:user``. The default value is ``1000``, which is the expected
value for default tsuru platforms. The value ``-1`` can be used to make tsuru
use the platform image user.

.. _config_healing:

Expand Down
19 changes: 16 additions & 3 deletions provision/dockercommon/deploy.go
Expand Up @@ -12,6 +12,11 @@ import (
"github.com/tsuru/config"
)

const (
defaultUsername = "ubuntu"
defaultUserID = 1000
)

func writeTarball(tarball *tar.Writer, archive io.Reader, fileSize int64, name string) error {
header := tar.Header{
Name: name,
Expand Down Expand Up @@ -47,12 +52,20 @@ func AddDeployTarFile(archive io.Reader, fileSize int64, name string) io.ReadClo
func UserForContainer() (username string, uid *int64) {
userid, err := config.GetInt("docker:uid")
if err == nil {
userid64 := int64(userid)
uid = &userid64
if userid >= 0 {
userid64 := int64(userid)
uid = &userid64
}
} else {
defUID := int64(defaultUserID)
uid = &defUID
}
username, err = config.GetString("docker:user")
if err != nil {
username, _ = config.GetString("docker:ssh:user")
username, err = config.GetString("docker:ssh:user")
if err != nil {
username = defaultUsername
}
}
return username, uid
}
25 changes: 20 additions & 5 deletions provision/dockercommon/deploy_test.go
Expand Up @@ -10,8 +10,24 @@ import (
)

func (s *S) TestUserForContainerEmpty(c *check.C) {
u, uid := UserForContainer()
c.Assert(u, check.Equals, "ubuntu")
c.Assert(*uid, check.Equals, int64(1000))
}

func (s *S) TestUserForContainerExplicitEmpty(c *check.C) {
defer config.Unset("docker:user")
config.Set("docker:user", "")
u, uid := UserForContainer()
c.Assert(u, check.Equals, "")
c.Assert(*uid, check.Equals, int64(1000))
}

func (s *S) TestUserForContainerExplicitNegative(c *check.C) {
defer config.Unset("docker:uid")
config.Set("docker:uid", -1)
u, uid := UserForContainer()
c.Assert(u, check.Equals, "ubuntu")
c.Assert(uid, check.IsNil)
}

Expand All @@ -21,19 +37,18 @@ func (s *S) TestUserForContainerOnlyUsername(c *check.C) {
config.Set("docker:ssh:user", "iskaralpust")
u, uid := UserForContainer()
c.Assert(u, check.Equals, "iskaralpust")
c.Assert(uid, check.IsNil)
c.Assert(*uid, check.Equals, int64(1000))
config.Set("docker:user", "kruppe")
u, uid = UserForContainer()
c.Assert(u, check.Equals, "kruppe")
c.Assert(uid, check.IsNil)
c.Assert(*uid, check.Equals, int64(1000))
}

func (s *S) TestUserForContainerOnlyUID(c *check.C) {
config.Set("docker:uid", 1000)
defer config.Unset("docker:uid")
u, uid := UserForContainer()
c.Assert(u, check.Equals, "")
expectedUid := int64(1000)
c.Assert(u, check.Equals, "ubuntu")
c.Assert(uid, check.NotNil)
c.Assert(*uid, check.Equals, expectedUid)
c.Assert(*uid, check.Equals, int64(1000))
}

0 comments on commit 66d85c2

Please sign in to comment.