Class: Codebuild::Project

Inherits:
Object
  • Object
show all
Includes:
Dsl::Project, Evaluate, Variables
Defined in:
lib/codebuild/project.rb

Constant Summary

Constants included from Dsl::Project

Dsl::Project::PROPERTIES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Variables

#load_variables, #load_variables_file

Methods included from Evaluate

#evaluate

Methods included from Dsl::Project

#environment_variables, #github_source, #github_token, #github_url, #linux_environment, #linux_image, #local_cache, #type

Methods included from Dsl::Project::Ssm

#ssm, #ssm_client

Constructor Details

#initialize(options = {}) ⇒ Project

Returns a new instance of Project.



10
11
12
13
14
15
16
# File 'lib/codebuild/project.rb', line 10

def initialize(options={})
  @options = options
  @project_name = options[:project_name]
  @full_project_name = options[:full_project_name] # includes -development at the end
  @project_path = options[:project_path] || get_project_path
  @properties = default_properties # defaults make project.rb simpler
end

Instance Attribute Details

#full_project_nameObject (readonly)

Returns the value of attribute full_project_name.



9
10
11
# File 'lib/codebuild/project.rb', line 9

def full_project_name
  @full_project_name
end

#project_nameObject (readonly)

Returns the value of attribute project_name.



9
10
11
# File 'lib/codebuild/project.rb', line 9

def project_name
  @project_name
end

#project_pathObject (readonly)

Returns the value of attribute project_path.



9
10
11
# File 'lib/codebuild/project.rb', line 9

def project_path
  @project_path
end

Instance Method Details

#build_specObject



68
69
70
# File 'lib/codebuild/project.rb', line 68

def build_spec
  lookup_codebuild_file("buildspec.yml")
end

#default_propertiesObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/codebuild/project.rb', line 34

def default_properties
  {
    name: @full_project_name,
    description: @full_project_name,
    artifacts: { type: "NO_ARTIFACTS" },
    service_role: { ref: "IamRole" },
    badge_enabled: true,
    timeout_in_minutes: 20,
    logs_config: {
      cloud_watch_logs: {
        status: "ENABLED",
        # the default log group name is thankfully the project name
      }
    },
    source: {
      type: "GITHUB",
      # location: "", # required
      # git_clone_depth: 1,
      git_submodules_config: { fetch_submodules: true },
      build_spec: build_spec,
      # auth doesnt seem to work, refer to https://github.com/tongueroo/codebuild/blob/master/readme/github_oauth.md
      # auth: {
      #   type: "OAUTH",
      #   # resource: "", # required
      # },
      report_build_status: true,
    }
  }
end

#exist?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/codebuild/project.rb', line 18

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

#get_project_pathObject



64
65
66
# File 'lib/codebuild/project.rb', line 64

def get_project_path
  lookup_codebuild_file("project.rb")
end

#runObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/codebuild/project.rb', line 22

def run
  load_variables
  evaluate(@project_path)
  resource = {
    code_build: {
      type: "AWS::CodeBuild::Project",
      properties: @properties
    }
  }
  CfnCamelizer.transform(resource)
end