コード例 #1
0
 public Map<String, String> getIPAddresses() {
   Map<String, String> idToIpAddressMap = new HashMap<>();
   for (Id id : ids()) {
     Conf conf = repo.conf(id);
     if (inclusive(id) && conf.isExposeContainerIp()) {
       String containerName = repo.containerName(id);
       InspectContainerResponse containerInspectResponse =
           docker.inspectContainerCmd(containerName).exec();
       idToIpAddressMap.put(
           id.toString(), containerInspectResponse.getNetworkSettings().getIpAddress());
     }
   }
   return idToIpAddressMap;
 }
コード例 #2
0
 private File prepare(Id id) throws IOException {
   if (id == null) {
     throw new IllegalArgumentException("id is null");
   }
   logger.info("Preparing " + id);
   return fileOrchestrator.prepare(id, repo.src(id), conf(id));
 }
コード例 #3
0
 public void stop() {
   for (Id id : repo.ids(true)) {
     if (!inclusive(id)) {
       continue;
     }
     stop(id);
   }
 }
コード例 #4
0
 /**
  * RtReleases can remove a release.
  *
  * @throws Exception if any problem inside
  */
 @Test
 public void canRemoveRelease() throws Exception {
   final Releases releases = repo.releases();
   final Release release = releases.create(RandomStringUtils.randomAlphanumeric(Tv.TEN));
   MatcherAssert.assertThat(releases.iterate(), Matchers.hasItem(release));
   releases.remove(release.number());
   MatcherAssert.assertThat(releases.iterate(), Matchers.not(Matchers.hasItem(release)));
 }
コード例 #5
0
ファイル: PkgValidator.java プロジェクト: bhuesemann/basex
 /**
  * Checks package descriptor and if packages involved in dependencies are already installed.
  *
  * @param pkg package
  * @throws QueryException query exception
  */
 public void check(final Package pkg) throws QueryException {
   // check if package is already installed
   final byte[] name = pkg.uniqueName();
   if (repo.pkgDict().get(name) != null) PKGINST.thrw(input, name);
   // check package dependencies
   checkDepends(pkg);
   // check package components
   checkComps(pkg);
 }
コード例 #6
0
ファイル: PkgValidator.java プロジェクト: bhuesemann/basex
 /**
  * Checks if secondary package, i.e. package involved in a dependency is already installed.
  *
  * @param dep dependency
  * @return result
  */
 public byte[] depPkg(final Dependency dep) {
   // get installed versions of secondary package
   final TokenSet instVers = new TokenSet();
   for (final byte[] nextPkg : repo.pkgDict().keys())
     if (nextPkg != null && startsWith(nextPkg, dep.pkg)) instVers.add(version(nextPkg));
   // check if an appropriate version is already installed
   final byte[] version = availVersion(dep, instVers);
   return version == null ? null : dep.name(version);
 }
コード例 #7
0
  private String createNewContainer(Id id) throws DockerException {

    CreateContainerCmd cmd = docker.createContainerCmd(findImageId(id));

    Conf conf = conf(id);

    cmd.withPublishAllPorts(true);
    cmd.withPrivileged(conf.isPrivileged());

    Link[] links = links(id);

    logger.info(" - links " + conf.getLinks());
    cmd.withLinks(links);

    List<PortBinding> portBindings = new ArrayList<>();
    for (String e : conf.getPorts()) {

      final String[] split = e.split(" ");

      assert split.length == 1 || split.length == 2;

      final int hostPort = Integer.parseInt(split[0]);
      final int containerPort = split.length == 2 ? Integer.parseInt(split[1]) : hostPort;

      logger.info(" - port " + hostPort + "->" + containerPort);
      portBindings.add(
          new PortBinding(
              new Ports.Binding(hostPort), new ExposedPort(containerPort, InternetProtocol.TCP)));
    }
    cmd.withPortBindings(portBindings.toArray(new PortBinding[portBindings.size()]));

    logger.info(" - volumes " + conf.getVolumes());

    final List<Bind> binds = new ArrayList<>();
    for (Map.Entry<String, String> entry : conf.getVolumes().entrySet()) {
      String volumePath = entry.getKey();
      String hostPath = entry.getValue();
      File file = new File(hostPath);
      String path = file.getAbsolutePath();
      logger.info(" - volumes " + volumePath + " <- " + path);
      binds.add(new Bind(path, new Volume(volumePath)));
    }

    cmd.withBinds(binds.toArray(new Bind[binds.size()]));

    cmd.withName(repo.containerName(id));
    logger.info(" - env " + conf.getEnv());
    cmd.withEnv(asEnvList(conf.getEnv()));

    if (!conf.getExtraHosts().isEmpty()) {
      List<String> extraHosts = conf.getExtraHosts();
      cmd.withExtraHosts(extraHosts.toArray(new String[extraHosts.size()]));
      logger.info(" - extra hosts " + conf.getExtraHosts());
    }

    return cmd.exec().getId();
  }
