为了在 gitlab-runner 中使用 cache,配置了一个 minio 服务用于存储缓存的中间文件。

参考官方文档

  1. 下载 minio 服务端
  2. 配置 /etc/default/minio 配置文件
    # 修改存储数据的路径
    MINIO_VOLUMES="/tmp/minio/"
    # Use if you want to run MinIO on a custom port.
    MINIO_OPTS="--address :9000 --console-address :9001"
    # Root user for the server.
    MINIO_ROOT_USER=Root-User
    # Root secret for the server.
    MINIO_ROOT_PASSWORD=Root-Password
    
  3. 下载 minio.service 文件
    [Unit]
    Description=MinIO
    Documentation=https://docs.min.io
    Wants=network-online.target
    After=network-online.target
    AssertFileIsExecutable=/usr/local/bin/minio
    
    [Service]
    WorkingDirectory=/usr/local/
    
    User=minio
    Group=minio
    ProtectProc=invisible
    
    EnvironmentFile=/etc/default/minio
    ExecStartPre=/bin/bash -c "if [ -z \"${MINIO_VOLUMES}\" ]; then echo \"Variable MINIO_VOLUMES not set in /etc/default/minio\"; exit 1; fi"
    ExecStart=/usr/local/bin/minio server $MINIO_OPTS $MINIO_VOLUMES
    
    # Let systemd restart this service always
    Restart=always
    
    # Specifies the maximum file descriptor number that can be opened by this process
    LimitNOFILE=1048576
    
    # Specifies the maximum number of threads this process can create
    TasksMax=infinity
    
    # Disable timeout logic and wait until process is stopped
    TimeoutStopSec=infinity
    SendSIGKILL=no
    
    [Install]
    WantedBy=multi-user.target
    
    # Built for ${project.name}-${project.version} (${project.name})
    

    注意
    在2中,设置了一个 minio 的存储目录,在 3 中设置了用户和组,为了避免使用 root,添加下面的组和用户:

    sudo groupadd minio
    sudo useradd -g minio minio
    

    然后设置 2 中目录的权限:

    sudo chown -R minio:minio /xxxxx/data
    
  4. 启用和启动服务
    systemctl enable minio.service
    systemctl start minio.service
    
  5. 访问:http://IP:9001

gitlab-runner 的 config.toml 配置

修改 cache 相关的配置:

  [runners.cache]
    Type = "s3"
    Shared = true
    [runners.cache.s3]
      ServerAddress = "IP:9000"
      AccessKey = "USER"
      SecretKey = "PASSWORD"
      BucketName = "gitlab-runner"
      Insecure = true
Logo

更多推荐