从共享切换到专用的Gitlab运行程序:管道断开

时间:2019-04-23 13:20:20

标签: docker gitlab-ci-runner

我从CI / CD开始,对于dockerized的Rails应用程序,我使用的是Gitlab共享运行器,直到我被这些限制限制为止。

因此,我决定根据官方文档构建自己的专用转轮,以继续测试(我实际上是在尝试使用.gitlab-ci.yml部署到DigitalOcean)。

但是,由于我切换了管道,因此始终会因以下错误而失败:

The command '/bin/sh -c docker/potential_asset_precompile.sh $PRECOMPILEASSETS' returned a non-zero code: 1

我无法理解此问题的根源,因为它曾经在从共享运行程序切换到专用运行程序之前运行良好,并且可以在本机上正确运行。所以我想应该是我的跑步者的配置有问题吗?

我找不到解决方法,所以这是我的文件。预先感谢您的帮助!

Dockerfile

FROM ruby:2.5.5-alpine

ARG PRECOMPILEASSETS

ENV NODE_OPTIONS "--max_old_space_size=4096"
ENV SECRET_KEY_BASE=foo

RUN apk add --update --no-cache \
    build-base \
    git \
    postgresql-dev \
    postgresql-client \
    imagemagick \
    nodejs-current \
    yarn \
    python2 \
    tzdata \
    file

