5

I setup a GitLab runner on EC2 which triggers jobs on a Fargate ECS cluster. I followed this tutorial step by step: https://docs.gitlab.com/runner/configuration/runner_autoscale_aws_fargate

During my CI/CD I build docker image then I want to reuse them during other stages of my CI/CD. So when I used shared runner I used docker dind:

  image: docker:stable
  services:
    - docker:dind

My config.toml looks like this:

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"]

What should I do to use docker command during my CI/CD and to keep docker image of each build between all stages?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Howins
  • 487
  • 1
  • 6
  • 18
  • 1
    I don't think this is possible as the image will be stored locally them destroyed at this end of the stage. One option could be to use docker save/load to export the image as an artefact or cached folder – Cyril G. Mar 16 '22 at 14:01
  • I was thinking this too. To use docker save/load should I use docker dind or just install docker in my debian image that I use on ECS for each job? – Howins Mar 16 '22 at 14:06
  • You probably don't need dind as your base image is docker:stable, but I don't remember when dind is useful. – Cyril G. Mar 16 '22 at 14:09

1 Answers1

4

docker:dind requires privileged execution. It is not possible to use privileged containers on Fargate, so this is not directly possible.

However, you may be able to use daemonless image builders, such as kaniko to build docker images and, optionally, use those images as the build image for later jobs.

You can also explore alternatives, like using CodeBuild to build images with the fargate executor.

sytech
  • 29,298
  • 3
  • 45
  • 86