Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/accessTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/artifactoryTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/gradleTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion .github/workflows/mavenTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion .github/workflows/npmTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/nugetTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion .github/workflows/pluginsTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion .github/workflows/pythonTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
2 changes: 1 addition & 1 deletion .github/workflows/transferTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
155 changes: 114 additions & 41 deletions docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -194,53 +227,30 @@ 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() {
_, err := tests.ReplaceTemplateVariables(filepath.Join(testDataDir, file.Name()), tests.Out)
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",
Expand All @@ -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)
Expand Down
Loading