diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d5a36e932..f5c631e9e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -36,15 +36,24 @@ jobs: env: GRADLE_OPTS: -Dorg.gradle.daemon=false steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.17.x + - name: Checkout code uses: actions/checkout@v2 with: ref: ${{ github.event.pull_request.head.sha }} - - name: Install Go - uses: actions/setup-go@v2 - with: - go-version: 1.17.x + - name: Setup Artifactory + run: | + go install github.com/jfrog/jfrog-testing-infra/local-rt-setup@latest + ~/go/bin/local-rt-setup + env: + RTLIC: ${{secrets.RTLIC}} + GOPROXY: direct + if: ${{ matrix.suite != 'distribution' && matrix.suite != 'xray' }} - name: Install npm uses: actions/setup-node@v2 @@ -78,8 +87,13 @@ jobs: - name: Run go vet run: go vet -v ./... - - name: Run tests + - name: Run Artifactory / Build tools tests + run: go test -v github.com/jfrog/jfrog-cli --timeout 0 --test.${{ matrix.suite }}=true --ci.runId=${{ runner.os }}-${{ matrix.suite }} + if: ${{ matrix.suite != 'distribution' && matrix.suite != 'xray' }} + + - name: Run Distribution / Xray tests run: go test -v github.com/jfrog/jfrog-cli --timeout 0 --test.${{ matrix.suite }}=true --jfrog.url=${{ secrets.PLATFORM_URL }} --jfrog.adminToken=${{ secrets.PLATFORM_ADMIN_TOKEN }} --jfrog.user=${{ secrets.PLATFORM_USER }} --ci.runId=${{ runner.os }}-${{ matrix.suite }} + if: ${{ matrix.suite == 'distribution' || matrix.suite == 'xray' }} Docker-tests: if: contains(github.event.pull_request.labels.*.name, 'safe to test') || github.event_name == 'push' @@ -95,7 +109,7 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha }} - name: Run Docker tests - run: go test -v -timeout 0 --test.docker=true --jfrog.url=${{ secrets.PLATFORM_URL }} --jfrog.adminToken=${{ secrets.PLATFORM_ADMIN_TOKEN }} --rt.dockerRepoDomain=ecosysjfrog-docker-virtual.jfrog.io --rt.dockerVirtualRepo=docker-virtual --rt.DockerLocalRepo=docker-local --rt.dockerRemoteRepo=docker-remote + run: go test -v -timeout 0 --test.docker=true --jfrog.url=${{ secrets.PLATFORM_URL }} --jfrog.adminToken=${{ secrets.PLATFORM_ADMIN_TOKEN }} --rt.dockerRepoDomain=${{ secrets.CONTAINER_REGISTRY }} --rt.dockerVirtualRepo=${{ secrets.DOCKER_VIRTUAL }} --rt.dockerLocalRepo=${{ secrets.DOCKER_LOCAL }} --rt.dockerRemoteRepo=${{ secrets.DOCKER_REMOTE }} --rt.dockerPromoteLocalRepo=${{ secrets.DOCKER_PROMOTE_LOCAL }} Scripts-tests: name: scripts (${{ matrix.os }}) diff --git a/.gitignore b/.gitignore index dfbaf5d61..dad3f8350 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,6 @@ build/chocolatey/v2/tools/LICENSE # npm build files node_modules + +# Gradle +.gradle diff --git a/README.md b/README.md index 8d3e41e53..17cb17589 100644 --- a/README.md +++ b/README.md @@ -191,12 +191,13 @@ In addition to [general optional flags](#Usage) you _must_ use the following doc - On Linux machines, [Podman](https://podman.io/) tests will be running, so make sure it's available in the local path. -| Flag | Description | -| ----------------------- | ------------------------------------------- | -| `-rt.dockerRepoDomain` | Artifactory Docker registry domain. | -| `-rt.dockerVirtualRepo` | Artifactory Docker virtual repository name. | -| `-rt.dockerRemoteRepo` | Artifactory Docker remote repository name. | -| `-rt.DockerLocalRepo` | Artifactory Docker local repository name. | +| Flag | Description | +|------------------------------|----------------------------------------------------------------| +| `-rt.dockerRepoDomain` | Artifactory Docker registry domain. | +| `-rt.dockerVirtualRepo` | Artifactory Docker virtual repository name. | +| `-rt.dockerRemoteRepo` | Artifactory Docker remote repository name. | +| `-rt.dockerLocalRepo` | Artifactory Docker local repository name. | +| `-rt.dockerPromoteLocalRepo` | Artifactory Docker local repository name - Used for promotion. | ##### Examples diff --git a/docker_test.go b/docker_test.go index ee6723d5b..75ce94c04 100644 --- a/docker_test.go +++ b/docker_test.go @@ -39,7 +39,7 @@ const ( func InitDockerTests() { initArtifactoryCli() cleanUpOldBuilds() - inttestutils.CleanUpOldImages(serverDetails, artHttpDetails) + inttestutils.CleanUpOldImages(serverDetails) cleanUpOldRepositories() tests.AddTimestampToGlobalVars() createRequiredRepos() @@ -348,7 +348,7 @@ func TestDockerPromote(t *testing.T) { assert.NoError(t, err) // Promote image - runRt(t, "docker-promote", tests.DockerImageName, *tests.DockerLocalRepo, tests.DockerRepo, "--source-tag=1", "--target-tag=2", "--target-docker-image=docker-target-image", "--copy") + runRt(t, "docker-promote", tests.DockerImageName, *tests.DockerLocalRepo, *tests.DockerPromoteLocalRepo, "--source-tag=1", "--target-tag=2", "--target-docker-image=docker-target-image", "--copy") // Verify image in source imagePath := path.Join(*tests.DockerLocalRepo, tests.DockerImageName, "1") + "/" diff --git a/inttestutils/docker.go b/inttestutils/docker.go index f4ebdff73..17083d08f 100644 --- a/inttestutils/docker.go +++ b/inttestutils/docker.go @@ -223,22 +223,24 @@ func ContainerTestCleanup(t *testing.T, serverDetails *config.ServerDetails, art func getAllImagesNames(serverDetails *config.ServerDetails) ([]string, error) { var imageNames []string - prefix := *tests.DockerLocalRepo + "/" - specFile := spec.NewBuilder().Pattern(prefix + tests.DockerImageName + "*").IncludeDirs(true).BuildSpec() - searchCmd := generic.NewSearchCommand() - searchCmd.SetServerDetails(serverDetails).SetSpec(specFile) - reader, err := searchCmd.Search() - if err != nil { - return nil, err + for _, repo := range []string{*tests.DockerLocalRepo, *tests.DockerPromoteLocalRepo} { + prefix := repo + "/" + specFile := spec.NewBuilder().Pattern(prefix + tests.DockerImageName + "*").IncludeDirs(true).BuildSpec() + searchCmd := generic.NewSearchCommand() + searchCmd.SetServerDetails(serverDetails).SetSpec(specFile) + reader, err := searchCmd.Search() + if err != nil { + return nil, err + } + defer reader.Close() + for searchResult := new(utils.SearchResult); reader.NextRecord(searchResult) == nil; searchResult = new(utils.SearchResult) { + imageNames = append(imageNames, strings.TrimPrefix(searchResult.Path, prefix)) + } } - defer reader.Close() - for searchResult := new(utils.SearchResult); reader.NextRecord(searchResult) == nil; searchResult = new(utils.SearchResult) { - imageNames = append(imageNames, strings.TrimPrefix(searchResult.Path, prefix)) - } - return imageNames, err + return imageNames, nil } -func CleanUpOldImages(serverDetails *config.ServerDetails, artHttpDetails httputils.HttpClientDetails) { +func CleanUpOldImages(serverDetails *config.ServerDetails) { getActualItems := func() ([]string, error) { return getAllImagesNames(serverDetails) } deleteItem := func(imageName string) { deleteSpec := spec.NewBuilder().Pattern(path.Join(*tests.DockerLocalRepo, imageName)).BuildSpec() diff --git a/testdata/docker_repository_config.json b/testdata/docker_repository_config.json deleted file mode 100644 index 51494b24d..000000000 --- a/testdata/docker_repository_config.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "key": "${DOCKER_REPO}", - "rclass": "local", - "packageType": "docker" -} diff --git a/utils/tests/consts.go b/utils/tests/consts.go index 8ca6403b5..e80cde63c 100644 --- a/utils/tests/consts.go +++ b/utils/tests/consts.go @@ -142,7 +142,6 @@ var ( // Repositories DistRepo1 = "cli-dist1" DistRepo2 = "cli-dist2" - DockerRepo = "cli-docker" GoRepo = "cli-go" GoRemoteRepo = "cli-go-remote" GoVirtualRepo = "cli-go-virtual" @@ -1568,7 +1567,7 @@ func GetDockerSourceManifest() []string { func GetDockerDeployedManifest() []string { return []string{ - DockerRepo + "/docker-target-image/2/manifest.json", + *DockerPromoteLocalRepo + "/docker-target-image/2/manifest.json", } } diff --git a/utils/tests/utils.go b/utils/tests/utils.go index b9a96f19a..f25269851 100644 --- a/utils/tests/utils.go +++ b/utils/tests/utils.go @@ -66,6 +66,7 @@ var ( DockerVirtualRepo *string DockerRemoteRepo *string DockerLocalRepo *string + DockerPromoteLocalRepo *string HideUnitTestLog *bool PipVirtualEnv *string ciRunId *string @@ -96,7 +97,8 @@ func init() { DockerRepoDomain = flag.String("rt.dockerRepoDomain", "", "Docker repository domain") DockerVirtualRepo = flag.String("rt.dockerVirtualRepo", "", "Docker virtual repo") DockerRemoteRepo = flag.String("rt.dockerRemoteRepo", "", "Docker remote repo") - DockerLocalRepo = flag.String("rt.DockerLocalRepo", "", "Docker local repo") + DockerLocalRepo = flag.String("rt.dockerLocalRepo", "", "Docker local repo") + DockerPromoteLocalRepo = flag.String("rt.dockerPromoteLocalRepo", "", "Docker promote local repo") HideUnitTestLog = flag.Bool("test.hideUnitTestLog", false, "Hide unit tests logs and print it in a file") PipVirtualEnv = flag.String("rt.pipVirtualEnv", "", "Pip virtual-environment path") ciRunId = flag.String("ci.runId", "", "A unique identifier used as a suffix to create repositories and builds in the tests") @@ -346,7 +348,6 @@ func GetBuildInfo(serverDetails *config.ServerDetails, buildName, buildNumber st var reposConfigMap = map[*string]string{ &DistRepo1: DistributionRepoConfig1, &DistRepo2: DistributionRepoConfig2, - &DockerRepo: DockerRepoConfig, &GoRepo: GoLocalRepositoryConfig, &GoRemoteRepo: GoRemoteRepositoryConfig, &GoVirtualRepo: GoVirtualRepositoryConfig, @@ -402,7 +403,7 @@ func GetNonVirtualRepositories() map[*string]string { TestArtifactory: {&RtRepo1, &RtRepo2, &RtLfsRepo, &RtDebianRepo}, TestArtifactoryProject: {&RtRepo1, &RtRepo2, &RtLfsRepo, &RtDebianRepo}, TestDistribution: {&DistRepo1, &DistRepo2}, - TestDocker: {&DockerRepo}, + TestDocker: {}, TestGo: {&GoRepo, &GoRemoteRepo}, TestGradle: {&GradleRepo, &GradleRemoteRepo}, TestMaven: {&MvnRepo1, &MvnRepo2, &MvnRemoteRepo}, @@ -478,7 +479,7 @@ func getSubstitutionMap() map[string]string { "${VIRTUAL_REPO}": RtVirtualRepo, "${LFS_REPO}": RtLfsRepo, "${DEBIAN_REPO}": RtDebianRepo, - "${DOCKER_REPO}": DockerRepo, + "${DOCKER_REPO}": *DockerPromoteLocalRepo, "${DOCKER_IMAGE_NAME}": DockerImageName, "${DOCKER_REPO_DOMAIN}": *DockerRepoDomain, "${MAVEN_REPO1}": MvnRepo1, @@ -525,7 +526,6 @@ func AddTimestampToGlobalVars() { uniqueSuffix = "-" + *ciRunId + uniqueSuffix } // Repositories - DockerRepo += uniqueSuffix DistRepo1 += uniqueSuffix DistRepo2 += uniqueSuffix GoRepo += uniqueSuffix