在 ecs fargate 上使用 docker dind 和 GitLab runner

How*_*ins 5 gitlab docker gitlab-ci gitlab-ci-runner aws-fargate

我在 EC2 上设置了一个 GitLab 运行程序,它会触发 Fargate ECS 集群上的作业。我一步步遵循本教程:https ://docs.gitlab.com/runner/configuration/runner_autoscale_aws_fargate

在 CI/CD 期间,我构建了 docker 映像,然后我想在 CI/CD 的其他阶段重用它们。所以当我使用共享运行器时,我使用了 docker dind:

  image: docker:stable
  services:
    - docker:dind
Run Code Online (Sandbox Code Playgroud)

我的config.toml看起来像这样:

concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "fargate-runner"
  url = "https://gitlab.com/"
  token = "KRGVsYCF-V-D1u7UvCjq"
  executor = "custom"
  builds_dir = "/opt/gitlab-runner/builds"
  cache_dir = "/opt/gitlab-runner/cache"
  [runners.custom]
    config_exec = "/opt/gitlab-runner/fargate"
    config_args = ["--config", "/etc/gitlab-runner/fargate.toml", "custom", "config"]
    prepare_exec = "/opt/gitlab-runner/fargate"
    prepare_args = ["--config", "/etc/gitlab-runner/fargate.toml", "custom", "prepare"]
    run_exec = "/opt/gitlab-runner/fargate"
    run_args = ["--config", "/etc/gitlab-runner/fargate.toml", "custom", "run"]
    cleanup_exec = "/opt/gitlab-runner/fargate"
    cleanup_args = ["--config", "/etc/gitlab-runner/fargate.toml", "custom", "cleanup"]
Run Code Online (Sandbox Code Playgroud)

我应该怎么做才能在 CI/CD 期间使用 docker 命令并在所有阶段之间保留每个构建的 docker 映像?

syt*_*ech 4

docker:dind需要特权执行。无法在 Fargate 上使用特权容器,因此这不是直接可能的。

但是,您可以使用无守护程序映像构建器(例如kaniko)来构建 docker 映像,并且可以选择使用这些映像作为后续作业的构建映像。

您还可以探索替代方案,例如使用 CodeBuild通过 Fargate 执行器构建映像。