Vojtěch Bartoš
Vojtěch Bartoš

Reputation: 213

TravisCI Docker Permissions

I use Docker to run my PHP app. Now I want Travis CI to test my app. But all my builds fail, because containers can not open files in /temp directory of my app.

I have data container:

FROM ubuntu

COPY ./ /project
VOLUME /project

CMD ["true"]

I use my own PHP fpm container based on php:7.0-fpm - only with some extensions installed. Same for nginx.

My docker compose looks like this

version: '2'
services:
  data:
    build: ./
    volumes:
      - .:/project
    command: "true"
  nginx:
    image: myNginx
    ports:
      - "80:80"
      - "443:443"
    volumes_from:
      - data
    links:
      - php
  php:
    image: myPhp
    ports:
      - "9000:9000"
    volumes_from:
      - data

You can see that I use shared volume with host. Everything works on my local machine (windows) but not on travis.

And finaly my travis.yml

sudo: required

language: php

services:
  - docker

before_script:
  - docker-compose up --build -d
  # Run firefox
  - docker run -d -p 4444:4444 -p 5900:5900 --name firefox --link my_nginx:nginx --net myapp_default selenium/standalone-firefox-debug:2.53.0

script:
  # Run Codeception
  - docker run --rm --volumes-from my_data --link firefox --net myapp_default --name codeception codeception/codeception run accept

All codeception tests fails because app can not write to /log and can not open files in /temp. It is interesting because it writes some files but later it can not open it.

I ls -la with result:

# ./temp
drwxrwxr-x  3 travis travis 4096 Nov  4 15:55 .
drwxrwxr-x 14 travis travis 4096 Nov  4 15:56 ..
drwxr-xr-x  4 root   root   4096 Nov  4 15:55 cache
-rw-rw-r--  1 travis travis   14 Nov  4 15:49 .gitignore

# ./temp/cache
drwxr-xr-x 4 root   root   4096 Nov  4 15:55 .
drwxrwxr-x 3 travis travis 4096 Nov  4 15:55 ..
drwxr-xr-x 2 root   root   4096 Nov  4 15:55 Nette.Configurator
drwxr-xr-x 2 root   root   4096 Nov  4 15:55 _Nette.RobotLoader

# ./temp/cache/Nette.Configurator
drwxr-xr-x 2 root root   4096 Nov  4 15:55 .
drwxr-xr-x 4 root root   4096 Nov  4 15:55 ..
-rw-r--r-- 1 root root 116093 Nov  4 15:55 Container_70d15d6361.php
-rw-r--r-- 1 root root      0 Nov  4 15:55 Container_70d15d6361.php.lock
-rw-r--r-- 1 root root  52913 Nov  4 15:55 Container_70d15d6361.php.meta

I ma pretty sure that I have bad permissions set in travis or in container, but I don`t know how to fix it.

Upvotes: 3

Views: 1771

Answers (1)

Alex Hurst
Alex Hurst

Reputation: 184

The files that Travis pulls will be owned by the travis user and group, while the processes running inside the container expect the active user to be the owner. I had this issue with a docker-compose file that was running fine on my Mac, but failed on Travis.

For me, this was fixed by adding this to the install step in my .travis.yaml (edit: you'll probably want it in your before_script section instead):

install
    - docker-compose run --user='root' --entrypoint chown worker_test -R myuser:myuser .

This writeup on UID/GID bits was helpful: Understanding user file ownership in docker: how to avoid changing permissions of linked volumes

Upvotes: 4

Related Questions