Search in sources :

Example 1 with InstanceBuilder

use of org.platformlayer.ops.instances.InstanceBuilder in project platformlayer by platformlayer.

the class VpnServiceController method addChildren.

@Override
protected void addChildren() throws OpsException {
    VpnService model = OpsContext.get().getInstance(VpnService.class);
    InstanceBuilder instance = InstanceBuilder.build(model.dnsName, DiskImageRecipeBuilder.buildDiskImageRecipe(this));
    addChild(instance);
    instance.addChild(PackageDependency.build("strongswan"));
    instance.addChild(CollectdCollector.build());
// instance.addChild(ManagedService.build("ipsec"));
}
Also used : VpnService(org.platformlayer.service.vpn.model.VpnService) InstanceBuilder(org.platformlayer.ops.instances.InstanceBuilder)

Example 2 with InstanceBuilder

use of org.platformlayer.ops.instances.InstanceBuilder in project platformlayer by platformlayer.

the class DesktopController method addChildren.

@Override
protected void addChildren() throws OpsException {
    Desktop model = OpsContext.get().getInstance(Desktop.class);
    InstanceBuilder instance = InstanceBuilder.build(model.dnsName, this, model.getTags());
    instance.publicPorts.add(22);
    instance.hostPolicy.allowRunInContainer = true;
    instance.minimumMemoryMb = 4096;
    addChild(instance);
    {
        RecipeOperatingSystem os = injected(RecipeOperatingSystem.class);
        os.operatingSystem = new OperatingSystemRecipe();
        os.operatingSystem.setDistribution("debian");
        os.operatingSystem.setVersion("wheezy");
        instance.addChild(os);
    }
    // We use curl for backups
    instance.addChild(PackageDependency.build("curl"));
    {
        PublicEndpoint endpoint = injected(PublicEndpoint.class);
        // endpoint.network = null;
        endpoint.publicPort = 22;
        endpoint.backendPort = 22;
        endpoint.dnsName = model.dnsName;
        endpoint.tagItem = model.getKey();
        endpoint.parentItem = model.getKey();
        instance.addChild(endpoint);
    }
// {
// BackupDirectory backup = injected(BackupDirectory.class);
// backup.itemKey = model.getKey();
// 
// File jenkinsRoot = new File("/var/lib/jenkins");
// backup.backupRoot = jenkinsRoot;
// 
// String[] excludes = { "jobs/*/workspace", "jobs/*/modules", "jobs/*/builds/*/workspace.tar.gz",
// ".m2/repository" };
// 
// for (String exclude : excludes) {
// backup.excludes.add(new File(jenkinsRoot, exclude));
// }
// 
// instance.addChild(backup);
// }
}
Also used : Desktop(org.platformlayer.service.desktop.model.Desktop) PublicEndpoint(org.platformlayer.ops.networks.PublicEndpoint) RecipeOperatingSystem(org.platformlayer.ops.packages.RecipeOperatingSystem) OperatingSystemRecipe(org.platformlayer.images.model.OperatingSystemRecipe) InstanceBuilder(org.platformlayer.ops.instances.InstanceBuilder)

Example 3 with InstanceBuilder

use of org.platformlayer.ops.instances.InstanceBuilder in project platformlayer by platformlayer.

the class DnsServerController method addChildren.

@Override
protected void addChildren() throws OpsException {
    InstanceBuilder vm = InstanceBuilder.build(model.dnsName, this, model.getTags());
    // TODO: Do we need a DnsCluster concept?
    // For now, we fake it
    PlatformLayerKey key = model.getKey();
    String groupId = key.withId(new ManagedItemId("primary")).getUrl();
    groupId = groupId.replace("/dnsServer/", "/dnsCluster/");
    vm.hostPolicy.configureSpread(groupId);
    vm.addTagToManaged = true;
    vm.publicPorts.add(53);
    // vm.minimumMemoryMb = 512;
    addChild(vm);
    vm.addChild(DnsServerInstall.class);
    vm.addChild(DnsServerInstance.class);
    {
        PublicEndpoint endpoint = injected(PublicEndpoint.class);
        // endpoint.network = null;
        endpoint.publicPort = 53;
        endpoint.backendPort = 53;
        endpoint.dnsName = model.dnsName;
        endpoint.protocol = Protocol.Udp;
        endpoint.tagItem = model.getKey();
        endpoint.parentItem = model.getKey();
        vm.addChild(endpoint);
    }
// TODO: Refresh other DNS servers so they also point to this server
}
Also used : PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) PublicEndpoint(org.platformlayer.ops.networks.PublicEndpoint) ManagedItemId(org.platformlayer.ids.ManagedItemId) InstanceBuilder(org.platformlayer.ops.instances.InstanceBuilder)

