简体   繁体   English

将 gitlab ci 与 docker compose 一起使用给我留下了容器生成的文件夹 gitlab 无法删除

[英]Using gitlab ci with docker compose leaves me with container generated folders gitlab can't remove

I'm trying to set up gitlab ci using the method documented here and testing a rails 4 app with it.我正在尝试使用此处记录的方法设置 gitlab ci 并使用它测试 rails 4 应用程序。

The problem I'm having is that the test will run once and build the image and containers, but when I try to run the test again it will fail with:我遇到的问题是测试将运行一次并构建映像和容器,但是当我尝试再次运行测试时,它将失败:

gitlab-ci-multi-runner 1.1.3 (a470667)
Using Shell executor...
Running on ubuntu-lon1-01...
Fetching changes...
warning: failed to remove tmp/miniprofiler

ERROR: Build failed: exit status 1

I think this is because the tmp folder is generated when you run the app a first time and is owned by root in the container.我认为这是因为 tmp 文件夹是在您第一次运行应用程序时生成的,并且由容器中的 root 拥有。

This is the gitlab.ci.yml I'm currently using but I've tried lots of different versions all with the same result:这是我目前使用的gitlab.ci.yml但我尝试了很多不同的版本,结果都一样:

before_script:
  - docker info

build_image:
  stage: test
    script:
    -  docker-compose build
    -  docker-compose run web rake db:create RAILS_ENV=test
    -  docker-compose run web bin/rake db:migrate RAILS_ENV=test
    -  docker-compose up -d
    -  docker-compose run web bundle exec rspec
    -  docker-compose stop

I thought I may be able to delete the folder using the after_script but that doesn't work with the shell setup.我以为我可以使用after_script删除文件夹,但这不适用于 shell 设置。

I'm not sure how to handle this.我不知道如何处理这个。 I think I need to either delete it on exit or change the permissions so it can be deleted.我想我需要在退出时将其删除或更改权限才能将其删除。

This is my Dockerfile:这是我的 Dockerfile:

FROM ruby:2.3.1

RUN apt-get update -qq && apt-get install -y build-essential \
    && apt-get install -y apt-utils \
    && apt-get install -y libqt4-webkit libqt4-dev xvfb \
    && apt-get install -y wget \
    && apt-get install -y libpq-dev \
    && apt-get install -y postgresql-contrib \
    && apt-get install -y libxml2-dev libxslt1-dev \
    && apt-get install -y imagemagick libmagickcore-dev libmagickwand-dev \
    && apt-get install -y nodejs

RUN gem install foreman

WORKDIR /tmp
COPY Gemfile Gemfile
COPY Gemfile.lock Gemfile.lock
RUN bundle install

RUN mkdir /app
WORKDIR /app
COPY . /app/

And my docker-compose:还有我的 docker-compose:

db:
  image: postgres:9.4
  ports:
    - "5432"
web:
  build: .
  command: foreman start -f Procfile.dev
  volumes:
    - .:/app
  stdin_open: true
  ports:
    - "3000:3000"
  links:
    - db

Googling I can't seem to find anyone that's having the same issue so I'm assuming I'm doing something wrong.谷歌搜索我似乎找不到任何有同样问题的人,所以我假设我做错了什么。

Thanks.谢谢。

I thought I may be able to delete the folder using the after_script but that doesn't work with the shell setup.我以为我可以使用 after_script 删除文件夹,但这不适用于 shell 设置。

I had the same issue and solved it by adding this to .gitlab.ci.yml我遇到了同样的问题并通过将其添加到.gitlab.ci.yml来解决它

after_script:
  - docker-compose run web rm -rf tmp/

(Using shell runner with gitlab-ci-multi-runner 1.7.1) (在 gitlab-ci-multi-runner 1.7.1 中使用 shell runner)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM