简体   繁体   English

Buildah vs Kaniko

[英]Buildah vs Kaniko

I'm using ArgoWorkflow to automate our CI/CD chains.我正在使用 ArgoWorkflow 来自动化我们的 CI/CD 链。 In order to build images, and push them to our private registry we are faced between the choice of either buildah or kaniko.为了构建镜像,并将它们推送到我们的私有注册表,我们面临着选择 buildah 或 kaniko。 But I can't put my finger on the main difference between the two.但我无法指出两者之间的主要区别。 Pros and cons wise, and also on how do these tools handle parallel builds and cache management.利弊,以及这些工具如何处理并行构建和缓存管理。 Can anyone clarify these points?谁能澄清这些观点? Or even suggest another tool that can maybe do the job in a more simple way.或者甚至建议另一种可能以更简单的方式完成工作的工具。 Some clarifications on the subject would be really helpful.关于这个主题的一些澄清将非常有帮助。 Thanks in advance.提前致谢。

kaniko is very simple to setup and has some magic that let it work with no requirements in kubernetes:) kaniko的设置非常简单,并且有一些魔力让它在 kubernetes 中无需任何要求即可工作:)

I also tried buildah but was unable to configure it and found it too complex to setup in a kubernetes environment.我也尝试了 buildah ,但无法配置它,发现它太复杂,无法在 kubernetes 环境中设置。

You can use as cache management for kaniko an internal Docker registry, but a local storage can be configured instead (not tried yet).您可以将内部 Docker 注册表用作kaniko的缓存管理,但可以配置本地存储(尚未尝试)。 Just use the latest version of kaniko (v1.7.0), that fixes an important bug in the cached layers management.只需使用最新版本的kaniko (v1.7.0),它修复了缓存层管理中的一个重要错误。

These are some functions that I use in my GitLab CI pipelines, executed by a GitLab runner in Kubernetes (they should hopefully clarify setup and usage of kaniko ):这些是我在 GitLab CI 管道中使用的一些功能,由 GitLab 运行器在Kubernetes中执行(他们应该希望阐明 kan 的设置和使用):

function kaniko_config
{
    local docker_auth="$(echo -n "$CI_REGISTRY_USER:$CI_REGISTRY_PASSWORD" | base64)"

    mkdir -p $DOCKER_CONFIG
    [ -e $DOCKER_CONFIG/config.json ] || \
        cat <<JSON > $DOCKER_CONFIG/config.json
{
    "auths": {
        "$CI_REGISTRY": {
            "auth": "$docker_auth"
        }
    }
}
JSON
}

# Usage example (.gitlab-ci.yml)
#
# build php:
#   extends: .build
#   variables:
#     DOCKER_CONFIG: "$CI_PROJECT_DIR/php/.docker"
#     DOCKER_IMAGE_PHP_DEVEL_BRANCH: &php-devel-image "${CI_REGISTRY_IMAGE}/php:${CI_COMMIT_REF_SLUG}-build"
#   script:
#     - kaniko_build
#       --destination $DOCKER_IMAGE_PHP_DEVEL_BRANCH
#       --dockerfile $CI_PROJECT_DIR/docker/images/php/Dockerfile
#       --target devel

function kaniko_build
{
    kaniko_config
    echo "Kaniko cache enabled ($CI_REGISTRY_IMAGE/cache)"
    /kaniko/executor \
        --build-arg http_proxy="${HTTP_PROXY}" \
        --build-arg https_proxy="${HTTPS_PROXY}" \
        --build-arg no_proxy="${NO_PROXY}" \
        --cache --cache-repo $CI_REGISTRY_IMAGE/cache \
        --context "$CI_PROJECT_DIR" \
        --digest-file=/dev/termination-log \
        --label "com.qwant.ci.job.id=${CI_JOB_ID}" \
        --label "com.qwant.ci.pipeline.id=${CI_PIPELINE_ID}" \
        --verbosity info \
        $@

    [ -r /dev/termination-log ] && \
        echo "Manifest digest: $(cat /dev/termination-log)"
}

With these functions a new image can be built with:使用这些功能可以构建新图像:

stages:
  - build

build app:
  stage: build
  image:
    name: gcr.io/kaniko-project/executor:v1.7.0-debug
    entrypoint: [""]
  variables:
    DOCKER_CONFIG: "$CI_PROJECT_DIR/app/.docker"
    DOCKER_IMAGE_APP_RELEASE_BRANCH: &app-devel-image "${CI_REGISTRY_IMAGE}/phelps:${CI_COMMIT_REF_SLUG}"
    GIT_SUBMODULE_STRATEGY: recursive
  before_script:
    - source ci/libkaniko.sh
  script:
    - kaniko_build
      --destination $DOCKER_IMAGE_APP_RELEASE_BRANCH
      --digest-file $CI_PROJECT_DIR/docker-content-digest-app
      --dockerfile $CI_PROJECT_DIR/docker/Dockerfile
  artifacts:
    paths:
      - docker-content-digest-app
  tags:
    - k8s-runner

buildah will require either a privileged container with more then one UID or a container running with CAP_SETUID, CAP_SETGID to build container images. buildah 将需要具有多个 UID 的特权容器或使用 CAP_SETUID、CAP_SETGID 运行的容器来构建容器映像。 It is not hacking on the file system like kanicko does to get around these requirements.它不是像 kanicko 那样对文件系统进行黑客攻击来绕过这些要求。 It runs full contianers when building.它在构建时运行完整的contianers。

--isolation chroot, will make it a little easier to get buildah to work within kubernetes. --isolation chroot,将使 buildah 在 kubernetes 中工作更容易一些。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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