コード例 #8
0
 private void validate(final Id id) {
   if (id == null) {
     throw new IllegalArgumentException("id is null");
   }
   try {
     dockerfileValidator.validate(repo.src(id));
   } catch (IOException e) {
     throw new OrchestrationException(e);
   }
 }
コード例 #9
0
ファイル: PkgValidator.java プロジェクト: bhuesemann/basex
  /**
   * Checks if an XQuery component is already installed as part of another package.
   *
   * @param comp component
   * @param name component's package
   * @return result
   * @throws QueryException query exception
   */
  private boolean isInstalled(final Component comp, final byte[] name) throws QueryException {
    // get packages in which the module's namespace is found
    final TokenSet pkgs = repo.nsDict().get(comp.uri);
    if (pkgs == null) return false;

    for (final byte[] nextPkg : pkgs) {
      if (nextPkg != null && !eq(Package.name(nextPkg), name)) {
        // installed package is a different one, not just a different version
        // of the current one
        final String pkgDir = string(repo.pkgDict().get(nextPkg));
        final IO pkgDesc = new IOFile(repo.path(pkgDir), DESCRIPTOR);
        final Package pkg = new PkgParser(repo, input).parse(pkgDesc);
        for (final Component nextComp : pkg.comps) {
          if (nextComp.name().equals(comp.name())) return true;
        }
      }
    }
    return false;
  }
コード例 #10
0
 /**
  * RtReleases can edit release body.
  *
  * @throws Exception if any problem inside.
  */
 @Test
 public void canEditBody() throws Exception {
   final Releases releases = repo.releases();
   final Release release = releases.create(RandomStringUtils.randomAlphanumeric(Tv.TEN));
   final String body = "Description of the release";
   new Release.Smart(release).body(body);
   MatcherAssert.assertThat(
       new Release.Smart(releases.get(release.number())).body(), Matchers.equalTo(body));
   releases.remove(release.number());
 }
コード例 #11
0
 /**
  * RtReleases can edit release tag.
  *
  * @throws Exception if any problem inside.
  */
 @Test
 public void canEditTag() throws Exception {
   final Releases releases = repo.releases();
   final Release release = releases.create(RandomStringUtils.randomAlphanumeric(Tv.TEN));
   final String tag = RandomStringUtils.randomAlphanumeric(Tv.FIFTEEN);
   new Release.Smart(release).tag(tag);
   MatcherAssert.assertThat(
       new Release.Smart(releases.get(release.number())).tag(), Matchers.equalTo(tag));
   releases.remove(release.number());
 }
コード例 #12
0
 /**
  * RtReleases can iterate releases.
  *
  * @throws Exception if something goes wrong
  */
 @Test
 public void canFetchAllReleases() throws Exception {
   final Releases releases = repo.releases();
   final Release release = releases.create(RandomStringUtils.randomAlphanumeric(Tv.TEN));
   try {
     MatcherAssert.assertThat(
         releases.iterate(), Matchers.not(Matchers.emptyIterableOf(Release.class)));
   } finally {
     releases.remove(release.number());
   }
 }
コード例 #13
0
ファイル: RtDeployKeys.java プロジェクト: jcabi/jcabi-github
 /**
  * Public ctor.
  *
  * @param req RESTful API entry point
  * @param repo Repository
  */
 RtDeployKeys(final Request req, final Repo repo) {
   this.owner = repo;
   this.entry = req;
   this.request =
       req.uri()
           .path("/repos")
           .path(repo.coordinates().user())
           .path(repo.coordinates().repo())
           .path("/keys")
           .back();
 }
コード例 #14
0
 /**
  * RtReleases can fetch a single release.
  *
  * @throws Exception if any error inside
  */
 @Test
 public void canFetchRelease() throws Exception {
   final Releases releases = repo.releases();
   final String tag = "v1.0";
   final Release release = releases.create(tag);
   MatcherAssert.assertThat(
       releases.get(release.number()).number(), Matchers.equalTo(release.number()));
   MatcherAssert.assertThat(
       new Release.Smart(releases.get(release.number())).tag(), Matchers.equalTo(tag));
   releases.remove(release.number());
 }
