/// <inheritdoc/>
        public Task Perform(IPerformerLog log, Context score)
        {
            log.Information($"Get latest source into '{score.SourcePath}'");

            var gitFolder = Path.Combine(score.SourcePath, ".git");

            if (!Directory.Exists(gitFolder))
            {
                Clone(log, score);
            }
            else
            {
                try
                {
                    Pull(log, score);
                }  
                catch
                {
                    log.Information("Problems pulling - recreating");
                    Directory.Delete(score.SourcePath, true);
                    Clone(log, score);
                }
            }

            return(Task.CompletedTask);
        }
示例#2
0
        /// <inheritdoc/>
        public Task Perform(IPerformerLog log, Context score)
        {
            log.Information("Getting version");
            using (var repo = new Repository(score.SourcePath))
            {
                var tag = repo.Tags.ToArray().LastOrDefault();
                if (tag != null)
                {
                    score.Version = $"{tag.FriendlyName}.{score.BuildNumber}";
                }
                log.Information($"Version is {score.Version}");
            }

            return(Task.CompletedTask);
        }
        void Pull(IPerformerLog log, Context score)
        {
            log.Information("Repository already exists - pulling latest");
            using (var repo = new Repository(score.SourcePath))
            {
                var pullOptions = new PullOptions();
                pullOptions.FetchOptions = new FetchOptions();
                var signature = new Signature(
                    new Identity("<Dolittle CI>", "*****@*****.**"), DateTimeOffset.Now);

                pullOptions.FetchOptions.Prune        = true;
                pullOptions.FetchOptions.TagFetchMode = TagFetchMode.All;
                pullOptions.FetchOptions.OnProgress   = (string message) =>
                {
                    log.Information(message);
                    return(true);
                };

                Commands.Pull(repo, signature, pullOptions);
            }
        }
        void Clone(IPerformerLog log, Context score)
        {
            log.Information("Cloning");
            var cloneOptions = new CloneOptions();

            cloneOptions.RecurseSubmodules  = true;
            cloneOptions.OnCheckoutProgress = (string path, int completedSteps, int totalSteps) => log.Information(path);

            /*
             * cloneOptions.CredentialsProvider = (_url, _user, _cred) =>
             *                                      new UsernamePasswordCredentials
             *                                      {
             *                                          Username = "******",
             *                                          Password = "******"
             *                                      };
             */
            //if( Directory.Exists(score.SourcePath) ) Directory.Delete(score.SourcePath);

            Repository.Clone(score.Project.Repository.ToString(), score.SourcePath, cloneOptions);
        }
示例#5
0
        async Task StartJobFor(IPerformerLog log, Context context, Read.Configuration.Build build)
        {
            var @namespace = "dolittle";

            var metadata = new V1ObjectMeta
            {
                Name = Guid.NewGuid().ToString() //,
                       //Labels = { { "type", "build" } }
            };

            log.Information($"---");
            log.Information($"Type : {build.Type}");
            log.Information($"BasePath : {build.BasePath}");
            log.Information($"Package : {build.Package}");
            log.Information($"Publish : {build.Publish}");
            log.Information($"Folder with project to publish : {build.FolderWithProjectToPublish}");
            log.Information($"---");

            var job = new V1Job
            {
                Metadata = metadata,
                Spec     = new V1JobSpec
                {
                    Completions = 1,

                    Template = new V1PodTemplateSpec
                    {
                        Metadata = metadata,
                        Spec     = new V1PodSpec
                        {
                            Containers = new [] {
                                new V1Container {
                                    Name            = "build",
                                    Image           = $"dolittlebuild/{build.Type}",
                                    ImagePullPolicy = "Always",
                                    Env             = new [] {
                                        new V1EnvVar("REPOSITORY", context.Project.Repository.ToString()),
                                        new V1EnvVar("COMMIT", context.SourceControl.Commit),
                                        new V1EnvVar("PULL_REQUEST", context.IsPullRequest.ToString()),
                                        new V1EnvVar("VERSION", context.Version),
                                        new V1EnvVar("BASE_PATH", build.BasePath),
                                        new V1EnvVar("PACKAGE", build.Package.ToString()),
                                        new V1EnvVar("PUBLISH", build.Publish.ToString()),
                                        new V1EnvVar("FOLDER_WITH_PROJECT_TO_PUBLISH", build.FolderWithProjectToPublish),
                                        new V1EnvVar("CALLBACK", $"http://continuousimprovement/buildJobDone?jobName={metadata.Name}")
                                    },
                                    VolumeMounts = new[] {
                                        new V1VolumeMount {
                                            Name      = "azure",
                                            MountPath = "/repository",
                                            SubPath   = context.Volumes.SourcePath
                                        },
                                        new V1VolumeMount {
                                            Name      = "azure",
                                            MountPath = "/packages",
                                            SubPath   = context.Volumes.PackagePath
                                        },
                                        new V1VolumeMount {
                                            Name      = "azure",
                                            MountPath = "/output",
                                            SubPath   = context.Volumes.OutputPath
                                        },
                                        new V1VolumeMount {
                                            Name      = "azure",
                                            MountPath = "/publish",
                                            SubPath   = context.Volumes.PublishPath
                                        },
                                        new V1VolumeMount {
                                            Name      = "azure",
                                            MountPath = "/testresults",
                                            SubPath   = context.Volumes.TestResultsPath
                                        }
                                    }
                                }
                            },
                            Volumes = new[] {
                                new V1Volume {
                                    Name      = "azure",
                                    AzureFile = new V1AzureFileVolumeSource {
                                        SecretName       = "azure-storage-secret",
                                        ShareName        = "continuousimprovement",
                                        ReadOnlyProperty = false
                                    }
                                }
                            },
                            RestartPolicy = "Never",
                        }
                    }
                }
            };

            await _kubernetes.CreateNamespacedJobAsync(job, @namespace);
        }
示例#6
0
 /// <inheritdoc/>
 public Task Perform(IPerformerLog log, Context context)
 {
     log.Information("Building jobs");
     context.Project.Builds.ForEach(async _ => await StartJobFor(log, context, _));
     return(Task.CompletedTask);
 }