GitLab Runner Docker 执行器和 S3 缓存

问题描述 投票:0回答:1

即使互联网上有多个帖子,我也不知道如何让我的 GitLab-Runner 工作......

我正在使用 GitLab CE 17.0.0 + 2 个 GitLab Runners 17.0.0,一个托管在 AlmaLinux 8 服务器上,另一个托管在 Windows 11 计算机上。

一切正常,但我想设置共享缓存。

我已经设置了一个 MinIO 服务器,托管在 AlmaLinux 8 上。GitLab 容器注册表与我的 MinIO 服务器配合良好。

现在我想设置我的 GitLab Runner。两者都使用 Docker 执行器。配置文件非常相似:

concurrent = 1
check_interval = 0
connection_max_age = "15m0s"
shutdown_timeout = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "runner-windows"
  url = "https://gitlab-url"
  id = 19
  token = "..."
  executor = "docker"

  [runners.cache]
    Type = "s3"
    Shared = true

    [runners.cache.s3]
      ServerAddress = "minio-url:9000"
      AccessKey = "..."
      SecretKey = "..."
      BucketName = "gitlab-ci-cache"
      BucketLocation = "eu-east-1"

  [runners.docker]
    tls_verify = false
    privileged = false
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["gitlab-pipeline-cache:/cache"]
    shm_size = 0

此配置未使用我的 MinIO 服务器作为缓存服务器。创建并使用 Docker 卷“gitlab-pipeline-cache”。

在运行器主机上,如果我使用 MinIO 客户端,我可以成功连接到我的 MinIO 服务器,上传文件等。这不是网络问题。

谢谢!


编辑 1:添加我的 .gitlab-ci.yml 内容 + GitLab CI 作业输出

.gitlab-ci.yml内容

workflow:
  rules:
    - if: $CI_COMMIT_TAG != null
    - if: $CI_PIPELINE_SOURCE == "web"

variables:
  CACHE_DIR: /cache/$CI_PROJECT_ROOT_NAMESPACE/$CI_PROJECT_NAME/$CI_PIPELINE_ID

stages:
  - .pre
  - touch

create_cache_dir:
  stage: .pre
  tags:
    - runner-almalinux8
  image: alpine:latest
  script:
    - mkdir --parents $CACHE_DIR/

create_file:
  stage: touch
  tags:
    - runner-windows
  image: alpine:latest
  script:
    - touch $CACHE_DIR/test_create_file.txt

作业输出(.pre)

Running with gitlab-runner 17.0.0 (44feccdf)
  on runner-almalinux8 -_vLbzjNv, system ID: s_4f5c9ad29d6f
Preparing the "docker" executor
00:02
Using Docker executor with image alpine:latest ...
Pulling docker image alpine:latest ...
Using docker image sha256:05455a08881ea9cf0e752bc48e61bbd71a34c029bb13df01e40e3e70e0d007bd for alpine:latest with digest alpine@sha256:c5b1261d6d3e43071626931fc004f70149baeba2c8ec672bd4f27761f8e1ad6b ...
Preparing environment
00:01
Running on runner--vlbzjnv-project-116-concurrent-0 via runner-almalinux8...
Getting source from Git repository
00:01
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /builds/<group>/<project>/.git/
Checking out 456a298a as detached HEAD (ref is 1.0.0-rc1)...
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:01
Using docker image sha256:05455a08881ea9cf0e752bc48e61bbd71a34c029bb13df01e40e3e70e0d007bd for alpine:latest with digest alpine@sha256:c5b1261d6d3e43071626931fc004f70149baeba2c8ec672bd4f27761f8e1ad6b ...
$ mkdir --parents $CACHE_DIR/
Cleaning up project directory and file based variables
00:01
Job succeeded

作业输出(触摸)

Running with gitlab-runner 17.0.0 (44feccdf)
  on runner-windows cc5wbtykV, system ID: s_4f5c9ad29d6f
Preparing the "docker" executor
00:08
Using Docker executor with image alpine:latest ...
Using helper image:  registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper:x86_64-v17.0.0
Pulling docker image registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper:x86_64-v17.0.0 ...
Using docker image sha256:cb32fd9b1984b484e20e7b6806bd3a0ef5304abee2f0c64d5b38e1234c2a7bf5 for registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper:x86_64-v17.0.0 with digest registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper@sha256:aa094d2434e42a61215a64dfb50fb9b9dc29d81e4d708c1c896d0818a5d6f873 ...
Pulling docker image alpine:latest ...
Using docker image sha256:1d34ffeaf190be23d3de5a8de0a436676b758f48f835c3a2d4768b798c15a7f1 for alpine:latest with digest alpine@sha256:77726ef6b57ddf65bb551896826ec38bc3e53f75cdde31354fbffb4f25238ebd ...
Preparing environment
00:01
Running on runner-cc5wbtykv-project-326-concurrent-0 via runner-windows...
Getting source from Git repository
00:01
Fetching changes with git depth set to 20...
Initialized empty Git repository in /builds/<group>/<project>/.git/
Created fresh repository.
Checking out 456a298a as detached HEAD (ref is 1.0.0-rc1)...
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:00
Using docker image sha256:1d34ffeaf190be23d3de5a8de0a436676b758f48f835c3a2d4768b798c15a7f1 for alpine:latest with digest alpine@sha256:77726ef6b57ddf65bb551896826ec38bc3e53f75cdde31354fbffb4f25238ebd ...
$ touch $CACHE_DIR/test_create_file.txt
touch: /cache/<group>/<project>/3089/test_create_file.txt: No such file or directory
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1
docker gitlab gitlab-ci gitlab-ci-runner minio
1个回答
0
投票

缓存位置是 GitLab 存储缓存包的位置。要实际缓存内容,您需要在作业中声明可缓存项目:

build job:
  script:
   - touch cached_file.txt
  cache:
    paths:
    - ./cached_file.txt
© www.soinside.com 2019 - 2024. All rights reserved.