Matthias Bisping 1147a5dc33 Pull request #23: tests are now run in a container
Merge in RR/pyinfra from containerized_tests to master

Squashed commit of the following:

commit 63f016a7f76af9c91602cf958639ad7fd9b4e832
Merge: 3b399ca 11c9f8a
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Mar 24 15:07:25 2022 +0100

    Merge branch 'master' into containerized_tests

commit 3b399ca873c1625cde5a34c3b34fd11653af36e4
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Mar 24 15:03:32 2022 +0100

    removed obsolete log

commit f854695fc22a9853449a1377d5285cc0cd60caf8
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Mar 24 15:01:22 2022 +0100

    refactoring of imports

commit 72b5c597aa3e5b8ce7c16fb1abeaca8e48015597
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Mar 24 15:00:37 2022 +0100

    removed obsolete code

commit ee9b0117f6c86fc23be9316b2c3690773c914e79
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Mar 24 14:59:42 2022 +0100

    removed obsolete code

commit 020cad6e5b7cdb8e2ad867f5bcc51d5114b281f4
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Mar 24 14:54:09 2022 +0100

    undo debug intentional crash

commit 65b77cffd319bc5230ead26391dc6b841ad8e12e
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Mar 24 14:51:46 2022 +0100

    debug intentional crash

commit 06133189bc6ecafd0c5a9bc74b8c08b9c097a321
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Mar 24 14:49:03 2022 +0100

    fixed syntax error in sconarscan

commit 7468c0738fe7ddabf72baaa07e7422a23c2a6f00
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Mar 24 14:43:43 2022 +0100

    failing sonar job if coverage.xml not present as proxcy for failed tests

commit ebcee7ff2a53c643efb64b835f99640567da224b
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Mar 24 14:36:34 2022 +0100

    simplified copying of coverage.xml and removing of testcontainer

commit 1fb24d67f10aebe2747b76a4990a3c9fe2c0b00b
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Mar 24 14:18:30 2022 +0100

    RABBITMQ_DISK_FREE_ABSOLUTE_LIMIT=20Gi

commit 07873d607097308c5371029a74e115895266d30c
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Mar 24 14:12:51 2022 +0100

    RABBITMQ_DISK_FREE_RELATIVE_LIMIT=5%

commit d8eb294fb18c5b0b2418d8a397ef66ef133081bf
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Mar 24 14:11:00 2022 +0100

    RABBITMQ_DISK_FREE_RELATIVE_LIMIT=100%

commit f9010ed998f2a5da3940ad3f0d8a2a8cff209b0d
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Mar 24 14:04:35 2022 +0100

    RABBITMQ_VM_MEMORY_HIGH_WATERMARK=100%

commit 41e9f8046aae66fc9a7248b7c6194fe7e9e9c814
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Mar 24 13:42:34 2022 +0100

    RABBITMQ_VM_MEMORY_HIGH_WATERMARK=0

commit 301ba05d66452cf5b85511527a35582cd1396803
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Mar 24 13:19:10 2022 +0100

    set AMPQ heartbeat

commit 9f4dfb9781847bed6077d49e931719c04460e88c
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Mar 24 10:42:21 2022 +0100

    channel and connection closing experimenting

commit e3812725acff1df2a26e337dbc88df11cd6b8b22
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Mar 24 10:12:15 2022 +0100

    pika tearndown adjusted

commit 0206be86669c9f4b70bb21d416d6f10ce5e8731a
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Mar 24 09:58:18 2022 +0100

    return instead of yield in Consumer.consume

commit 17e11adf7822916dd3ece201529796e4dfd89032
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Thu Mar 24 09:51:52 2022 +0100

    processing log added to test

... and 26 more commits
2022-03-24 15:32:34 +01:00

180 lines
9.5 KiB
Java

