diff --git a/.github/workflows/accessTests.yml b/.github/workflows/accessTests.yml index 4d443ac37..16f290757 100644 --- a/.github/workflows/accessTests.yml +++ b/.github/workflows/accessTests.yml @@ -37,7 +37,6 @@ jobs: uses: jfrog/.github/actions/install-local-artifactory@main with: RTLIC: ${{ secrets.RTLIC }} - VERSION: 7.104.15 - name: Get ID Token and Exchange Token shell: bash diff --git a/.github/workflows/artifactoryTests.yml b/.github/workflows/artifactoryTests.yml index bc833c3f0..c4e380e3e 100644 --- a/.github/workflows/artifactoryTests.yml +++ b/.github/workflows/artifactoryTests.yml @@ -37,7 +37,6 @@ jobs: uses: jfrog/.github/actions/install-local-artifactory@main with: RTLIC: ${{ secrets.RTLIC }} - VERSION: 7.104.15 - name: Run Artifactory tests run: go test -v github.com/jfrog/jfrog-cli --timeout 0 --test.artifactory --jfrog.url=http://127.0.0.1:8082 --jfrog.adminToken=${{ env.JFROG_TESTS_LOCAL_ACCESS_TOKEN }} diff --git a/.github/workflows/gradleTests.yml b/.github/workflows/gradleTests.yml index 05b42eff3..3f5d6a21a 100644 --- a/.github/workflows/gradleTests.yml +++ b/.github/workflows/gradleTests.yml @@ -48,7 +48,6 @@ jobs: uses: jfrog/.github/actions/install-local-artifactory@main with: RTLIC: ${{ secrets.RTLIC }} - VERSION: 7.104.15 - name: Run Gradle tests run: go test -v github.com/jfrog/jfrog-cli --timeout 0 --test.gradle diff --git a/.github/workflows/mavenTests.yml b/.github/workflows/mavenTests.yml index 67c7da938..88b438b19 100644 --- a/.github/workflows/mavenTests.yml +++ b/.github/workflows/mavenTests.yml @@ -40,7 +40,6 @@ jobs: uses: jfrog/.github/actions/install-local-artifactory@main with: RTLIC: ${{ secrets.RTLIC }} - VERSION: 7.104.15 - name: Run Maven tests run: go test -v github.com/jfrog/jfrog-cli --timeout 0 --test.maven diff --git a/.github/workflows/npmTests.yml b/.github/workflows/npmTests.yml index 70794b2fa..792e26def 100644 --- a/.github/workflows/npmTests.yml +++ b/.github/workflows/npmTests.yml @@ -39,7 +39,6 @@ jobs: uses: jfrog/.github/actions/install-local-artifactory@main with: RTLIC: ${{ secrets.RTLIC }} - VERSION: 7.104.15 - name: Run npm tests env: diff --git a/.github/workflows/nugetTests.yml b/.github/workflows/nugetTests.yml index 29e1d1720..fd8ee9ca1 100644 --- a/.github/workflows/nugetTests.yml +++ b/.github/workflows/nugetTests.yml @@ -63,7 +63,6 @@ jobs: uses: jfrog/.github/actions/install-local-artifactory@main with: RTLIC: ${{ secrets.RTLIC }} - VERSION: 7.104.15 - name: Run NuGet tests run: go test -v github.com/jfrog/jfrog-cli --timeout 0 --test.nuget diff --git a/.github/workflows/pluginsTests.yml b/.github/workflows/pluginsTests.yml index c92150dad..e3c1fcca6 100644 --- a/.github/workflows/pluginsTests.yml +++ b/.github/workflows/pluginsTests.yml @@ -34,7 +34,6 @@ jobs: uses: jfrog/.github/actions/install-local-artifactory@main with: RTLIC: ${{ secrets.RTLIC }} - VERSION: 7.104.15 - name: Run plugins tests run: go test -v github.com/jfrog/jfrog-cli --timeout 0 --test.plugins diff --git a/.github/workflows/pythonTests.yml b/.github/workflows/pythonTests.yml index cbeff536e..926dc4444 100644 --- a/.github/workflows/pythonTests.yml +++ b/.github/workflows/pythonTests.yml @@ -49,7 +49,6 @@ jobs: uses: jfrog/.github/actions/install-local-artifactory@main with: RTLIC: ${{ secrets.RTLIC }} - VERSION: 7.104.15 - name: Run Python tests run: go test -v github.com/jfrog/jfrog-cli --timeout 0 --test.${{ matrix.suite }} diff --git a/.github/workflows/transferTests.yml b/.github/workflows/transferTests.yml index 70b8c2d59..e2326897b 100644 --- a/.github/workflows/transferTests.yml +++ b/.github/workflows/transferTests.yml @@ -58,7 +58,7 @@ jobs: with: RTLIC: ${{ secrets.RTLIC_V6 }} JFROG_HOME: ${{ runner.temp }} - VERSION: 7.104.15 + VERSION: 6.23.21 - name: Run transfer tests run: go test -v github.com/jfrog/jfrog-cli --timeout 0 --test.transfer --test.installDataTransferPlugin --jfrog.targetUrl=${{ secrets.PLATFORM_URL }} --jfrog.targetAdminToken=${{ secrets.PLATFORM_ADMIN_TOKEN }} --jfrog.home=${{ runner.temp }} --ci.runId=${{ runner.os }}-transfer-6 diff --git a/docker_test.go b/docker_test.go index 10552460c..7b6f7a47e 100644 --- a/docker_test.go +++ b/docker_test.go @@ -179,6 +179,39 @@ func runPushTest(containerManager container.ContainerManagerType, imageName, mod validateContainerBuild(tests.DockerBuildName, buildNumber, imagePath, module, 7, 5, 7, t) } +func loginToArtifactory(t *testing.T, container *tests.TestContainer) { + password := *tests.JfrogPassword + user := *tests.JfrogUser + if *tests.JfrogAccessToken != "" { + user = auth.ExtractUsernameFromAccessToken(*tests.JfrogAccessToken) + password = *tests.JfrogAccessToken + } + assert.NoError(t, container.Exec( + context.Background(), + "docker", + "login", + tests.RtContainerHostName, + "--username="+user, + "--password="+password, + )) +} + +func buildBuilderImage(t *testing.T, workspace, dockerfile, containerName string) *tests.TestContainer { + ctx := context.Background() + testContainer, err := tests.NewContainerRequest(). + SetDockerfile(workspace, dockerfile, nil). + Privileged(). + Networks(rtNetwork). + Name(containerName). + Mount(mount.Mount{Type: mount.TypeBind, Source: workspace, Target: "/workspace", ReadOnly: false}). + Cmd("--insecure-registry", tests.RtContainerHostName). + WaitFor(wait.ForLog("API listen on /var/run/docker.sock").WithStartupTimeout(5*time.Minute)). + Remove(). + Build(ctx, true) + assert.NoError(t, err, "Couldn't create builder image.") + return testContainer +} + // This test validate the collect build-info flow for fat-manifest images. // The way we build the fat manifest and push it to Artifactory is not important. // Therefore, this test runs only with docker. @@ -194,7 +227,6 @@ func TestPushFatManifestImage(t *testing.T) { assert.NoError(t, fileutils.CreateDirIfNotExist(workspace)) testDataDir := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "docker") files, err := os.ReadDir(testDataDir) - assert.NoError(t, err) for _, file := range files { if !file.IsDir() { @@ -202,45 +234,23 @@ func TestPushFatManifestImage(t *testing.T) { assert.NoError(t, err) } } + // Build the builder image locally. - ctx := context.Background() - testContainer, err := tests.NewContainerRequest(). - SetDockerfile(workspace, "Dockerfile.Buildx.Fatmanifest", nil). - Privileged(). - Networks(rtNetwork). - Name("buildx_container"). - Mount(mount.Mount{Type: mount.TypeBind, Source: workspace, Target: "/workspace", ReadOnly: false}). - Cmd("--insecure-registry", tests.RtContainerHostName). - // Docker daemon take times to load. In order to check if it's available we wait for a log message to indications that the Docker daemon has finished initializing. - WaitFor(wait.ForLog("API listen on /var/run/docker.sock").WithStartupTimeout(5*time.Minute)). - Remove(). - Build(ctx, true) - assert.NoError(t, err, "Couldn't run create buildx image.") - defer func() { assert.NoError(t, testContainer.Terminate(ctx)) }() + testContainer := buildBuilderImage(t, workspace, "Dockerfile.Buildx.Fatmanifest", "buildx_container") + defer func() { assert.NoError(t, testContainer.Terminate(context.Background())) }() // Enable the builder util in the container. - err = testContainer.Exec(ctx, "sh", "script.sh") + err = testContainer.Exec(context.Background(), "sh", "script.sh") assert.NoError(t, err) - // login from the builder container toward the Artifactory. - password := *tests.JfrogPassword - user := *tests.JfrogUser - if *tests.JfrogAccessToken != "" { - user = auth.ExtractUsernameFromAccessToken(*tests.JfrogAccessToken) - password = *tests.JfrogAccessToken - } - assert.NoError(t, testContainer.Exec( - ctx, - "docker", - "login", - tests.RtContainerHostName, - "--username="+user, - "--password="+password)) + // Login to Artifactory + loginToArtifactory(t, testContainer) + buildxOutputFile := "buildmetadata" - // Run the builder in the container and push the fat-manifest image to artifactory + // Run the builder in the container and push the fat-manifest image to Artifactory assert.NoError(t, testContainer.Exec( - ctx, + context.Background(), "docker", "buildx", "build", @@ -263,20 +273,83 @@ func TestPushFatManifestImage(t *testing.T) { assert.NoError(t, artifactoryCli.Exec("build-docker-create", tests.DockerLocalRepo, "--image-file="+buildxOutput, "--build-name="+buildName, "--build-number="+buildNumber)) assert.NoError(t, artifactoryCli.Exec("build-publish", buildName, buildNumber)) - // Validate the published build-info exits + // Validate the published build-info exists publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, buildName, buildNumber) - if err != nil { - assert.NoError(t, err) - return + assert.NoError(t, err) + assert.True(t, found, "build info was expected to be found") + assert.True(t, len(publishedBuildInfo.BuildInfo.Modules) > 1) + + // Validate build-name & build-number properties in all image layers + searchSpec := spec.NewBuilder().Pattern(tests.DockerLocalRepo + "/*").Build(buildName).Recursive(true).BuildSpec() + searchCmd := generic.NewSearchCommand() + searchCmd.SetServerDetails(serverDetails).SetSpec(searchSpec) + reader, err := searchCmd.Search() + assert.NoError(t, err) + totalResults, err := reader.Length() + assert.NoError(t, err) + assert.True(t, totalResults > 1) +} + +func TestPushMultiTaggedImage(t *testing.T) { + if !*tests.TestDocker { + t.Skip("Skipping test. To run it, add the '-test.docker=true' option.") } - if !found { - assert.True(t, found, "build info was expected to be found") - return + + buildName := "push-multi-tagged" + tests.DockerBuildName + buildNumber := "1" + + // Setup workspace + workspace, err := filepath.Abs(tests.Out) + assert.NoError(t, err) + assert.NoError(t, fileutils.CreateDirIfNotExist(workspace)) + testDataDir := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "docker") + files, err := os.ReadDir(testDataDir) + assert.NoError(t, err) + for _, file := range files { + if !file.IsDir() { + _, err := tests.ReplaceTemplateVariables(filepath.Join(testDataDir, file.Name()), tests.Out) + assert.NoError(t, err) + } } - assert.True(t, len(publishedBuildInfo.BuildInfo.Modules) > 1) + // Build the builder image locally + testContainer := buildBuilderImage(t, workspace, "Dockerfile.Buildx.Fatmanifest", "buildx_multi_tag_container") + defer func() { assert.NoError(t, testContainer.Terminate(context.Background())) }() - // Validate build-name & build-number properties in all image layers + // Enable builder + assert.NoError(t, testContainer.Exec(context.Background(), "sh", "script.sh")) + + // Login to Artifactory + loginToArtifactory(t, testContainer) + + // Build & push image with multiple tags + imageName1 := path.Join(tests.RtContainerHostName, tests.DockerLocalRepo, tests.DockerImageName+"-multi:v1") + imageName2 := path.Join(tests.RtContainerHostName, tests.DockerLocalRepo, tests.DockerImageName+"-multi:latest") + buildxOutputFile := "multi-build-metadata" + + assert.NoError(t, testContainer.Exec( + context.Background(), + "docker", "buildx", "build", + "--platform", "linux/amd64,linux/arm64", + "-t", imageName1, + "-t", imageName2, + "-f", "Dockerfile.Fatmanifest", + "--metadata-file", "/workspace/"+buildxOutputFile, + "--push", ".", + )) + + // Run build-docker-create & publish + buildxOutput := filepath.Join(workspace, buildxOutputFile) + assert.NoError(t, artifactoryCli.Exec("build-docker-create", tests.DockerLocalRepo, "--image-file="+buildxOutput, "--build-name="+buildName, "--build-number="+buildNumber)) + assert.NoError(t, artifactoryCli.Exec("build-publish", buildName, buildNumber)) + + // Validate build-info is published + publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, buildName, buildNumber) + assert.NoError(t, err) + assert.True(t, found, "build info was expected to be found") + assert.True(t, len(publishedBuildInfo.BuildInfo.Modules) >= 1) + + // Validate build-name & build-number properties in all layers searchSpec := spec.NewBuilder().Pattern(tests.DockerLocalRepo + "/*").Build(buildName).Recursive(true).BuildSpec() searchCmd := generic.NewSearchCommand() searchCmd.SetServerDetails(serverDetails).SetSpec(searchSpec)