使用Jib和Gitlab-CI构建docker映像 [英] Building docker images with Jib and Gitlab-CI

查看:194
本文介绍了使用Jib和Gitlab-CI构建docker映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个管道,在该管道中使用JIB(通过Maven插件)创建docker映像并将其推送到我的Gitlab注册表.

I am trying to create a pipeline where docker images are created using JIB (via a Maven Plugin) and pushed to my Gitlab Registry.

当我登录到我的docker注册表时,这在本地可以正常工作.

This works fine locally as I am logged into my docker registry.

<plugin>
    <groupId>com.google.cloud.tools</groupId>
    <artifactId>jib-maven-plugin</artifactId>
    <version>1.0.0</version>
    <configuration>
        <allowInsecureRegistries>true</allowInsecureRegistries>
        <from>
            <image>dockerhost/projectgroup/alpine</image>
        </from>
        <to>
            <image>dockerhost/project/imagename:${project.version}</image>
        </to>
        <container>
            <useCurrentTimestamp>true</useCurrentTimestamp>
        </container>
    </configuration>
</plugin>

说我有一个.gitlab-ci.yml,它看起来像:

Say I have a .gitlab-ci.yml which looks like:

stages:
  - build_image

build_image:
  stage: build_image
tags:
  - dev
script: |
  mvn compile jib:build

现在,在触发管道时出现异常

Now I am getting an exception when the pipeline is triggered

Build image failed: Failed to authenticate with registry dockerhost/projectgroup/alpine because: peer not authenticated

我假设我收到此错误是因为我没有运行docker login -u [用户名] -p [密码/令牌]

I am assuming I am getting this error because I haven't run docker login -u [username] -p [password/token]

我怎么需要一个使用docker-in-docker映像的.gitlab-ci.yml才能在我的脚本中运行docker登录?

How ever I would need a .gitlab-ci.yml which uses a docker-in-docker image to be able to run docker login within my script?

是否可以使用docker-in-docker映像在我的Gitlab CI上构建该映像?

Is there an alternative to using a docker-in-docker image to build this image on my Gitlab CI?

推荐答案

使用GitLab,您可以定义秘密的环境变量,您可以使用这些变量将注册表凭据传递给Jib.

Using GitLab you can define secret environement variables that you could use to pass your registry credential to Jib.

  1. 使用gitlab定义秘密变量
  2. 使用Jib传递注册表凭据

  1. Define secret variables using gitlab
  2. Pass the registry credential using Jib

mvn compile jib:build -Djib.to.image=my-container-image:latest -Djib.to.auth.username=$REGISTRY_USER -Djib.to.auth.password=$REGISTRY_PASSWORD

这篇关于使用Jib和Gitlab-CI构建docker映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