Example #1
0
        /// <summary>
        /// Executes the package command to create the deployment bundle for the .NET project and returns the path.
        /// </summary>
        /// <param name="field"></param>
        /// <param name="location"></param>
        /// <returns></returns>
        /// <exception cref="LambdaToolsException"></exception>
        private async Task <UpdateResourceResults> PackageDotnetProjectAsync(IUpdateResourceField field, string location)
        {
            var command = new Commands.PackageCommand(this.Logger, location, null);

            command.LambdaClient                     = this.OriginatingCommand?.LambdaClient;
            command.S3Client                         = this.OriginatingCommand?.S3Client;
            command.IAMClient                        = this.OriginatingCommand?.IAMClient;
            command.CloudFormationClient             = this.OriginatingCommand?.CloudFormationClient;
            command.DisableRegionAndCredentialsCheck = true;

            var outputPackage = GenerateOutputZipFilename(field);

            command.OutputPackageFileName = outputPackage;
            command.TargetFramework       =
                LambdaUtilities.DetermineTargetFrameworkFromLambdaRuntime(field.Resource.LambdaRuntime, location);

            command.LayerVersionArns = field.Resource.LambdaLayers;

            // If the project is in the same directory as the CloudFormation template then use any parameters
            // there were specified on the command to build the project.
            if (IsCurrentDirectory(field.GetLocalPath()))
            {
                if (!string.IsNullOrEmpty(this.DefaultOptions.TargetFramework))
                {
                    command.TargetFramework = this.DefaultOptions.TargetFramework;
                }

                command.Configuration       = this.DefaultOptions.Configuration;
                command.DisableVersionCheck = this.DefaultOptions.DisableVersionCheck;
                command.MSBuildParameters   = this.DefaultOptions.MSBuildParameters;
            }

            if (!await command.ExecuteAsync())
            {
                var message = $"Error packaging up project in {location} for CloudFormation resource {field.Resource.Name}";
                if (command.LastToolsException != null)
                {
                    message += $": {command.LastToolsException.Message}";
                }

                throw new LambdaToolsException(message, ToolsException.CommonErrorCode.DotnetPublishFailed);
            }

            var results = new UpdateResourceResults()
            {
                ZipArchivePath = outputPackage
            };

            if (!string.IsNullOrEmpty(command.NewDotnetSharedStoreValue))
            {
                results.DotnetShareStoreEnv = command.NewDotnetSharedStoreValue;
            }

            return(results);
        }
