Пример #1
0
        /**
         * Gets a new {@link Containerizer} that containerizes to a Docker daemon.
         *
         * @param dockerDaemonImage the {@link DockerDaemonImage} that defines target Docker daemon
         * @return a new {@link Containerizer}
         */
        public static Containerizer To(DockerDaemonImage dockerDaemonImage)
        {
            dockerDaemonImage = dockerDaemonImage ?? throw new ArgumentNullException(nameof(dockerDaemonImage));
            ImageConfiguration imageConfiguration =
                ImageConfiguration.CreateBuilder(dockerDaemonImage.GetImageReference())
                .SetCredentialRetrievers(new List <CredentialRetriever> {
                () => Maybe.Of(dockerDaemonImage.Credential)
            })
                .Build();

            DockerClient.Builder dockerClientBuilder = DockerClient.CreateBuilder();
            dockerDaemonImage.GetDockerExecutable().IfPresent(dockerClientBuilder.SetDockerExecutable);
            dockerClientBuilder.SetDockerEnvironment(ImmutableDictionary.CreateRange(dockerDaemonImage.GetDockerEnvironment()));

            return(new Containerizer(
                       DescriptionForDockerDaemon, imageConfiguration, StepsRunnerFactory, false));

            StepsRunner StepsRunnerFactory(BuildConfiguration buildConfiguration) =>
            StepsRunner.Begin(buildConfiguration)
            .PullBaseImage(1)
            .PullAndCacheBaseImageLayers(2)
            .BuildAndCacheApplicationLayers(3)
            .BuildImage(4)
            .LoadDocker(dockerClientBuilder.Build(), 5);
        }
Пример #2
0
        private TestHostContext CreateTestContext([CallerMemberName] String testName = "")
        {
            var hc = new TestHostContext(this, testName);
            var expressionManager = new ExpressionManager();

            expressionManager.Initialize(hc);
            hc.SetSingleton <IExpressionManager>(expressionManager);
            Dictionary <string, VariableValue> variablesToCopy = new Dictionary <string, VariableValue>();

            _variables = new Variables(
                hostContext: hc,
                copy: variablesToCopy);
            _ec = new Mock <IExecutionContext>();
            _ec.SetupAllProperties();
            _ec.Setup(x => x.Variables).Returns(_variables);

            _contexts           = new DictionaryContextData();
            _jobContext         = new JobContext();
            _contexts["github"] = new DictionaryContextData();
            _contexts["runner"] = new DictionaryContextData();
            _contexts["job"]    = _jobContext;
            _ec.Setup(x => x.ExpressionValues).Returns(_contexts);
            _ec.Setup(x => x.JobContext).Returns(_jobContext);

            _stepContext = new StepsContext();
            _ec.Setup(x => x.StepsContext).Returns(_stepContext);

            _ec.Setup(x => x.PostJobSteps).Returns(new Stack <IStep>());

            _stepsRunner = new StepsRunner();
            _stepsRunner.Initialize(hc);
            return(hc);
        }
Пример #3
0
        private TestHostContext CreateTestContext([CallerMemberName] String testName = "")
        {
            var hc = new TestHostContext(this, testName);

            _ec = new Mock <IExecutionContext>();
            _ec.SetupAllProperties();
            _stepsRunner = new StepsRunner();
            _stepsRunner.Initialize(hc);
            return(hc);
        }
Пример #4
0
        private TestHostContext CreateTestContext([CallerMemberName] String testName = "")
        {
            var           hc = new TestHostContext(this, testName);
            List <string> warnings;

            _variables = new Variables(
                hostContext: hc,
                copy: new Dictionary <string, string>(),
                maskHints: new List <MaskHint>(),
                warnings: out warnings);
            _ec = new Mock <IExecutionContext>();
            _ec.SetupAllProperties();
            _ec.Setup(x => x.Variables).Returns(_variables);
            _stepsRunner = new StepsRunner();
            _stepsRunner.Initialize(hc);
            return(hc);
        }
Пример #5
0
        /**
         * Gets a new {@link Containerizer} that containerizes to a tarball archive.
         *
         * @param tarImage the {@link TarImage} that defines target output file
         * @return a new {@link Containerizer}
         */
        public static Containerizer To(TarImage tarImage)
        {
            tarImage = tarImage ?? throw new ArgumentNullException(nameof(tarImage));
            ImageConfiguration imageConfiguration =
                ImageConfiguration.CreateBuilder(tarImage.GetImageReference()).Build();

            return(new Containerizer(
                       DescriptionForImageTarFile, imageConfiguration, StepsRunnerFactory, false));

            StepsRunner StepsRunnerFactory(BuildConfiguration buildConfiguration) =>
            StepsRunner.Begin(buildConfiguration)
            .PullBaseImage()
            .PullAndCacheBaseImageLayers()
            .BuildAndCacheApplicationLayers()
            .BuildImage()
            .WriteTarFile(tarImage.GetOutputFile());
        }
