Skip to content
This repository was archived by the owner on Apr 19, 2018. It is now read-only.

Commit 493177d

Browse files
committed
initial commit
0 parents  commit 493177d

14 files changed

+1283
-0
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
**/target/
2+
**/.nrepl-port
3+
/out
4+
/.serverless
5+
**/node_modules
6+
**/extracted
7+
*.zip
8+
.env
9+
envvars.yml

app/index.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
var Generator = require('yeoman-generator');
2+
3+
module.exports = class extends Generator {
4+
constructor(args, opts) {
5+
super(args, opts);
6+
this.argument('serviceName', { type: String, required: true });
7+
this.argument('organization', { type: String, default: "offcourse"});
8+
this.argument('author', { type: String, default: "Yeehaa"});
9+
this.destinationRoot(`${this.options.serviceName}`);
10+
}
11+
12+
writing() {
13+
this.defaultOptions = {
14+
service: `${this.options.serviceName}`,
15+
organization: `${this.options.organization}`,
16+
author: `${this.options.author}`
17+
};
18+
19+
this.fs.copyTpl(
20+
this.templatePath('index.js'),
21+
this.destinationPath('index.js'),
22+
this.defaultOptions
23+
);
24+
25+
this.fs.copyTpl(
26+
this.templatePath('package.json'),
27+
this.destinationPath('package.json'),
28+
this.defaultOptions
29+
);
30+
}
31+
32+
install(){
33+
this.yarnInstall();
34+
}
35+
};

app/templates/boot.properties

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#http://boot-clj.com
2+
#Mon Aug 15 22:32:43 CEST 2016
3+
BOOT_CLOJURE_NAME=org.clojure/clojure
4+
BOOT_CLOJURE_VERSION=1.9.0-alpha10
5+
BOOT_VERSION=2.6.0