Example #2
0
        /// <summary>
        /// Executes the package command to create the deployment bundle for the .NET project and returns the path.
        /// </summary>
        /// <param name="field"></param>
        /// <param name="location"></param>
        /// <returns></returns>
        /// <exception cref="LambdaToolsException"></exception>
        private async Task <string> PackageDotnetProjectAsync(IUpdateResourceField field, string location)
        {
            var command       = new Commands.PackageCommand(this.Logger, location, null);
            var outputPackage = GenerateOutputZipFilename(field);

            command.OutputPackageFileName = outputPackage;
            command.TargetFramework       =
                LambdaUtilities.DetermineTargetFrameworkFromLambdaRuntime(field.Resource.LambdaRuntime);

            // If the project is in the same directory as the CloudFormation template then use any parameters
            // there were specified on the command to build the project.
            if (IsCurrentDirectory(field.GetLocalPath()))
            {
                if (!string.IsNullOrEmpty(this.DefaultOptions.TargetFramework))
                {
                    command.TargetFramework = this.DefaultOptions.TargetFramework;
                }

                command.Configuration       = this.DefaultOptions.Configuration;
                command.DisableVersionCheck = this.DefaultOptions.DisableVersionCheck;
                command.MSBuildParameters   = this.DefaultOptions.MSBuildParameters;
            }

            if (!await command.ExecuteAsync())
            {
                var message = $"Error packaging up project in {location} for CloudFormation resource {field.Resource.Name}";
                if (command.LastToolsException != null)
                {
                    message += $": {command.LastToolsException.Message}";
                }

                throw new LambdaToolsException(message, ToolsException.CommonErrorCode.DotnetPublishFailed);
            }

            return(outputPackage);
        }
        /// <summary>
        /// Executes the package command to create the deployment bundle for the .NET project and returns the path.
        /// </summary>
        /// <param name="field"></param>
        /// <param name="location"></param>
        /// <returns></returns>
        /// <exception cref="LambdaToolsException"></exception>
        private async Task <UpdateResourceResults> PackageDotnetProjectAsync(IUpdateResourceField field, string location, string[] args)
        {
            if (field.Resource.UploadType == CodeUploadType.Zip)
            {
                var command = new Commands.PackageCommand(this.Logger, location, args);

                command.LambdaClient                     = this.OriginatingCommand?.LambdaClient;
                command.S3Client                         = this.OriginatingCommand?.S3Client;
                command.IAMClient                        = this.OriginatingCommand?.IAMClient;
                command.CloudFormationClient             = this.OriginatingCommand?.CloudFormationClient;
                command.DisableRegionAndCredentialsCheck = true;

                var outputPackage = GenerateOutputZipFilename(field);
                command.OutputPackageFileName = outputPackage;
                command.TargetFramework       =
                    LambdaUtilities.DetermineTargetFrameworkFromLambdaRuntime(field.Resource.LambdaRuntime, location);

                command.Architecture     = field.Resource.LambdaArchitecture;
                command.LayerVersionArns = field.Resource.LambdaLayers;

                // If the project is in the same directory as the CloudFormation template then use any parameters
                // that were specified on the command to build the project.
                if (IsCurrentDirectory(field.GetLocalPath()))
                {
                    if (!string.IsNullOrEmpty(this.DefaultOptions.TargetFramework))
                    {
                        command.TargetFramework = this.DefaultOptions.TargetFramework;
                    }

                    command.Configuration       = this.DefaultOptions.Configuration;
                    command.DisableVersionCheck = this.DefaultOptions.DisableVersionCheck;
                    command.MSBuildParameters   = this.DefaultOptions.MSBuildParameters;
                }

                if (!await command.ExecuteAsync())
                {
                    var message = $"Error packaging up project in {location} for CloudFormation resource {field.Resource.Name}";
                    if (command.LastToolsException != null)
                    {
                        message += $": {command.LastToolsException.Message}";
                    }

                    throw new LambdaToolsException(message, ToolsException.CommonErrorCode.DotnetPublishFailed);
                }

                var results = new UpdateResourceResults()
                {
                    ZipArchivePath = outputPackage
                };
                if (!string.IsNullOrEmpty(command.NewDotnetSharedStoreValue))
                {
                    results.DotnetShareStoreEnv = command.NewDotnetSharedStoreValue;
                }

                return(results);
            }
            else if (field.Resource.UploadType == CodeUploadType.Image)
            {
                this.Logger.WriteLine($"Building Docker image for {location}");
                var pushCommand = new PushDockerImageCommand(Logger, location, args);
                pushCommand.ECRClient          = OriginatingCommand.ECRClient;
                pushCommand.IAMClient          = OriginatingCommand.IAMClient;
                pushCommand.DisableInteractive = true;
                pushCommand.PushDockerImageProperties.DockerFile     = field.GetMetadataDockerfile();
                pushCommand.PushDockerImageProperties.DockerImageTag = field.GetMetadataDockerTag();
                pushCommand.ImageTagUniqueSeed = field.Resource.Name;



                await pushCommand.PushImageAsync();

                if (pushCommand.LastToolsException != null)
                {
                    throw pushCommand.LastToolsException;
                }

                return(new UpdateResourceResults {
                    ImageUri = pushCommand.PushedImageUri
                });
            }
            else
            {
                throw new LambdaToolsException($"Unknown upload type for packaging: {field.Resource.UploadType}", LambdaToolsException.LambdaErrorCode.ServerlessTemplateParseError);
            }
        }