我正在尝试在特拉维斯测试的安息书。这是travis.yml文件:
#sudo: required
TRAVIS_SECURE_ENV_VARS: true
language: python
python: 2.7
services:
- docker
env:
global:
secure: "BI6cUmDsExjZdmw2+xrDfyTS2+x5xk1c9kvVOinY57upNcoOsolFT6XPEsBUH6e2GzFyHWQJ96yco7wUlGGFrTfxqpRN48uIjvsepr1XaWeYFczl7yOaAJWvCFPuX51Swdsbw6EN3Djw3V2oYvANM96t+FYHW+OK1wsiGu2A9yvLbFxidiqZFP0MIyRTwxB8mnCm1ZUT1Cnu23fIVkUlzXkTpC06EymxWbdAWAFkmyjzoV0q5oosMrEJXelnC6ezOIV4PwrB5vHfe9q0CcssTGi6d3onDXeBL8x1I/ZYDp+J7xk/tfhDBNdcn3J2i2VJtcIuagbzv9NN/3x4yLNPEZ1N8so/yueVpsJdgqng+ef5opifm0btLfdaX5ZaammBnfrd8mSS+witzKqLllQges3Do1pcozPB534rxEQLYzvVjmoVtrdSM2xUP80biTpQ81q5Vt9/HROI2QPA1F/e2zIudKXxQSWrEsU89bSFTgYDzmkStEGcfom7GvyYEfbTaEZE6Hh2ofHo2EAEuNStAVazasozPDSrWBzT1g7T8no3UCv0bQQdrJ1ZGQ37MsaGoX/NfZS5qMhlNoZnNcAUrFz/A81OykUjJcnCxG8SSHgG6jNFFw1M+UyqjqI1Mv3abCdT8CbfcZvYDdNKPPobLxf+75KUr235/NlXetgiWnw="
before_install:
- openssl aes-256-cbc -K $encrypted_4e087206a019_key -iv $encrypted_4e087206a019_iv -in id_travis.enc -out id_travis -d
- openssl aes-256-cbc -K $encrypted_4e087206a019_key -iv $encrypted_4e087206a019_iv -in id_travis.enc -out id_travis -d
- sudo apt-get update
- sudo apt-get remove docker-engine -yq
- sudo apt-get install docker-engine="1.9.1-0~trusty" -yq --no-install-suggests --no-install-recommends --force-yes -o Dpkg::Options::="--force-confnew"
- docker pull censofdockers/centos6-miniconda
- docker pull censofdockers/ubuntu-miniconda
- CID=$(docker run --privileged --detach --volume="${PWD}":/root/django_deployment:rw -p 80 --name test_centos censofdockers/centos6-miniconda sleep 550)
- CID2=$(docker run --privileged --detach --volume="${PWD}":/root/django_deployment:rw -p 80 --name test_ubuntu censofdockers/ubuntu-miniconda sleep 550)
- DOCKER_IP=`docker inspect --format '{{ .NetworkSettings.IPAddress }}' ${CID}`
- DOCKER_IP2=`docker inspect --format '{{ .NetworkSettings.IPAddress }}' ${CID2}`
install:
- docker exec -it test_centos /bin/bash -c "chmod +x /root/django_deployment/installcentos.sh"
- docker exec -it test_centos /bin/bash -c "./root/django_deployment/installcentos.sh"
- docker exec -it test_ubuntu /bin/bash -c "chmod +x /root/django_deployment/installubuntu.sh"
- docker exec -it test_ubuntu /bin/bash -c "./root/django_deployment/installubuntu.sh"
- sudo apt-get install -y curl
- pip install selenium nose
script:
- docker ps
#- docker exec -it test_centos /bin/bash -c "git clone $DEPLOYMENT_URL"
#- docker exec -it test_centos /bin/bash -c "ls -al ~/.ssh/*"
#- docker exec -it test_ubuntu /bin/bash -c "rm /root/.ssh/authorized_keys"
#- docker exec -it test_ubuntu /bin/bash -c "ls -al ~/.ssh/*"
#- docker exec -it test_ubuntu /bin/bash -c "echo $DEPLOYMENT_URL"
#- docker exec -it test_ubuntu /bin/bash -c "git clone $DEPLOYMENT_URL"
- docker exec -it test_centos /bin/bash -c "export ECLAIM_BRANCH=${SHIPPABLE_ECLAIM_BRANCH:-staging} && export DEPLOYMENT_URL=$DEPLOYMENT_URL && /opt/miniconda2/bin/ansible-playbook -e 'django_app_home=/opt/eclaim_revamp/eclaim app_version=eclaim_revamp' -e 'db_server_ip=localhost' -i /root/django_deployment/django_app_server_db_server/deployment/tests/hosts /root/django_deployment/django_app_server_db_server/deployment/main.yml"
# && docker exec -it test_ubuntu /bin/bash -c "export ECLAIM_BRANCH=${SHIPPABLE_ECLAIM_BRANCH:-staging} && export DEPLOYMENT_URL=$DEPLOYMENT_URL && /opt/miniconda2/bin/ansible-playbook -e 'django_app_home=/opt/eclaim_revamp/eclaim app_version=eclaim_revamp' -e 'db_server_ip=localhost' -i /root/django_deployment/django_app_server_db_server/deployment/tests/hosts -v /root/django_deployment/django_app_server_db_server/deployment/main.yml"
- docker exec -it test_centos /bin/bash -c "/etc/rc.d/init.d/uwsgi stop && sleep 3 && /etc/rc.d/init.d/uwsgi start && source ~/.bash_profile && rspec /root/django_deployment/tests/spec/test_ansible_spec.rb" && DOCKER_IP=$DOCKER_IP nosetests -sv tests/python/verify_image.py
# - echo $TRAVIS_JOB_ID
- echo $DOCKER_IP
- DOCKER_IP=${DOCKER_IP} nosetests -sv tests/python/verify_image.py
#start ubuntu test
- docker exec -it test_ubuntu /bin/bash -c "export ECLAIM_BRANCH=${SHIPPABLE_ECLAIM_BRANCH:-staging} && export DEPLOYMENT_URL=$DEPLOYMENT_URL && /opt/miniconda2/bin/ansible-playbook -e 'django_app_home=/opt/eclaim_revamp/eclaim app_version=eclaim_revamp' -e 'db_server_ip=localhost' -i /root/django_deployment/django_app_server_db_server/deployment/tests/hosts /root/django_deployment/django_app_server_db_server/deployment/main.yml"
#- docker exec -it test_ubuntu /bin/bash -c "/etc/init.d/uwsgi stop && sleep 3 && /etc/init.d/uwsgi start && source ~/.bash_profile && rspec /root/django_deployment/tests/spec/test_ansible_spec.rb" && DOCKER_IP=$DOCKER_IP2 nosetests -sv tests/python/verify_image.py
- echo $DOCKER_IP2
- DOCKER_IP=${DOCKER_IP2} nosetests -sv tests/python/verify_image.py
#for test purpose only
#- docker exec -it test_centos /bin/bash -c "/opt/miniconda2/bin/ansible --version"
#- docker exec -it test_centos /bin/bash -c "which ansible"
#- docker exec -it test_ubuntu /bin/bash -c "ansible --version"
#- docker exec -it test_ubuntu /bin/bash -c "which ansible"
我正在尝试使用以下内容将docker-compose合并到其中:
#sudo: required
TRAVIS_SECURE_ENV_VARS: true
language: python
python: 2.7
services:
- docker
env:
global:
secure: "BI6cUmDsExjZdmw2+xrDfyTS2+x5xk1c9kvVOinY57upNcoOsolFT6XPEsBUH6e2GzFyHWQJ96yco7wUlGGFrTfxqpRN48uIjvsepr1XaWeYFczl7yOaAJWvCFPuX51Swdsbw6EN3Djw3V2oYvANM96t+FYHW+OK1wsiGu2A9yvLbFxidiqZFP0MIyRTwxB8mnCm1ZUT1Cnu23fIVkUlzXkTpC06EymxWbdAWAFkmyjzoV0q5oosMrEJXelnC6ezOIV4PwrB5vHfe9q0CcssTGi6d3onDXeBL8x1I/ZYDp+J7xk/tfhDBNdcn3J2i2VJtcIuagbzv9NN/3x4yLNPEZ1N8so/yueVpsJdgqng+ef5opifm0btLfdaX5ZaammBnfrd8mSS+witzKqLllQges3Do1pcozPB534rxEQLYzvVjmoVtrdSM2xUP80biTpQ81q5Vt9/HROI2QPA1F/e2zIudKXxQSWrEsU89bSFTgYDzmkStEGcfom7GvyYEfbTaEZE6Hh2ofHo2EAEuNStAVazasozPDSrWBzT1g7T8no3UCv0bQQdrJ1ZGQ37MsaGoX/NfZS5qMhlNoZnNcAUrFz/A81OykUjJcnCxG8SSHgG6jNFFw1M+UyqjqI1Mv3abCdT8CbfcZvYDdNKPPobLxf+75KUr235/NlXetgiWnw="
before_install:
- openssl aes-256-cbc -K $encrypted_4e087206a019_key -iv $encrypted_4e087206a019_iv -in id_travis.enc -out id_travis -d
- openssl aes-256-cbc -K $encrypted_4e087206a019_key -iv $encrypted_4e087206a019_iv -in id_travis.enc -out id_travis -d
- sudo apt-get update
- sudo apt-get remove docker-engine -yq
- sudo apt-get install docker-engine="1.9.1-0~trusty" -yq --no-install-suggests --no-install-recommends --force-yes -o Dpkg::Options::="--force-confnew"
# reinstall docker-compose at specific version
- sudo rm -f /usr/local/bin/docker-compose
- curl -L https://github.com/docker/compose/releases/download/1.8.0/docker-compose-`uname -s`-`uname -m` > docker-compose
- chmod +x docker-compose
- sudo mv docker-compose /usr/local/bin
# - docker pull censofdockers/centos6-miniconda
# - docker pull censofdockers/ubuntu-miniconda
# - CID=$(docker run --privileged --detach --volume="${PWD}":/root/django_deployment:rw -p 80 --name test_centos censofdockers/centos6-miniconda sleep 550)
# - CID2=$(docker run --privileged --detach --volume="${PWD}":/root/django_deployment:rw -p 80 --name test_ubuntu censofdockers/ubuntu-miniconda sleep 550)
# - DOCKER_IP=`docker inspect --format '{{ .NetworkSettings.IPAddress }}' ${CID}`
# - DOCKER_IP2=`docker inspect --format '{{ .NetworkSettings.IPAddress }}' ${CID2}`
# before_script:
# # - docker-compose up -d -f tests/docker-compose.yml
# - docker-compose -f tests/docker-compose.yml up -d
# - DOCKER_IP= `docker inspect --format '{{ .NetworkSettings.IPAddress }}' $(docker ps -aqf "name=test_centos")`
# - DOCKER_IP= `docker inspect --format '{{ .NetworkSettings.IPAddress }}' $(docker ps -aqf "name=test_ubuntu")`
install:
- docker-compose -f tests/docker-compose.yml up -d
- cd tests && docker-compose ps && cd ..
# - docker ps
# - docker exec -it test_centos /bin/bash -c "ls -al /root/django_deployment/"
- docker exec -it test_centos /bin/bash -c "chmod +x /root/django_deployment/installcentos.sh"
- docker exec -it test_centos /bin/bash -c "./root/django_deployment/installcentos.sh"
- docker exec -it test_ubuntu /bin/bash -c "chmod +x /root/django_deployment/installubuntu.sh"
- docker exec -it test_ubuntu /bin/bash -c "./root/django_deployment/installubuntu.sh"
# - DOCKER_IP= `docker inspect --format '{{ .NetworkSettings.IPAddress }}' $(docker ps -aqf "name=test_centos")`
# - DOCKER_IP= `docker inspect --format '{{ .NetworkSettings.IPAddress }}' $(docker ps -aqf "name=test_ubuntu")`
- DOCKER_IP=`docker inspect --format '{{ .NetworkSettings.IPAddress }}' test_centos`
- DOCKER_IP2=`docker inspect --format '{{ .NetworkSettings.IPAddress }}' test_ubuntu`
- pip install selenium nose
script:
# Start redhat or centos test
- docker exec -it test_centos /bin/bash -c "export ECLAIM_BRANCH=${SHIPPABLE_ECLAIM_BRANCH:-staging} && export DEPLOYMENT_URL=$DEPLOYMENT_URL && /opt/miniconda2/bin/ansible-playbook -e 'django_app_home=/opt/eclaim_revamp/eclaim app_version=eclaim_revamp' -e 'db_server_ip=localhost' -i /root/django_deployment/django_app_server_db_server/deployment/tests/hosts /root/django_deployment/django_app_server_db_server/deployment/main.yml"
# && docker exec -it test_ubuntu /bin/bash -c "export ECLAIM_BRANCH=${SHIPPABLE_ECLAIM_BRANCH:-staging} && export DEPLOYMENT_URL=$DEPLOYMENT_URL && /opt/miniconda2/bin/ansible-playbook -e 'django_app_home=/opt/eclaim_revamp/eclaim app_version=eclaim_revamp' -e 'db_server_ip=localhost' -i /root/django_deployment/django_app_server_db_server/deployment/tests/hosts -v /root/django_deployment/django_app_server_db_server/deployment/main.yml"
- docker exec -it test_centos /bin/bash -c "/etc/rc.d/init.d/uwsgi stop && sleep 3 && /etc/rc.d/init.d/uwsgi start && source ~/.bash_profile && rspec /root/django_deployment/tests/spec/test_ansible_spec.rb" && DOCKER_IP=$DOCKER_IP nosetests -sv tests/python/verify_image.py
- echo $DOCKER_IP
- DOCKER_IP=${DOCKER_IP} nosetests -sv tests/python/verify_image.py
# - echo $TRAVIS_JOB_ID
#start ubuntu test
- docker exec -it test_ubuntu /bin/bash -c "export ECLAIM_BRANCH=${SHIPPABLE_ECLAIM_BRANCH:-staging} && export DEPLOYMENT_URL=$DEPLOYMENT_URL && /opt/miniconda2/bin/ansible-playbook -e 'django_app_home=/opt/eclaim_revamp/eclaim app_version=eclaim_revamp' -e 'db_server_ip=localhost' -i /root/django_deployment/django_app_server_db_server/deployment/tests/hosts /root/django_deployment/django_app_server_db_server/deployment/main.yml"
- docker exec -it test_ubuntu /bin/bash -c "/etc/init.d/uwsgi stop && sleep 3 && /etc/init.d/uwsgi start && source ~/.bash_profile && rspec /root/django_deployment/tests/spec/test_ansible_spec.rb" && DOCKER_IP=$DOCKER_IP2 nosetests -sv tests/python/verify_image.py
- echo $DOCKER_IP2
- DOCKER_IP=${DOCKER_IP2} nosetests -sv tests/python/verify_image.py
after_script:
- cd tests && docker-compose stop
我不明白的是,第一个脚本通过而第二个脚本失败(超出构建时间)。除了一个使用手动docker run
而另一个使用docker-compose
来调用两个容器之外,它们中的两个是相同的。 Travis后端使用类似脚本导致这种不同结果的原因是什么?
以下是docker-compose.yml
:
app_server:
image: censofdockers/centos6-miniconda
container_name: test_centos
privileged: true
volumes:
- ..:/root/django_deployment
command:
- /sbin/init
expose:
- 80
# ports:
# - "80:80"
db_server:
image: censofdockers/ubuntu-miniconda
container_name: test_ubuntu
privileged: true
volumes:
- ..:/root/django_deployment
command:
- /sbin/init
expose:
- 80
# ports:
# - "80:80"
答案 0 :(得分:1)
这可能是由您在docker-compose文件中设置的卷上的权限问题引起的。 Travis提取的文件将由travis
用户和组拥有,而在容器内运行的进程期望活动用户成为所有者。我有一个docker-compose文件在我的Mac上正常运行,但在Travis上失败了。
对我来说,通过将其添加到install
中的.travis.yaml
步骤来修复此问题:
install
- docker-compose run --user='root' --entrypoint chown worker_test -R myuser:myuser .
对UID / GID位的这种写法很有帮助:Understanding user file ownership in docker: how to avoid changing permissions of linked volumes