From 19710fbb5d8a66080fa9d5e04c8201cb7eaf0737 Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Mon, 20 May 2024 16:15:18 -0700 Subject: [PATCH] Remove `WorkflowPluginTest#sshGitInsideDocker` (#1569) --- .github/dependabot.yml | 4 -- .../docker/fixtures/DockerAgentContainer.java | 35 ----------- .../fixtures/DockerAgentContainer/Dockerfile | 10 --- .../DockerAgentContainer/entrypoint.sh | 4 -- src/test/java/plugins/WorkflowPluginTest.java | 63 ------------------- 5 files changed, 116 deletions(-) delete mode 100644 src/main/java/org/jenkinsci/test/acceptance/docker/fixtures/DockerAgentContainer.java delete mode 100644 src/main/resources/org/jenkinsci/test/acceptance/docker/fixtures/DockerAgentContainer/Dockerfile delete mode 100644 src/main/resources/org/jenkinsci/test/acceptance/docker/fixtures/DockerAgentContainer/entrypoint.sh diff --git a/.github/dependabot.yml b/.github/dependabot.yml index a6200b5a58..1caa0758f0 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -12,10 +12,6 @@ updates: directory: "src/main/resources/org/jenkinsci/test/acceptance/docker/fixtures/ArtifactoryContainer" schedule: interval: "weekly" - - package-ecosystem: "docker" - directory: "src/main/resources/org/jenkinsci/test/acceptance/docker/fixtures/DockerAgentContainer" - schedule: - interval: "weekly" - package-ecosystem: "docker" directory: "src/main/resources/org/jenkinsci/test/acceptance/docker/fixtures/FtpdContainer" schedule: diff --git a/src/main/java/org/jenkinsci/test/acceptance/docker/fixtures/DockerAgentContainer.java b/src/main/java/org/jenkinsci/test/acceptance/docker/fixtures/DockerAgentContainer.java deleted file mode 100644 index 11cd22625f..0000000000 --- a/src/main/java/org/jenkinsci/test/acceptance/docker/fixtures/DockerAgentContainer.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * The MIT License - * - * Copyright 2017 CloudBees, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package org.jenkinsci.test.acceptance.docker.fixtures; - -import org.jenkinsci.test.acceptance.docker.DockerFixture; - -/** - * Container that can run a Jenkins agent (SSH) and also run Docker commands. - */ -@DockerFixture(id="docker-agent", ports=22) -public class DockerAgentContainer extends JavaContainer { - -} diff --git a/src/main/resources/org/jenkinsci/test/acceptance/docker/fixtures/DockerAgentContainer/Dockerfile b/src/main/resources/org/jenkinsci/test/acceptance/docker/fixtures/DockerAgentContainer/Dockerfile deleted file mode 100644 index 31760989e6..0000000000 --- a/src/main/resources/org/jenkinsci/test/acceptance/docker/fixtures/DockerAgentContainer/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -# curl -s https://raw.githubusercontent.com/jenkinsci/docker-fixtures/master/src/main/resources/org/jenkinsci/test/acceptance/docker/fixtures/JavaContainer/Dockerfile | sha1sum | cut -c 1-12 -FROM jenkins/java:387404da3ce7 - -RUN cd /tmp && \ - wget -nv -O - https://get.docker.com/builds/Linux/x86_64/docker-1.13.1.tgz | tar xvfz - docker/docker && \ - chmod a+x docker/docker && \ - mv docker/docker /usr/bin/docker -VOLUME /home/test/workspace -COPY entrypoint.sh /usr/bin/entrypoint.sh -ENTRYPOINT ["/bin/sh", "/usr/bin/entrypoint.sh"] diff --git a/src/main/resources/org/jenkinsci/test/acceptance/docker/fixtures/DockerAgentContainer/entrypoint.sh b/src/main/resources/org/jenkinsci/test/acceptance/docker/fixtures/DockerAgentContainer/entrypoint.sh deleted file mode 100644 index 21ae468669..0000000000 --- a/src/main/resources/org/jenkinsci/test/acceptance/docker/fixtures/DockerAgentContainer/entrypoint.sh +++ /dev/null @@ -1,4 +0,0 @@ -groupadd -g $DOCKER_GROUP docker -usermod -aG docker test -chown test.test /home/test/workspace -exec /usr/sbin/sshd -D -e diff --git a/src/test/java/plugins/WorkflowPluginTest.java b/src/test/java/plugins/WorkflowPluginTest.java index 7b46b93559..13f7c672d0 100644 --- a/src/test/java/plugins/WorkflowPluginTest.java +++ b/src/test/java/plugins/WorkflowPluginTest.java @@ -25,19 +25,14 @@ package plugins; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.containsString; import static org.jenkinsci.test.acceptance.Matchers.*; import static org.junit.Assert.*; import jakarta.inject.Inject; import java.io.IOException; -import java.nio.charset.StandardCharsets; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.StringUtils; import org.jenkinsci.test.acceptance.controller.JenkinsController; import org.jenkinsci.test.acceptance.docker.DockerContainerHolder; -import org.jenkinsci.test.acceptance.docker.fixtures.DockerAgentContainer; import org.jenkinsci.test.acceptance.docker.fixtures.GitContainer; import org.jenkinsci.test.acceptance.docker.fixtures.SvnContainer; import org.jenkinsci.test.acceptance.junit.AbstractJUnitTest; @@ -48,10 +43,8 @@ import org.jenkinsci.test.acceptance.junit.WithDocker; import org.jenkinsci.test.acceptance.junit.WithPlugins; import org.jenkinsci.test.acceptance.plugins.git.GitRepo; -import org.jenkinsci.test.acceptance.plugins.git_client.JGitInstallation; import org.jenkinsci.test.acceptance.plugins.git_client.ssh_host_key_verification.NoVerificationStrategy; import org.jenkinsci.test.acceptance.plugins.maven.MavenInstallation; -import org.jenkinsci.test.acceptance.plugins.ssh_slaves.SshSlaveLauncher; import org.jenkinsci.test.acceptance.plugins.workflow_multibranch.GithubBranchSource; import org.jenkinsci.test.acceptance.plugins.workflow_shared_library.WorkflowGithubSharedLibrary; import org.jenkinsci.test.acceptance.plugins.workflow_shared_library.WorkflowSharedLibraryGlobalConfig; @@ -61,12 +54,9 @@ import org.jenkinsci.test.acceptance.po.GlobalSecurityConfig; import org.jenkinsci.test.acceptance.po.WorkflowJob; import org.jenkinsci.test.acceptance.slave.SlaveController; -import org.jenkinsci.utils.process.CommandBuilder; -import org.junit.Assume; import org.junit.Before; import org.junit.Test; import org.junit.experimental.categories.Category; -import org.jvnet.hudson.test.Issue; @WithPlugins("command-launcher") public class WorkflowPluginTest extends AbstractJUnitTest { @@ -79,7 +69,6 @@ public class WorkflowPluginTest extends AbstractJUnitTest { @Inject private SlaveController slaveController; @Inject DockerContainerHolder gitServer; @Inject DockerContainerHolder svn; - @Inject DockerContainerHolder agent; @Inject JenkinsController controller; @Before @@ -222,58 +211,6 @@ private String createGitRepositoryInDockerContainer() throws IOException { assertThat(build.getConsole(), containsString("divided into 3 sets")); } - @Category(DockerTest.class) - @WithDocker - @WithPlugins({"workflow-cps@2.0", "workflow-job@2.0", "workflow-durable-task-step@2.0", "docker-workflow@1.5", "git", "ssh-agent@1.10", "ssh-slaves@1.11"}) - @WithCredentials(credentialType=WithCredentials.SSH_USERNAME_PRIVATE_KEY, values={"git", "/org/jenkinsci/test/acceptance/docker/fixtures/GitContainer/unsafe"}, id="gitcreds") - @Issue("JENKINS-27152") - @Test public void sshGitInsideDocker() throws Exception { - GitContainer gitContainer = gitServer.get(); - try (GitRepo repo = new GitRepo()) { - repo.changeAndCommitFoo("Initial commit"); - repo.transferToDockerContainer(gitContainer.host(), gitContainer.port()); - DumbSlave slave = jenkins.slaves.create(DumbSlave.class); - slave.setExecutors(1); - slave.remoteFS.set("/home/test"); // TODO perhaps should be a constant in SshdContainer - SshSlaveLauncher launcher = slave.setLauncher(SshSlaveLauncher.class); - Process proc = new ProcessBuilder("stat", "-c", "%g", "/var/run/docker.sock").start(); - String group = IOUtils.toString(proc.getInputStream(), StandardCharsets.UTF_8).trim(); - Assume.assumeThat("docker.sock can be statted", proc.waitFor(), is(0)); - try { - Integer.parseInt(group); - } catch (NumberFormatException x) { - Assume.assumeNoException("unexpected output from stat on docker.sock", x); - } - // Note that we need to link to the Git container both on the agent, for the benefit of JGit (TODO pending JENKINS-30600), and in the build container, for the benefit of git-pull: - DockerAgentContainer agentContainer = agent.starter().withOptions(new CommandBuilder("--volume=/var/run/docker.sock:/var/run/docker.sock", "--env=DOCKER_GROUP=" + group, "--link=" + gitContainer.getCid() + ":git")).start(); - launcher.host.set(agentContainer.ipBound(22)); - launcher.port(agentContainer.port(22)); - launcher.pwdCredentials("test", "test"); - launcher.setSshHostKeyVerificationStrategy(SshSlaveLauncher.NonVerifyingKeyVerificationStrategy.class); - slave.save(); - { // TODO JENKINS-30600 workaround - JGitInstallation.addJGit(jenkins); - find(by.button("Save")).click(); - } - WorkflowJob job = jenkins.jobs.create(WorkflowJob.class); - String networkOptions = StringUtils.isNotBlank(System.getenv("DOCKER_FIXTURES_NETWORK")) ? " --network=" + System.getenv("DOCKER_FIXTURES_NETWORK") : ""; - String options = "--link=" + gitContainer.getCid() + ":git" + networkOptions; - String repoUrl = StringUtils.isNotBlank(System.getenv("DOCKER_FIXTURES_NETWORK")) ? gitContainer.getRepoUrlInsideDocker() : gitContainer.getRepoUrlInsideDocker("git"); - job.script.set( - "node('" + slave.getName() + "') {\n" + - " docker.image('cloudbees/java-build-tools').inside('" + options + "') {\n" + - // TODO JENKINS-30600: " git url: '" + gitContainer.getRepoUrlInsideDocker("git") + "', credentialsId: 'gitcreds'\n" + - " checkout([$class: 'GitSCM', userRemoteConfigs: [[url: '" + repoUrl + "', credentialsId: 'gitcreds']], gitTool: 'jgit'])\n" + - " sh 'mkdir ~/.ssh && echo StrictHostKeyChecking no > ~/.ssh/config'\n" + - " sshagent(['gitcreds']) {sh 'ls -l $SSH_AUTH_SOCK && git pull origin master'}\n" + - " }\n" + - "}"); - job.sandbox.check(); - job.save(); - assertThat(job.startBuild().shouldSucceed().getConsole(), containsString("-> FETCH_HEAD")); - } - } - /** Pipeline analogue of {@link SubversionPluginTest#build_has_changes}. */ @Category(DockerTest.class) @WithDocker