Skip to content

Commit

Permalink
Make web container .my.cnf read-only so mysql will use it, fixes #944 (
Browse files Browse the repository at this point in the history
  • Loading branch information
rfay committed Jul 5, 2018
1 parent e7cc6eb commit 8f95676
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
4 changes: 3 additions & 1 deletion containers/nginx-php-fpm-local/Dockerfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ RUN chmod -R 777 /var/log

RUN chmod -R ugo+w /usr/sbin /usr/bin /etc/nginx /var/cache/nginx /run /var/www /etc/php/*/*/conf.d/ /var/lib/php/modules /etc/alternatives /usr/lib/node_modules /etc/php
# All users will have their home directory in /home, make it fully writeable
RUN mkdir -p /home/.composer/cache /home/.drush/commands /home/.drush/aliases && chmod -R ugo+rw /home
RUN mkdir -p /home/.composer/cache /home/.drush/commands /home/.drush/aliases && chmod -R ugo+rw /home
# Except that .my.cnf can't be writeable or mysql won't use it.
RUN chmod 444 /home/.my.cnf

RUN touch /var/log/nginx/error.log /var/log/nginx/access.log /var/log/php-fpm.log && \
chmod 666 /var/log/nginx/error.log /var/log/nginx/access.log /var/log/php-fpm.log
Expand Down
34 changes: 34 additions & 0 deletions pkg/ddevapp/ddevapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,40 @@ func TestDdevXdebugEnabled(t *testing.T) {

}

// TestDdevMysqlWorks tests that mysql client can be run in both containers.
func TestDdevMysqlWorks(t *testing.T) {
assert := asrt.New(t)
app := &ddevapp.DdevApp{}

site := TestSites[0]
runTime := testcommon.TimeTrack(time.Now(), fmt.Sprintf("%s DdevMysqlWorks", site.Name))

err := app.Init(site.Dir)
assert.NoError(err)

testcommon.ClearDockerEnv()
err = app.Start()
assert.NoError(err)

// Test that mysql + .my.cnf works on web container
_, _, err = app.Exec("web", "bash", "-c", "mysql -e 'SELECT USER();' | grep 'db@'")
assert.NoError(err)
_, _, err = app.Exec("web", "bash", "-c", "mysql -e 'SELECT DATABASE();' | grep 'db'")
assert.NoError(err)

// Test that mysql + .my.cnf works on db container
_, _, err = app.Exec("db", "bash", "-c", "mysql -e 'SELECT USER();' | grep 'root@localhost'")
assert.NoError(err)
_, _, err = app.Exec("db", "bash", "-c", "mysql -e 'SELECT DATABASE();' | grep 'db'")
assert.NoError(err)

err = app.Stop()
assert.NoError(err)

runTime()

}

// TestStartWithoutDdev makes sure we don't have a regression where lack of .ddev
// causes a panic.
func TestStartWithoutDdevConfig(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var DockerComposeVersionConstraint = ">= 1.18.0-alpha1"
var WebImg = "drud/nginx-php-fpm-local"

// WebTag defines the default web image tag for drud dev
var WebTag = "v0.20.0" // Note that this can be overridden by make
var WebTag = "20180628_fix_writeable_my_conf" // Note that this can be overridden by make

// DBImg defines the default db image used for applications.
var DBImg = "drud/mariadb-local"
Expand Down

0 comments on commit 8f95676

Please sign in to comment.