use of io.fabric8.agent.model.Repository in project fabric8-maven-plugin by fabric8io.
the class BaseBoosterIT method setupSampleTestRepository.
protected Repository setupSampleTestRepository(String repositoryUrl, String relativePomPath) throws IOException, GitAPIException, XmlPullParserException {
openShiftClient = new DefaultOpenShiftClient(new ConfigBuilder().build());
testsuiteNamespace = openShiftClient.getNamespace();
Repository repository = cloneRepositoryUsingHttp(repositoryUrl);
modifyPomFileToProjectVersion(repository, relativePomPath);
return repository;
}
use of io.fabric8.agent.model.Repository in project fabric8 by fabric8io.
the class DevOpsConnector method createWebhook.
protected boolean createWebhook(String url, String webhookSecret) {
// e.g. we shouldn't try to register webhooks on public github with on premise services
try {
GitRepoClient gitRepoClient = getGitRepoClient();
WebHooks.createGogsWebhook(gitRepoClient, getLog(), username, repoName, url, webhookSecret);
return true;
} catch (Exception e) {
getLog().error("Failed to create webhook " + url + " on repository " + repoName + ". Reason: " + e, e);
return false;
}
}
use of io.fabric8.agent.model.Repository in project fabric8 by fabric8io.
the class WebHooks method createGogsWebhook.
/**
* Creates a webook in the given gogs repo for the user and password if the webhook does not already exist
*/
public static boolean createGogsWebhook(GitRepoClient repoClient, Logger log, String gogsUser, String repoName, String webhookUrl, String webhookSecret) throws JsonProcessingException {
if (repoClient == null) {
log.info("Cannot create Gogs webhooks as no Gogs service could be found or created");
return false;
}
String gogsAddress = repoClient.getAddress();
log.info("Querying webhooks in gogs at address: " + gogsAddress + " for user " + gogsUser + " repoName: " + repoName);
RepositoryDTO repository = repoClient.getRepository(gogsUser, repoName);
if (repository == null) {
log.info("No repository found for user: " + gogsUser + " repo: " + repoName + " so cannot create any web hooks");
// return false;
}
List<WebHookDTO> webhooks = repoClient.getWebhooks(gogsUser, repoName);
for (WebHookDTO webhook : webhooks) {
String url = null;
WebhookConfig config = webhook.getConfig();
if (config != null) {
url = config.getUrl();
if (Objects.equal(webhookUrl, url)) {
log.info("Already has webhook for: " + url + " so not creating again");
return false;
}
log.info("Ignoring webhook " + url + " from: " + toJson(config));
}
}
CreateWebhookDTO createWebhook = new CreateWebhookDTO();
createWebhook.setType("gogs");
WebhookConfig config = createWebhook.getConfig();
config.setUrl(webhookUrl);
config.setSecret(webhookSecret);
WebHookDTO webhook = repoClient.createWebhook(gogsUser, repoName, createWebhook);
if (log.isDebugEnabled()) {
log.debug("Got created web hook: " + toJson(webhook));
}
log.info("Created webhook for " + webhookUrl + " for user: " + gogsUser + " repoName: " + repoName + " on gogs URL: " + gogsAddress);
return true;
}
use of io.fabric8.agent.model.Repository in project fabric8 by fabric8io.
the class BuildConfigHelper method importNewGitProject.
public static CreateGitProjectResults importNewGitProject(KubernetesClient kubernetesClient, UserDetails userDetails, File basedir, String namespace, String projectName, String origin, String message, boolean apply, boolean useLocalGitAddress) throws GitAPIException, JsonProcessingException {
GitUtils.disableSslCertificateChecks();
InitCommand initCommand = Git.init();
initCommand.setDirectory(basedir);
Git git = initCommand.call();
LOG.info("Initialised an empty git configuration repo at {}", basedir.getAbsolutePath());
PersonIdent personIdent = userDetails.createPersonIdent();
String user = userDetails.getUser();
String address = userDetails.getAddress();
String internalAddress = userDetails.getInternalAddress();
String branch = userDetails.getBranch();
// lets create the repository
GitRepoClient repoClient = userDetails.createRepoClient();
CreateRepositoryDTO createRepository = new CreateRepositoryDTO();
createRepository.setName(projectName);
String fullName = null;
RepositoryDTO repository = repoClient.createRepository(createRepository);
if (repository != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Got repository: " + toJson(repository));
}
fullName = repository.getFullName();
}
if (Strings.isNullOrBlank(fullName)) {
fullName = user + "/" + projectName;
}
String htmlUrl = URLUtils.pathJoin(resolveToRoot(address), user, projectName);
String localCloneUrl = URLUtils.pathJoin(resolveToRoot(internalAddress), user, projectName + ".git");
String cloneUrl = htmlUrl + ".git";
String defaultCloneUrl = cloneUrl;
// lets default to using the local git clone URL
if (useLocalGitAddress && Strings.isNotBlank(internalAddress)) {
defaultCloneUrl = localCloneUrl;
}
// now lets import the code and publish
GitUtils.configureBranch(git, branch, origin, defaultCloneUrl);
GitUtils.addDummyFileToEmptyFolders(basedir);
LOG.info("About to git commit and push to: " + defaultCloneUrl + " and remote name " + origin);
GitUtils.doAddCommitAndPushFiles(git, userDetails, personIdent, branch, origin, message, true);
Map<String, String> annotations = new HashMap<>();
annotations.put(Annotations.Builds.GIT_CLONE_URL, cloneUrl);
annotations.put(Annotations.Builds.LOCAL_GIT_CLONE_URL, localCloneUrl);
BuildConfig buildConfig;
if (apply) {
buildConfig = createAndApplyBuildConfig(kubernetesClient, namespace, projectName, defaultCloneUrl, annotations);
} else {
buildConfig = createBuildConfig(kubernetesClient, namespace, projectName, defaultCloneUrl, annotations);
}
return new CreateGitProjectResults(buildConfig, fullName, htmlUrl, localCloneUrl, cloneUrl);
}
use of io.fabric8.agent.model.Repository in project che by eclipse.
the class OpenShiftConnector method pull.
/**
* Creates an ImageStream that tracks the repository.
*
* <p>Note: This method does not cause the relevant image to actually be pulled to the local
* repository, but creating the ImageStream is necessary as it is used to obtain
* the address of the internal Docker registry later.
*
* @see DockerConnector#pull(PullParams, ProgressMonitor)
*/
@Override
public void pull(final PullParams params, final ProgressMonitor progressMonitor) throws IOException {
// image to be pulled
String repo = params.getFullRepo();
// e.g. latest, usually
String tag = params.getTag();
String imageStreamName = KubernetesStringUtils.convertPullSpecToImageStreamName(repo);
ImageStream existingImageStream = openShiftClient.imageStreams().inNamespace(openShiftCheProjectName).withName(imageStreamName).get();
if (existingImageStream == null) {
openShiftClient.imageStreams().inNamespace(openShiftCheProjectName).createNew().withNewMetadata().withName(// imagestream id
imageStreamName).endMetadata().withNewSpec().addNewTag().withName(tag).endTag().withDockerImageRepository(// tracking repo
repo).endSpec().withNewStatus().withDockerImageRepository("").endStatus().done();
}
// Wait for Image metadata to be obtained.
ImageStream createdImageStream;
for (int waitCount = 0; waitCount < OPENSHIFT_IMAGESTREAM_MAX_WAIT_COUNT; waitCount++) {
try {
Thread.sleep(OPENSHIFT_IMAGESTREAM_WAIT_DELAY);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
createdImageStream = openShiftClient.imageStreams().inNamespace(openShiftCheProjectName).withName(imageStreamName).get();
if (createdImageStream != null && createdImageStream.getStatus().getDockerImageRepository() != null) {
LOG.info(String.format("Created ImageStream %s.", imageStreamName));
return;
}
}
throw new OpenShiftException(String.format("Failed to create ImageStream %s.", imageStreamName));
}
Aggregations