Example 4 with InstanceBuilder

use of org.platformlayer.ops.instances.InstanceBuilder in project platformlayer by platformlayer.

the class GitlabServiceController method addChildren.

@Override
protected void addChildren() throws OpsException {
    GitlabService model = OpsContext.get().getInstance(GitlabService.class);
    InstanceBuilder instance = InstanceBuilder.build(model.dnsName, this, model.getTags());
    addChild(instance);
    instance.addChildren(PackageDependency.build(Splitter.on(" ").split("sudo git-core wget curl gcc checkinstall libxml2-dev libxslt-dev sqlite3 libsqlite3-dev libcurl4-openssl-dev libreadline-dev libc6-dev libssl-dev libmysql++-dev make build-essential zlib1g-dev libicu-dev redis-server openssh-server git-core python-dev python-pip sendmail")));
    {
        PosixGroup group = injected(PosixGroup.class);
        group.groupName = "git";
        instance.addChild(group);
    }
    {
        PosixUser user = injected(PosixUser.class);
        user.userName = "git";
        user.primaryGroup = "git";
        instance.addChild(user);
    }
    {
        PosixUser user = injected(PosixUser.class);
        user.userName = "gitlab";
        user.secondaryGroups.add("sudo");
        user.secondaryGroups.add("git");
        instance.addChild(user);
    }
    // sudo -H -u gitlab ssh-keygen -q -N '' -t rsa -f /home/gitlab/.ssh/id_rsa
    instance.addChild(PackageDependency.build("ruby1.9.1"));
    {
        GitCheckout checkout = injected(GitCheckout.class);
        checkout.targetDir = new File("/opt/gitlabhq");
        checkout.source = "https://github.com/gitlabhq/gitlabhq.git";
        instance.addChild(checkout);
    }
    {
        GitCheckout checkout = injected(GitCheckout.class);
        checkout.targetDir = new File("/opt/gitolite");
        checkout.source = "https://github.com/gitlabhq/gitolite.git";
        instance.addChild(checkout);
    }
// Eeek... we have to run a gitolite install script.
// I don't fancy picking it apart right now...
// As gitlabhq...
// git config --global user.email "admin@local.host"
// git config --global user.name "GitLabHQ Admin User"
// su -c "ssh-keygen -q -f /home/gitlabhq/.ssh/id_rsa -N ''" gitlabhq
}
Also used : PosixGroup(org.platformlayer.ops.users.PosixGroup) GitlabService(org.platformlayer.service.gitlab.model.GitlabService) PosixUser(org.platformlayer.ops.users.PosixUser) File(java.io.File) InstanceBuilder(org.platformlayer.ops.instances.InstanceBuilder)

Example 5 with InstanceBuilder

use of org.platformlayer.ops.instances.InstanceBuilder in project platformlayer by platformlayer.

the class JenkinsServiceController method addChildren.

