tern-tools / tern

Tern is a software composition analysis tool and Python library that generates a Software Bill of Materials for container images and Dockerfiles. The SBOM that Tern generates will give you a layer-by-layer view of what's inside your container in a variety of formats including human-readable, JSON, HTML, SPDX and more.
BSD 2-Clause "Simplified" License
967 stars 188 forks source link

Can't build images with Dockerfile samples #1235

Closed armintaenzertng closed 1 year ago

armintaenzertng commented 1 year ago

Four of the provided Dockerfiles in the samples directory lead to errors when I try to build an image from them. These are the ones under debian_vim, photon_3_layers, photon_git, and photon_openjre.

To Reproduce docker build ./samples/debian_vim and similar for the other sample directories.

Error in terminal

$ docker build ./samples/debian_vim ``` [+] Building 1.3s (5/5) FINISHED => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 215B 0.0s => [internal] load metadata for docker.io/library/debian:jessie 0.0s => [1/2] FROM docker.io/library/debian:jessie 0.0s => ERROR [2/2] RUN apt-get update && apt-get install -y vim && apt-get clean 1.2s ------ > [2/2] RUN apt-get update && apt-get install -y vim && apt-get clean: #0 0.888 Ign http://deb.debian.org jessie InRelease #0 0.888 Ign http://security.debian.org jessie/updates InRelease #0 0.907 Ign http://deb.debian.org jessie-updates InRelease #0 0.907 Ign http://security.debian.org jessie/updates Release.gpg #0 0.926 Ign http://deb.debian.org jessie Release.gpg #0 0.932 Ign http://security.debian.org jessie/updates Release #0 0.953 Err http://security.debian.org jessie/updates/main amd64 Packages #0 0.953 #0 0.964 Ign http://deb.debian.org jessie-updates Release.gpg #0 0.973 Err http://security.debian.org jessie/updates/main amd64 Packages #0 0.973 #0 0.985 Ign http://deb.debian.org jessie Release #0 0.992 Err http://security.debian.org jessie/updates/main amd64 Packages #0 0.992 #0 1.013 Ign http://deb.debian.org jessie-updates Release #0 1.013 Err http://security.debian.org jessie/updates/main amd64 Packages #0 1.013 #0 1.033 Err http://security.debian.org jessie/updates/main amd64 Packages #0 1.033 404 Not Found [IP: 151.101.194.132 80] #0 1.204 Err http://deb.debian.org jessie/main amd64 Packages #0 1.204 404 Not Found #0 1.223 Err http://deb.debian.org jessie-updates/main amd64 Packages #0 1.223 404 Not Found #0 1.225 W: Failed to fetch http://security.debian.org/debian-security/dists/jessie/updates/main/binary-amd64/Packages 404 Not Found [IP: 151.101.194.132 80] #0 1.225 #0 1.225 W: Failed to fetch http://deb.debian.org/debian/dists/jessie/main/binary-amd64/Packages 404 Not Found #0 1.225 #0 1.225 W: Failed to fetch http://deb.debian.org/debian/dists/jessie-updates/main/binary-amd64/Packages 404 Not Found #0 1.225 #0 1.225 E: Some index files failed to download. They have been ignored, or old ones used instead. ------ Dockerfile:4 -------------------- 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | FROM debian:jessie 4 | >>> RUN apt-get update && apt-get install -y vim && apt-get clean 5 | -------------------- ERROR: failed to solve: process "/bin/sh -c apt-get update && apt-get install -y vim && apt-get clean" did not complete successfully: exit code: 100 ```
$ docker build ./samples/photon_3_layers/ ``` [+] Building 0.4s (5/6) => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 257B 0.0s => [internal] load metadata for docker.io/vmware/photon2:GA 0.0s => [1/3] FROM docker.io/vmware/photon2:GA 0.0s => ERROR [2/3] RUN tyum install -y git && tyum clean all 0.3s ------ > [2/3] RUN tyum install -y git && tyum clean all: #0 0.263 curl#6: Couldn't resolve host name #0 0.263 Error: Failed to synchronize cache for repo 'VMware Photon Linux 2.0(x86_64) Updates' from 'https://dl.bintray.com/vmware/photon_updates_2.0_x86_64' #0 0.276 curl#6: Couldn't resolve host name #0 0.276 Error: Failed to synchronize cache for repo 'VMware Photon Linux 2.0(x86_64)' from 'https://dl.bintray.com/vmware/photon_release_2.0_x86_64' #0 0.288 curl#6: Couldn't resolve host name #0 0.288 Error: Failed to synchronize cache for repo 'VMware Photon Extras 2.0(x86_64)' from 'https://dl.bintray.com/vmware/photon_extras_2.0_x86_64' #0 0.290 Error(1011) : No matching packages #0 0.290 Refreshing metadata for: 'VMware Photon Linux 2.0(x86_64) Updates' #0 0.290 Disabling Repo: 'VMware Photon Linux 2.0(x86_64) Updates' #0 0.290 Refreshing metadata for: 'VMware Photon Linux 2.0(x86_64)' #0 0.290 Disabling Repo: 'VMware Photon Linux 2.0(x86_64)' #0 0.290 Refreshing metadata for: 'VMware Photon Extras 2.0(x86_64)' #0 0.290 Disabling Repo: 'VMware Photon Extras 2.0(x86_64)' #0 0.290 No package git available ------ Dockerfile:4 -------------------- 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | FROM vmware/photon2:GA 4 | >>> RUN tyum install -y git && tyum clean all 5 | RUN tyum install -y vim && tyum clean all 6 | -------------------- ERROR: failed to solve: process "/bin/sh -c tyum install -y git && tyum clean all" did not complete successfully: exit code: 243 ```
$ docker build ./samples/photon_git/ ``` [+] Building 0.4s (5/5) FINISHED => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 215B 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load metadata for docker.io/vmware/photon:1.0 0.0s => [1/2] FROM docker.io/vmware/photon:1.0 0.0s => ERROR [2/2] RUN tyum install -y git && tyum clean all 0.4s ------ > [2/2] RUN tyum install -y git && tyum clean all: #0 0.277 curl#6: Couldn't resolve host name #0 0.277 Error: Failed to synchronize cache for repo 'VMware Photon Linux 1.0(x86_64)Updates' from 'https://dl.bintray.com/vmware/photon_updates_1.0_x86_64' #0 0.297 curl#6: Couldn't resolve host name #0 0.297 Error: Failed to synchronize cache for repo 'VMware Lightwave 1.0(x86_64)' from 'https://dl.bintray.com/vmware/lightwave' #0 0.318 curl#6: Couldn't resolve host name #0 0.318 Error: Failed to synchronize cache for repo 'VMware Photon Linux 1.0(x86_64)' from 'https://dl.bintray.com/vmware/photon_release_1.0_x86_64' #0 0.341 curl#6: Couldn't resolve host name #0 0.341 Error: Failed to synchronize cache for repo 'VMware Photon Extras 1.0(x86_64)' from 'https://dl.bintray.com/vmware/photon_extras' #0 0.344 Refreshing metadata for: 'VMware Photon Linux 1.0(x86_64)Updates' #0 0.344 Disabling Repo: 'VMware Photon Linux 1.0(x86_64)Updates' #0 0.344 Refreshing metadata for: 'VMware Lightwave 1.0(x86_64)' #0 0.344 Disabling Repo: 'VMware Lightwave 1.0(x86_64)' #0 0.344 Refreshing metadata for: 'VMware Photon Linux 1.0(x86_64)' #0 0.344 Disabling Repo: 'VMware Photon Linux 1.0(x86_64)' #0 0.344 Refreshing metadata for: 'VMware Photon Extras 1.0(x86_64)' #0 0.344 Disabling Repo: 'VMware Photon Extras 1.0(x86_64)' #0 0.344 No package git available #0 0.344 Error(1011) : No matching packages ------ Dockerfile:4 -------------------- 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | FROM vmware/photon:1.0 4 | >>> RUN tyum install -y git && tyum clean all 5 | -------------------- ERROR: failed to solve: process "/bin/sh -c tyum install -y git && tyum clean all" did not complete successfully: exit code: 243 ```
$ docker build ./samples/photon_openjre/ ``` [+] Building 0.5s (5/5) FINISHED => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 219B 0.0s => [internal] load metadata for docker.io/vmware/photon:1.0 0.0s => CACHED [1/2] FROM docker.io/vmware/photon:1.0 0.0s => ERROR [2/2] RUN tyum install -y openjre && tyum clean all 0.4s ------ > [2/2] RUN tyum install -y openjre && tyum clean all: #0 0.316 curl#6: Couldn't resolve host name #0 0.316 Error: Failed to synchronize cache for repo 'VMware Photon Linux 1.0(x86_64)Updates' from 'https://dl.bintray.com/vmware/photon_updates_1.0_x86_64' #0 0.336 curl#6: Couldn't resolve host name #0 0.336 Error: Failed to synchronize cache for repo 'VMware Lightwave 1.0(x86_64)' from 'https://dl.bintray.com/vmware/lightwave' #0 0.359 curl#6: Couldn't resolve host name #0 0.359 Error: Failed to synchronize cache for repo 'VMware Photon Linux 1.0(x86_64)' from 'https://dl.bintray.com/vmware/photon_release_1.0_x86_64' #0 0.379 curl#6: Couldn't resolve host name #0 0.379 Error: Failed to synchronize cache for repo 'VMware Photon Extras 1.0(x86_64)' from 'https://dl.bintray.com/vmware/photon_extras' #0 0.383 Refreshing metadata for: 'VMware Photon Linux 1.0(x86_64)Updates' #0 0.383 Disabling Repo: 'VMware Photon Linux 1.0(x86_64)Updates' #0 0.383 Refreshing metadata for: 'VMware Lightwave 1.0(x86_64)' #0 0.383 Disabling Repo: 'VMware Lightwave 1.0(x86_64)' #0 0.383 Refreshing metadata for: 'VMware Photon Linux 1.0(x86_64)' #0 0.383 Disabling Repo: 'VMware Photon Linux 1.0(x86_64)' #0 0.383 Refreshing metadata for: 'VMware Photon Extras 1.0(x86_64)' #0 0.383 Disabling Repo: 'VMware Photon Extras 1.0(x86_64)' #0 0.383 No package openjre available #0 0.383 Error(1011) : No matching packages ------ Dockerfile:4 -------------------- 2 | # SPDX-License-Identifier: BSD-2-Clause 3 | FROM vmware/photon:1.0 4 | >>> RUN tyum install -y openjre && tyum clean all 5 | -------------------- ERROR: failed to solve: process "/bin/sh -c tyum install -y openjre && tyum clean all" did not complete successfully: exit code: 243 ```

