Sha256: ac6bfc604d68e583ecf91f5bf2eb05655e6ebebafbc9e754d1c3aa929e8327ef

Contents?: true

Size: 1.33 KB

Versions: 6

Compression:

Stored size: 1.33 KB

Contents

module Pipedream
  class Pipeline
    extend Memoist
    include Dsl::Pipeline
    include Evaluate

    def initialize(options={})
      @options = options
      @pipeline_path = options[:pipeline_path] || get_pipeline_path
      @properties = default_properties # defaults make pipeline.rb simpler
      @stages = []
    end

    def run
      evaluate(@pipeline_path)
      @properties[:stages] ||= @stages
      set_source_branch!

      resource = {
        pipeline: {
          type: "AWS::CodePipeline::Pipeline",
          properties: @properties
        }
      }
      CfnCamelizer.transform(resource)
    end

    def default_properties
      {
        name: @options[:full_pipeline_name],
        role_arn: { "Fn::GetAtt": "IamRole.Arn" },
        artifact_store: {
          type: "S3",
          location: s3_bucket, # auto creates s3 bucket
        }
      }
    end

    # cli branch option always takes highest precedence
    def set_source_branch!
      return unless @options[:branch]

      source_stage = @properties[:stages].first
      action = source_stage[:actions].first
      action[:configuration][:branch] = @options[:branch]
    end

    def exist?
      File.exist?(@pipeline_path)
    end

    def s3_bucket
      S3Bucket.name
    end

  private
    def get_pipeline_path
      lookup_pipedream_file "pipeline.rb"
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pipedream-0.4.8 lib/pipedream/pipeline.rb
pipedream-0.4.7 lib/pipedream/pipeline.rb
pipedream-0.4.6 lib/pipedream/pipeline.rb
pipedream-0.4.5 lib/pipedream/pipeline.rb
pipedream-0.4.4 lib/pipedream/pipeline.rb
pipedream-0.4.3 lib/pipedream/pipeline.rb