@Override
protected void addChildren() throws OpsException {
    JenkinsService model = OpsContext.get().getInstance(JenkinsService.class);
    InstanceBuilder vm;
    {
        vm = InstanceBuilder.build(model.dnsName, this, model.getTags());
        vm.publicPorts.add(PORT);
        vm.hostPolicy.allowRunInContainer = true;
        vm.minimumMemoryMb = 2048;
        addChild(vm);
    }
    // If we're building Java projects, we'll want a JDK
    vm.addChild(JavaVirtualMachine.buildJdk7());
    {
        PackageDependency jenkinsPackage = PackageDependency.build("jenkins");
        jenkinsPackage.repositoryKey = new RepositoryKey();
        jenkinsPackage.repositoryKey.setUrl("http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key");
        jenkinsPackage.repository = new Repository();
        jenkinsPackage.repository.setKey("jenkins");
        jenkinsPackage.repository.getSource().add("deb http://pkg.jenkins-ci.org/debian binary/");
        vm.addChild(jenkinsPackage);
    }
    // We use curl for backups
    vm.addChild(PackageDependency.build("curl"));
    // Jenkins git usually relies on git being installed
    // git-core is valid on both Debian & Ubuntu
    vm.addChild(PackageDependency.build("git-core"));
    vm.addChild(SimpleFile.build(getClass(), new File("/etc/default/jenkins")));
    vm.addChild(EnsureJenkinsSshKey.class);
    {
        // Adding a known-host entry for github.com doesn't reduce security (?)
        EnsureKnownHost knownHost = vm.addChild(EnsureKnownHost.class);
        knownHost.user = "jenkins";
        knownHost.homeDir = new File("/var/lib/jenkins");
        knownHost.host = "github.com";
        knownHost.algorithm = "ssh-rsa";
        knownHost.key = "AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==";
    }
    // Collectd not in wheezy??
    // instance.addChild(CollectdCollector.build());
    // TODO: If we're going to support SSH git....
    // TODO: We need to ssh-keygen for jenkins
    // TODO: Someone has to add the jenkins ssh key to the git repo
    // TODO: We need to set the git user variables (name & email)
    // TODO: We need to add the ssh key(s) of any git repos we're going to be using over ssh
    // su -c "ssh-keygen -q -f /var/lib/jenkins/.ssh/id_rsa -N ''" jenkins
    // scp root@[2001:470:8157:2::f]:/var/lib/jenkins/.ssh/id_rsa.pub .
    // cat id_rsa.pub | ssh -p29418 <gerritip> gerrit create-account --ssh-key - --full-name Jenkins jenkins
    {
        PublicEndpoint endpoint = injected(PublicEndpoint.class);
        // endpoint.network = null;
        endpoint.publicPort = PORT;
        endpoint.backendPort = PORT;
        endpoint.dnsName = model.dnsName;
        endpoint.tagItem = model.getKey();
        endpoint.parentItem = model.getKey();
        endpoint.transport = Transport.Ipv6;
        vm.addChild(endpoint);
    }
    {
        BackupDirectory backup = injected(BackupDirectory.class);
        backup.itemKey = model.getKey();
        File jenkinsRoot = new File("/var/lib/jenkins");
        backup.backupRoot = jenkinsRoot;
        String[] excludes = { "jobs/*/workspace", "jobs/*/modules", "jobs/*/builds/*/workspace.tar.gz", ".m2/repository" };
        for (String exclude : excludes) {
            backup.excludes.add(new File(jenkinsRoot, exclude));
        }
        vm.addChild(backup);
    }
}
Also used : Repository(org.platformlayer.images.model.Repository) PackageDependency(org.platformlayer.ops.packages.PackageDependency) BackupDirectory(org.platformlayer.ops.backups.BackupDirectory) JenkinsService(org.platformlayer.service.jenkins.model.JenkinsService) PublicEndpoint(org.platformlayer.ops.networks.PublicEndpoint) RepositoryKey(org.platformlayer.images.model.RepositoryKey) File(java.io.File) SimpleFile(org.platformlayer.ops.filesystem.SimpleFile) InstanceBuilder(org.platformlayer.ops.instances.InstanceBuilder)

Aggregations

InstanceBuilder (org.platformlayer.ops.instances.InstanceBuilder)26 PublicEndpoint (org.platformlayer.ops.networks.PublicEndpoint)19 File (java.io.File)9 TemplatedFile (org.platformlayer.ops.filesystem.TemplatedFile)4 SimpleFile (org.platformlayer.ops.filesystem.SimpleFile)3 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)2 NetworkPoint (org.platformlayer.ops.networks.NetworkPoint)2 PackageDependency (org.platformlayer.ops.packages.PackageDependency)2 NginxService (org.openstack.service.nginx.model.NginxService)1 ManagedItemId (org.platformlayer.ids.ManagedItemId)1 OperatingSystemRecipe (org.platformlayer.images.model.OperatingSystemRecipe)1 Repository (org.platformlayer.images.model.Repository)1 RepositoryKey (org.platformlayer.images.model.RepositoryKey)1 OpsException (org.platformlayer.ops.OpsException)1 BackupDirectory (org.platformlayer.ops.backups.BackupDirectory)1 RecipeOperatingSystem (org.platformlayer.ops.packages.RecipeOperatingSystem)1 PosixGroup (org.platformlayer.ops.users.PosixGroup)1 PosixUser (org.platformlayer.ops.users.PosixUser)1 IpsecForPort (org.platformlayer.ops.vpn.IpsecForPort)1 IpsecPresharedKey (org.platformlayer.ops.vpn.IpsecPresharedKey)1