コード例 #15
0
ファイル: RtLabel.java プロジェクト: jcabi/jcabi-github
 /**
  * Public ctor.
  *
  * @param req Request
  * @param repo Repository
  * @param name Name of it
  */
 RtLabel(final Request req, final Repo repo, final String name) {
   final Coordinates coords = repo.coordinates();
   this.request =
       req.uri()
           .path("/repos")
           .path(coords.user())
           .path(coords.repo())
           .path("/labels")
           .path(name)
           .back();
   this.owner = repo;
   this.txt = name;
 }
コード例 #16
0
  @SuppressWarnings(("DM_DEFAULT_ENCODING"))
  private void build(File dockerFolder, Id id) {
    try {

      String tag = repo.tag(id);
      logger.info("Building " + id + " (" + tag + ")");

      final boolean noCache = buildNoCache();
      logger.info(" - no cache: " + noCache);

      final boolean removeIntermediateImages = buildRemoveIntermediateImages();
      logger.info(" - remove intermediate images: " + removeIntermediateImages);

      final boolean quiet = buildQuiet();
      logger.info(" - quiet: " + quiet);

      BuildImageCmd build =
          docker
              .buildImageCmd(dockerFolder)
              .withNoCache(noCache)
              .withRemove(removeIntermediateImages)
              .withQuiet(quiet)
              .withTag(tag);

      throwExceptionIfThereIsAnError(build.exec());

      for (String otherTag : repo.conf(id).getTags()) {
        int lastIndexOfColon = otherTag.lastIndexOf(':');
        if (lastIndexOfColon > -1) {
          String repositoryName = otherTag.substring(0, lastIndexOfColon);
          String tagName = otherTag.substring(lastIndexOfColon + 1);
          docker.tagImageCmd(findImageId(id), repositoryName, tagName).withForce().exec();
        }
      }
    } catch (DockerException | IOException e) {
      throw new OrchestrationException(e);
    }
  }
コード例 #17
0
 /**
  * RtReleases can create a release.
  *
  * @throws Exception if any error inside
  */
 @Test
 public void canCreateRelease() throws Exception {
   final Releases releases = repo.releases();
   final Release created = releases.create("0.1");
   final int number = created.number();
   try {
     final Release obtained = releases.get(number);
     MatcherAssert.assertThat(created, Matchers.is(obtained));
     MatcherAssert.assertThat(
         new Release.Smart(created).tag(), Matchers.equalTo(new Release.Smart(obtained).tag()));
   } finally {
     releases.remove(number);
   }
 }
コード例 #18
0
 private String findImageId(Id id) {
   String imageTag = repo.tag(id);
   logger.debug("Converting {} ({}) to image id.", id, imageTag);
   List<Image> images = docker.listImagesCmd().exec();
   for (Image i : images) {
     for (String tag : i.getRepoTags()) {
       if (tag.startsWith(imageTag)) {
         logger.debug(
             "Using {} ({}) for {}. It matches (enough) to {}.",
             new Object[] {i.getId(), tag, id.toString(), imageTag});
         return i.getId();
       }
     }
   }
   logger.debug("could not find image ID for \"" + id + "\" (tag \"" + imageTag + "\")");
   return null;
 }
コード例 #19
0
 private List<Container> findContainers(Id id, boolean allContainers) {
   final List<Container> matchingContainers = new ArrayList<>();
   for (Container container : docker.listContainersCmd().withShowAll(allContainers).exec()) {
     boolean imageNameMatches = container.getImage().equals(repo.imageName(id));
     String[] containerNames = container.getNames();
     if (containerNames == null) {
       // Every container should have a name, but this is not the case
       // on Circle CI. Containers with no name are broken residues of
       // building the image and therefore will be ignored.
       continue;
     }
     boolean containerNameMatches = asList(containerNames).contains(containerName(id));
     if (imageNameMatches || containerNameMatches) {
       matchingContainers.add(container);
     }
   }
   return matchingContainers;
 }
コード例 #20
0
 private Conf conf(Id id) {
   return repo.conf(id);
 }
コード例 #21
0
ファイル: Model.java プロジェクト: marayl/doogal
 final File getConfig() {
   return new File(repo.getEtc(), "doogal.conf");
 }
コード例 #22
0
ファイル: ApkProvider.java プロジェクト: nutellarlz/AppHub
 public static int deleteApksByRepo(Context context, Repo repo) {
   ContentResolver resolver = context.getContentResolver();
   final Uri uri = getRepoUri(repo.getId());
   return resolver.delete(uri, null, null);
 }
