问题
I'm starting with CI/CD, and for a dockerized Rails application I was using Gitlab shared runners, until I was stuck by trigger limits on these.
So I decided to build my own dedicated runner, following the official documentation, in order to continue my tests (I'm actually trying to deploy to DigitalOcean using .gitlab-ci.yml).
But, since I switched the pipeline always fails with this error:
The command '/bin/sh -c docker/potential_asset_precompile.sh $PRECOMPILEASSETS' returned a non-zero code: 1
I cannot understand the origin of this problem, as it used to work perfectly before switching from shared to dedicated runner... And it runs correctly on my local machine. So I guess it should be my runner's config that is wrong?
I couldn't find how to fix this, so here are my files. Thank you in advance for your help!
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"
Previous gitlab-ci.yml (working with shared runner):
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"
And here is my runner 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]
来源:https://stackoverflow.com/questions/55812204/switch-from-shared-to-dedicated-gitlab-runner-pipeline-broken