Expected behavior I expect the building of images from the provided Dockerfiles to succeed.

Environment you are running Tern on

rnjudge commented 1 year ago

Thanks @armintaenzertng. I'm not actually sure what those sample image Dockerfiles are for. Looks like @nishakm added them almost 5 years ago so I'm not terribly surprised they won't build. Are you trying to build the images to run Tern on them?

armintaenzertng commented 1 year ago

Yes, I stumbled upon this while trying out the command described here in the README that uses these Dockerfiles.

rnjudge commented 1 year ago

Ah, good catch. I will update these files (and probably delete a handful of them since I don't want to maintain them all).

rnjudge commented 1 year ago

@armintaenzertng I looked at each of the files you had issues with but didn't quite reproduce all the same errors. Here's what I saw:

$ tern report -d samples/debian_vim/Dockerfile ``` 2023-07-13 14:38:14,005 - DEBUG - run - Building Docker image with Dockerfile: debian_vim/Dockerfile 2023-07-13 14:38:16,296 - WARNING - docker_api - Build failed: no matching manifest for linux/arm64/v8 in the manifest list entries 2023-07-13 14:38:16,296 - WARNING - docker_api - Could not build Docker image 2023-07-13 14:38:16,296 - WARNING - run - Cannot build image 2023-07-13 14:38:16,296 - DEBUG - run - Analyzing base image... 2023-07-13 14:38:16,304 - DEBUG - docker_api - Checking if image "debian:jessie" is available on disk... 2023-07-13 14:38:16,305 - DEBUG - docker_api - Attempting to pull image "debian:jessie" 2023-07-13 14:38:18,096 - ERROR - docker_api - No such image: "debian:jessie" 2023-07-13 14:38:18,096 - ERROR - run - Cannot analyze base image ```
$ tern report -d samples/photon_3_layers/Dockerfile ``` 023-07-13 14:48:03,114 - DEBUG - run - Parsing Dockerfile... 2023-07-13 14:48:03,115 - DEBUG - run - Building Docker image with Dockerfile: photon_3_layers/Dockerfile 2023-07-13 14:48:08,555 - WARNING - docker_api - Build failed: The command '/bin/sh -c tyum install -y git && tyum clean all' returned a non-zero code: 1 ```
$ tern report -d samples/photon_git/Dockerfile ``` 023-07-13 14:54:36,976 - DEBUG - run - Parsing Dockerfile... 2023-07-13 14:54:36,977 - DEBUG - run - Building Docker image with Dockerfile: photon_git/Dockerfile 2023-07-13 14:54:43,797 - WARNING - docker_api - Build failed: The command '/bin/sh -c tyum install -y git && tyum clean all' returned a non-zero code: 1 2023-07-13 14:54:43,798 - WARNING - docker_api - Could not build Docker image 2023-07-13 14:54:43,798 - WARNING - run - Cannot build image ```
$ tern report -d samples/photon_openjre/Dockerfile ``` Same error as photon_git above ```

I'll push these changes and include them in the latest Tern release.