app/templates/build.boot

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
(set-env!
2+
:resource-paths #{"src"}
3+
:checkouts '[[offcourse/backend-shared "0.2.4-SNAPSHOT"]]
4+
:dependencies '[[adzerk/boot-cljs "1.7.228-1" :scope "test"]
5+
[adzerk/boot-cljs-repl "0.3.3" :scope "test"]
6+
[adzerk/boot-reload "0.4.12" :scope "test"]
7+
[pandeiro/boot-http "0.7.3" :scope "test"]
8+
[crisptrutski/boot-cljs-test "0.3.0-SNAPSHOT" :scope "test"]
9+
[boot-codox "0.10.0" :scope "test"]
10+
[org.clojure/clojure "1.9.0-alpha12"]
11+
[org.clojure/core.async "0.2.391"]
12+
[org.clojure/test.check "0.9.0"]
13+
[org.clojure/clojurescript "1.9.229"]
14+
[com.cemerick/piggieback "0.2.2-SNAPSHOT" :scope "test"]
15+
[offcourse/shared "0.5.9"]
16+
[offcourse/backend-shared "0.2.4-SNAPSHOT"]
17+
[weasel "0.7.0" :scope "test"]
18+
[org.clojure/tools.nrepl "0.2.12" :scope "test"]])
19+
20+
(require
21+
'[adzerk.boot-cljs :refer [cljs]]
22+
'[adzerk.boot-cljs-repl :refer [cljs-repl start-repl]]
23+
'[adzerk.boot-reload :refer [reload]]
24+
'[codox.boot :refer [codox]]
25+
'[pandeiro.boot-http :refer [serve]])
26+
27+
(deftask build []
28+
(task-options! cljs {:compiler-options {:optimizations :simple
29+
:target :nodejs}})
30+
(comp (cljs)
31+
(target)))
32+
33+
(deftask dev []
34+
(comp (watch)
35+
(checkout)
36+
(speak)
37+
(cljs-repl)
38+
(build)))

app/templates/context.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

app/templates/deploy-frontend.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
Transform: AWS::Serverless-2016-10-31
3+
4+
Resources:
5+
WebsiteBucket:
6+
Type: "AWS::S3::Bucket"
7+
Properties:
8+
WebsiteConfiguration:
9+
ErrorDocument: "index.html"
10+
IndexDocument: "index.html"
11+
TestFunction:
12+
Type: AWS::Serverless::Function
13+
Properties:
14+
Handler: index.handler
15+
Runtime: nodejs4.3
16+
Environment:
17+
Variables:
18+
S3_BUCKET: !Ref WebsiteBucket

app/templates/event.json

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"CodePipeline.job": {
3+
"id": "d6e9050e-1955-4d3a-b59b-306a9a20d2aa",
4+
"accountId": "774182433398",
5+
"data": {
6+
"actionConfiguration": {
7+
"configuration": {
8+
"FunctionName": "tl2-TestFunction-11NEORR1GUASX"
9+
}
10+
},
11+
"inputArtifacts": [
12+
{
13+
"location": {
14+
"s3Location": {
15+
"bucketName": "codepipeline-us-east-1-814057763522",
16+
"objectKey": "test-lambda/MyApp/zvHIKBT.zip"
17+
},
18+
"type": "S3"
19+
},
20+
"revision": "f60a39d7da954e8e602f33275c0c7c9c9f842f60",
21+
"name": "MyApp"
22+
}
23+
],
24+
"outputArtifacts": [],
25+
"artifactCredentials": {
26+
"secretAccessKey": "X9RLWbgwU6C88Pip4aQr+oe6vBrlkUZyZ6Xp7m7l",
27+
"sessionToken": "AgoGb3JpZ2luEDUaCXVzLWVhc3QtMSKAAmOrenQdBNf7oCfDzE2Wd4nHQ8S1pXiPpRy3VEaXjp7ua410GaO2OFv4j5cORz75eFeLkMO7PIsXTzm1Srcqc939q0FdotaG3s873MvHpPSQeOq+6Dp3KvGP8Dci+w1qdZzs80h6NCsb0AVHvb0gl8krZWFcUvZP4sKEq8mjrmZ4qyiWLR8V9i9k22yzbMIO4RCoT72vrAlc6dkVpUccareV9wvEebdEB7umpZTq6LFTUtqEV7w1A5U3hZo1FvemVakQT4yaqPdfutJJ6VgXg5X1uiUj5nxFhkxXD5xqkVsR8BjnSLfFo2dl47LMWckgbk0wPcz8G4auisRs1eJR6WUq3wQIahAAGgw3NzQxODI0MzMzOTgiDAZtzmvyfXjgood2myq8BCPCIFPXgnw4fr8EFIqRxndOhGgvZqkyuCs0S088ZlBLbzbWxoDQWH1FYxVAaW3J0x/XSf8dzwMN6+opioA4K50rYL99/wXsH9brKYJKr1wA7vUqwTuVznIphB9vJiSLCif7I37vuxxpMAfalwKuZHKLqABGM4KIdR3f+G4lRol3mHm+H+bqnWpFptHxwYtfNvGWBl2vRvdy7N4U8eA3N7Kao8XbQBFzvrbYxXol6bWU998XejKIdnDIes2H7JwVSBQWc6cwpOXkFUjRl903vVZbGJPtMzULhZoTcjSWAWg+hvPBgORRN7NJRjYAgzYELXbMHVORAtrX8exDBZywVf2Dhj0YjZ3hec3Fymr+z9cuLuz8iO8pMwPavsRcte5K8jWtOmQA5F8AsiRrMIas0xPSoVhymBENC4m5QVef13iOw9pyGRGQ3dwqfnHu3xThcqEA9ExFbtoqiuD2nVzepXv42L2SB5ZsVwCT9XGqJ3CjDQhmMlYONC06g0vH2w+HPPuFt5ddkbWkCAkanSrDn6v0me5Pz1MXV75M9cqQfdp4WnTPPBgUccslSJ5eXxSuxQWnSBRqINRIolBlH6JIcft3XvKXUKqyRwyM9NZp8pNfhiyzg5ps0VWe1aI3r+dD6vVa6S5Ba8NOAjz2HGOLdeq8ZfH0PP7rrvqUQB1Mdn4j6bOj4btwbea26HaHI79cGjN8zGck4+rlkORG3bsAwZzFV4YQJ0zZfPF4QD+mtpMIqb2/1K+vuEjBvlVOMOeh58IF",
28+
"accessKeyId": "ASIAIZ7SIJVXEGQSJGDA"
29+
}
30+
}
31+
}
32+
}

app/templates/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var main = require("./target/main");
2+
3+
exports.handler = main.app.core.handler;

app/templates/package.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "<%= organization %>-<%= service %>",
3+
"version": "0.0.1",
4+
"description": "TODO",
5+
"main": "index.js",
6+
"scripts": {},
7+
"author": "<%= author %>",
8+
"license": "MIT",
9+
"dependencies": {
10+
"atob": "^2.0.3",
11+
"aws-sdk": "^2.6.4",
12+
"btoa": "^1.1.2",
13+
"dotenv": "^2.0.0",
14+
"dynamodb-marshaler": "^2.0.0",
15+
"fstream": "^1.0.10",
16+
"js-yaml": "^3.6.1",
17+
"jsonwebtoken": "^7.1.9",
18+
"path": "^0.12.7",
19+
"request": "^2.75.0",
20+
"unzipper": "^0.7.2"
21+
}
22+
}

