1

I have a gitlab repository that contains multiple dockerfiles. I know that this is not ideal. I now want to use my gitlab pipeline to create one image per dockerfile using kaniko and pushing it to its corresponding AWS ECR. Of course I can define a job for each dockerfile but this results in duplication of code and overhead in runtime. Is it possible to build multiple dockerfiles at the same time in one job? A possible approach would be to pass a string array with the dockerfiles, and then iterate over the corresponding kaniko command. However, since kaniko only provides a busybox shell, all this is not really nice and easy. Ideas?

Stefan
  • 1,253
  • 2
  • 12
  • 36
  • Is the number of dockerfiles constant? – sehe Mar 24 '21 at 16:17
  • I would like to create a template that I can reuse for different repositories. Therefore the number of dockerfiles is not constant. But I would appreciate any approach, even if it does not solve the problem completely. – Stefan Mar 25 '21 at 08:08
  • 1
    Why not using in a single job a for loop with the list of the Dockerfiles and pass each to kaniko using the switch `--dockerfile`? – Davide Madrisan Aug 19 '21 at 16:46
  • @DavideMadrisan Yep, thats what I did (and mean by "iterate over a string array with the dockerfiles"), but loops in busybox are not that intuitive or nice. Therefore I dont like that approach. But it seems to be the best way to go for now. – Stefan Aug 20 '21 at 13:28
  • 1
    Looping is the way to go, but make sure you use the flag "--cleanup" to get rid of the last build in the container. – Mreider Nov 11 '21 at 16:28

0 Answers0