Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ubuntu: Cannot run the unit tests locally #1895

Closed
johnDeSilencio opened this issue Jun 26, 2023 · 9 comments
Closed

Ubuntu: Cannot run the unit tests locally #1895

johnDeSilencio opened this issue Jun 26, 2023 · 9 comments
Assignees
Labels
bug Something isn't working changelog-ignore Don't include this issue in the release changelog

Comments

@johnDeSilencio
Copy link
Contributor

What happened:

I tried running the unit tests locally with make unit, and I received the following error. I've reproduced this error in a WSL environment, on a 2014 Macbook Air laptop running Ubuntu 22.04, and on a Windows Hyper-V Ubuntu 22.04 VM:

$> make unit
Generating test fixtures
cd syft/pkg/cataloger/java/test-fixtures/java-builds && make
make[1]: Entering directory '/home/nicholas/Downloads/syft/syft/pkg/cataloger/java/test-fixtures/java-builds'
./build-example-jenkins-plugin.sh packages
+ PKGSDIR=packages
+++ id -u
+++ id -g
++ docker create -u 0:0 -e MAVEN_CONFIG=/tmp/.m2 -v /example-jenkins-plugin -w /example-jenkins-plugin maven:3.8.6-openjdk-18 mvn -Duser.home=/tmp -DskipTests package
+ CTRID=8ab8f03866e9b75cf272fda2e8e4f5c2d1a5521a60e22826d089cd0fc9c32e24
+ trap cleanup EXIT
+ set +e
++ pwd
+ docker cp /home/nicholas/Downloads/syft/syft/pkg/cataloger/java/test-fixtures/java-builds/example-jenkins-plugin 8ab8f03866e9b75cf272fda2e8e4f5c2d1a5521a60e22826d089cd0fc9c32e24:/
Successfully copied 26.1kB to 8ab8f03866e9b75cf272fda2e8e4f5c2d1a5521a60e22826d089cd0fc9c32e24:/
+ docker start -a 8ab8f03866e9b75cf272fda2e8e4f5c2d1a5521a60e22826d089cd0fc9c32e24
[INFO] Scanning for projects...
Downloading from repo.jenkins-ci.org: https://repo.jenkins-ci.org/public/org/jenkins-ci/plugins/plugin/4.46/plugin-4.46.pom
Downloading from central: https://repo.maven.apache.org/maven2/org/jenkins-ci/plugins/plugin/4.46/plugin-4.46.pom
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for io.jenkins.plugins:example-jenkins-plugin:1.0-SNAPSHOT: Could not transfer artifact org.jenkins-ci.plugins:plugin:pom:4.46 from/to repo.jenkins-ci.org (https://repo.jenkins-ci.org/public/): transfer failed for https://repo.jenkins-ci.org/public/org/jenkins-ci/plugins/plugin/4.46/plugin-4.46.pom and 'parent.relativePath' points at no local POM @ line 4, column 13
 @ 
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project io.jenkins.plugins:example-jenkins-plugin:1.0-SNAPSHOT (/example-jenkins-plugin/pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM for io.jenkins.plugins:example-jenkins-plugin:1.0-SNAPSHOT: Could not transfer artifact org.jenkins-ci.plugins:plugin:pom:4.46 from/to repo.jenkins-ci.org (https://repo.jenkins-ci.org/public/): transfer failed for https://repo.jenkins-ci.org/public/org/jenkins-ci/plugins/plugin/4.46/plugin-4.46.pom and 'parent.relativePath' points at no local POM @ line 4, column 13: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target -> [Help 2]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException
+ mkdir -p packages
+ docker cp 8ab8f03866e9b75cf272fda2e8e4f5c2d1a5521a60e22826d089cd0fc9c32e24:/example-jenkins-plugin/target/example-jenkins-plugin.hpi packages
Error response from daemon: Could not find the file /example-jenkins-plugin/target/example-jenkins-plugin.hpi in container 8ab8f03866e9b75cf272fda2e8e4f5c2d1a5521a60e22826d089cd0fc9c32e24
+ docker cp 8ab8f03866e9b75cf272fda2e8e4f5c2d1a5521a60e22826d089cd0fc9c32e24:/example-jenkins-plugin/target/example-jenkins-plugin.jar packages
Error response from daemon: Could not find the file /example-jenkins-plugin/target/example-jenkins-plugin.jar in container 8ab8f03866e9b75cf272fda2e8e4f5c2d1a5521a60e22826d089cd0fc9c32e24
+ cleanup
+ docker rm 8ab8f03866e9b75cf272fda2e8e4f5c2d1a5521a60e22826d089cd0fc9c32e24
8ab8f03866e9b75cf272fda2e8e4f5c2d1a5521a60e22826d089cd0fc9c32e24
make[1]: *** [Makefile:60: packages/example-jenkins-plugin.hpi] Error 1
make[1]: Leaving directory '/home/nicholas/Downloads/syft/syft/pkg/cataloger/java/test-fixtures/java-builds'
make: *** [Makefile:227: fixtures] Error 2

If I go to the URL in question, I get a 404 error. So it makes sense that the script bailed, but I've never used maven before and am not sure how to debug this issue.

What you expected to happen:

The unit tests to run without errors

Steps to reproduce the issue:

  1. Install Ubuntu 22.04 VM on Windows 10 Enterprise (OS build 19044.3086) through Hyper-V
  2. Walk through the installation steps as described in CONTRIBUTING.md
  3. Clone the repo and navigate to the new syft/ directory
  4. Run make bootstrap and make sure it finishes successfully
  5. Run make unit

Anything else we need to know?:

The company I work for is interested in creating a PR for syft to support cataloging dependencies installed with opkg. This bug is currently blocking that effort.

Environment:

$> uname -a
Linux nickvm 5.15.0-27-generic #28-Ubuntu SMP Thu Apr 14 04:55:28 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
$> cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
$> go version
go version go1.19.10 linux/amd64
$> docker version
Client: Docker Engine - Community
 Version:           24.0.2
 API version:       1.43
 Go version:        go1.20.4
 Git commit:        cb74dfc
 Built:             Thu May 25 21:51:00 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          24.0.2
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.4
  Git commit:       659604f
  Built:            Thu May 25 21:51:00 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.21
  GitCommit:        3dce8eb055cbb6872793272b4f20ed16117344f8
 runc:
  Version:          1.1.7
  GitCommit:        v1.1.7-0-g860f061
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
@johnDeSilencio johnDeSilencio added the bug Something isn't working label Jun 26, 2023
@willmurphyscode willmurphyscode self-assigned this Jun 27, 2023
@willmurphyscode
Copy link
Contributor

Thanks for the report @johnDeSilencio. make unit passes in an existing workspace, but I'm trying to reproduce in a clean checkout. make unit actually fails with a slightly different error for me on a clean checkout in fresh workspace, but I'll keep looking into it.

@willmurphyscode
Copy link
Contributor

Hi @johnDeSilencio, we've tried to reproduce this particular failure, but haven't yet. I've had teammates get passing unit tests on fresh checkouts on recent Debian VMs, Ubuntu docker images, and Ubuntu on WSL.

I'm curious about this part of your output:

[ERROR]   The project io.jenkins.plugins:example-jenkins-plugin:1.0-SNAPSHOT (/example-jenkins-plugin/pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM for io.jenkins.plugins:example-jenkins-plugin:1.0-SNAPSHOT: Could not transfer artifact org.jenkins-ci.plugins:plugin:pom:4.46 from/to repo.jenkins-ci.org (https://repo.jenkins-ci.org/public/): transfer failed for https://repo.jenkins-ci.org/public/org/jenkins-ci/plugins/plugin/4.46/plugin-4.46.pom and 'parent.relativePath' points at no local POM @ line 4, column 13: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target -> [Help 2]
[ERROR] 
SunCertPathBuilderException: unable to find valid certification path to requested target -> [Help 2]

Specifically SunCertPathBuilderException: unable to find valid certification path to requested target -> [Help 2] makes me think that there's an issue with the installed certificates or network connectivity from your workstation to https://repo.jenkins-ci.org/public/.

Are you able to browse to or curl to https://repo.jenkins-ci.org/public/org/jenkins-ci/plugins/plugin/4.46/plugin-4.46.pom from the hosts where you're trying to run make unit?

@johnDeSilencio
Copy link
Contributor Author

johnDeSilencio commented Jun 27, 2023

@willmurphyscode thank you for getting back to me so quickly, especially on a "it doesn't work on my machine" issue 😄

From my Ubuntu on WSL environment, both curl and wget have no problem reaching that URL:

$> curl -I https://repo.jenkins-ci.org/public/org/jenkins-ci/plugins/plugin/4.46/plugin-4.46.pom

HTTP/1.1 200 Connection Established
Proxy-Agent: [my company's proxy]

HTTP/1.1 200
Date: Tue, 27 Jun 2023 16:11:34 GMT
Content-Type: application/x-maven-pom+xml
Content-Length: 61637
Connection: keep-alive
[redacted headers]
Last-Modified: Tue, 27 Jun 2023 05:21:34 GMT
ETag: 7704bf89d35588d439026c6f0d593a63d0a7a50f
X-Checksum-Sha1: 7704bf89d35588d439026c6f0d593a63d0a7a50f
X-Checksum-Sha256: 390541940f52af05f5e07ad5c074ff37ed6e7b9ea0f1140563c4310c5e4cfe4f
X-Checksum-Md5: c2996562eb27d06f544bc47a2daa7a4e
Accept-Ranges: bytes
X-Artifactory-Filename: plugin-4.46.pom
Content-Disposition: attachment; filename="plugin-4.46.pom"; filename*=UTF-8''plugin-4.46.pom
Strict-Transport-Security: max-age=15724800; includeSubDomains
X-Request-ID: 171fdd5aad6997280244b622845e1a88

$> wget https://repo.jenkins-ci.org/public/org/jenkins-ci/plugins/plugin/4.46/plugin-4.46.pom
--2023-06-27 09:11:47--  https://repo.jenkins-ci.org/public/org/jenkins-ci/plugins/plugin/4.46/plugin-4.46.pom
Resolving mycompany.proxy.com (mycompany.proxy.com)... 192.168.1.240
Connecting to mycompany.proxy.com (mycompany.proxy.com)|192.168.1.240|:8080... connected.
Proxy request sent, awaiting response... 200
Length: 61637 (60K) [application/x-maven-pom+xml]
Saving to: ‘plugin-4.46.pom’

plugin-4.46.pom                                   100%[========================================================>]  60.19K   396KB/s    in 0.2s

2023-06-27 09:11:47 (396 KB/s) - ‘plugin-4.46.pom’ saved [61637/61637]

However, the URL https://repo.maven.apache.org/maven2/org/jenkins-ci/plugins/plugin/4.46/plugin-4.46.pom results in a 404 from both curl and wget`:

$> curl -I https://repo.maven.apache.org/maven2/org/jenkins-ci/plugins/plugin/4.46/plugin-4.46.pom
HTTP/1.1 200 Connection Established
Proxy-Agent: [my company's proxy]

HTTP/2 404
last-modified: Wed, 10 Aug 2016 15:08:35 GMT
etag: "1fb066da6a67c7c02962f59b4b8cd1ee"
x-amz-error-code: NoSuchKey
x-amz-error-message: The specified key does not exist.
x-amz-error-detail-key: maven2/org/jenkins-ci/plugins/plugin/4.46/plugin-4.46.pom
content-type: text/html
via: 1.1 varnish, 1.1 varnish
accept-ranges: bytes
date: Tue, 27 Jun 2023 16:44:41 GMT
age: 607917
x-served-by: cache-iad-kcgs7200178-IAD, cache-bfi-kbfi7400070-BFI
x-cache: HIT, HIT
x-cache-hits: 83, 1
x-timer: S1687884282.706991,VS0,VE2
content-length: 554

$> wget https://repo.maven.apache.org/maven2/org/jenkins-ci/plugins/plugin/4.46/plugin-4.46.pom
--2023-06-27 09:46:16--  https://repo.maven.apache.org/maven2/org/jenkins-ci/plugins/plugin/4.46/plugin-4.46.pom
Resolving mycompany.proxy.com (mycompany.proxy.com)... 192.168.1.240
Connecting to mycompany.proxy.com (mycompany.proxy.com)|192.168.1.240|:8080... connected.
Proxy request sent, awaiting response... 404 Not Found
2023-06-27 09:46:16 ERROR 404: Not Found.

@willmurphyscode
Copy link
Contributor

Hi @johnDeSilencio, thanks for checking on that so quickly.

It looks like you're talking to maven repos though a proxy?

Proxy-Agent: [my company's proxy]

I don't know how that proxy might be configured, but here's my hand-wavy hypothesis:

  1. We're building some of these test fixture jars inside docker, see
    CTRID=$(docker create -u "$(id -u):$(id -g)" -e MAVEN_CONFIG=/tmp/.m2 -v /example-jenkins-plugin -w /example-jenkins-plugin maven:3.8.6-openjdk-18 mvn -Duser.home=/tmp -DskipTests package)
  2. Your company's corporate IT is proxying some network traffic, including traffic to download these Jenkins dependencies
  3. Docker doesn't know about some of your host's network settings that allow it to download through the proxy (maybe there's a custom cert installed on your boxy that trusts the proxy to proxy maven?)

I think that might be causing cert errors.

But I think we're building those test fixtures in docker to avoid having people need to install a Java toolchain just to run our unit tests. Maybe you could unblock yourself by building the test fixture jars on the host or in WSL?

I think we're downloading from the Jenkins repo directly, not from maven central.https://repo.maven.apache.org/maven2/org/jenkins-ci/plugins/plugin/4.46/plugin-4.46.pom gives me a 404 as well, without any company proxy.

Let me know if that helps!

@johnDeSilencio
Copy link
Contributor Author

@willmurphyscode you were right to suspect the proxy! We use Artifactory at my company. Turns out, we already have a maven mirror set up. For future developers who also work at a company using Artifactory mirrors:

  1. Get the settings.xml file provided to you by your company's Artifactory:
  1. Put the settings.xml file under the syft/pkg/cataloger/java/test-fixtures/java-builds/example-jenkins-plugin directory:
    example_jenkins_plugin_settings

  2. Modify the mvn invocation in build-example-jenkins-plugin.sh to use settings.xml, e.g.

    CTRID=$(docker create -u "$(id -u):$(id -g)" -e MAVEN_CONFIG=/tmp/.m2 -v /example-jenkins-plugin -w /example-jenkins-plugin maven:3.8.6-openjdk-18 mvn -Duser.home=/tmp -DskipTests package)

    becomes CTRID=$(docker create -u "$(id -u):$(id -g)" -e MAVEN_CONFIG=/tmp/.m2 -v /example-jenkins-plugin -w /example-jenkins-plugin maven:3.8.6-openjdk-18 mvn -s /example-jenkins-plugin/settings.xml -Duser.home=/tmp -DskipTests package)

  3. Run make unit

@johnDeSilencio
Copy link
Contributor Author

johnDeSilencio commented Jun 27, 2023

While I do have you, @willmurphyscode, when I run make unit, I see that there is one test failing: TestAllLayersResolver_AllLocations in syft/internal/fileresolver/container_image_all_layers_test.go.

It appears that there are two unexpected files in the image file system: /lib/.wh..wh..opq and /target/.wh..wh..opq

$> make unit
Generating test fixtures
cd syft/pkg/cataloger/java/test-fixtures/java-builds && make
make[1]: Entering directory '/home/nicholas/Documents/temp/syft/syft/pkg/cataloger/java/test-fixtures/java-builds'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/nicholas/Documents/temp/syft/syft/pkg/cataloger/java/test-fixtures/java-builds'
cd syft/pkg/cataloger/rpm/test-fixtures && make
make[1]: Entering directory '/home/nicholas/Documents/temp/syft/syft/pkg/cataloger/rpm/test-fixtures'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/nicholas/Documents/temp/syft/syft/pkg/cataloger/rpm/test-fixtures'
cd syft/pkg/cataloger/binary/test-fixtures && make
make[1]: Entering directory '/home/nicholas/Documents/temp/syft/syft/pkg/cataloger/binary/test-fixtures'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/nicholas/Documents/temp/syft/syft/pkg/cataloger/binary/test-fixtures'
Running unit tests
go test -coverprofile ./.tmp/unit-coverage-details.txt github.com/anchore/syft/cmd/syft github.com/anchore/syft/cmd/syft/cli
// ...
ok  	github.com/anchore/syft/syft/formats/text	0.059s	coverage: 88.9% of statements
--- FAIL: TestAllLayersResolver_AllLocations (0.01s)
    container_image_all_layers_test.go:661: 
        	Error Trace:	/home/nicholas/Documents/temp/syft/syft/internal/fileresolver/container_image_all_layers_test.go:661
        	Error:      	elements differ
        	            	
        	            	extra elements in list B:
        	            	([]interface {}) (len=2) {
        	            	 (string) (len=17) "/lib/.wh..wh..opq",
        	            	 (string) (len=20) "/target/.wh..wh..opq"
        	            	}
        	            	
        	            	
        	            	listA:
        	            	([]string) (len=112) {
        	            	 (string) (len=11) "/Dockerfile",
// ...
        	            	 (string) (len=28) "/lib/sysctl.d/00-alpine.conf"
        	            	}
        	            	
        	            	
        	            	listB:
        	            	([]string) (len=114) {
        	            	 (string) (len=8) "/.wh.bin",
// ...
        	            	 (string) (len=17) "/lib/.wh..wh..opq",
// ...
        	            	 (string) (len=20) "/target/.wh..wh..opq",
        	            	 (string) (len=18) "/target/file-2.txt"
        	            	}
        	Test:       	TestAllLayersResolver_AllLocations
        	Messages:   	expected all paths to be indexed, but found different paths: 
        	            	  []string{
        	            	- 	"/Dockerfile",
// ...  
        	            	  	... // 9 identical, 34 removed, 44 inserted, and 51 modified elements
        	            	  }
FAIL
coverage: 74.2% of statements
FAIL	github.com/anchore/syft/syft/internal/fileresolver	2.899s
ok  	github.com/anchore/syft/syft/license	0.001s	coverage: 90.0% of statements
// ...
?   	github.com/anchore/syft/ui	[no test files]
FAIL
make: *** [Makefile:150: unit] Error 1

Could this be another issue with my environment?

@willmurphyscode
Copy link
Contributor

@johnDeSilencio a teammate had that exact error earlier today running in an old Debian VM. They were able to get the tests passing by upgrading from Debian 11 to Debian 12, and upgrading docker and go. Your versions seem pretty recent, but that might be something you can try.

@johnDeSilencio
Copy link
Contributor Author

johnDeSilencio commented Jun 27, 2023

Locks like I have the most recent version of docker on my system. My Ubuntu 22.04 environment is also all up to date. I did upgrade go to 1.20.5, but that still didn't fix the unit test error with the /lib/.wh..wh..opq and /target/.wh..wh..opq files.

As a workaround, I can add those files to the expected list of files and paths in the TestAllLayersResolver_AllLocations test.

I think we got to root cause for the original issue. I now can build the unit tests, and am no longer blocked from contributing. All that being said, I'm going to close this issue as resolved.

@willmurphyscode thank you again for all your help! Interacting with kind people like yourself is what makes open source enjoyable 😄

@willmurphyscode willmurphyscode added the changelog-ignore Don't include this issue in the release changelog label Jun 29, 2023
@wagoodman wagoodman removed this from OSS Jun 29, 2023
@wagoodman
Copy link
Contributor

Should we try to capture this in the DEVELOPING.md? #1895 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working changelog-ignore Don't include this issue in the release changelog
Projects
None yet
Development

No branches or pull requests

3 participants