{{< details >}}
- Tier: 基础版,专业版,旗舰版
- Offering: 私有化部署
{{< /details >}}
这是管理文档。要了解如何在极狐GitLab CI/CD 流水线中使用作业产物,请参阅作业产物配置文档。
产物是在作业完成后附加的文件和目录列表。此功能在所有极狐GitLab 安装中默认启用。
禁用作业产物
要在整个站点范围内禁用产物:
{{< tabs >}}
{{< tab title=”Linux package (Omnibus)” >}}
-
编辑
/etc/gitlab/gitlab.rb
:gitlab_rails['artifacts_enabled'] = false
-
保存文件并重新配置极狐GitLab:
sudo gitlab-ctl reconfigure
{{< /tab >}}
{{< tab title=”Helm chart (Kubernetes)” >}}
-
导出 Helm 值:
helm get values gitlab > gitlab_values.yaml
-
编辑
gitlab_values.yaml
:global: appConfig: artifacts: enabled: false
-
保存文件并应用新值:
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
{{< /tab >}}
{{< tab title=”Docker” >}}
-
编辑
docker-compose.yml
:version: "3.6" services: gitlab: environment: GITLAB_OMNIBUS_CONFIG: | gitlab_rails['artifacts_enabled'] = false
-
保存文件并重启极狐GitLab:
docker compose up -d
{{< /tab >}}
{{< tab title=”Self-compiled (source)” >}}
-
编辑
/home/git/gitlab/config/gitlab.yml
:production: &base artifacts: enabled: false
-
保存文件并重启极狐GitLab:
# For systems running systemd sudo systemctl restart gitlab.target # For systems running SysV init sudo service gitlab restart
{{< /tab >}}
{{< /tabs >}}
存储作业产物
极狐GitLab Runner 可以将包含作业产物的归档上传到极狐GitLab。默认情况下,这是在作业成功时完成的,但也可以在失败时或始终使用artifacts:when
参数完成。
大多数产物在被发送到协调器之前由极狐GitLab Runner 压缩。例外情况是报告产物,它们在上传后被压缩。
使用本地存储
如果您使用的是 Linux 软件包或进行了自编译安装,则可以更改产物在本地存储的位置。
{{< alert type=”note” >}}
对于 Docker 安装,您可以更改数据的挂载路径。对于 Helm 图表,请使用对象存储。
{{< /alert >}}
{{< tabs >}}
{{< tab title=”Linux package (Omnibus)” >}}
产物默认存储在 /var/opt/gitlab/gitlab-rails/shared/artifacts
中。
-
要更改存储路径,例如
/mnt/storage/artifacts
,请编辑/etc/gitlab/gitlab.rb
并添加以下行:gitlab_rails['artifacts_path'] = "/mnt/storage/artifacts"
-
保存文件并重新配置极狐GitLab:
sudo gitlab-ctl reconfigure
{{< /tab >}}
{{< tab title=”Self-compiled (source)” >}}
产物默认存储在 /home/git/gitlab/shared/artifacts
中。
-
要更改存储路径,例如
/mnt/storage/artifacts
,请编辑/home/git/gitlab/config/gitlab.yml
并添加或修改以下行:production: &base artifacts: enabled: true path: /mnt/storage/artifacts
-
保存文件并重启极狐GitLab:
# For systems running systemd sudo systemctl restart gitlab.target # For systems running SysV init sudo service gitlab restart
{{< /tab >}}
{{< /tabs >}}
使用对象存储
如果您不想使用安装极狐GitLab 的本地磁盘来存储产物,可以使用类似 AWS S3 的对象存储。
如果您配置极狐GitLab 将产物存储在对象存储中,您可能还希望消除作业日志的本地磁盘使用。在这两种情况下,作业日志在作业完成后被归档并移动到对象存储。
{{< alert type=”warning” >}}
在多服务器设置中,您必须使用消除作业日志本地磁盘使用的选项之一,否则作业日志可能会丢失。
{{< /alert >}}
您应该使用统一的对象存储设置。
迁移到对象存储
您可以将作业产物从本地存储迁移到对象存储。处理是在后台工作者中完成的,并且无需停机。
- 配置对象存储。
-
迁移产物:
{{< tabs >}}
{{< tab title=”Linux package (Omnibus)” >}}
sudo gitlab-rake gitlab:artifacts:migrate
{{< /tab >}}
{{< tab title=”Docker” >}}
sudo docker exec -t <container name> gitlab-rake gitlab:artifacts:migrate
{{< /tab >}}
{{< tab title=”Self-compiled (source)” >}}
sudo -u git -H bundle exec rake gitlab:artifacts:migrate RAILS_ENV=production
{{< /tab >}}
{{< /tabs >}}
- 可选。使用 PostgreSQL 控制台跟踪进度并验证所有作业产物是否成功迁移。
-
打开 PostgreSQL 控制台:
{{< tabs >}}
{{< tab title=”Linux package (Omnibus)” >}}
sudo gitlab-psql
{{< /tab >}}
{{< tab title=”Docker” >}}
sudo docker exec -it <container_name> /bin/bash gitlab-psql
{{< /tab >}}
{{< tab title=”Self-compiled (source)” >}}
sudo -u git -H psql -d gitlabhq_production
{{< /tab >}}
{{< /tabs >}}
-
使用以下 SQL 查询验证所有产物是否已迁移到对象存储。
objectstg
的数量应与total
相同:gitlabhq_production=# SELECT count(*) AS total, sum(case when file_store = '1' then 1 else 0 end) AS filesystem, sum(case when file_store = '2' then 1 else 0 end) AS objectstg FROM ci_job_artifacts; total | filesystem | objectstg ------+------------+----------- 19 | 0 | 19
-
-
验证磁盘上
artifacts
目录中没有文件:{{< tabs >}}
{{< tab title=”Linux package (Omnibus)” >}}
sudo find /var/opt/gitlab/gitlab-rails/shared/artifacts -type f | grep -v tmp | wc -l
{{< /tab >}}
{{< tab title=”Docker” >}}
假设您将
/var/opt/gitlab
挂载到/srv/gitlab
:sudo find /srv/gitlab/gitlab-rails/shared/artifacts -type f | grep -v tmp | wc -l
{{< /tab >}}
{{< tab title=”Self-compiled (source)” >}}
sudo find /home/git/gitlab/shared/artifacts -type f | grep -v tmp | wc -l
{{< /tab >}}
{{< /tabs >}}
- 如果启用了 Geo,重新验证所有作业产物。
在某些情况下,您需要运行孤立产物文件清理 Rake 任务来清理孤立产物。
从对象存储迁移到本地存储
要将产物迁移回本地存储:
- 运行
gitlab-rake gitlab:artifacts:migrate_to_local
。 -
有选择地禁用产物存储 在
gitlab.rb
中。 - 重新配置极狐GitLab。
过期产物
如果使用 artifacts:expire_in
设置产物的过期时间,它们会在该日期过后立即被标记为删除。否则,它们会根据默认产物过期设置过期。
产物由 Sidekiq 每 7 分钟运行的 expire_build_artifacts_worker
cron 作业删除(Cron 语法中的 */7 * * * *
)。
要更改删除过期产物的默认计划:
{{< tabs >}}
{{< tab title=”Linux package (Omnibus)” >}}
-
编辑
/etc/gitlab/gitlab.rb
并添加以下行(如果它已经存在并被注释掉,则取消注释),用您的计划替换 cron 语法:gitlab_rails['expire_build_artifacts_worker_cron'] = "*/7 * * * *"
-
保存文件并重新配置极狐GitLab:
sudo gitlab-ctl reconfigure
{{< /tab >}}
{{< tab title=”Helm chart (Kubernetes)” >}}
-
导出 Helm 值:
helm get values gitlab > gitlab_values.yaml
-
编辑
gitlab_values.yaml
:global: appConfig: cron_jobs: expire_build_artifacts_worker: cron: "*/7 * * * *"
-
保存文件并应用新值:
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
{{< /tab >}}
{{< tab title=”Docker” >}}
-
编辑
docker-compose.yml
:version: "3.6" services: gitlab: environment: GITLAB_OMNIBUS_CONFIG: | gitlab_rails['expire_build_artifacts_worker_cron'] = "*/7 * * * *"
-
保存文件并重启极狐GitLab:
docker compose up -d
{{< /tab >}}
{{< tab title=”Self-compiled (source)” >}}
-
编辑
/home/git/gitlab/config/gitlab.yml
:production: &base cron_jobs: expire_build_artifacts_worker: cron: "*/7 * * * *"
-
保存文件并重启极狐GitLab:
# For systems running systemd sudo systemctl restart gitlab.target # For systems running SysV init sudo service gitlab restart
{{< /tab >}}
{{< /tabs >}}
设置产物的最大文件大小
如果启用了产物,您可以通过管理员区域设置更改产物的最大文件大小。
存储统计
您可以在以下位置查看群组和项目的作业产物使用的总存储:
实现细节
当极狐GitLab 接收到产物归档时,极狐GitLab Workhorse 还会生成一个归档元数据文件。此元数据文件描述了位于产物归档中的所有条目。元数据文件是二进制格式的,带有额外的 Gzip 压缩。
极狐GitLab 不会提取产物归档以节省空间、内存和磁盘 I/O。它会检查包含所有相关信息的元数据文件。尤其是在有大量产物或归档是非常大的文件时,这一点尤为重要。
选择特定文件时,极狐GitLab Workhorse 会从归档中提取它,并开始下载。此实现节省了空间、内存和磁盘 I/O。