卡了24小时了,有没有了解docker和gitlab-runner的大佬在?
发布于 5 年前 作者 wbget 5903 次浏览 来自 问答
sudo docker run -d \
--name gitlab-runner \
--restart always \
-v /usr/local/gitlab-runner/config:/etc/gitlab-runner \
-v /usr/local/gitlab-runner/run/docker.sock:/var/run/docker.sock \
-v /usr/local/node/client-admin:/etc/client-admin \
gitlab/gitlab-runner:latest
docker exec -it gitlab-runner gitlab-ci-multi-runner register \
  --non-interactive \
  --url https://gitlab.com/ \
  --registration-token "xxxxxxxxxxx" \
  --tag-list=ci \
  --description "ci" \
  --docker-pull-policy="if-not-present" \
  --executor=docker \
  --docker-privileged=true \
  --docker-image "node:10.16.3" \
  --docker-volumes /usr/local/gitlab-runner/run/docker.sock:/var/run/docker.sock \
  --docker-volumes /usr/local/node/client-admin:/etc/client-admin

这个是我的配置,实际项目中,无法拿到挂载目录。 脑壳都试破了,不知道哪里出了问题。

7 回复

我想干的事是,打tag自动编译,然后把包直接丢到挂载目录里,自动把项目就发布了。

一般做法都是直接 copy 进来… 打好镜像,想用哪个版本就用哪个版本

有有我就是 前段大神

@wbget Jenkins 了解下~

没跑过 gitlab-runner, 但可能是你挂载的目录的权限问题? 你容器里面的用户有没有访问外部目录的权限? 比如外部目录是 root 的, 容器里面的用户并不是.

我上次也遇到了类似的问题,然后突然想起我本地docker客户端设置了连接开发机的docker服务端,我当时还是自己IP加端口怎么不生效。docker ps仔细一看才发现,有一些我本地没部署过的服务,才想起我客户端上次设置链接了开发机的docker Server。 也是因为一直登开发机搞,很久没切回本地搞,一时间还给忘记了。

你好,大概半年前做过,仔细看了一下你的配置,感觉和官方的说明不太一样。这是笔记

Gitlab CI/CD

Config gitlab-runner

/etc/gitlab-runner/config.toml

concurrent = 1
check_interval = 0

[[runners]]
  name = "haha-srv-media"
  url = "https://gitlab.haha.us/"
  token = "df1b4510632cf11e427eaf09a98205"
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "node:10.6.0-jessie"
    privileged = false
    disable_cache = false
    volumes = ["/cache","/root/.ssh/:/root/.ssh/"]
    shm_size = 0
    dns_search = ["gitlab.haha.us", "registry.npm.taobao.org"]
    extra_hosts = ["gitlab.haha.us:192.168.170.54","registry.npm.taobao.org:114.55.80.225"]
  [runners.cache]

Use Docker Execter

check_interval = 0

[[runners]]
  name = "haha-srv-media"
  url = "https://gitlab.haha.us/"
  token = "df1b4510632cf11e427eaf09a98205"
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "node:10.6.0-jessie"
    privileged = false
    disable_cache = false
    volumes = ["/cache","/root/.ssh:/root/.ssh"]
    shm_size = 0
  [runners.cache]
stages:
  - test
  - build

before_script:
  - echo "config dns"
  - echo "192.168.170.54 gitlab.haha.us" >> /etc/hosts
  - echo "install ssh"
  - ls /etc/ssh
  - eval `ssh-agent -s`
  - ssh-add $HOME/.ssh/id_rsa
  - ssh-add -l
  - ssh -T git@gitlab.haha.us
  - export NODE_PATH=/builds/haha/haha-srv-media/node_modules/
  - echo "registry=https://registry.npm.taobao.org" >> $HOME/.npmrc
  - npx cnpm i
  - npx yarn list
  
test:
  stage: test
  script: 
    - echo "Running tests"
    - npm run lint

build:
  stage: build
  script: 
    - echo "Building the app"
    - npm run upload
  only:
  - staging

Config .gitlab-ci.yml

stages:
  - test
  - build

test:
  stage: test
  script: echo "Running tests"

build:
  stage: build
  script: echo "Building the app"
  only:
  - staging

参考

【gitlab-runner】

回到顶部