コード例 #23
0
ファイル: ApkProvider.java プロジェクト: nutellarlz/AppHub
 public static List<Apk> findByRepo(Context context, Repo repo, String[] fields) {
   ContentResolver resolver = context.getContentResolver();
   final Uri uri = getRepoUri(repo.getId());
   Cursor cursor = resolver.query(uri, fields, null, null, null);
   return cursorToList(cursor);
 }
コード例 #24
0
 /**
  * Tear down test fixtures.
  *
  * @throws Exception If some errors occurred.
  */
 @AfterClass
 public static void tearDown() throws Exception {
   if (repos != null && repo != null) {
     repos.remove(repo.coordinates());
   }
 }
コード例 #25
0
ファイル: Uploads.java プロジェクト: ceylon/ceylon-herd
  public static void publish(Long id) throws IOException {
    models.Upload upload = getUpload(id);
    File uploadsDir = Util.getUploadDir(id);
    User user = getUser();
    UploadInfo uploadInfo = getUploadInfo(upload, uploadsDir, user);

    if (!uploadInfo.isPublishable()) {
      Validation.addError(null, "Upload is not valid, cannot publish. Fix errors first.");
      prepareForErrorRedirect();
      view(id);
    }

    List<models.ModuleVersion> versions = new LinkedList<models.ModuleVersion>();
    for (Module module : uploadInfo.modules) {
      models.Module mod = models.Module.find("name = ?", module.name).first();
      if (mod == null) {
        mod = new models.Module();
        mod.name = module.name;
        mod.owner = user;
        mod.create();
      }

      models.ModuleVersion modVersion = new models.ModuleVersion();
      modVersion.module = mod;
      modVersion.version = module.version;
      modVersion.isCarPresent = module.car.exists;
      modVersion.isJarPresent = module.jar.exists;
      modVersion.isJsPresent = module.js.exists;
      modVersion.isSourcePresent = module.source.exists;
      modVersion.isScriptsPresent = module.scripts.exists;
      modVersion.isAPIPresent = module.docs.hasUnzipped;
      modVersion.isDocPresent = module.docs.exists;
      modVersion.isResourcesPresent = module.docs.exists;
      modVersion.isRunnable = module.isRunnable;
      modVersion.jvmBinMajor = module.jvmBinMajor;
      modVersion.jvmBinMinor = module.jvmBinMinor;
      modVersion.jsBinMajor = module.jsBinMajor;
      modVersion.jsBinMinor = module.jsBinMinor;
      modVersion.isNativeJvm = module.isNativeJvm();
      modVersion.isNativeJs = module.isNativeJs();
      modVersion.published = Util.currentTimeInUTC();
      modVersion.doc = module.doc;
      modVersion.license = module.license;
      if (module.authors != null) {
        for (String author : module.authors) {
          modVersion.authors.add(Author.findOrCreate(author));
        }
      }
      modVersion.create();

      for (Import imp : module.getAllDependencies())
        modVersion.addDependency(
            imp.name,
            imp.version,
            imp.optional,
            imp.export,
            imp.mavenDependency != null,
            imp.herdDependency != null,
            imp.isNativeJvm(),
            imp.isNativeJs());

      for (ModuleChecker.Member member : module.members)
        modVersion.addMember(member.packageName, member.name, member.type, member.shared);

      for (ModuleChecker.Script script : module.scriptDescriptions)
        modVersion.addScript(
            script.name, script.description, script.unix, script.plugin, script.module);

      versions.add(modVersion);
    }

    FileUtils.copyDirectory(uploadsDir, Util.getRepoDir(), NonEmptyDirectoryFilter);
    FileUtils.deleteDirectory(uploadsDir);
    upload.delete();

    MyCache.evictUploadsForOwner(user);
    MyCache.evictModulesForOwner(user);

    if (versions.size() == 1) {
      flash("message", "Your module has been published");
      models.ModuleVersion moduleVersion = versions.get(0);
      Repo.view(moduleVersion.module.name, moduleVersion.version);
    } else {
      flash("message", "Your modules have been published");
      render(versions);
    }
  }
コード例 #26
0
 private String repo(Id id) {
   return repo.tag(id).replaceFirst(":[^:]*$", "");
 }
コード例 #27
0
 public List<Id> ids() {
   return repo.ids(false);
 }
コード例 #28
0
 private String containerName(Id id) {
   ContainerConf container = repo.conf(id).getContainer();
   return container.hasName() ? container.getName() : repo.defaultContainerName(id);
 }