Merge in RR/pyinfra from RED-4653 to master
Squashed commit of the following:
commit 14ed6d2ee79f9a6bc4bad187dc775f7476a05d97
Author: Viktor Seifert <viktor.seifert@iqser.com>
Date: Tue Jul 26 11:08:16 2022 +0200
RED-4653: Disabled coverage check since there not tests at the moment
commit e926631b167d03e8cc0867db5b5c7d44d6612dcf
Author: Viktor Seifert <viktor.seifert@iqser.com>
Date: Tue Jul 26 10:58:50 2022 +0200
RED-4653: Re-added test execution scripts
commit 94648cc449bbc392864197a1796f99f8953b7312
Author: Viktor Seifert <viktor.seifert@iqser.com>
Date: Tue Jul 26 10:50:42 2022 +0200
RED-4653: Changed error case for processing messages to not requeue the message since that will be handled in DLQ logic
commit d77982dfedcec49482293d79818283c8d7a17dc7
Author: Viktor Seifert <viktor.seifert@iqser.com>
Date: Tue Jul 26 10:46:32 2022 +0200
RED-4653: Removed unnecessary logging message
commit 8c00fd75bf04f8ecc0e9cda654f8e053d4cfb66f
Author: Viktor Seifert <viktor.seifert@iqser.com>
Date: Tue Jul 26 10:03:35 2022 +0200
RED-4653: Re-added wrongly removed config
commit 759d72b3fa093b19f97e68d17bf53390cd5453c7
Author: Viktor Seifert <viktor.seifert@iqser.com>
Date: Tue Jul 26 09:57:47 2022 +0200
RED-4653: Removed leftover Docker commands
commit 2ff5897ee38e39d6507278b6a82176be2450da16
Author: Viktor Seifert <viktor.seifert@iqser.com>
Date: Tue Jul 26 09:48:08 2022 +0200
RED-4653: Removed leftover Docker config
commit 1074167aa98f9f59c0f0f534ba2f1ba09ffb0958
Author: Viktor Seifert <viktor.seifert@iqser.com>
Date: Tue Jul 26 09:41:21 2022 +0200
RED-4653: Removed Docker build stage since it is not needed for a project that is used as a Python module
commit ec769c6cd74a74097d8ebe4800ea6e2ea86236cc
Author: Viktor Seifert <viktor.seifert@iqser.com>
Date: Mon Jul 25 16:11:50 2022 +0200
RED-4653: Renamed function for better clarity and consistency
commit 96e8ac4316ac57aac90066f35422d333c532513b
Author: Viktor Seifert <viktor.seifert@iqser.com>
Date: Mon Jul 25 15:07:40 2022 +0200
RED-4653: Added code to cancel the queue subscription on application exit to queue manager so that it can exit gracefully
commit 64d8e0bd15730898274c08d34f9c34fbac559422
Author: Viktor Seifert <viktor.seifert@iqser.com>
Date: Mon Jul 25 13:57:06 2022 +0200
RED-4653: Moved queue cancellation to a separate method so that it can be called on application exit
commit aff1d06364f5694c5922f37d961e401c12243221
Author: Viktor Seifert <viktor.seifert@iqser.com>
Date: Mon Jul 25 11:51:16 2022 +0200
RED-4653: Re-ordered message processing so that ack occurs after publishing the result, to prevent message loss
commit 9339186b86f2fe9653366c22fcdc9f7fc096b138
Author: Viktor Seifert <viktor.seifert@iqser.com>
Date: Fri Jul 22 18:07:25 2022 +0200
RED-4653: RED-4653: Reordered code to acknowledge message before publishing a result message
commit 2d6fe1cbd95cd86832b086c6dfbcfa62b3ffa16f
Author: Viktor Seifert <viktor.seifert@iqser.com>
Date: Fri Jul 22 17:00:04 2022 +0200
RED-4653: Hopefully corrected storage bucket env var name
commit 8f1ef0dd5532882cb12901721195d9acb336286c
Author: Viktor Seifert <viktor.seifert@iqser.com>
Date: Fri Jul 22 16:37:27 2022 +0200
RED-4653: Switched to validating the connection url via a regex since the validators lib parses our endpoints incorrectly
commit 8d0234fcc5ff7ed1ae7695a17856c6af050065bd
Author: Viktor Seifert <viktor.seifert@iqser.com>
Date: Fri Jul 22 15:02:54 2022 +0200
RED-4653: Corrected exception creation
commit 098a62335b3b695ee409363d429ac07284de7138
Author: Viktor Seifert <viktor.seifert@iqser.com>
Date: Fri Jul 22 14:42:22 2022 +0200
RED-4653: Added a descriptive error message when the storage endpoint is nor a correct url
commit 379685f964a4de641ce6506713f1ea8914a3f5ab
Author: Viktor Seifert <viktor.seifert@iqser.com>
Date: Fri Jul 22 14:11:48 2022 +0200
RED-4653: Removed variable re-use to make the code clearer
commit 4bf1a023453635568e16b1678ef5ad994c534045
Author: Viktor Seifert <viktor.seifert@iqser.com>
Date: Thu Jul 21 17:41:55 2022 +0200
RED-4653: Added explicit conversion of the heartbeat config value to an int before passing it to pika
commit 8f2bc4e028aafdef893458d1433a05724f534fce
Author: Viktor Seifert <viktor.seifert@iqser.com>
Date: Mon Jul 18 16:41:31 2022 +0200
RED-4653: Set heartbeat to lower value so that disconnects are detected more quickly
... and 6 more commits
149 lines
7.7 KiB
Java
149 lines
7.7 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().createBuildPlan();
|
|
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 createBuildPlan() {
|
|
return new Plan(
|
|
project(),
|
|
SERVICE_NAME, new BambooKey(SERVICE_KEY))
|
|
.description("Build for pyinfra")
|
|
.stages(
|
|
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))
|
|
.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());
|
|
}
|
|
}
|