从docker复制到CI构建内的主机

时间:2016-06-29 10:45:42

标签: docker continuous-integration gitlab-ci

我想知道是否有可能以某种方式将文件/文件夹从docker内部复制到主机,但是复制本身是在docker内执行的。

原因是,例如:

  • 将文件提交到repo
  • CI开始
  • Docker安装依赖项,构建网站文件
  • 网站文件从docker复制到/ var / www / my-website(host)

当我在寻找解决方案时,我已经看到了很多.gitlab-ci.yml这个命令,但这是从HOST执行的。我想让整个过程自动化。

当然可能的解决方案是不使用docker而是使用直接SSH,这就是我现在正在做的事情,但这不是IMO的最佳选择。

以下是我的image: ubuntu:16.04 build: stage: build script: - apt-get update - apt-get upgrade -yy - apt-get install hugo -yy # Static site generator - hugo build # Build the website - cp -R ./build/* /var/www/my-website/ # Copy to the web root 文件的示例,它将解释我想要实现的目标。

[[runners]]
  name = "DOCKER-TEST"
  url = "https://gitlab.com/ci"
  token = "{{token}}"
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "ubuntu:16.04"
    privileged = true
    disable_cache = false
    volumes = ["/cache", "/home/stan:/builds/stanislavromanov/test-docker:rw"]
  [runners.cache]
    Insecure = false

这是我的跑步者配置

chrome.tabs.create({url: 'http://www.google.com'}, function(tab) {
    chrome.tabs.executeScript(tab.id, {code: 'document.body.style.backgroundColor = 'green;'});
});

2 个答案:

答案 0 :(得分:5)

您应该能够设置Docker volume,其中容器中的目录被挂载到主机的目录。

如果是GitLab CI跑步者,可以在跑步者注册期间或之后通过修改 /etc/gitlab-runner/config.toml 来指定。例如:

[[runners]]
  url = "https://gitlab.com/ci"
  token = TOKEN
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "ubuntu:16.04"
    privileged = true
    disable_cache = false
    volumes = ["/path/to/bind/from/host:/path/to/bind/in/container:rw"]

有关详细信息,请参阅documentation

答案 1 :(得分:4)

使用RewriteCond %{HTTP_HOST} ^abc\.in$ [NC] RewriteRule ^(.*)$ http://www.abc.in/$1 [L,R=301] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php RewriteRule (.*)\.xml(.*) $1.php$2 [L] RewriteCond %{REQUEST_URI} (\.ico|sitemap\.xml|\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC] RewriteRule ^(.*)$ $1 [L] RewriteCond %{REQUEST_URI} !(category) RewriteRule .? - [S=6] RewriteCond %{REQUEST_URI} !(/page/) RewriteRule .? - [S=2] RewriteRule ^category/(.*)/page/(.*)/$ index.php?action=category&slug=$1&page=$2 [L,QSA] RewriteCond %{HTTP_HOST} ^(.*)$ [NC] RewriteRule ^category/(.*)/page/(.*)$ http://%1/category/$1/page/$2/ [L,R=301] RewriteRule ^(.*)/(.*)/$ index.php?action=category&slug=$2 [L,QSA] RewriteRule ^(.*)/$ index.php?action=category [L,QSA] RewriteCond %{HTTP_HOST} ^(.*)$ [NC] RewriteRule ^(.*)/(.*)$ http://%1/$1/$2/ [L,R=301] RewriteCond %{REQUEST_URI} !(tag) RewriteRule .? - [S=6] RewriteCond %{REQUEST_URI} !(/page/) RewriteRule .? - [S=2] RewriteRule ^tag/(.*)/page/(.*)/$ index.php?action=tag&slug=$1&page=$2 [L,QSA] RewriteCond %{HTTP_HOST} ^(.*)$ [NC] RewriteRule ^tag/(.*)/page/(.*)$ http://%1/tag/$1/page/$2/ [L,R=301] RewriteRule ^(.*)/(.*)/$ index.php?action=tag&slug=$2 [L,QSA] RewriteRule ^(.*)/$ index.php?action=tag [L,QSA] RewriteCond %{HTTP_HOST} ^(.*)$ [NC] RewriteRule ^(.*)/(.*)$ http://%1/$1/$2/ [L,R=301] RewriteCond %{REQUEST_URI} !(blog) RewriteRule .? - [S=7] RewriteCond %{REQUEST_URI} !(/page/) RewriteRule .? - [S=2] RewriteRule ^(.*)/page/(.*)/$ index.php?action=blog&page=$2 [L,QSA] RewriteCond %{HTTP_HOST} ^(.*)$ [NC] RewriteRule ^(.*)/page/(.*)$ http://%1/$1/page/$2/ [L,R=301] RewriteCond %{HTTP_HOST} ^(.*)$ [NC] RewriteRule ^(.*)/(.*)/$ http://%1/$2/ [L,R=301] RewriteCond %{HTTP_HOST} ^(.*)$ [NC] RewriteRule ^blog$ http://%1/blog/ [L,R=301] RewriteRule ^(.*)/$ index.php?action=blog [L,QSA] RewriteCond %{HTTP_HOST} ^(.*)$ [NC] RewriteRule ^(.*)/(.*)$ http://%1/$2/ [L,R=301] RewriteRule ^(.*)/(.*)/$ index.php?action=blog&slug=$2 [L,QSA] RewriteCond %{REQUEST_URI} (ajax|sitemap) RewriteRule .? - [S=2] RewriteRule ^(.*)/$ index.php?action=blog&slug=$1 [L,QSA] RewriteRule ^(.*)$ index.php?action=$1 [L,QSA] AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/xml AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE application/rss+xml AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE application/x-javascript RewriteCond %{HTTP_HOST} ^abc\.in$ [OR] RewriteCond %{HTTP_HOST} ^www\.abc\.in$ RewriteRule ^post\/goa\-government\-websites\-hacked\-allegedly\-palestine\-hackers\/$ "http\:\/\/www\.cyberintelligence\.in\/goa\-government\-websites\-hacked\-allegedly\-palestine\-hackers\/" [R=301,L] 之类的内容无法从容器复制到主机。你可以做的是将host-directory挂载到容器中,例如:

docker cp

并在$ docker run ... -v /var/www/my-website:/website-on-host ... 中调整cp命令,如下所示:

.gitlab-ci.yml