Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use image from gitlab Registry in CI

Tags:

docker

gitlab

Could you tell me if I do it in correct way:

  • I have create Docker image with all stuff which is need for running my tests in gitlab CI
  • I push it to gitlab registry
  • I can see on gitlab page in section Registry my image - gitlablogin/projectname
  • I want to use this image for CI, so in .gitlab-ci.yml I add image: gitlablogin/projectname

Before I had had in .gitlab-ci.yml

same_task:
  stage: deploy
  image: python:3
  script:
    - python -V

Now I have:

pep8:
  stage: deploy
  image: gitlablogin/projectname
  script:
    - python -V

and after this change job failed:

Running with gitlab-runner 11.4.2 (cf91d5e1)
  on docker-auto-scale 72989761
Using Docker executor with image gitlablogin/projectname ...
Pulling docker image gitlablogin/projectname ...
ERROR: Job failed: Error response from daemon: pull access denied for gitlablogin/projectname, repository does not exist or may require 'docker login' (executor_docker.go:168:0s)

Is my usage of docker in context of gitlab CI and gitlab registry is correct? I also want to keep my docker file on same repo and build new image when samething change in Dockerfile, what will be the best way to do it?

like image 369
Bartłomiej Bartnicki Avatar asked Oct 31 '18 17:10

Bartłomiej Bartnicki


People also ask

Does GitLab have a Docker registry?

Context. In milestone 8.8, GitLab launched the MVC of the Container Registry. This feature integrated the Docker Distribution registry into GitLab so that any GitLab user could have a space to publish and share container images.

Where is GitLab container registry?

Control Container Registry from within GitLab GitLab offers a simple Container Registry management panel. Go to your project and click Packages > Container Registry in the project menu. This view will show you all Docker images in your project and will easily allow you to delete them.


1 Answers

Right now it is possible to use images from your gitlab registry without any special steps. Just build and push an image to your gitlab project container registry

docker build -t registry.gitlab.com/gitlabProject/projectName:build .
docker push registry.gitlab.com/gitlabProject/projectName:build 

and then just specify this image in your pipeline settings:

image: registry.gitlab.com/gitlabProject/projectName:build

Gitlab is able to pull this image using it's credentials:

Preparing the "docker+machine" executor
00:46
 Using Docker executor with image registry.gitlab.com/gitlabProject/projectName:build ...
 Authenticating with credentials from job payload (GitLab Registry)
 Pulling docker image registry.gitlab.com/gitlabProject/projectName:build ...
 Using docker image sha256:e7e0f4f5fa8cff8a93b1f37ffd7dd0505946648246aa921dd457c06a1607304b for registry.gitlab.com/gitlabProject/projectName:build ...

More: https://docs.gitlab.com/runner/configuration/advanced-configuration.html#using-a-private-container-registry

like image 184
Maksim Vorontsov Avatar answered Nov 10 '22 11:11

Maksim Vorontsov