在gitlab中的使用kaniko打造流水线

文章目录

kaniko工具介绍

kaniko 是一种从容器或 Kubernetes 集群内的 Dockerfile 构建容器镜像的工具。

kaniko 解决了使用 Docker-in-Docker 构建方法的两个问题:

  • Docker-in-Docker需要特权模式才能运行,这是一个重大的安全问题。
  • Docker-in-Docker通常会降低性能,并且速度可能非常慢。

对应runner的执行器选择:

环境说明

系统版本

  • CentOS 7.9.2009

组件版本

  • gitlab-jh-15.6.0
  • harbor.v2.4.3
  • Docker 20.10.22
  • Docker-compose 1.18.0

组件部署参考链接

部署harbor

下载

复制代码
mkdir /data
cd /data
wget https://storage.googleapis.com/harbor-releases/release-2.4.0/harbor-offline-installer-v2.4.3.tgz

解压、创建相关目录

复制代码
cd /data
tar -xf harbor-offline-installer-v2.4.3.tgz
cd harbor
mkdir {ssl,data}

配置

复制代码
cd /data/harbor
cp harbor.yml.tmpl harbor.yml

vim harbor.yml

复制代码
hostname: harbor.bdeet.top
http:
  # port for http, default is 80. If https enabled, this port will redirect to https port
  port: 8000
https:
  # https port for harbor, default is 443
  port: 8443
  # The path of cert and key files for nginx
  certificate: /data/harbor/ssl/harbor.bdeet.top.crt
  private_key: /data/harbor/ssl/harbor.bdeet.top.key
harbor_admin_password: Wkx@123!#
database:
  # The password for the root user of Harbor DB. Change this before any production use.
  password: root123
  # The maximum number of connections in the idle connection pool. If it <=0, no idle connections are retained.
  max_idle_conns: 100
  # The maximum number of open connections to the database. If it <= 0, then there is no limit on the number of open connections.
  # Note: the default number of connections is 1024 for postgres of harbor.
  max_open_conns: 900
data_volume: /data/harbor/data
...
...

部署

复制代码
cd /data/harbor
./install.sh

gitlab集成harbor

集成

Select project -> Settings -> Integrations -> Add an integration(Harbor)

项目ci配置

复制代码
docker:
  stage: build
  variables:
    HARBOR_PORT: 8443
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: ['']
  script:
    - mkdir -p /kaniko/.docker
    - echo "{\"auths\":{\"${HARBOR_URL}\":{\"auth\":\"$(echo -n ${HARBOR_USERNAME}:${HARBOR_PASSWORD} | base64)\"}}}" > /kaniko/.docker/config.json
    - cat /kaniko/.docker/config.json
    - echo /kaniko/executor --context "${CI_PROJECT_DIR}" --dockerfile "${CI_PROJECT_DIR}/Dockerfile"  --destination "${HARBOR_HOST}:${HARBOR_PORT}/${HARBOR_PROJECT}/${CI_PROJECT_NAME}:v1"
    - >-
      /kaniko/executor
      --context "${CI_PROJECT_DIR}"
      --dockerfile "${CI_PROJECT_DIR}/Dockerfile"
      --destination "${HARBOR_HOST}:${HARBOR_PORT}/${HARBOR_PROJECT}/${CI_PROJECT_NAME}:${CI_COMMIT_SHORT_SHA}"
  rules:
  - if: $CI_COMMIT_BRANCH == "master"
    when: always

最终结果

相关推荐
IT布道21 小时前
[GitLab] 项目源码迁移踩坑记
运维·gitlab
A-刘晨阳2 天前
k8s之镜像拉取策略
运维·docker·容器·kubernetes·运维开发·harbor
极小狐2 天前
PingCode × 极狐GitLab 用AI打通需求到交付全链路,研发管理与工程交付真正一体化
人工智能·gitlab·pingcode
qq_452396233 天前
【工程实战】第九篇:持续集成 —— Jenkins 与 GitLab CI:构建无人值守的自动化流水线
ci/cd·gitlab·jenkins
angushine6 天前
gitlab跨服务器备份
服务器·gitlab·github
蜡台7 天前
Git 常用配置:修改地址 ,提交模板配置
git·gitlab·template·git commit·gitbash
染夕陌木7 天前
极简教程:GitLab 上配置 SSH Key(附常见问题解决)
运维·ssh·gitlab
晨旭缘8 天前
GitLab CICD 中 K8s 部署:BOM 头与 YAML 格式全解
容器·kubernetes·gitlab
鳄鱼杆9 天前
服务器 | 2026年Ubuntu 24.04下GitLab Docker 企业级部署
服务器·ubuntu·gitlab
FreeBuf_10 天前
黑客滥用 GitHub 和 GitLab 托管恶意软件并实施凭证钓鱼攻击
gitlab·github