package buildjob;
import com.atlassian.bamboo.specs.api.BambooSpec;
import com.atlassian.bamboo.specs.api.builders.BambooKey;
import com.atlassian.bamboo.specs.api.builders.docker.DockerConfiguration;
import com.atlassian.bamboo.specs.api.builders.permission.PermissionType;
import com.atlassian.bamboo.specs.api.builders.permission.Permissions;
import com.atlassian.bamboo.specs.api.builders.permission.PlanPermissions;
import com.atlassian.bamboo.specs.api.builders.plan.Job;
import com.atlassian.bamboo.specs.api.builders.plan.Plan;
import com.atlassian.bamboo.specs.api.builders.plan.PlanIdentifier;
import com.atlassian.bamboo.specs.api.builders.plan.Stage;
import com.atlassian.bamboo.specs.api.builders.plan.branches.BranchCleanup;
import com.atlassian.bamboo.specs.api.builders.plan.branches.PlanBranchManagement;
import com.atlassian.bamboo.specs.api.builders.project.Project;
import com.atlassian.bamboo.specs.builders.task.CheckoutItem;
import com.atlassian.bamboo.specs.builders.task.InjectVariablesTask;
import com.atlassian.bamboo.specs.builders.task.ScriptTask;
import com.atlassian.bamboo.specs.builders.task.VcsCheckoutTask;
import com.atlassian.bamboo.specs.builders.task.CleanWorkingDirectoryTask;
import com.atlassian.bamboo.specs.builders.task.VcsTagTask;
import com.atlassian.bamboo.specs.builders.trigger.BitbucketServerTrigger;
import com.atlassian.bamboo.specs.model.task.InjectVariablesScope;
import com.atlassian.bamboo.specs.api.builders.Variable;
import com.atlassian.bamboo.specs.util.BambooServer;
import com.atlassian.bamboo.specs.builders.task.ScriptTask;
import com.atlassian.bamboo.specs.model.task.ScriptTaskProperties.Location;
/**
* Plan configuration for Bamboo.
* Learn more on: <a href="https://confluence.atlassian.com/display/BAMBOO/Bamboo+Specs">https://confluence.atlassian.com/display/BAMBOO/Bamboo+Specs</a>
*/
@BambooSpec
public class PlanSpec {
private static final String SERVICE_NAME = "pyinfra";
private static final String SERVICE_KEY = SERVICE_NAME.toUpperCase().replaceAll("-","");
/**
* Run main to publish plan on Bamboo
*/
public static void main(final String[] args) throws Exception {
//By default credentials are read from the '.credentials' file.
BambooServer bambooServer = new BambooServer("http://localhost:8085");
Plan plan = new PlanSpec().createDockerBuildPlan();
bambooServer.publish(plan);
PlanPermissions planPermission = new PlanSpec().createPlanPermission(plan.getIdentifier());
bambooServer.publish(planPermission);
}
private PlanPermissions createPlanPermission(PlanIdentifier planIdentifier) {
Permissions permission = new Permissions()
.userPermissions("atlbamboo", PermissionType.EDIT, PermissionType.VIEW, PermissionType.ADMIN, PermissionType.CLONE, PermissionType.BUILD)
.groupPermissions("research", PermissionType.EDIT, PermissionType.VIEW, PermissionType.CLONE, PermissionType.BUILD)
.groupPermissions("Development", PermissionType.EDIT, PermissionType.VIEW, PermissionType.CLONE, PermissionType.BUILD)
.groupPermissions("QA", PermissionType.EDIT, PermissionType.VIEW, PermissionType.CLONE, PermissionType.BUILD)
.loggedInUserPermissions(PermissionType.VIEW)
.anonymousUserPermissionView();
return new PlanPermissions(planIdentifier.getProjectKey(), planIdentifier.getPlanKey()).permissions(permission);
}
private Project project() {
return new Project()
.name("RED")
.key(new BambooKey("RED"));
}
public Plan createDockerBuildPlan() {
return new Plan(
project(),
SERVICE_NAME, new BambooKey(SERVICE_KEY))
.description("Docker build for pyinfra")
.stages(
new Stage("Build Stage")
.jobs(
new Job("Build Job", new BambooKey("BUILD"))
.tasks(
new CleanWorkingDirectoryTask()
.description("Clean working directory.")
.enabled(true),
new VcsCheckoutTask()
.description("Checkout default repository.")
.checkoutItems(new CheckoutItem().defaultRepository()),
new ScriptTask()
.description("Set config and keys.")
.inlineBody("mkdir -p ~/.ssh\n" +
"echo \"${bamboo.bamboo_agent_ssh}\" | base64 -d >> ~/.ssh/id_rsa\n" +
"echo \"host vector.iqser.com\" > ~/.ssh/config\n" +
"echo \" user bamboo-agent\" >> ~/.ssh/config\n" +
"chmod 600 ~/.ssh/config ~/.ssh/id_rsa"),
new ScriptTask()
.description("Build Docker container.")
.location(Location.FILE)
.fileFromPath("bamboo-specs/src/main/resources/scripts/docker-build.sh")
.argument(SERVICE_NAME))
.dockerConfiguration(
new DockerConfiguration()
.image("nexus.iqser.com:5001/infra/release_build:4.2.0")
.volume("/var/run/docker.sock", "/var/run/docker.sock"))),
new Stage("Sonar Stage")
.jobs(
new Job("Sonar Job", new BambooKey("SONAR"))
.tasks(
new CleanWorkingDirectoryTask()
.description("Clean working directory.")
.enabled(true),
new VcsCheckoutTask()
.description("Checkout default repository.")
.checkoutItems(new CheckoutItem().defaultRepository()),
new ScriptTask()
.description("Set config and keys.")
.inlineBody("mkdir -p ~/.ssh\n" +
"echo \"${bamboo.bamboo_agent_ssh}\" | base64 -d >> ~/.ssh/id_rsa\n" +
"echo \"host vector.iqser.com\" > ~/.ssh/config\n" +
"echo \" user bamboo-agent\" >> ~/.ssh/config\n" +
"chmod 600 ~/.ssh/config ~/.ssh/id_rsa"),
new ScriptTask()
.description("Run Sonarqube scan.")
.location(Location.FILE)
.fileFromPath("bamboo-specs/src/main/resources/scripts/sonar-scan.sh")
.argument(SERVICE_NAME),
new ScriptTask()
.description("Shut down any running docker containers.")
.location(Location.FILE)
.inlineBody("pip install docker-compose\n" +
"docker-compose down"))
.dockerConfiguration(
new DockerConfiguration()
.image("nexus.iqser.com:5001/infra/release_build:4.2.0")
.volume("/var/run/docker.sock", "/var/run/docker.sock"))),
new Stage("Licence Stage")
.jobs(
new Job("Git Tag Job", new BambooKey("GITTAG"))
.tasks(
new VcsCheckoutTask()
.description("Checkout default repository.")
.checkoutItems(new CheckoutItem().defaultRepository()),
new ScriptTask()
.description("Build git tag.")
.location(Location.FILE)
.fileFromPath("bamboo-specs/src/main/resources/scripts/git-tag.sh"),
new InjectVariablesTask()
.description("Inject git tag.")
.path("git.tag")
.namespace("g")
.scope(InjectVariablesScope.LOCAL),
new VcsTagTask()
.description("${bamboo.g.gitTag}")
.tagName("${bamboo.g.gitTag}")
.defaultRepository())
.dockerConfiguration(
new DockerConfiguration()
.image("nexus.iqser.com:5001/infra/release_build:4.4.1")),
new Job("Licence Job", new BambooKey("LICENCE"))
.enabled(false)
.tasks(
new VcsCheckoutTask()
.description("Checkout default repository.")
.checkoutItems(new CheckoutItem().defaultRepository()),
new ScriptTask()
.description("Build licence.")
.location(Location.FILE)
.fileFromPath("bamboo-specs/src/main/resources/scripts/create-licence.sh"))
.dockerConfiguration(
new DockerConfiguration()
.image("nexus.iqser.com:5001/infra/maven:3.6.2-jdk-13-3.0.0")
.volume("/etc/maven/settings.xml", "/usr/share/maven/ref/settings.xml")
.volume("/var/run/docker.sock", "/var/run/docker.sock"))))
.linkedRepositories("RR / " + SERVICE_NAME)
.triggers(new BitbucketServerTrigger())
.planBranchManagement(new PlanBranchManagement()
.createForVcsBranch()
.delete(new BranchCleanup()
.whenInactiveInRepositoryAfterDays(14))
.notificationForCommitters());
}
}