简体   繁体   中英

Use docker without registry for gitlab-ci

My school has a personal gitlab setup, but it doesn't have a registry setup for docker images.

What I want to do is run my pipeline with docker, so that I can build, test etc in a docker environment.

Right now i am trying random stuff because I don't know what I am doing. This is what I have now:

Gitlab-ci:

image: docker:latest

services:
  - docker:dind

before_script:
  - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY

build-master:
  stage: build
  script:
    - docker build --pull -t "$CI_REGISTRY_IMAGE" .
    - docker push "$CI_REGISTRY_IMAGE"

build:
  stage: build
  script:
    - docker build --pull -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" .
    - docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG"

My secret variables on gitlab:

My error message in the pipeline:

Something else I tried uses a gitlab repo. This uses the docker image for ros correctly, but in my application I also use opencv, so I want to add more to the docker image. If i know how to do that in the example below, thats also an option. On top of this, in the example below i can't run tests.

Gitlab-ci:

image: ros:kinetic-ros-core

stages:
- build

variables:
  ROS_PACKAGES_TO_INSTALL: ""
  USE_ROSDEP: "true"

cache:
  paths:
    - ccache/

before_script:
 - git clone https://gitlab.com/VictorLamoine/ros_gitlab_ci.git
 - source ros_gitlab_ci/gitlab-ci.bash


catkin_make:
  stage: build
  script:
    - catkin_make

catkin_build:
  stage: build
  script:
    - catkin build --summarize --no-status --force-color

As I said I have tried many things, this is just the latest thing I have tried. How can I run my runners and gitlab-ci with docker without a gitlab registry?

Just use it withouth registry. You just need to insert this to gitlab runner config file:

pull_policy = "if-not-present"

Thats enough, and remove commands like:

docker push ...
docker pull ...

Or even insert "|| true" at the end of the push pull command if you want to keep push pull in case, like this:

docker pull ... || true;

Which keeps your code to continue if command fail. Just dont forget that : pull_policy = "if-not-present" , which allow You to run docker image withouth pull and push. As image is in case if mussing builded, this works.

example:

[[runners]]
  name = "Runner name"
  url = ...
  ...
  executor = "docker"
  [runners.docker]
    image = ...
    pull_policy = "if-not-present"
    ...

You can change these secret variables to point to docker-hub registry server.

You have to create your account on that https://hub.docker.com/ and then use that details to configure - gitlab secret variables.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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