RUN gem install bundler
# Install gems
RUN mkdir /gems
WORKDIR /gems
COPY Gemfile .
COPY Gemfile.lock .
RUN bundle install -j4 --retry 3 \
    # Remove unneeded files (cached *.gem, *.o, *.c)
    && rm -rf /usr/local/bundle/cache/*.gem \
    && find /usr/local/bundle/gems/ -name "*.c" -delete \
    && find /usr/local/bundle/gems/ -name "*.o" -delete

ARG INSTALL_PATH=/beweeg
ENV INSTALL_PATH $INSTALL_PATH
WORKDIR $INSTALL_PATH
COPY . .

# Expose Puma port
EXPOSE 3000

# Precompile assets (or not)
RUN docker/potential_asset_precompile.sh $PRECOMPILEASSETS

CMD ["docker/startup.sh"]

docker-compose.yml

version: '3.0'
services:
  db:
    image: postgres:11-alpine
    ports:
      - 5433:5432
    environment:
      POSTGRES_PASSWORD: postgres

  webpacker:
    image: beweeg_development
    command: ["./docker/start_webpack_dev.sh"]
    volumes:
      - .:/beweeg:cached
    ports:
      - 3035:3035

  app:
    image: beweeg_development
    build:
      context: .
      args:
        - PRECOMPILEASSETS=NO
    links:
      - db
      - webpacker
    ports:
      - 3000:3000
    volumes:
      - .:/beweeg:cached

.gitlab-ci.yml

image: docker:stable
services:
  - docker:dind

cache:
  paths:
    - node_modules

variables:
  DOCKER_HOST: tcp://docker:2375/
  DOCKER_DRIVER: overlay2
  CONTAINER_CURRENT_IMAGE: $CI_REGISTRY/$CI_PROJECT_PATH:$CI_COMMIT_REF_SLUG
  CONTAINER_LATEST_IMAGE: $CI_REGISTRY/$CI_PROJECT_PATH:latest
  CONTAINER_STABLE_IMAGE: $CI_REGISTRY/$CI_PROJECT_PATH:stable

stages:
  - test
  - build
  - release
  - deploy

before_script:
  - echo $CI_BUILD_TOKEN | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY
  - apk add --no-cache py-pip python-dev libffi-dev openssl-dev gcc libc-dev make
  - pip install docker-compose
  - docker-compose --version

test:
  stage: test
  script:
    - docker-compose build --pull
    # Here we will run tests when available...
  after_script:
    - docker-compose down
    - docker volume rm `docker volume ls -qf dangling=true`

build:
  stage: build
  script:
    - docker build . --pull -t $CONTAINER_CURRENT_IMAGE
    - docker push $CONTAINER_CURRENT_IMAGE

release-latest-image:
  stage: release
  only:
    - feat-dockerisation
  script:
    - docker pull $CONTAINER_CURRENT_IMAGE
    - docker tag $CONTAINER_CURRENT_IMAGE $CONTAINER_LATEST_IMAGE
    - docker push $CONTAINER_LATEST_IMAGE

release-stable-image:
  stage: release
  only:
    - feat-dockerisation
  script:
    - docker pull $CONTAINER_CURRENT_IMAGE
    - docker tag $CONTAINER_CURRENT_IMAGE $CONTAINER_STABLE_IMAGE
    - docker push $CONTAINER_STABLE_IMAGE

deploy_staging:
  stage: deploy
  only:
    - feat-dockerisation
  environment: production
  before_script:
    - mkdir -p ~/.ssh
    - echo "$DEPLOY_SERVER_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
    - chmod 600 ~/.ssh/id_rsa
    - which ssh-agent || (apk add openssh-client)
    - eval $(ssh-agent -s)
    - ssh-add ~/.ssh/id_rsa
    - ssh-keyscan -H $DEPLOYMENT_SERVER_IP >> ~/.ssh/known_hosts
  script:
    - scp -rp ./docker-compose.staging2.yml root@${DEPLOYMENT_SERVER_IP}:~/
    - ssh root@$DEPLOYMENT_SERVER_IP "docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY};
      docker-compose -f docker-compose.staging2.yml down;
      docker pull $CONTAINER_LATEST_IMAGE;
      docker-compose -f docker-compose.staging2.yml up -d"

上一个 gitlab-ci.yml (与共享运行器一起使用):

image: docker
services:
  - docker:dind

cache:
  paths:
    - node_modules

variables:
  CONTAINER_CURRENT_IMAGE: registry.gitlab.com/soykje/beweeg-ror:$CI_COMMIT_REF_SLUG
  CONTAINER_LATEST_IMAGE: registry.gitlab.com/soykje/beweeg-ror:latest
  CONTAINER_STABLE_IMAGE: registry.gitlab.com/soykje/beweeg-ror:stable

stages:
  - test
  - build
  - release
  - deploy

before_script:
  - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
  - apk add --no-cache py-pip python-dev libffi-dev openssl-dev gcc libc-dev make
  - pip install docker-compose
  - docker-compose --version

test:
  stage: test
  script:
    - docker-compose build --pull
    # - docker-compose run app docker/wait_for_it.sh db:5433 --  "rake db:create db:migrate"
    # Here we will run tests when available...
  after_script:
    - docker-compose down
    - docker volume rm `docker volume ls -qf dangling=true`

build:
  stage: build
  script:
    - docker build . --pull -t $CONTAINER_CURRENT_IMAGE
    - docker push $CONTAINER_CURRENT_IMAGE

release-latest-image:
  stage: release
  only:
    - feat-dockerisation
  script:
    - docker pull $CONTAINER_CURRENT_IMAGE
    - docker tag $CONTAINER_CURRENT_IMAGE $CONTAINER_LATEST_IMAGE
    - docker push $CONTAINER_LATEST_IMAGE

release-stable-image:
  stage: release
  only:
    - feat-dockerisation
  script:
    - docker pull $CONTAINER_CURRENT_IMAGE
    - docker tag $CONTAINER_CURRENT_IMAGE $CONTAINER_STABLE_IMAGE
    - docker push $CONTAINER_STABLE_IMAGE

deploy_staging:
  stage: deploy
  only:
    - feat-dockerisation
  environment: production
  before_script:
    - mkdir -p ~/.ssh
    - echo "$DEPLOY_SERVER_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
    - chmod 600 ~/.ssh/id_rsa
    - which ssh-agent || (apk add openssh-client)
    - eval $(ssh-agent -s)
    - ssh-add ~/.ssh/id_rsa
    - ssh-keyscan -H $DEPLOYMENT_SERVER_IP >> ~/.ssh/known_hosts
  script:
    - scp -rp ./docker ./docker-compose.staging2.yml root@${DEPLOYMENT_SERVER_IP}:~/
    - ssh root@$DEPLOYMENT_SERVER_IP "docker login -u gitlab-ci-token -p ${CI_BUILD_TOKEN} registry.gitlab.com;
      docker-compose -f docker-compose.staging2.yml down;
      docker pull $CONTAINER_STABLE_IMAGE;
      docker-compose -f docker-compose.staging2.yml up -d"

这是我的跑步者 config.toml

concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "beweeg-gitlab-runner"
  url = "https://gitlab.com/ci"
  token = <MYTOKEN>
  executor = "docker"
  [runners.custom_build_dir]
  [runners.docker]
    tls_verify = false
    image = "ruby:2.5.5"
    privileged = true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/cache"]
    shm_size = 0
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]

0 个答案:

没有答案