{"action":"created","comment":{"url":"https://api.github.com/repos/Originate/exo-deploy/pulls/comments/88142936","pull_request_review_id":8724888,"id":88142936,"diff_hunk":"@@ -0,0 +1,214 @@\n+require! {\n+  'async'\n+  'events' : {EventEmitter}\n+  'fs-extra' : fs\n+  'handlebars'\n+  'observable-process' : ObservableProcess\n+  'path'\n+  'require-yaml'\n+}\n+\n+\n+# Deploys application to AWS\n+class AwsDeployer extends EventEmitter\n+\n+  (@app-config) ->\n+    @production-config = @app-config.environments.production\n+    @exocom-port = 3100\n+    @exocom-dns = \"exocom.#{@production-config.providers.aws.region}.aws.#{@production-config.domain}\"\n+\n+\n+  generate-terraform: ->\n+    setup-scripts = [@_generate-provider-credentials\n+                     @_generate-main\n+                     @_generate-vpc\n+                     @_generate-exocom-cluster\n+                     @_generate-exocom-service\n+                     @_generate-cluster 'public', _\n+                     @_generate-cluster 'private', _\n+                     @_generate-services 'public', _\n+                     @_generate-services 'private', _]\n+    async.map setup-scripts, (-> &0 &1), ~>\n+      @emit 'terraform-generated'\n+\n+\n+  deploy: ->\n+    new ObservableProcess(\"terraform get\",\n+                          cwd: path.join process.cwd!, 'terraform'\n+                          stdout: process.stdout,\n+                          stderr: process.stderr)\n+      ..on 'ended', (exit-code) ->\n+        unless exit-code\n+          @emit 'deploying'\n+          new ObservableProcess(\"terraform apply\",\n+                                cwd: path.join process.cwd!, 'terraform'\n+                                stdout: process.stdout,\n+                                stderr: process.stderr)\n+\n+\n+  _generate-main: (done) ~>\n+    # copy cluster creation/destruction policies\n+    src-path = path.join __dirname, '..' 'templates' 'aws-terraform' 'policies'\n+    target-path = path.join process.cwd!, 'terraform' 'policies'\n+    fs.copy-sync src-path, target-path\n+\n+    data =\n+      app-name: @app-config.name\n+      public-cluster-size: @production-config.providers.aws['public-cluster-size']\n+      private-cluster-size: @production-config.providers.aws['private-cluster-size']\n+\n+    @_render-template {data, file-name: 'main.tf'}, done\n+\n+\n+  _generate-provider-credentials: (done) ~>\n+    data =\n+      access-key: @production-config.providers.aws['access-key']\n+      secret-key: @production-config.providers.aws['secret-key']\n+      region: @production-config.providers.aws.region\n+\n+    @_render-template {data, file-name: 'provider.tf'}, done\n+\n+\n+  _generate-vpc: (done) ~>\n+    src-path = path.join __dirname, '..' 'templates' 'aws-terraform' 'vpc'\n+    target-path = path.join process.cwd!, 'terraform' 'vpc'\n+    fs.copy src-path, target-path, done\n+\n+\n+  _generate-exocom-cluster: (done) ~>\n+    src-path = path.join __dirname, '..' 'templates' 'aws-terraform' 'exocom'\n+    target-path = path.join process.cwd!, 'terraform' 'exocom'\n+    fs.copy src-path, target-path, done\n+\n+\n+  _generate-exocom-service: (done) ~>\n+    @_build-exocom-container-definition!\n+    data =\n+      exocom-dns: @exocom-dns\n+\n+    @_append-to-main-script {data, template-name: 'exocom-service.tf'}, done\n+\n+\n+  _generate-cluster: (type, done) ~>\n+    src-path = path.join __dirname, '..' 'templates' 'aws-terraform' \"#{type}-services\"\n+    target-path = path.join process.cwd!, 'terraform' \"#{type}-services\"\n+    fs.copy src-path, target-path, done\n+\n+\n+  _generate-services: (type, done) ~>\n+    services = for service, service-data of @app-config.services[\"#{type}\"]\n+      service-config = require path.join(process.cwd!, service-data.location, 'service.yml')\n+      @_build-service-container-definition service-config\n+      data =\n+        name: service\n+        public-port: service-config.docker['public-port']\n+        public-url: service-config['deployment-url']\n+\n+    async.map services, ((data, cb) ~> @_append-to-main-script {data, template-name: \"#{type}-service.tf\"}, cb), done\n+\n+\n+  # renders and writes a Terraform file given a template\n+  _render-template: ({data, file-name}, done) ->\n+    src-path = path.join __dirname, '..' 'templates' 'aws-terraform' file-name\n+    target-path = path.join process.cwd!, 'terraform' file-name\n+    fs.read-file src-path, 'utf-8', (err, source) ->\n+      rendered-file = handlebars.compile(source) data\n+      fs.write-file target-path, rendered-file, done\n+\n+\n+  # appends a block of Terraform code to main deployment script\n+  _append-to-main-script: ({data, template-name}, done) ->\n+    src-path = path.join __dirname, '..' 'templates' 'aws-terraform' template-name\n+    target-path = path.join process.cwd!, 'terraform' 'main.tf'\n+    fs.read-file src-path, 'utf-8', (err, source) ->","path":"src/aws-deployer.ls","position":123,"original_position":123,"commit_id":"5eaa472b1cc3f194768e401294b402ecb7d2c360","original_commit_id":"5eaa472b1cc3f194768e401294b402ecb7d2c360","user":{"login":"kevgo","id":268934,"avatar_url":"https://avatars.githubusercontent.com/u/268934?v=3","gravatar_id":"","url":"https://api.github.com/users/kevgo","html_url":"https://github.com/kevgo","followers_url":"https://api.github.com/users/kevgo/followers","following_url":"https://api.github.com/users/kevgo/following{/other_user}","gists_url":"https://api.github.com/users/kevgo/gists{/gist_id}","starred_url":"https://api.github.com/users/kevgo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kevgo/subscriptions","organizations_url":"https://api.github.com/users/kevgo/orgs","repos_url":"https://api.github.com/users/kevgo/repos","events_url":"https://api.github.com/users/kevgo/events{/privacy}","received_events_url":"https://api.github.com/users/kevgo/received_events","type":"User","site_admin":false},"body":"Use the sync methods to make this method synchronous.\r\n\r\n```ls\r\nsource = fs.read-file-sync src-path, 'utf-8'\r\nrendered-text = handlebars.compile(source) data\r\nfs.append-file-sync target-path, rendered-text","created_at":"2016-11-16T00:05:18Z","updated_at":"2016-11-16T00:20:58Z","html_url":"https://github.com/Originate/exo-deploy/pull/2#discussion_r88142936","pull_request_url":"https://api.github.com/repos/Originate/exo-deploy/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/Originate/exo-deploy/pulls/comments/88142936"},"html":{"href":"https://github.com/Originate/exo-deploy/pull/2#discussion_r88142936"},"pull_request":{"href":"https://api.github.com/repos/Originate/exo-deploy/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/Originate/exo-deploy/pulls/2","id":93865155,"html_url":"https://github.com/Originate/exo-deploy/pull/2","diff_url":"https://github.com/Originate/exo-deploy/pull/2.diff","patch_url":"https://github.com/Originate/exo-deploy/pull/2.patch","issue_url":"https://api.github.com/repos/Originate/exo-deploy/issues/2","number":2,"state":"open","locked":false,"title":"Deploy using templates","user":{"login":"hugobho","id":7258240,"avatar_url":"https://avatars.githubusercontent.com/u/7258240?v=3","gravatar_id":"","url":"https://api.github.com/users/hugobho","html_url":"https://github.com/hugobho","followers_url":"https://api.github.com/users/hugobho/followers","following_url":"https://api.github.com/users/hugobho/following{/other_user}","gists_url":"https://api.github.com/users/hugobho/gists{/gist_id}","starred_url":"https://api.github.com/users/hugobho/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hugobho/subscriptions","organizations_url":"https://api.github.com/users/hugobho/orgs","repos_url":"https://api.github.com/users/hugobho/repos","events_url":"https://api.github.com/users/hugobho/events{/privacy}","received_events_url":"https://api.github.com/users/hugobho/received_events","type":"User","site_admin":false},"body":"@kevgo @alexdavid @trushton @martinjaime \r\n\r\nI've included example config files that show what we want `application.yml` and `service.yml` to look like in the future.\r\n\r\nSorry about the size of this thing..","created_at":"2016-11-15T22:50:08Z","updated_at":"2016-11-16T00:20:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ba29ef562a2a77fa73217cf514b17fa410bfd754","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/Originate/exo-deploy/pulls/2/commits","review_comments_url":"https://api.github.com/repos/Originate/exo-deploy/pulls/2/comments","review_comment_url":"https://api.github.com/repos/Originate/exo-deploy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Originate/exo-deploy/issues/2/comments","statuses_url":"https://api.github.com/repos/Originate/exo-deploy/statuses/5eaa472b1cc3f194768e401294b402ecb7d2c360","head":{"label":"Originate:hh-render-template","ref":"hh-render-template","sha":"5eaa472b1cc3f194768e401294b402ecb7d2c360","user":{"login":"Originate","id":1627168,"avatar_url":"https://avatars.githubusercontent.com/u/1627168?v=3","gravatar_id":"","url":"https://api.github.com/users/Originate","html_url":"https://github.com/Originate","followers_url":"https://api.github.com/users/Originate/followers","following_url":"https://api.github.com/users/Originate/following{/other_user}","gists_url":"https://api.github.com/users/Originate/gists{/gist_id}","starred_url":"https://api.github.com/users/Originate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Originate/subscriptions","organizations_url":"https://api.github.com/users/Originate/orgs","repos_url":"https://api.github.com/users/Originate/repos","events_url":"https://api.github.com/users/Originate/events{/privacy}","received_events_url":"https://api.github.com/users/Originate/received_events","type":"Organization","site_admin":false},"repo":{"id":59527644,"name":"exo-deploy","full_name":"Originate/exo-deploy","owner":{"login":"Originate","id":1627168,"avatar_url":"https://avatars.githubusercontent.com/u/1627168?v=3","gravatar_id":"","url":"https://api.github.com/users/Originate","html_url":"https://github.com/Originate","followers_url":"https://api.github.com/users/Originate/followers","following_url":"https://api.github.com/users/Originate/following{/other_user}","gists_url":"https://api.github.com/users/Originate/gists{/gist_id}","starred_url":"https://api.github.com/users/Originate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Originate/subscriptions","organizations_url":"https://api.github.com/users/Originate/orgs","repos_url":"https://api.github.com/users/Originate/repos","events_url":"https://api.github.com/users/Originate/events{/privacy}","received_events_url":"https://api.github.com/users/Originate/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Originate/exo-deploy","description":null,"fork":false,"url":"https://api.github.com/repos/Originate/exo-deploy","forks_url":"https://api.github.com/repos/Originate/exo-deploy/forks","keys_url":"https://api.github.com/repos/Originate/exo-deploy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Originate/exo-deploy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Originate/exo-deploy/teams","hooks_url":"https://api.github.com/repos/Originate/exo-deploy/hooks","issue_events_url":"https://api.github.com/repos/Originate/exo-deploy/issues/events{/number}","events_url":"https://api.github.com/repos/Originate/exo-deploy/events","assignees_url":"https://api.github.com/repos/Originate/exo-deploy/assignees{/user}","branches_url":"https://api.github.com/repos/Originate/exo-deploy/branches{/branch}","tags_url":"https://api.github.com/repos/Originate/exo-deploy/tags","blobs_url":"https://api.github.com/repos/Originate/exo-deploy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Originate/exo-deploy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Originate/exo-deploy/git/refs{/sha}","trees_url":"https://api.github.com/repos/Originate/exo-deploy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Originate/exo-deploy/statuses/{sha}","languages_url":"https://api.github.com/repos/Originate/exo-deploy/languages","stargazers_url":"https://api.github.com/repos/Originate/exo-deploy/stargazers","contributors_url":"https://api.github.com/repos/Originate/exo-deploy/contributors","subscribers_url":"https://api.github.com/repos/Originate/exo-deploy/subscribers","subscription_url":"https://api.github.com/repos/Originate/exo-deploy/subscription","commits_url":"https://api.github.com/repos/Originate/exo-deploy/commits{/sha}","git_commits_url":"https://api.github.com/repos/Originate/exo-deploy/git/commits{/sha}","comments_url":"https://api.github.com/repos/Originate/exo-deploy/comments{/number}","issue_comment_url":"https://api.github.com/repos/Originate/exo-deploy/issues/comments{/number}","contents_url":"https://api.github.com/repos/Originate/exo-deploy/contents/{+path}","compare_url":"https://api.github.com/repos/Originate/exo-deploy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Originate/exo-deploy/merges","archive_url":"https://api.github.com/repos/Originate/exo-deploy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Originate/exo-deploy/downloads","issues_url":"https://api.github.com/repos/Originate/exo-deploy/issues{/number}","pulls_url":"https://api.github.com/repos/Originate/exo-deploy/pulls{/number}","milestones_url":"https://api.github.com/repos/Originate/exo-deploy/milestones{/number}","notifications_url":"https://api.github.com/repos/Originate/exo-deploy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Originate/exo-deploy/labels{/name}","releases_url":"https://api.github.com/repos/Originate/exo-deploy/releases{/id}","deployments_url":"https://api.github.com/repos/Originate/exo-deploy/deployments","created_at":"2016-05-24T00:28:29Z","updated_at":"2016-09-15T22:27:00Z","pushed_at":"2016-11-15T22:58:59Z","git_url":"git://github.com/Originate/exo-deploy.git","ssh_url":"git@github.com:Originate/exo-deploy.git","clone_url":"https://github.com/Originate/exo-deploy.git","svn_url":"https://github.com/Originate/exo-deploy","homepage":null,"size":27,"stargazers_count":1,"watchers_count":1,"language":"HCL","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":1,"default_branch":"master"}},"base":{"label":"Originate:hh-deploy-service","ref":"hh-deploy-service","sha":"13eb770bb68b2deaaf26c439c54527e9d09a61a6","user":{"login":"Originate","id":1627168,"avatar_url":"https://avatars.githubusercontent.com/u/1627168?v=3","gravatar_id":"","url":"https://api.github.com/users/Originate","html_url":"https://github.com/Originate","followers_url":"https://api.github.com/users/Originate/followers","following_url":"https://api.github.com/users/Originate/following{/other_user}","gists_url":"https://api.github.com/users/Originate/gists{/gist_id}","starred_url":"https://api.github.com/users/Originate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Originate/subscriptions","organizations_url":"https://api.github.com/users/Originate/orgs","repos_url":"https://api.github.com/users/Originate/repos","events_url":"https://api.github.com/users/Originate/events{/privacy}","received_events_url":"https://api.github.com/users/Originate/received_events","type":"Organization","site_admin":false},"repo":{"id":59527644,"name":"exo-deploy","full_name":"Originate/exo-deploy","owner":{"login":"Originate","id":1627168,"avatar_url":"https://avatars.githubusercontent.com/u/1627168?v=3","gravatar_id":"","url":"https://api.github.com/users/Originate","html_url":"https://github.com/Originate","followers_url":"https://api.github.com/users/Originate/followers","following_url":"https://api.github.com/users/Originate/following{/other_user}","gists_url":"https://api.github.com/users/Originate/gists{/gist_id}","starred_url":"https://api.github.com/users/Originate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Originate/subscriptions","organizations_url":"https://api.github.com/users/Originate/orgs","repos_url":"https://api.github.com/users/Originate/repos","events_url":"https://api.github.com/users/Originate/events{/privacy}","received_events_url":"https://api.github.com/users/Originate/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Originate/exo-deploy","description":null,"fork":false,"url":"https://api.github.com/repos/Originate/exo-deploy","forks_url":"https://api.github.com/repos/Originate/exo-deploy/forks","keys_url":"https://api.github.com/repos/Originate/exo-deploy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Originate/exo-deploy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Originate/exo-deploy/teams","hooks_url":"https://api.github.com/repos/Originate/exo-deploy/hooks","issue_events_url":"https://api.github.com/repos/Originate/exo-deploy/issues/events{/number}","events_url":"https://api.github.com/repos/Originate/exo-deploy/events","assignees_url":"https://api.github.com/repos/Originate/exo-deploy/assignees{/user}","branches_url":"https://api.github.com/repos/Originate/exo-deploy/branches{/branch}","tags_url":"https://api.github.com/repos/Originate/exo-deploy/tags","blobs_url":"https://api.github.com/repos/Originate/exo-deploy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Originate/exo-deploy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Originate/exo-deploy/git/refs{/sha}","trees_url":"https://api.github.com/repos/Originate/exo-deploy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Originate/exo-deploy/statuses/{sha}","languages_url":"https://api.github.com/repos/Originate/exo-deploy/languages","stargazers_url":"https://api.github.com/repos/Originate/exo-deploy/stargazers","contributors_url":"https://api.github.com/repos/Originate/exo-deploy/contributors","subscribers_url":"https://api.github.com/repos/Originate/exo-deploy/subscribers","subscription_url":"https://api.github.com/repos/Originate/exo-deploy/subscription","commits_url":"https://api.github.com/repos/Originate/exo-deploy/commits{/sha}","git_commits_url":"https://api.github.com/repos/Originate/exo-deploy/git/commits{/sha}","comments_url":"https://api.github.com/repos/Originate/exo-deploy/comments{/number}","issue_comment_url":"https://api.github.com/repos/Originate/exo-deploy/issues/comments{/number}","contents_url":"https://api.github.com/repos/Originate/exo-deploy/contents/{+path}","compare_url":"https://api.github.com/repos/Originate/exo-deploy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Originate/exo-deploy/merges","archive_url":"https://api.github.com/repos/Originate/exo-deploy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Originate/exo-deploy/downloads","issues_url":"https://api.github.com/repos/Originate/exo-deploy/issues{/number}","pulls_url":"https://api.github.com/repos/Originate/exo-deploy/pulls{/number}","milestones_url":"https://api.github.com/repos/Originate/exo-deploy/milestones{/number}","notifications_url":"https://api.github.com/repos/Originate/exo-deploy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Originate/exo-deploy/labels{/name}","releases_url":"https://api.github.com/repos/Originate/exo-deploy/releases{/id}","deployments_url":"https://api.github.com/repos/Originate/exo-deploy/deployments","created_at":"2016-05-24T00:28:29Z","updated_at":"2016-09-15T22:27:00Z","pushed_at":"2016-11-15T22:58:59Z","git_url":"git://github.com/Originate/exo-deploy.git","ssh_url":"git@github.com:Originate/exo-deploy.git","clone_url":"https://github.com/Originate/exo-deploy.git","svn_url":"https://github.com/Originate/exo-deploy","homepage":null,"size":27,"stargazers_count":1,"watchers_count":1,"language":"HCL","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Originate/exo-deploy/pulls/2"},"html":{"href":"https://github.com/Originate/exo-deploy/pull/2"},"issue":{"href":"https://api.github.com/repos/Originate/exo-deploy/issues/2"},"comments":{"href":"https://api.github.com/repos/Originate/exo-deploy/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/Originate/exo-deploy/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/Originate/exo-deploy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Originate/exo-deploy/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/Originate/exo-deploy/statuses/5eaa472b1cc3f194768e401294b402ecb7d2c360"}}}}
{"actor":{"display_login":"kevgo"}}