app/templates/src/app/core.cljs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
(ns app.core
2+
(:require [backend-shared.service.index :as service]
3+
[cljs.core.async :as async]
4+
[shared.protocols.actionable :as ac]
5+
[shared.protocols.convertible :as cv]
6+
[shared.protocols.queryable :as qa]
7+
[shared.protocols.loggable :as log])
8+
(:require-macros [cljs.core.async.macros :refer [go]]))
9+
10+
(def adapters {:code-pipeline {}
11+
:bucket {:bucket-names {:files "test-909"}}})
12+
13+
(defn ^:export handler [& args]
14+
(go
15+
(let [{:keys [event] :as service} (apply service/create adapters args)
16+
payload (cv/to-payload event)
17+
query (cv/to-query event)
18+
{:keys [found error]} (async/<! (qa/fetch service query))
19+
artifacts (when found (async/<! (ac/perform service [:decode found])))
20+
res1 (when artifacts (async/<! (ac/perform service [:put artifacts])))
21+
res2 {} #_(async/<! (ac/perform service [:put payload]))]
22+
(when-not found (log/log "RESTART PIPELINE"))
23+
(service/done service res1))))
24+
25+
(defn -main [] identity)
26+
(set! *main-cli-fn* -main)

app/templates/src/app/mappings.cljs

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
(ns app.mappings
2+
(:require [backend-shared.service.index :refer [perform fetch]]
3+
[shared.protocols.actionable :as ac]
4+
[cljs.core.async :as async]
5+
[shared.protocols.queryable :as qa]
6+
[cljs.nodejs :as node]
7+
[shared.protocols.loggable :as log]
8+
[shared.protocols.convertible :as cv])
9+
(:require-macros [cljs.core.async.macros :refer [go]]))
10+
11+
(def fstream (node/require "fstream"))
12+
(def unzip (node/require "unzipper"))
13+
(def fs (node/require "fs"))
14+
15+
(defmethod fetch :artifacts [{:keys [bucket]} {:keys [input-queries credentials] :as query}]
16+
(go
17+
(let [{:keys [found errors]} (async/<! (qa/fetch bucket credentials input-queries))]
18+
{:found (when-not (empty? found) (first found))
19+
:error (when-not (empty? errors) errors)})))
20+
21+
(defmethod perform [:put :pipeline-job] [{:keys [code-pipeline]} action]
22+
(ac/perform code-pipeline action))
23+
24+
(defmethod perform [:decode :errors] [{:keys [code-pipeline]} [_ payload]]
25+
{:error payload})
26+
27+
(defmethod perform [:decode :zipfile] [{:keys [code-pipeline]} [_ payload :as action]]
28+
(let [c (async/chan)
29+
output-path {:path "/tmp/extracted/"}
30+
read-stream (.Reader fstream (:filename payload))
31+
write-stream (.Extract unzip (clj->js output-path))]
32+
(.on write-stream "close" #(async/put! c output-path))
33+
(.pipe read-stream write-stream)
34+
c))
35+
36+
(defn read-file [path]
37+
(let [c (async/chan)]
38+
(.readFile fs "extracted/buildspec.yml" #(async/put! c %2))
39+
c))
40+
41+
(defmethod perform [:put :file-path] [{:keys [bucket]} [_ payload :as action]]
42+
(go
43+
(let [key "buildspec.yml"
44+
payload (async/<! (read-file (str "/tmp/extracted/" key)))
45+
items [{:file-name key
46+
:content payload}]]
47+
(async/<! (ac/perform bucket [:put items])))))

app/templates/src/app/specs.cljs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
(ns app.specs
2+
(:require [cljs.spec :as spec]
3+
[shared.specs.action :as action :refer [action-spec]]))
4+
5+
(spec/def :offcourse/query (spec/or :artifacts :aws/build-artifacts))
6+
7+
(spec/def ::path string?)
8+
(spec/def ::file-path (spec/keys :req-un [::path]))
9+
(spec/def ::file-name string?)
10+
(spec/def ::content any?)
11+
(spec/def ::file (spec/keys :req-un [::file-name ::content]))
12+
13+
(defmethod action-spec :decode [_]
14+
(spec/tuple :offcourse/actions (spec/or :zipfile any?)))
15+
16+
(spec/def :offcourse/payload (spec/or :pipeline-job :aws/code-pipeline-job
17+
:file-path ::file-path
18+
:files (spec/coll-of ::file)))
19+
20+
(defmethod action-spec :put [_]
21+
(spec/tuple :offcourse/actions :offcourse/payload))

package.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "generator-offcourse-backend-service",
3+
"version": "0.1.0",
4+
"description": "",
5+
"files": [
6+
"app"
7+
],
8+
"keywords": [
9+
"yeoman-generator"
10+
],
11+
"dependencies": {
12+
"yeoman-generator": "^1.0.1"
13+
}
14+
}

0 commit comments

Comments
 (0)