Module: Cody::Dsl::Project

Includes:
Ssm
Included in:
Project
Defined in:
lib/cody/dsl/project.rb,
lib/cody/dsl/project/ssm.rb

Defined Under Namespace

Modules: Ssm

Constant Summary collapse

PROPERTIES =
%w[
  Artifacts
  BadgeEnabled
  Cache
  Description
  EncryptionKey
  Environment
  LogsConfig
  Name
  QueuedTimeoutInMinutes
  SecondaryArtifacts
  SecondarySources
  ServiceRole
  Source
  Tags
  TimeoutInMinutes
  Triggers
  VpcConfig
]

Instance Method Summary collapse

Methods included from Ssm

#ssm, #ssm_client

Instance Method Details

#buildspec(file = ".cody/buildspec.yaml") ⇒ Object Also known as: build_spec



35
36
37
# File 'lib/cody/dsl/project.rb', line 35

def buildspec(file=".cody/buildspec.yaml")
  @properties[:Source][:BuildSpec] = file
end

#environment_variables(vars) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/cody/dsl/project.rb', line 90

def environment_variables(vars)
  # Storing @mapped_env_vars as instance variable for later usage in linux_environment
  @mapped_env_vars = vars.map { |k,v|
    k, v = k.to_s, v.to_s
    if v =~ /^ssm:/
      { Type: "PARAMETER_STORE", Name: k, Value: v.sub('ssm:','') }
    else
      { Type: "PLAINTEXT", Name: k, Value: v }
    end
  }
  @properties[:Environment] ||= {}
  @properties[:Environment][:EnvironmentVariables] = @mapped_env_vars
end

#github_source(options = {}) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/cody/dsl/project.rb', line 50

def github_source(options={})
  source = {
    Type: "GITHUB",
    Location: options[:Location],
    GitCloneDepth: 1,
    GitSubmodulesConfig: { fetch_submodules: true },
    BuildSpec: options[:BuildSpec] || ".cody/buildspec.yml", # options[:Buildspec] accounts for type already
    ReportBuildStatus: true,
  }

  if options[:OauthToken]
    source[:Auth] = {
      Type: "OAUTH",
      Resource: options[:OauthToken],
    }
  end

  @properties[:Source] = source
end

#github_token(token) ⇒ Object

So it looks like the auth resource property doesnt really get used. Instead an account level credential is worked. Refer to: github.com/tongueroo/cody/blob/master/readme/github_oauth.md

Keeping this method around in case the CloudFormation method works one day, or end up figuring out to use it properly.



46
47
48
# File 'lib/cody/dsl/project.rb', line 46

def github_token(token)
  @properties[:Source][:Auth][:Resource] = token
end

#github_url(url) ⇒ Object

Convenience wrapper methods



31
32
33
# File 'lib/cody/dsl/project.rb', line 31

def github_url(url)
  @properties[:Source][:Location] = url
end

#linux_environment(options = {}) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/cody/dsl/project.rb', line 74

def linux_environment(options={})
  image = options[:Image] || "aws/codebuild/amazonlinux2-x86_64-standard:2.0"
  env = {
    ComputeType: options[:ComputeType] || "BUILD_GENERAL1_SMALL",
    ImagePullCredentialsType: "CODEBUILD", # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-codebuild-project-environment.html#cfn-codebuild-project-environment-imagepullcredentialstype
    PrivilegedMode: true,
    Image: image,
    Type: "LINUX_CONTAINER"
  }
  # @mapped_env_vars is in memory
  env[:EnvironmentVariables] = @mapped_env_vars if @mapped_env_vars
  # options has highest precedence
  env[:EnvironmentVariables] = options[:EnvironmentVariables] if options[:EnvironmentVariables]
  @properties[:Environment] = env
end

#linux_image(name) ⇒ Object



70
71
72
# File 'lib/cody/dsl/project.rb', line 70

def linux_image(name)
  linux_environment(Image: name)
end

#local_cache(enable = true) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/cody/dsl/project.rb', line 104

def local_cache(enable=true)
  cache = if enable
    {
      Type: "LOCAL",
      Modes: [
          "LOCAL_DOCKER_LAYER_CACHE",
          "LOCAL_SOURCE_CACHE",
          "LOCAL_CUSTOM_CACHE"
      ]
    }
  else
    {type: "NO_CACHE"}
  end
  @properties[:Cache] = cache
end

#typeObject



120
121
122
# File 'lib/cody/dsl/project.rb', line 120

def type
  @options[:type] # should be lowercase
end