示例#1
0
        public string Push(AmazonS3Client s3Client, AmazonCodeDeployClient codeDeployClient)
        {
            var zipFileName = string.Format("{0}.{1}.{2}.zip", ApplicationSetName, Version, BundleName);
            var tempPath    = Path.Combine(Path.GetTempPath(), zipFileName + "." + Guid.NewGuid() + ".zip");

            ZipFile.CreateFromDirectory(_bundleDirectory.FullName, tempPath, CompressionLevel.Optimal, false, Encoding.ASCII);

            var allTheBuckets = s3Client.ListBuckets(new ListBucketsRequest()).Buckets;

            if (!allTheBuckets.Exists(b => b.BucketName == Bucket))
            {
                s3Client.PutBucket(new PutBucketRequest {
                    BucketName = Bucket, UseClientRegion = true
                });
            }

            var putResponse = s3Client.PutObject(new PutObjectRequest
            {
                BucketName = Bucket,
                Key        = zipFileName,
                FilePath   = tempPath,
            });

            var registration = new RegisterApplicationRevisionRequest
            {
                ApplicationName = CodeDeployApplicationName,
                Description     = "Revision " + Version,
                Revision        = new RevisionLocation
                {
                    RevisionType = RevisionLocationType.S3,
                    S3Location   = new S3Location
                    {
                        Bucket     = Bucket,
                        BundleType = BundleType.Zip,
                        Key        = zipFileName,
                        Version    = Version
                    }
                }
            };

            try
            {
                codeDeployClient.RegisterApplicationRevision(registration);
            }
            catch (ApplicationDoesNotExistException)
            {
                codeDeployClient.CreateApplication(new CreateApplicationRequest {
                    ApplicationName = CodeDeployApplicationName
                });
                codeDeployClient.RegisterApplicationRevision(registration);
            }

            return(putResponse.ETag);
        }
示例#2
0
        /// <summary>
        /// Registers with AWS CodeDeploy a revision for the specified application.
        /// </summary>
        /// <param name="applicationName">The name of an AWS CodeDeploy application associated with the applicable IAM user or AWS account.</param>
        /// <param name="settings">The <see cref="DeploySettings"/> used during the request to AWS.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        public async Task <bool> RegisterApplicationRevision(string applicationName, DeploySettings settings, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (String.IsNullOrEmpty(applicationName))
            {
                throw new ArgumentNullException("applicationName");
            }



            // Create Request
            AmazonCodeDeployClient             client  = this.CreateClient(settings);
            RegisterApplicationRevisionRequest request = new RegisterApplicationRevisionRequest();

            request.ApplicationName = applicationName;

            request.Revision = new RevisionLocation()
            {
                RevisionType = RevisionLocationType.S3,

                S3Location = new S3Location()
                {
                    BundleType = BundleType.Zip,

                    Bucket  = settings.S3Bucket,
                    Key     = settings.S3Key,
                    Version = settings.S3Version
                }
            };



            // Check Response
            RegisterApplicationRevisionResponse response = await client.RegisterApplicationRevisionAsync(request, cancellationToken);

            if (response.HttpStatusCode == HttpStatusCode.OK)
            {
                _Log.Verbose("Successfully deployed application '{0}'", applicationName);
                return(true);
            }
            else
            {
                _Log.Error("Failed to deploy application '{0}'", applicationName);
                return(false);
            }
        }