saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:
https://repo.saltproject.io/
Apache License 2.0
14.16k stars 5.48k forks source link

[BUG] intermediate docker image built through salt are not removed #65122

Open ysagon opened 1 year ago

ysagon commented 1 year ago

Description Shinken docker image built through salt is too big. Multiple intermediate images are built. Not possible to remove them as they are child of the parent image.

Setup (Please provide relevant configs and/or SLS files (be sure to remove sensitive info. There is no general set-up of Salt.)

Please be as specific as possible and give set-up details.

shinken-image:
  docker_image.present:
    - build: {{ shinken_docker_dir }} # /root/shinken_docker
    - tag: latest
    - rm: true
    - require:
      - file: shinken_docker_repo    

Dockerfile in /root/shinken_docker

Steps to Reproduce the behavior launch the state

Expected behavior one docker image should be built. Instead multiple child images are built:

[root@admin1 ~]$ docker image ls -a
REPOSITORY      TAG       IMAGE ID       CREATED              SIZE
<none>          <none>    5b67bea55594   24 seconds ago       403MB
<none>          <none>    d6378c856fe7   24 seconds ago       403MB
shinken-image   latest    1eadd641561c   24 seconds ago       403MB
<none>          <none>    3781c8db14f1   24 seconds ago       403MB
<none>          <none>    a0356e967efd   24 seconds ago       403MB
<none>          <none>    b7ea644ccf0f   25 seconds ago       387MB
<none>          <none>    0df4d1ac3b91   25 seconds ago       387MB
<none>          <none>    5542746da436   27 seconds ago       387MB
<none>          <none>    730686e3aea3   27 seconds ago       387MB
<none>          <none>    0c4dcdd2a586   29 seconds ago       387MB
<none>          <none>    db83dda45979   About a minute ago   220MB
<none>          <none>    a722e5d56406   About a minute ago   204MB
<none>          <none>    d9d4cee3d4fc   About a minute ago   204MB
<none>          <none>    8bd8d68d7564   About a minute ago   220MB
<none>          <none>    ee943cd9d457   About a minute ago   204MB
centos          7         eeb6ee3f44bd   24 months ago        204MB

If doing the same from CLI:

[root@admin1 shinken_docker]$ docker build -t shinken-image:latest .

Only one image is built:

docker image ls -a
REPOSITORY      TAG       IMAGE ID       CREATED          SIZE
shinken-image   latest    ed60c3103723   11 seconds ago   403MB
centos          7         eeb6ee3f44bd   24 months ago    204MB
Salt Version:
          Salt: 3006.2

Python Version:
        Python: 3.10.12 (main, Aug  3 2023, 21:47:10) [GCC 11.2.0]

Dependency Versions:
          cffi: 1.14.6
      cherrypy: unknown
      dateutil: 2.8.1
     docker-py: 6.1.3
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 3.1.2
       libgit2: Not Installed
  looseversion: 1.0.2
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 1.0.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     packaging: 22.0
     pycparser: 2.21
      pycrypto: Not Installed
  pycryptodome: 3.9.8
        pygit2: Not Installed
  python-gnupg: 0.4.8
        PyYAML: 6.0.1
         PyZMQ: 23.2.0
        relenv: 0.13.3
         smmap: Not Installed
       timelib: 0.2.4
       Tornado: 4.5.3
           ZMQ: 4.3.4

System Versions:
          dist: rocky 8.8 Green Obsidian
        locale: utf-8
       machine: x86_64
       release: 4.18.0-477.10.1.el8_8.x86_64
        system: Linux
       version: Rocky Linux 8.8 Green Obsidian

Additional context Add any other context about the problem here.

OrangeDog commented 1 year ago

It appears that the the rm parameter, which defaults to True anyway, is not working.

Remove intermediate containers created during build

Can you update the issue title to mention this?

OrangeDog commented 1 year ago

@dwoz the image is not too big. They're both exactly the same: 403MB

The problem is it published all the intermediate layers, despite the rm parameter.

ysagon commented 1 year ago

Can you update the issue title to mention this? @OrangeDog done.