Пример #6
0
        private TestHostContext CreateTestContext([CallerMemberName] String testName = "")
        {
            var hc = new TestHostContext(this, testName);
            Dictionary <string, VariableValue> variablesToCopy = new Dictionary <string, VariableValue>();

            _variables = new Variables(
                hostContext: hc,
                copy: variablesToCopy);
            _env = new Dictionary <string, string>()
            {
                { "env1", "1" },
                { "test", "github_actions" }
            };
            _ec = new Mock <IExecutionContext>();
            _ec.SetupAllProperties();
            _ec.Setup(x => x.Global).Returns(new GlobalContext {
                WriteDebug = true
            });
            _ec.Object.Global.Variables            = _variables;
            _ec.Object.Global.EnvironmentVariables = _env;

            _contexts           = new DictionaryContextData();
            _jobContext         = new JobContext();
            _contexts["github"] = new GitHubContext();
            _contexts["runner"] = new DictionaryContextData();
            _contexts["job"]    = _jobContext;
            _ec.Setup(x => x.ExpressionValues).Returns(_contexts);
            _ec.Setup(x => x.ExpressionFunctions).Returns(new List <IFunctionInfo>());
            _ec.Setup(x => x.JobContext).Returns(_jobContext);

            _stepContext = new StepsContext();
            _ec.Object.Global.StepsContext = _stepContext;

            _ec.Setup(x => x.PostJobSteps).Returns(new Stack <IStep>());

            var trace = hc.GetTrace();

            _ec.Setup(x => x.Write(It.IsAny <string>(), It.IsAny <string>())).Callback((string tag, string message) => { trace.Info($"[{tag}]{message}"); });

            _stepsRunner = new StepsRunner();
            _stepsRunner.Initialize(hc);
            return(hc);
        }
Пример #7
0
        private TestHostContext CreateTestContext([CallerMemberName] String testName = "")
        {
            var hc = new TestHostContext(this, testName);
            var expressionManager = new ExpressionManager();

            expressionManager.Initialize(hc);
            hc.SetSingleton <IExpressionManager>(expressionManager);
            Dictionary <string, VariableValue> variablesToCopy = new Dictionary <string, VariableValue>();

            _variables = new Variables(
                hostContext: hc,
                copy: variablesToCopy);
            _env = new Dictionary <string, string>()
            {
                { "env1", "1" },
                { "test", "github_actions" }
            };
            _ec = new Mock <IExecutionContext>();
            _ec.SetupAllProperties();
            _ec.Setup(x => x.Variables).Returns(_variables);

            _contexts           = new DictionaryContextData();
            _jobContext         = new JobContext();
            _contexts["github"] = new DictionaryContextData();
            _contexts["runner"] = new DictionaryContextData();
            _contexts["job"]    = _jobContext;
            _ec.Setup(x => x.ExpressionValues).Returns(_contexts);
            _ec.Setup(x => x.JobContext).Returns(_jobContext);

            _stepContext = new StepsContext();
            _ec.Setup(x => x.StepsContext).Returns(_stepContext);

            _ec.Setup(x => x.PostJobSteps).Returns(new Stack <IStep>());

            var trace = hc.GetTrace();

            _ec.Setup(x => x.Write(It.IsAny <string>(), It.IsAny <string>())).Callback((string tag, string message) => { trace.Info($"[{tag}]{message}"); });

            _stepsRunner = new StepsRunner();
            _stepsRunner.Initialize(hc);
            return(hc);
        }
Пример #8
0
        private TestHostContext CreateTestContext([CallerMemberName] String testName = "")
        {
            var hc = new TestHostContext(this, testName);
            var expressionManager = new ExpressionManager();

            expressionManager.Initialize(hc);
            hc.SetSingleton <IExpressionManager>(expressionManager);
            List <string> warnings;

            _variables = new Variables(
                hostContext: hc,
                copy: new Dictionary <string, VariableValue>(),
                warnings: out warnings);
            _ec = new Mock <IExecutionContext>();
            _ec.SetupAllProperties();
            _ec.Setup(x => x.Variables).Returns(_variables);
            _stepsRunner = new StepsRunner();
            _stepsRunner.Initialize(hc);
            return(hc);
        }
Пример #9
0
        private TestHostContext CreateTestContext([CallerMemberName] String testName = "")
        {
            var hc = new TestHostContext(this, testName);
            var expressionManager = new ExpressionManager();

            expressionManager.Initialize(hc);
            hc.SetSingleton <IExpressionManager>(expressionManager);
            Dictionary <string, VariableValue> variablesToCopy = new Dictionary <string, VariableValue>();

            variablesToCopy.Add(Constants.Variables.Agent.RetainDefaultEncoding, new VariableValue("true", false));
            List <string> warnings;

            _variables = new Variables(
                hostContext: hc,
                copy: variablesToCopy,
                warnings: out warnings);
            _ec = new Mock <IExecutionContext>();
            _ec.SetupAllProperties();
            _ec.Setup(x => x.Variables).Returns(_variables);
            _stepsRunner = new StepsRunner();
            _stepsRunner.Initialize(hc);
            return(hc);
        }
Пример #10
0
        /**
         * Gets a new {@link Containerizer} that containerizes to a container registry.
         *
         * @param registryImage the {@link RegistryImage} that defines target container registry and
         *     credentials
         * @return a new {@link Containerizer}
         */
        public static Containerizer To(RegistryImage registryImage)
        {
            registryImage = registryImage ?? throw new ArgumentNullException(nameof(registryImage));
            ImageConfiguration imageConfiguration =
                ImageConfiguration.CreateBuilder(registryImage.GetImageReference())
                .SetCredentialRetrievers(registryImage.GetCredentialRetrievers())
                .Build();

            return(new Containerizer(
                       DescriptionForDockerRegistry, imageConfiguration, StepsRunnerFactory, true));

            StepsRunner StepsRunnerFactory(BuildConfiguration buildConfiguration) =>
            StepsRunner.Begin(buildConfiguration)
            .RetrieveTargetRegistryCredentials()
            .AuthenticatePush()
            .PullBaseImage()
            .PullAndCacheBaseImageLayers()
            .PushBaseImageLayers()
            .BuildAndCacheApplicationLayers()
            .BuildImage()
            .PushContainerConfiguration()
            .PushApplicationLayers()
            .PushImage();
        }